亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Paypal Smart Payment Buttons — 如何在服務器端創建訂單并將訂單 ID

Paypal Smart Payment Buttons — 如何在服務器端創建訂單并將訂單 ID

偶然的你 2022-06-17 14:37:29
我正在集成 Paypal Checkout 并在他們的文檔中關注如何在此處設置客戶端 SDK。我不想在客戶端設置訂單項目和總和,而是使用服務器端設置來處理步驟 4末尾提到的訂單。使用他們的 PHP SDK 我可以設法設置訂單沒有問題,但我努力讓事情正常工作的地方是如何將這個創建的訂單傳遞給客戶端。創建的訂單的返回對象具有 ID 和 URL 以啟動捕獲它,但點擊鏈接實際上提供了與單擊 Paypal 按鈕不同的用戶體驗,所以我想仍然使用按鈕,但使用創建的訂單。使用他們的示例代碼:  paypal.Buttons({    createOrder: function(data, actions) {      // This function sets up the details of the transaction, including the amount and line item details.      return actions.order.create({        purchase_units: [{          amount: {            value: '0.01'          }        }]      });    },    onApprove: function(data, actions) {      // This function captures the funds from the transaction.      return actions.order.capture().then(function(details) {        // This function shows a transaction success message to your buyer.        alert('Transaction completed by ' + details.payer.name.given_name);      });    }  }).render('#paypal-button-container');  //This function displays Smart Payment Buttons on your web page.本質上,我有一個來自服務器端調用的訂單 ID,不需要使用“createOrder”調用,但是如何將我的訂單 ID 傳遞給paypal.Buttons()設置,以便當用戶點擊呈現的 Paypal 按鈕時,他們會被發送批準我創建的訂單?PS:我知道您在驗證并捕獲訂單之后,但是為什么有人想在他們的客戶端 Javascript 中設置訂單費用?對我來說,這似乎是一個根本錯誤的想法。我在這里錯過了什么嗎?
查看完整描述

1 回答

?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

解決方案是相當明顯的,但不知何故,我在早些時候看時并沒有偶然發現它。createOrder需要返回訂單 ID,這可以按照記錄完成:


method: 'post',

    headers: {

      'content-type': 'application/json'

    }

  }).then(function(res) {

    return res.json();

  }).then(function(data) {

    return data.orderID; // Use the same key name for order ID on the client and server

  });


查看完整回答
反對 回復 2022-06-17
  • 1 回答
  • 0 關注
  • 260 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號