贝宝订阅混乱

约翰

我从事一个项目已经2年多了,我终于准备好启动了,但是首先我必须集成基于订阅的付款方式,这样我才能从中赚钱。我已经尝试整合Paypal订阅了大约2个月了,这是一个很大的障碍。另外,这使我秃顶。请帮忙!

我认为,有一种概述说明来描述我接受接受基于订阅的付款所需要遵循的明确过程,这真的很有帮助。详细程度将包括每个步骤应在何处进行;前端或后端(服务器),以及了解哪些数据流向何处所必需的任何中间步骤。其次,智能按钮的实际代码带有一些注释,这些注释指示代码正在处理过程的哪一部分。也许有很多问题要问,但是我将不胜感激,并且我相信对于寻求与我目前一样的其他人来说,这是一个很好的资源。

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

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

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

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

但是,如果我设置了intent = authorize,则单击智能按钮,贝宝窗口将显示并迅速消失,然后出现此错误:

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>

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

普雷斯顿PHX

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

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

谁告诉您对订阅执行两项操作?

请参阅“订阅集成”指南,其中没有提及这些内容。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章