簡體   English   中英

Paypal 訂閱混亂

[英]Paypal subscription confusion

我已經在一個項目上工作了 2 年多,我終於准備好啟動了,但首先我必須集成一個基於訂閱的支付選項,這樣我才能真正從這件事上賺到一些錢。 我已經嘗試集成 paypal 訂閱 2 個月了,這是一個重大的阻礙。 此外,這導致我 go 禿頭。 請幫忙!

我認為有一種概述解釋來描述我需要遵循的明確流程以接受基於訂閱的付款會非常有幫助。 詳細程度將包括每個步驟應該發生的位置; 前端或后端(服務器),以及了解哪些數據流向何處所需的任何中間步驟。 其次,智能按鈕的實際代碼帶有一些注釋,指示代碼正在處理的過程的哪一部分。 也許有很多問題要問,但將不勝感激,我相信對於其他希望像我現在一樣做同樣事情的人來說,這是一個很好的資源。

目前,我的主要問題是,當我將 URL 設置為指向 paypal SDK 在我的腳本中時,我被告知要在我的腳本中包含 &intent=authorize,但我被告知要在我的腳本中包含 &intent=authorize,但我被告知錯誤消息=capture 我被告知我需要設置intent=authorize。 所以現在我對我應該做什么感到困惑; 授權交易或捕獲交易。 paypal 技術支持向我提供了 paypal 開發人員網站上的 2 個不同指南的鏈接,這些指南似乎相互矛盾 - 第一個鏈接沒有提及捕獲或授權付款,第二個鏈接確實如此。 但我不明白第二個鏈接的上下文。 第一個鏈接是所有客戶端,第二個鏈接是客戶端和服務器端。 為什么需要這些 intent=ca[ture/authorize? 我認為一旦有人同意並完成訂閱的注冊,並且我已經捕獲了他們的訂閱 ID,我不需要做任何其他事情就可以在我的計划中按月設置接收資金,我會只需查詢 paypal API 即可了解他們是否已在客戶登錄我的服務時付款。

我已經設置了一個沙盒帳戶,並且我已經創建了一個產品和一個計划。 客戶登錄后,我已使用我的計划 ID 呈現智能按鈕。

If I set intent=capture in the paypal SDK script URL, the paypal window opens, you select payment and agree, and then I get this error in my console:

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()

誰告訴你用訂閱做這些事情的?

請參閱訂閱集成指南,其中沒有提及這些內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM