0
我有一些代碼以建立Paypal進行請求的URL,但在某些項目它返回下列錯誤(響應被轉換成一個陣列中後):貝寶setExpressCheckout NVP錯誤
Array
(
[TIMESTAMP] => 2012-08-15T14:23:10Z
[CORRELATIONID] => XXXXXXXXXXXXXXXXX
[ACK] => Failure
[VERSION] => 87.0
[BUILD] => 3435050
[L_ERRORCODE0] => 10413
[L_SHORTMESSAGE0] => Transaction refused because of an invalid argument. See additional error messages for details.
[L_LONGMESSAGE0] => The totals of the cart item amounts do not match order amounts.
[L_SEVERITYCODE0] => Error
)
這裏是我通過cURL發送的網址:
https://api.sandbox.paypal.com/nvp?
METHOD=setExpressCheckout
&VERSION=87.0
&USER=test_user.mysite.co.uk
&PWD=1340704478&SIGNATURE=AxhCd62FkHm-KuS.WvqjUnQ.l8WyAuePJQjoYT0C5lGiwjpcVIJHURjI
&RETURNURL=http://www.mysite.co.uk/checkout/order/confirm
&CANCELURL=http://www.mysite.co.uk/checkout/order/error
&L_PAYMENTREQUEST_0_NAME0=Likit+Snaks+&L_PAYMENTREQUEST_0_NUMBER0=LIKIT-SNAKS
&L_PAYMENTREQUEST_0_DESC0=Flavour%3A+Apple+&+Cinnamon
&L_PAYMENTREQUEST_0_AMT0=2.08
&L_PAYMENTREQUEST_0_QTY0=1
&PAYMENTREQUEST_0_CURRENCYCODE=GBP
&PAYMENTREQUEST_0_ITEMAMT=2.08
&PAYMENTREQUEST_0_SHIPPINGAMT=3.65
&PAYMENTREQUEST_0_TAXAMT=0.52
&PAYMENTREQUEST_0_AMT=6.25
但是總和不會加起來嗎?
如果有幫助,這裏是它建立鏈接的PHP:
private function buildRequestItemsURL()
{
$this->db->select("bi_id, prod_id, bi_psc_id, prod_title, prod_sku, bi_price, bi_qty, basket_delivery");
$query = $this->db->get_where("basket_views", array("basket_session" => session_id()));
$i = 0;
$total = 0;
$url = "";
foreach($query->result() as $row)
{
$row->options = "";
if($i==0)
{
if(number_format($row->basket_delivery, 2) == 0.00)
{
header("location: http://www.mysite.co.uk/checkout/basket");
}
else
{
$delivery = $row->basket_delivery;
}
}
$this->db->select("opt_1_name AS Colour, opt_2_name AS Size, opt_3_name AS Flavour, opt_4_name AS Material, opt_5_name AS Style");
$this->db->where("psc_id", $row->bi_psc_id);
$query = $this->db->get("product_stock_view bio", 1);
foreach($query->first_row() as $key => $value)
{
$row->options .= (!is_null($value)) ? "{$key}: {$value}, " : "";
}
$row->bi_price = number_format($row->bi_price * 0.8, 2);
$row->options = substr($row->options, 0, -2);
$url .= "&L_PAYMENTREQUEST_0_NAME{$i}={$row->prod_title}&L_PAYMENTREQUEST_0_NUMBER{$i}={$row->prod_sku}&L_PAYMENTREQUEST_0_DESC{$i}={$row->options}&L_PAYMENTREQUEST_0_AMT{$i}={$row->bi_price}&L_PAYMENTREQUEST_0_QTY{$i}={$row->bi_qty}";
$total += (($row->bi_price)*$row->bi_qty);
++$i;
}
$itemTotal = $total;
$total += $delivery;
$total += ($itemTotal * 0.25);
$total = number_format($total, 2);
$itemTotal = number_format($itemTotal, 2);
$vat = $total - $itemTotal - $delivery;
$vat = number_format($vat, 2);
$url .= "&PAYMENTREQUEST_0_CURRENCYCODE=GBP&PAYMENTREQUEST_0_ITEMAMT={$itemTotal}&PAYMENTREQUEST_0_SHIPPINGAMT={$delivery}&PAYMENTREQUEST_0_TAXAMT={$vat}&PAYMENTREQUEST_0_AMT=".$total;
$url = urlencode($url);
$url = str_replace("%3F", "?", $url);
$url = str_replace("%26", "&", $url);
$url = str_replace("%3D", "=", $url);
return $url;
}
$url = "?METHOD=setExpressCheckout&VERSION=87.0&USER=user.mysite.co.uk&PWD=1340704478&SIGNATURE=AxhCd62FkHm-KuS.WvqjUnQ.l8WyAuePJQjoYT0C5lGiwjpcVIJHURjI&RETURNURL=http://www.mysite.co.uk/checkout/order/confirm&CANCELURL=http://www.mysite.co.uk/checkout/order/error";
$url .= $this->buildRequestItemsURL();
$url = "https://api.sandbox.paypal.com/nvp".$url;