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