我正在尝试调用ExpressCheckout并执行Instant Update API,但无论我做什么,它似乎都会返回无效的运送总错误。我知道在实时运行时你需要使用SSL,但是我试图对沙盒进行测试并仍然遇到这些错误。
我的简单HTML测试页:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Express Checkout with Callback API - PayPal</title>
</head>
<body>
<h1 align="center"> Express Checkout with Callback API </h1>
<h3 align="center"> PayPal </h3>
<form method=post action=https://api-3t.sandbox.paypal.com/nvp>
<input type=hidden name=USER value=xxxxxxxxxxx>
<input type=hidden name=PWD value=xxxxxxxx>
<input type=hidden name=SIGNATURE value=xxxxxxxxxxxxxxxxxxxxxxx>
<input type=hidden name=VERSION value=63.0>
<input type=hidden name=PAYMENTREQUEST_0_PAYMENTACTION value=Sale>
<input name=PAYMENTREQUEST_0_AMT value=19.95>
<input type=hidden name=RETURNURL value=https://www.YourReturnURL.com>
<input type=hidden name=CANCELURL value=https://www.YourCancelURL.com>
<input type=hidden name=MAXAMT value=100.00>
<input type=hidden name=callback value=....../callback.php>
<input type=hidden name= callbacktimeout value=5>
<input type=hidden name= l_shippingoptionisdefault0 value=true>
<input type=hidden name= l_shippingoptionname0 value=Ground>
<input type=hidden name= l_shippingoptionlabel0 value=5 Days>
<input type=hidden name= l_shippingoptionamount0 value=10.00>
<input type=hidden name= shippingamt value=10.00>
<input type=submit name=METHOD value=SetExpressCheckout>
</form>
</body>
</html>
我的callback.php脚本托管在我的服务器上:
<?php
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req = "&$key=$value";
}
//Build string
$method = $_POST['METHOD'];
$version = $_POST['CALLBACKVERSION'];
$token = $_POST['TOKEN'];
$currencycode = $_POST['CURRENCYCODE'];
$localecode = $_POST['LOCALECODE'];
$street = $_POST['SHIPTOSTREET'];
$street2 = $_POST['SHIPTOSTREET2'];
$city = $_POST['SHIPTOCITY'];
$state = $_POST['SHIPTOSTATE'];
$country = $_POST['SHIPTOCOUNTRY'];
$zip = $_POST['SHIPTOZIP'];
//If PayPal acocunt has US address
if ($country=="US") {
echo "METHOD=CallbackResponse&L_SHIPPINGOPTIONNAME0=Ground&L_SHIPPINGOPTIONLABEL0=5 to 7 Days&L_SHIPPINGOPTIONAMOUNT0=10.00&L_SHIPPINGOPTIONISDEFAULT0=true";
}
//If PayPal account has a non-US address
else {
echo "METHOD=CallbackResponse&L_SHIPPINGOPTIONNAME0=Next Day Air&L_SHIPPINGOPTIONLABEL0=7 to 14 Days&L_SHIPPINGOPTIONAMOUNT0=20.00&L_SHIPPINGOPTIONISDEFAULT0=true";
}
?>
我已从代码中删除了一些敏感信息,并将所有运费值更改了100次,所以如果有一些愚蠢的错误,请原谅。感谢任何帮助,谢谢!
答案 0 :(得分:0)
根据Paypal's Developer Guide(第58页)声称需要CURRENCYCODE
。虽然在我的测试中似乎并非如此。但它值得一试。
此外,对您的值进行网址编码也可能会这样做...因此请将空格设为+ s。
我用它作为工作测试响应:
L_INSURANCEAMOUNT1=1.35&L_SHIPPINGOPTIONISDEFAULT2=false&L_SHIPPINGOPTIONNAME0=1%3A+&L_SHIPPINGOPTIONNAME1=2%3A+&L_SHIPPINGOPTIONLABEL0=asdf&L_SHIPPINGOPTIONLABEL1=UPS+Express+2+Days&OFFERINSURANCEOPTION=true&CURRENCYCODE=USD&L_INSURANCEAMOUNT2=1.28&L_TAXAMT0=2.20&L_SHIPPINGOPTIONAMOUNT1=10.00&L_SHIPPINGOPTIONAMOUNT0=20.00&L_SHIPPINGOPTIONAMOUNT2=9.99&L_SHIPPINGOPTIONISDEFAULT1=true&L_SHIPPINGOPTIONISDEFAULT0=false&L_SHIPPINGOPTIONNAME2=3%3A+&L_SHIPPINGOPTIONLABEL2=UPS+Ground+2+to+7+Days&L_TAXAMT1=2.00&METHOD=CallbackResponse&L_INSURANCEAMOUNT0=1.35&L_TAXAMT2=1.99