![](/img/trans.png)
[英]How to redirect user after to another page using PayPal smart buttons
[英]Paypal Smart Button: how to redirect to a PHP page after successfull payment?
我正在嘗試將 paypal 付款集成到我的 web 網站中。
編輯:
成功付款后,我想重定向到 PHP 頁面來操作付款數據,例如:保存到 db 交易和付款 id、付款人 email、發送 email 等。
所以這是我的“onApprove”function:
onApprove: function(data, actions) {
var EXECUTE_URL = 'https://www.mywebsite.com/actions/paymentsuccess.php';
return fetch(EXECUTE_URL, {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
paymentID: data.paymentID,
payerID: data.payerID,
payerEmail: data.payerEmail,
payerName: data.payerName,
payerPhone: data.payerPhone
})
});
},
如何調用 PHP 頁面(可能帶有 POST )並傳遞所有支付數據,並詳細說明該頁面(我不需要留在支付頁面)?
謝謝
如果您需要做某事,您應該在服務器上的“EXECUTE_URL”中進行(或使用更多當前的集成,捕獲 URL)這是任何重要業務任務應該完成的地方。
但是,如果您想將用戶重定向到某個結果點(而不是“做某事”),這應該發生在提取之后,並且只有在提取成功時才會發生。 您需要自己添加一個 JS 重定向。
所以基本上,添加處理 fetch 響應的.then()
代碼。
對於當前的集成(使用捕獲,而不是執行),這是一個解析獲取響應的示例實現: https://developer.paypal.com/demo/checkout/#/pattern/server
如果順便說一句,您使用的是 paypal sdk 那么您應該真正遵循有關確認頁面的文檔,並在已經加載了貝寶的 sdk 對象的同一頁面上顯示您想要的用戶信息
onApprove: function (data, actions) {
// Get the order details
return actions.order.get().then(function (orderDetails) {
// Show a confirmation using the details from orderDetails
// Then listen for a click on your confirm button
document.querySelector('#confirm-button')
.addEventListener('click', function () {
// Capture the transaction funds
return actions.order.capture().then(function () {
// Show a confirmation to the buyer
});
});
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.