Calling a function between createOrder and onApprove.

swisalem
New Community Member

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');

 

Login to Me Too
2 REPLIES 2

Brisbane22
Contributor
Contributor

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)

 

Login to Me Too

Brisbane22
Contributor
Contributor

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.

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.