简体   繁体   English

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

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

I am trying to create Paypal subscription through its Rest API using live client and secret.我正在尝试使用实时客户端和秘密通过其 Rest API 创建 Paypal 订阅。 The API returns success message. API 返回成功消息。 The GET subscription API returns the active subscription created, however I don't see any active subscription in my Paypal dashbaord. GET 订阅 API 返回创建的活动订阅,但是我在我的 Paypal 仪表板中没有看到任何活动订阅。 Paypal support says the subscription ID does not exist. Paypal 支持说订阅 ID 不存在。 Has anyone encountered such issue with Paypal API?有没有人遇到Paypal API这样的问题? I have attached API JSON response and snapshot herewith.我附上了 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"
    }
]

} }

获取有效订阅

First of all, everything in your question shows creating a plan.首先,您问题中的所有内容都表明正在制定计划。 A plan is not a subscription, it is the cycle details to be able to create a subscription.计划不是订阅,它是能够创建订阅的周期详细信息。

Secondly, creating a subscription still will not do anything unless a payer signs in to approve it.其次,除非付款人登录批准,否则创建订阅仍然不会执行任何操作。 For a payer to approve a subscription, use a PayPal button.对于批准订阅的付款人,请使用 PayPal 按钮。 This is detailed in the Subscriptions Integration Guide .这在订阅集成指南中有详细说明。

Note that the createSubscription function can create a subscription for approval itself, by passing it an object with a plan_id (and optionally a plan object to override some part of that plan_id).请注意, createSubscription function 可以通过将带有 plan_id 的plan_id传递给它(以及可选的plan object 以覆盖该 plan_id 的某些部分)来创建订阅以供批准。 This is the most simple method.这是最简单的方法。

Alternatively, the subscription can be created via API, at a route on your server which that function will fetch when the button is clicked.或者,可以通过 API 创建订阅,在您服务器上的路由中,单击按钮时 function 将获取该路由。 Something like:就像是:

  <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