Calling a function between createOrder and onApprove.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Im making a website fo a movie theater (a school project) and when the customer presses the confirm button (to complete the payment) i want to check some things like if the seats he chose are not taken by someone else, if the seats are still free - the payment can be done, but if the seats are taken i want to abort the payment and send him to the home page and show an error message.
So, i need to call the function as soon as the customer hits the confirm button and i cant seem to find a way.
paypal.Buttons({
style: {
layout: 'horizontal',
label: 'checkout'
},
// Set up the transaction
createOrder: function (data, actions) {
setInterval(checkValidSeats, 1000);
return actions.order.create({
purchase_units: [{
amount: {
value: !{JSON.stringify(priceafter)}
}
}]
});
},
// Finalize the transaction
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
// Show a success message to the buyer
$('#alert-modal-title').html('Success!');
$('#alert-modal-body').html('Transaction completed by ' + details.payer.name.given_name + '!');
$('#alert-modal').modal('show');
});
}
}).render('#checkout');
- Labels:
-
Payments REST APIs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Late reply but hope it can help
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
What about trying something like
onApprove: function (data, actions) {
if (some problem) {
return actions.order.patch([
{
op: 'replace' // etc etc whatever is appropriate
} ]);
}
return actions.order.capture().then(function (details) {
or maybe an
actions.order.reject (not sure if 'reject' is the correct name, I haven't had to use it)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Update:
I believe it is
return actions.reject();
which would take you back to your screen. You could update your own screen before doing the reject, and it would show once the paypal overlay iframe is removed.

Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Are there any restrictions to charge using only html, vanilla javascript and php with rest api? in REST APIs
- PayPal integration with Next, Lambda and API Gateway - 400 Invalid Request in Sandbox Environment
- paypal angular sandbox, receiving not approved order ,when Capture even OnApprove is triggered in Sandbox Environment
- Prevent changing shipping address via SET_PROVIDED_ADDRESS not working. Orders V2 Advanced Checkout in REST APIs
- How do I handle INSTRUMENT_DECLINED error? in REST APIs