[英]Paypal Smart Button: how to redirect to a PHP page after successfull payment?
[英]PayPal Smart Button - How To Edit Redirect Url
我正在嘗試在我的 PayPal 智能按鈕生成的代碼中輸入重定向 url 鏈接,但不知道該怎么做。 我希望我能在這里得到幫助。
我希望能夠在成功付款后將客戶重定向到例如( https://www.example.com/request/ )。
以下是 Paypal 的智能按鈕代碼:
function initPayPalButton() { paypal.Buttons({ style: { shape: 'rect', color: 'gold', layout: 'vertical', label: 'paypal',
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{"description":"Digital Service","amount":{"currency_code":"USD","value":1}}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Full available details
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
// Show a success message within this page, e.g.
const element = document.getElementById('paypal-button-container');
element.innerHTML = '';
element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
},
onError: function(err) {
console.log(err);
}
}).render('#paypal-button-container');
}
initPayPalButton();
您需要注釋掉第一部分,並取消注釋第二部分,如下所示:
// Show a success message within this page, e.g.
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '';
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL:
actions.redirect('https://www.example.com/thankyou/');
// Or go to another URL: actions.redirect('thank_you.html');
您的問題的答案在代碼示例中,就在這里。
function redirect(url){
window.setTimeout(function(){
window.location.href = url;
}, 300);
}
<button onclick="redirect("https://www.google.com")">Redirect</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.