dongyi2425 2016-09-13 14:08
浏览 36
已采纳

Paypal Payments REST API更新付款以添加项目

I'm trying to add a second Item to a created payment via a PatchRequest but can't seem to figure it out.

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. I already tried /transactions/0/item_list and /transactions/0/item_list/items with the same result.

Any help would be very much appreciated.

  • 写回答

1条回答 默认 最新

  • doukucai0099 2016-10-18 14:52
    关注

    I had the same Error Message.

    The Problem were the missing square brackets round the JSON.

    The right path is '/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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程