将多个项目发送到paypal rest api的正确方法是什么?我已经阅读了文档和示例,据我所知:
申报交易
-
添加交易明细
声明New ItemList
循环订单
-
为每个订单声明一个新项目
-
添加项目详细信息
结束循环
将项添加到ItemList
将ItemList添加到Transaction
添加到交易
这是我一直在玩的代码,但是我得到了通常的paypal重定向错误,这是付款时出现错误时的标准错误 .
foreach ($orders as $unitcost)
{
$totalamount = $totalamount + ($unitcost['price'] * $unitcost['quantity']);
}
$transaction = new Transaction();
$transaction->setamount($totalamount);
$transaction->setDescription('Order from Shop');
$itemList = new ItemList();
foreach($orders as $unpaid)
{
$itemid = $unpaid['itemid'];
$stmt = $db->prepare("SELECT name FROM `items` WHERE id = ?");
$stmt->bindValue(1, $itemid);
$stmt->execute();
$name = $stmt->fetchColumn();
$items = new Item();
$items->setQuantity('1');
$items->setName($name);
$items->setPrice($unpaid['price']);
$items->setCurrency($currency);
}
$itemList->setItems(array($items));
$transaction->setItemList($itemList);
我可以使用amount和amountdetails类成功发送单个项目,它只是添加了我正在努力的多个项目 .
1 回答
得到它了!
;