Php 将项目数组发送到paypal收银台
如何将我已经存储在集合中的项目发送到paypal收银台,我已经集成了整个过程,但目前它仅适用于paypal提供的测试项目,我还无法集成我自己的项目集合 我的购物车项目 我的物品如下:Php 将项目数组发送到paypal收银台,php,laravel,paypal,Php,Laravel,Paypal,如何将我已经存储在集合中的项目发送到paypal收银台,我已经集成了整个过程,但目前它仅适用于paypal提供的测试项目,我还无法集成我自己的项目集合 我的购物车项目 我的物品如下: $items = Session::get('items'); //Json $decoded_items= json_decode($items,true); //decoded to array 如果我返回$items我拥有整个收藏: { "Items":[ {
$items = Session::get('items'); //Json
$decoded_items= json_decode($items,true); //decoded to array
如果我返回$items
我拥有整个收藏:
{
"Items":[
{
"id":1,
"inventoryID":1,
"title":"Product 1",
"quantity":1,
"unit_price":20,
"image":"img.png"
},
{
"id":2,
"inventoryID":1,
"title":"Product2",
"quantity":1,
"unit_price":25,
"image":"img.png"
}
],
"items_count":2,
"products_count":2
}
但是如果我返回$decoded_items['items']代码>我刚得到数组:
[
{
"id":1,
"inventoryID":1,
"title":"Product 1",
"quantity":1,
"unit_price":20,
"image":"img.png"
},
{
"id":2,
"inventoryID":1,
"title":"Product2",
"quantity":1,
"unit_price":25,
"image":"img.png"
}
]
贝宝示例
paypal示例运行良好,如下所示:
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity(1)
->setSku("123123") // Similar to `item_number` in Classic API
->setPrice(7.5);
$item2 = new Item();
$item2->setName('Granola bars')
->setCurrency('USD')
->setQuantity(5)
->setSku("321321") // Similar to `item_number` in Classic API
->setPrice(2);
$itemList = new ItemList();
$itemList->setItems(array($item1,$item2));
我试过了
考虑到这个例子以及我获取物品的方式,我尝试了:
$items = Session::get('items');
$decoded_items= json_decode($items,true);
foreach($decoded_items['Items'] as $element) {
$name=$element['title'];
$quantity=$element['quantity'];
$sku= $element['id'];
$price=$element['unit_price'];
$item = new Item();
$item-> setName($name)
->setCurrency('USD')
->setQuantity($quantity)
->setSku($sku) // Similar to `item_number` in Classic API
->setPrice($price);
$results[] = $item;
}
$itemList = new ItemList();
$itemList->setItems($results);
但是把我的东西送到paypal支付窗口永远不会打开
提前感谢:)上面的JSON转储是复制和粘贴,还是您手动键入的?我这样问是因为在这两种情况下,“Product2”
后面都缺少一个逗号。谢谢你,只要修复它,结构是复制的,但名称是手工写的json\u decode
在我这方面可以很好地使用上面的代码更正json。我第一眼看到的另一件事是,在示例中,当它似乎接受字符串时,您正在将一个整数传递给->setSku()
。您可以尝试使用(字符串)$sku
强制转换它。除此之外,您还需要提供更多的代码。关于我的代码,您认为我还需要提供什么?您提到了语法错误。这实际上是在阻止任何东西运行,还是只是一个IDE警告?在定义PayPal数据后,您能否成功转储dd($results)
,或者在到达之前代码是否已停止?您的日志中有错误吗?如果这里没有问题,那么听起来问题可能在于您向PayPal提供数据的方式,而您在当前帖子中没有提供这些数据,即更多代码。