贝宝订阅混乱

Paypal subscription confusion

我已经在一个项目上工作了 2 年多,我终于准备好发布了,但首先我必须整合一个基于订阅的支付选项,这样我才能真正从这个项目中赚到一些钱。近 2 个月以来,我一直在尝试整合贝宝订阅,但这是一个重大阻碍。此外,这导致我秃头。请帮忙!

我认为如果有一种概述说明来描述我需要遵循的明确流程以接受基于订阅的付款,那将非常有帮助。详细程度将包括每个步骤应该发生的位置;前端或后端(服务器),以及了解哪些数据流向何处所需的任何中间步骤。其次是智能按钮的实际代码,带有一些注释,指示代码处理的过程的哪一部分。也许这有很多要求,但我将不胜感激,我相信对于那些希望像我现在一样做的人来说,这是一个很好的资源。

目前,我的主要问题是当我在我的脚本中设置指向 paypal SDK 的 URL 以包含 &intent=authorize 时,我在错误消息中被告知我需要设置intent=capture,但是当我设置 intent=capture 时,我被告知我需要设置 intent=authorize。所以现在我对我应该做什么感到困惑;授权交易或捕获交易。在贝宝开发者网站上,贝宝技术支持向我提供了 link 2 种不同的指南,这些指南似乎相互矛盾 - 第一个 link 没有提到捕获或授权付款,第二个 link 确实如此。但是我不明白第二个 link 的上下文。第一个 link 是所有客户端,第二个 link 是客户端和服务器端。为什么需要这些 intent=ca[ture/authorize ?我认为一旦有人同意并完成注册订阅,并且我已经获取了他们的订阅 ID,我不需要做任何其他事情就可以在我的计划中按月设置接收资金,我会只需查询 paypal API 即可了解他们是否已在客户登录我的服务时付款。

我已经设置了一个沙盒帐户,并且创建了一个产品和一个计划。在客户登录后,我得到了带有我的计划 ID 的智能按钮。

如果我在 paypal SDK 脚本中设置 intent=capture URL,paypal window 打开,您 select 付款并同意,然后我在控制台中收到此错误:

env: "sandbox"
err: "Error: Use intent=authorize to use client-side authorize"
referer: "localhost:88"
timestamp: "1589939180937"
uid: "fad5852fa3_mde6ndq6mdu"

但是如果我设置 intent=authorize,我点击智能按钮,paypal window 出现并迅速消失,然后我得到这个错误:

buttonSessionID: "e3bf3c6c3d_mdi6mdi6mzq"
env: "sandbox"
err: "Uncaught Error: Expected intent from order api call to be authorize, got capture. Please ensure you are passing intent=capture to the sdk url"
referer: "www.sandbox.paypal.com"
sessionID: "fad5852fa3_mde6ndq6mdu"
timestamp: "1589940160835"

这是我的代码:

<!DOCTYPE html>

<head>
  <!-- Add meta tags for mobile and IE -->
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>

<body>
  <!-- Set up a container element for the button -->
  <div id="paypal-button-container"></div>

  <!-- Include the PayPal JavaScript SDK -->
  <script
    src="https://www.paypal.com/sdk/js?client-id=CLIENT-ID-HERE&currency=USD&vault=true&intent=capture"></script>

  <script>
    let planid = 'P-48A5110983270751ML2P5NVI';

    // Render the PayPal button into #paypal-button-container
    paypal.Buttons({

      // Set up the transaction
      createSubscription: function (data, actions) {
        // Create Subscription
        return actions.subscription.create({ "plan_id": planid });
      },
      onApprove: function (data, actions) {

        // Authorize the transaction
        actions.order.authorize().then(function (authorization) {

          // Get the authorization id
          var authorizationID = authorization.purchase_units[0]
            .payments.authorizations[0].id

          // Call your server to validate and capture the transaction
          return fetch('/api/company/paypal-transaction-complete', {
            method: 'post',
            headers: {
              'content-type': 'application/json'
            },
            body: JSON.stringify({
              orderID: data.orderID,
              authorizationID: authorizationID,
              data: data,
              authorization: authorization
            })
          });
        });
      }
      // Finalize the transaction? Which one do I want, to authorize or to finalize??
      // onApprove: function (data, actions) {
      //   let result = actions.subscription.get();
      //   return actions.order.capture().then(function(details) {
      //   // Do I need to send something to my server here?
      //   // Show a success message to the buyer
      //   alert('Transaction completed by ' + details.payer.name.given_name + '!');
      //   });
      // }

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

在此先感谢您的帮助。这是一个最令人沮丧的项目。

为什么要在 URL 订阅中使用 intent=authorize / intent=capture?

为什么要使用 actions.order.authorize() 订阅?

谁告诉你要通过订阅来完成这些事情中的

请参阅 Subscriptions Integration 指南,其中未提及这些内容。