【问题标题】:PayPal Rest API. Why Agreement Id IS not Set贝宝休息 API。为什么未设置协议 ID
【发布时间】:2015-04-06 22:19:07
【问题描述】:

我正在使用 PayPal REST API 来创建协议。我想知道为什么在创建计费协议时响应中没有 id。 return_url 中仅存在执行令牌。

创建付款时会返回一个 ID。

请求

POST https://api.sandbox.paypal.com/v1/payments/billing-agreements HTTP/1.1 Content-Type: application/json User-Agent: PayPalSDK/rest-sdk-dotnet 0.11.0 (core=1.6.0;lang=DOTNET;v=4.5;clr=4.0.30319.34014;bit=64;os=Microsoft Windows NT 6.2.9200.0) Authorization: Bearer A015NObhWZJY-ZZHdSmMvYL7GFA6A-pY7pK4zV1J8wysWJE PayPal-Request-Id: 98a56a18-2306-4301-a366-e53a5db54536 Host: api.sandbox.paypal.com Content-Length: 246 Expect: 100-continue

{"name":"plan \"PN123\" subscription","description":"plan \"PN123\" subscription with payments every 12 months.","start_date":"2015-02-06T16:58:56z","payer":{"payment_method":"paypal"},"plan":{"id":"P-2Y404528U1543832BL7HBW6A"}}

漂亮的请求 Json

{
  "name":"A plan \"PN123\" subscription",
  "description":"plan \"PN123\" subscription with payments every 12 months.",
  "start_date":"2015-02-06T16:58:56z",
  "payer":{
     "payment_method":"paypal"
  },
  "plan":{
     "id":"P-2Y404528U1543832BL7HBW6A"
  }
}

回应

HTTP/1.1 201 Created Server: Apache-Coyote/1.1 PROXY_SERVER_INFO: host=slcsbplatformapiserv3001.slc.paypal.com;threadId=374466 Paypal-Debug-Id: 739b28e849ee7 SERVER_INFO: paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=501225&TopLevelTxnStartTime=14b5fce3a78&Host=slcsbpaymentsplatformserv3001.slc.paypal.com&pid=22725 Content-Language: * Date: Fri, 06 Feb 2015 16:52:05 GMT Content-Type: application/json Content-Length: 1174

来自响应的漂亮 json

{
  "name":"plan \"PN123\" subscription",
  "description":"plan \"PN123\" subscription with payments every 12 months.",
  "plan":{
     "id":"P-2Y404528U1543832BL7HBW6A",
     "state":"ACTIVE",
     "name":"PN123",
     "description":"plan \"PN123\" subscription",
     "type":"INFINITE",
     "payment_definitions":[
        {
           "id":"PD-8RD12495MY6350633L7HBW6I",
           "name":"Regular Payments",
           "type":"REGULAR",
           "frequency":"Month",
           "amount":{
              "currency":"USD",
              "value":"20"
           },
           "cycles":"0",
           "charge_models":[

           ],
           "frequency_interval":"12"
        }
     ],
     "merchant_preferences":{
        "setup_fee":{
           "currency":"USD",
           "value":"0"
        },
        "max_fail_attempts":"0",
        "return_url":"http://example.com/Subscription/Renew.aspx?result=ApproveAgreement",
        "cancel_url":"http://example.com/Subscription/Renew.aspx?result=CancelAgreement",
        "auto_bill_amount":"NO",
        "initial_fail_amount_action":"CONTINUE"
     }
  },
  "links":[
     {
        "href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-4R936998H4630535M",
        "rel":"approval_url",
        "method":"REDIRECT"
     },
     {
        "href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-4R936998H4630535M/agreement-execute",
        "rel":"execute",
        "method":"POST"
     }
  ],
  "start_date":"2015-02-06T16:58:56z"
}

【问题讨论】:

    标签: api rest paypal


    【解决方案1】:

    付款执行后,您将在 paypal 上作为您的付款类型获得 ID。

    1. 创建Billing Agreement。您将获得一个 EC-Token 和 URL
    2. Success, Execute Billing Agreement

    您可以使用 PayPal-PHP-SDK 运行samples attached,在自己实现代码之前进行尝试。此外,大部分示例代码都可以复制粘贴以轻松上手。

    以下是示例的屏幕截图: 1. 创建协议。使用暗黑线指向的 URL 2. 已执行的协议。如您所见,它具有协议 ID。

    【讨论】:

    • 你是对的。但是创建和执行协议的场景与我所看到的付款不同。当客户批准付款时,其 ID 可以作为查询字符串参数在返回 url 中找到,因此可以在执行之前检索付款信息。
    • 同意。这是我们之前注意到的,并相应地向内部团队提出。他们正试图使其与付款的规范保持一致。但是,与此同时,这也肯定会起作用。当它可用时,我会更新这个线程。
    • 我仍然看不到如何将协议中的用户与成功执行协议的用户联系起来:(
    • @DiegoPamio 我知道这已经晚了,但以防其他人读到它。您想使用 ec-token。它在您创建协议时生成,并在协议批准后被发送回服务器,以便您可以链接两者。
    猜你喜欢
    • 2014-02-15
    • 2016-04-25
    • 2012-05-04
    • 2013-10-18
    • 2017-02-01
    • 2018-10-05
    • 2014-11-02
    • 2015-05-28
    • 2015-10-16
    相关资源
    最近更新 更多