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;