gpt4 book ai didi

php - Paypal setExpressCheckout nvp错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:20:06 31 4
gpt4 key购买 nike

我有一些代码可以为 Paypal 构建请求 URL,但在某些项目上它返回以下错误(在响应转换为数组后):

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 发送的 url:

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

但是总数不是相加吗?

如果有帮助,这里是构建 url 的 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;

最佳答案

问题出在产品描述中的 &。我更改了代码,使其将产品属性单独编码为 $url 字符串,从而删除了 &。这是新的 buildRequestItemsURL 函数代码:

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()));

foreach($query->result() as $row)
{

$row->prod_title = urlencode($row->prod_title);
$row->prod_sku = urlencode($row->prod_sku);

}

$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.crowstonstack.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)) ? urlencode("{$key}: {$value}, ") : "";

}
$row->bi_price = number_format($row->bi_price * 0.8, 2);
$row->options = substr($row->options, 0, -2);
$row->prod_title = str_replace("&", "%26", $row->prod_title);
$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;

return $url;

}

关于php - Paypal setExpressCheckout nvp错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11971516/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com