繁体   English   中英

nodeJS Paypal REST API 修改计划给出损坏但工作的链接

[英]nodeJS Paypal REST API to revise plan give broken but working link

我正在尝试将 Paypal 集成到我在 NodeJS 中的应用程序中。 我正在使用 REST API 因为官方的 npm 数据包已被弃用。 假设我的产品有两个计划planAplanB ,这对于像订阅这样的定期付款是必需的。 假设客户订阅了 planA,费用为 10 美元。 一段时间后,他想改用 20 美元的 planB 来解锁平台中的优质内容。

我发现 API: POST/v1/billing/subscriptions/{id}/revise应该能够发送planID planB以切换到它。 您还可以发送effective_time字段来指定更改何时生效。 调用此 API 后,Paypal 回复 6 个链接,我使用第一个( approve )将客户重定向到 Paypal 域以确认它的计划。 用户登录后,确认并单击“接受并订阅”新计划,页面总是给我以下错误: Things don't appear to be working at the moment. Please try again later. Things don't appear to be working at the moment. Please try again later. ,尽管计划更改顺利(我可以通过仪表板进行验证)。

我想知道我能做些什么来避免这个错误。 我想澄清一下,在设置中,通过仪表板,在Account settings -> Website payments payment -> Website preferences下,我暂时将Block non-encrypted website payment选项设置为Off 谢谢大家!

设置“阻止非加密网站支付”与此问题无关,不会产生任何影响。 它仅适用于传统的纯 HTML 付款,您不必担心。


您描述的问题似乎是 PayPal 站点的问题,并且可能仅在沙盒模式或某些浏览器/cookie 中发生。 您可以根据需要进行测试,并在需要时联系 PayPal 的支持人员。

也可以使用 JS SDK 进行修改,而不是重定向。 对于仅客户端集成(无 API),可以使用actions.subscription.revise来完成。 SDK 参考中搜索该文本。

要将 JS SDK 与您正在使用的 API 调用结合起来,请让您的按钮代码从您的服务器获取修改后的订阅 ID。 这是一个创建示例,您可以将其调整为修改,因为它本质上是相同的(您可能只是使用/revise端点 /path/on/your/server)

  <script src="https://www.paypal.com/sdk/js?client-id=..........&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/docs/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