[英]Paypal Payments REST API Updating Payment to Add Item
I'm trying to add a second Item to a created payment via a PatchRequest but can't seem to figure it out. 我正在尝试通过PatchRequest将第二个项目添加到创建的付款中,但似乎无法弄清楚。
Here is my code: 这是我的代码:
$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);
So the request looks like this: 因此,请求如下所示:
[{"op":"add","path":"/transactions/0/item_list/items/1","value":{"description":"Testartikel","price":"50.00","currency":"EUR","quantity":1}}]
I get this error: 我收到此错误:
{"name":"MALFORMED_REQUEST","message":"MALFORMED_REQUEST","information_link":"https://developer.paypal.com/docs/api/#MALFORMED_REQUEST","debug_id":"682441321797"}
I guess the path /transactions/0/item_list/items/1
might be wrong but i couldn't figure out what would be the correct one. 我猜路径
/transactions/0/item_list/items/1
可能是错误的,但我不知道什么是正确的。 I already tried /transactions/0/item_list
and /transactions/0/item_list/items
with the same result. 我已经尝试过
/transactions/0/item_list
和/transactions/0/item_list/items
具有相同的结果。
Any help would be very much appreciated. 任何帮助将不胜感激。
I had the same Error Message. 我有同样的错误信息。
The Problem were the missing square brackets round the JSON. 问题是JSON周围缺少方括号。
The right path is '/transactions/0/item_list/items'. 正确的路径是“ / 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);
This worked for me. 这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.