我试图通过PatchRequest向创建的付款添加第二个项目,但似乎无法弄明白。
这是我的代码:
$patch = new \PayPal\Api\Patch();
$patch->setOp('add');
$patch->setPath('/transactions/0/item_list/items/1');
$json = '
{
"description":"Testartikel",
"price":"50.00",
"currency":"EUR",
"quantity":1
}';
$data = json_decode($json);
$patch->setValue($data);
$patches[] = $patch;
$patchRequest = new \PayPal\Api\PatchRequest();
$patchRequest->setPatches($patches);
$payment->update($patchRequest, $apiContext);
所以请求看起来像这样:
[{"op":"add","path":"/transactions/0/item_list/items/1","value":{"description":"Testartikel","price":"50.00","currency":"EUR","quantity":1}}]
我收到此错误:
{"name":"MALFORMED_REQUEST","message":"MALFORMED_REQUEST","information_link":"https://developer.paypal.com/docs/api/#MALFORMED_REQUEST","debug_id":"682441321797"}
我想路径/transactions/0/item_list/items/1
可能是错误的,但我无法弄清楚哪一个是正确的。我已尝试使用相同的结果/transactions/0/item_list
和/transactions/0/item_list/items
。
非常感谢任何帮助。
答案 0 :(得分:-1)
我有同样的错误信息。
问题是围绕JSON的缺少方括号。
正确的路径是' / transactions / 0 / item_list / items'。
$json = '
[
{
"description":"Testartikel",
"price":"50.00",
"currency":"EUR",
"quantity":1
}
]';
$patchAdd = new \PayPal\Api\Patch();
$patchAdd->setOp('add')
->setPath('/transactions/0/item_list/items')
->setValue(json_decode($json));
$patchRequest = new \PayPal\Api\PatchRequest();
$patchRequest->setPatches(array($patchAdd);
这对我有用。