I have integrated an Express checkout button into my webpage and configured the server-side process with client code:
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
var CREATE_PAYMENT_URL = "<create_payment_url>";
var EXECUTE_PAYMENT_URL = "<execute_payment_url>";
paypal.Button.render({
env: "sandbox",
payment: function (resolve, reject) {
return paypal.request.post(CREATE_PAYMENT_URL)
.then(function (data) {
resolve(data.id);
})
.catch(function (err) {
reject(err);
});
},
onAuthorize: function (data) {
return paypal.request.post(EXECUTE_PAYMENT_URL, { paymentID: data.paymentID, payerID: data.payerID })
.then(function (data) {
document.querySelector('#paypal-button').innerText = 'Payment Complete!';
console.log("Success", data);
})
.catch(function (err) {
console.log("Error", err);
});
}
}, "#paypal-button");
</script>
Although I am using the server-side .NET SDK to facilitate payment creation and processing with generic handlers, I am facing an issue where the entire page reloads after the payment is executed.
My goal is to manage the results/errors through execution listeners using the callbacks defined with the .then() and .catch() methods in paypal.request.post(EXECUTE_PAYMENT_URL, ...).
In PayPal's interactive demo available at https://developer.paypal.com/demo/checkout/#/pattern/server, the listener functions as expected.
Any suggestions on how I can address this issue would be greatly appreciated.