繁体   English   中英

我调用了 Paypal 订阅 API,它返回了成功消息,但在 Paypal 仪表板中看不到任何活动订阅

[英]I called Paypal subscription API which returns success message but don't see any active subscription in the Paypal dashboard

我正在尝试使用实时客户端和秘密通过其 Rest API 创建 Paypal 订阅。 API 返回成功消息。 GET 订阅 API 返回创建的活动订阅,但是我在我的 Paypal 仪表板中没有看到任何活动订阅。 Paypal 支持说订阅 ID 不存在。 有没有人遇到Paypal API这样的问题? 我附上了 API JSON 响应和快照。

{
"plans": [
    {
        "id": "P-4UJ45561KJ704964LMJ2QDZQ",
        "product_id": "PROD-4EX86934CR7151923",
        "name": "Certified business economist IHK | VO 2022",
        "status": "ACTIVE",
        "description": "The business economist IHK is divided into the following five subjects with the new examination regulations 2022",
        "usage_type": "LICENSED",
        "create_time": "2022-05-06T11:09:26Z",
        "links": [
            {
                "href": "https://api.paypal.com/v1/billing/plans/P-4UJ45561KJ704964LMJ2QDZQ",
                "rel": "self",
                "method": "GET",
                "encType": "application/json"
            }
        ]
    }
],
"total_items": 1,
"total_pages": 1,
"links": [
    {
        "href": "https://api.paypal.com/v1/billing/plans?product_id=PROD-4EX86934CR7151923&page_size=2&page=1",
        "rel": "self",
        "method": "GET",
        "encType": "application/json"
    }
]

}

获取有效订阅

首先,您问题中的所有内容都表明正在制定计划。 计划不是订阅,它是能够创建订阅的周期详细信息。

其次,除非付款人登录批准,否则创建订阅仍然不会执行任何操作。 对于批准订阅的付款人,请使用 PayPal 按钮。 这在订阅集成指南中有详细说明。

请注意, createSubscription function 可以通过将带有 plan_id 的plan_id传递给它(以及可选的plan object 以覆盖该 plan_id 的某些部分)来创建订阅以供批准。 这是最简单的方法。

或者,可以通过 API 创建订阅,在您服务器上的路由中,单击按钮时 function 将获取该路由。 就像是:

  <script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID_GOES_HERE&amp;vault=true&amp;intent=subscription"></script>

  <div id="paypal-button-container"></div>

  <script>
    paypal.Buttons({
      style: {
          label:'subscribe'  //Optional text in button
      },
      createSubscription: function(data, actions) {
          return fetch('/path/on/your/server/paypal/subscription/create/', {
              method: 'post'
          }).then(function(res) {
              return res.json();
          }).then(function(serverData) {
              console.log(serverData);
              return serverData.id;
          });
      },

      onApprove: function(data, actions) {
      /*  Optional: At this point, notify your server of the activated subscription...

          fetch('/path/on/your/server/paypal/subscription/activated/' + data.subscriptionID , {
              method: 'post'
          }).then(function(res) {
              return res.json();
          }).then(function(serverData) {
              //
          });
      */
          //You could additionally subscribe to a webhook for the BILLING.SUBSCRIPTION.ACTIVATED event (just in case), as well as other future subscription events
          //Ref: https://developer.paypal.com/api-basics/notifications/webhooks/event-names/#subscriptions

          // Show a message to the buyer, or redirect to a success page
          alert('You successfully subscribed! ' + data.subscriptionID);
      }

    }).render('#paypal-button-container');
  </script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM