【问题标题】:Paypal subscription confusion贝宝订阅混乱
【发布时间】:2020-09-06 07:01:51
【问题描述】:

我已经在一个项目上工作了 2 年多,我终于准备好启动了,但首先我必须集成一个基于订阅的支付选项,这样我才能真正从这件事上赚到一些钱。我已经尝试整合贝宝订阅 2 个月了,这是一个主要的阻碍。另外,这导致我秃顶。请帮忙!

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

目前,我的主要问题是,当我在脚本中设置指向 paypal SDK 的 URL 以包含 &intent=authorize 时,我在错误消息中被告知我需要设置 intent=capture,但是当我设置了intent=capture 我被告知我需要设置intent=authorize。所以现在我对我应该做什么感到困惑;授权交易或捕获交易。贝宝技术支持向我提供了贝宝开发者网站上两个不同指南的链接,这些指南似乎相互矛盾——第一个链接没有说明捕获或授权付款,第二个链接确实如此。但我不明白第二个链接的上下文。第一个链接是所有客户端,第二个链接是客户端和服务器端。为什么需要这些 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,我点击了智能按钮,paypal窗口出现并迅速消失,然后我得到这个错误:

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>

提前感谢您的帮助。这是一个最令人沮丧的项目。

【问题讨论】:

  • 是的,paypal 的支付系统及其文档一团糟,我正在尝试将 custom 字段传递给 paypal,以便通过 IPN 取回该字段,这让我付出了离婚和焦虑的代价!还是不行。

标签: javascript html api paypal subscription


【解决方案1】:

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

您为什么将actions.order.authorize() 用于订阅?

谁告诉您通过订阅任一个做这些事情?

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

【讨论】:

  • 我给 paypal 发了邮件,他们让我去看看 developer.paypal.com/docs/checkout/integration-features/… 这很混乱。我会检查您的链接,然后再检查。感谢您的信息
  • 让您查看那里的人是否清楚地了解您正在处理订阅?我认为你根本不应该看那里。这是一个糟糕的误导。
  • 当然。不过好消息!您的文档链接似乎有效!所以我想我应该抓住从 onApprove 回调返回的数据对象并将其放入数据库中。那么当用户在未来的数据中登录时,有没有办法查询贝宝以确保他们获得最新的付款?您能否指导我查看有关在何处提出该请求的文档或快速解释?再次感谢你的帮助!你不知道我是多么感谢你在这方面的专业知识!
  • 在订阅集成指南的左下角有一个参考和一个订阅资源组的链接,因此您可以考虑查询。
  • 另一种设计是侦听有关支付订阅的 Webhook 事件 (PAYMENT.SALE.COMPLETED) 并跟踪该状态——这实际上是一种更常用的设计,但可能更复杂.
猜你喜欢
  • 2019-08-04
  • 2016-04-03
  • 2011-07-17
  • 2012-04-26
  • 2016-07-08
  • 2020-08-29
相关资源
最近更新 更多