簡體   English   中英

使用PayPal REST API的多個項目

[英]Multiple items with PayPal REST API

我有一個動態的訂單/購物車,它通過Ajax將Json發送到PHP,然后通過PayPal rest api進行處理。 用戶可以一次購買多個產品。

我基本上克隆了這個示例: http : //paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/CreatePaymentUsingPayPal.html,並且它可以處理硬編碼的項目/變量。

一些PHP:

$data = json_decode(file_get_contents('php://input'), true);

$items = array();
$arr_length = count($data);
for ($i=0;$i<$arr_length;$i++) {
   $item[$i] = new Item();
   $item[$i]->setName($data[$i]['productName'])
                 ->setCurrency($data[$i]['currency'])
                 ->setQuantity($data[$i]['quantity'])
                 ->setPrice($data[$i]['price'])
                 ->setSku(uniqid());

    $items[] = $item[$i];
}

$itemList = new ItemList();
$itemList->setItems($items);

json像這樣傳遞:

$.ajax({
            url: "process.php",
            type: 'POST',
            data: jsonData,
            success: function(data){
              // location = data;
              console.log(data);
        },
        error:function(){
            $("#status").html('There is error while submit');
        }
        });

這是var_dump($ items);的結果。

<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>\vendor\paypal\rest-api-sdk-php\lib\PayPal\Common\PayPalResourceModel.php</b> on line <b>45</b><br />
array(3) {
  [0]=>
  object(PayPal\Api\Item)#8 (1) {
    ["_propMap":"PayPal\Common\PayPalModel":private]=>
    array(5) {
      ["name"]=>
      string(15) "Product1"
      ["currency"]=>
      string(3) "EUR"
      ["quantity"]=>
      int(1)
      ["price"]=>
      string(2) "99"
      ["sku"]=>
      string(13) "555c79be1c489"
    }
  }
  [1]=>
  object(PayPal\Api\Item)#9 (1) {
    ["_propMap":"PayPal\Common\PayPalModel":private]=>
    array(5) {
      ["name"]=>
      string(15) "Product2"
      ["currency"]=>
      string(3) "EUR"
      ["quantity"]=>
      string(2) "21"
      ["price"]=>
      string(4) "2079"
      ["sku"]=>
      string(13) "555c79be1c4b3"
    }
  }
  [2]=>
  object(PayPal\Api\Item)#10 (1) {
    ["_propMap":"PayPal\Common\PayPalModel":private]=>
    array(5) {
      ["name"]=>
      string(15) "Product3"
      ["currency"]=>
      string(3) "EUR"
      ["quantity"]=>
      int(1)
      ["price"]=>
      string(2) "99"
      ["sku"]=>
      string(13) "555c79be1c4d2"
    }
  }
}

不知道這是什么問題。 當我轉發實際的$ approvalUrl = $ payment-> getApprovalLink()時,我進入了重定向循環。

在第45行的\\ vendor \\ paypal \\ rest-api-sdk-php \\ lib \\ PayPal \\ Common \\ PayPalResourceModel.php中為foreach()提供了無效參數

當然不是正確的錯誤消息。

錯誤已在結帳表單的javascript部分中。 小計價格不正確,最終在PayPal端未正確匯總。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM