Paypal Rest API/更新计划无法更新安装费

Posted

技术标签:

【中文标题】Paypal Rest API/更新计划无法更新安装费【英文标题】:Paypal Rest API/Update Plan cannot update setup fee 【发布时间】:2021-07-19 08:10:02 【问题描述】:

我正在尝试使用其余 API 来更新计费计划的设置费用。该计划处于活动状态,但目前未使用。我为每个客户制定了每个服务的计划,因为每个客户的价值都不同,如果他们没有完成付款流程并在未来某个日期回来,价值可能会改变。

因此,如果他们在某个时间回来,我可能需要更新 setup_fee,根据 API 文档 setup_fee 可以通过 PATCH 更改。

所以这是变更请求之前的计划。


  "id": "P-7H193472JB2565539MCC4REI",
  "product_id": "PROD-3GK52832VM631252R",
  "name": "Access to Gig",
  "status": "ACTIVE",
  "description": "Access to Gig",
  "usage_type": "LICENSED",
  "billing_cycles": [
    
      "pricing_scheme": 
        "version": 6,
        "fixed_price": 
          "currency_code": "USD",
          "value": "9.44"
        ,
        "create_time": "2021-04-25T20:25:47Z",
        "update_time": "2021-04-25T20:25:47Z"
      ,
      "frequency": 
        "interval_unit": "MONTH",
        "interval_count": 1
      ,
      "tenure_type": "REGULAR",
      "sequence": 1,
      "total_cycles": 0
    
  ],
  "payment_preferences": 
    "service_type": "PREPAID",
    "auto_bill_outstanding": true,
    "setup_fee": 
      "currency_code": "USD",
      "value": "19.57"
    ,
    "setup_fee_failure_action": "CANCEL",
    "payment_failure_threshold": 1
  ,
  "quantity_supported": false,
  "create_time": "2021-04-25T19:52:49Z",
  "update_time": "2021-04-25T20:25:47Z",
  "links": [
    
      "href": "https://api.sandbox.paypal.com/v1/billing/plans/P-7H193472JB2565539MCC4REI",
      "rel": "self",
      "method": "GET",
      "encType": "application/json"
    ,
    
      "href": "https://api.sandbox.paypal.com/v1/billing/plans/P-7H193472JB2565539MCC4REI",
      "rel": "edit",
      "method": "PATCH",
      "encType": "application/json"
    ,
    
      "href": "https://api.sandbox.paypal.com/v1/billing/plans/P-7H193472JB2565539MCC4REI/deactivate",
      "rel": "self",
      "method": "POST",
      "encType": "application/json"
    
  ]

所以现在我想更新 setup_fee。

PATCH https://api.sandbox.paypal.com/v1/billing/plans/P-7H193472JB2565539MCC4REI
Authorization: Bearer <ACCESS TOKEN>
Content-Type: application/json


   "path" : "payment_preferences/setup_fee",
   "value" : 
      "setup_fee" : 
         "value" : "220.80",
         "currency_code" : "USD"
      
   ,
   "op" : "replace"

作为回应,我得到:


      'details' => [
                     
                       'location' => 'body',
                       'issue' => 'MALFORMED_REQUEST_JSON',
                       'field' => '/',
                       'description' => 'The request JSON is not well formed.'
                     
                   ],
      'links' => [],
      'message' => 'Request is not well-formed, syntactically incorrect, or violates schema.',
      'name' => 'INVALID_REQUEST',
      'debug_id' => '9444da3d14a00'
    ;

知道为什么会失败吗?我试图改变“值”条目的方式,就像实际的 setup_fee 一样,或者作为带有整个 setup_fee 结构的哈希。

感谢

【问题讨论】:

你可以试试"path" : "/payment_preferences/setup_fee", 我没有得到你的评论,这已经是你说的了?我是不是拼错了什么? 我也试过这个: "op" : "replace", "value" : "currency_code" : "USD", "value" : "220.80" , "path" : " payment_preferences/setup_fee" 哦,我看到前面的斜线,刚刚尝试了同样的问题。 TY 试试"path" : "/payment_preferences/setup_fee/value", "value":"220.80" 【参考方案1】:

原来我有多个问题,是的,第一个是我需要路径为“/payment_preferences/setup_fee”,我忘记了前导斜杠。

而且,我需要将 json 数据作为结构数组而不是结构。

[
  
    "op":"replace",
    "path":"/payment_preferences/setup_fee",
    "value":
    
        "currency_code":"USD",
        "value":"500.00"
    
  
]

谢谢大家。

【讨论】:

以上是关于Paypal Rest API/更新计划无法更新安装费的主要内容,如果未能解决你的问题,请参考以下文章

paypal rest api 更新付款的项目

PayPal Rest API:如何将卡添加或更新到计费协议 api?

PayPal Rest API - 使用更新的交易信息执行付款

PayPal REST API 更新计费协议

在 PayPal 计划更新 API 中使用补丁/更新间隔单位时出现 INVALID_PATCH_PATH 错误

Paypal REST API - 计费协议