我调用了 Paypal 订阅 API returns 成功消息,但在 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 returns 成功消息。 GET 订阅 API returns 已创建活动订阅,但是我在我的 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 按钮。这在 Subscriptions Integration Guide.

中有详细说明

请注意,createSubscription 函数可以通过向其传递一个带有 plan_id 的对象(以及可选的 plan 对象来覆盖其中的某些部分来创建订阅以供自己批准plan_id)。这是最简单的方法。

或者,订阅可以通过 API 在您服务器上的某个路径上创建,单击该按钮时该函数将获取该路径。类似于:

  <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>