Reputation: 93
I'm actually trying to create an application that use Papal API v2.
I succesfully create the oreder and get money on sandbox. I use JS Paypal method onApprove to call order.capture to get the order and create the subscription on my systems. But if there are some issue on my serverside code, how i can block the order on paypal API to stop get money from user if something going bad?
paypal.Buttons({
locale: 'it_IT',
style: {
shape: 'pill',
color: 'blue',
layout: 'vertical',
label: 'buynow',
fundingicons: 'true',
},
createOrder: function (data, actions) {
return actions.order.create(my_PlanOrderDef);
},
onApprove: function (data, actions) {
console.log(data)
console.log(actions)
return actions.order.capture().then(function (details) {
if (!CloseProcess(details)) {
console.log("FAIL! HERE SOMETHING GOING BAD ON MY LOGIC, AND I NEED TO CANCEL THE ORDER PAYMENT");
return false;
}
});
},
onError: function (err) {
console.log(err);
}
}).render('#btnPaypalContainer');
CloseProcess method just call my serverside logic to create a subscription on my system. I probably miss something in paypal v2 logics so apologize me, any idea to accomplish this task?
Thank You
Upvotes: 0
Views: 748
Reputation: 30359
When an order is created, it is valid for 72 hours.
When an order becomes approved, it is valid for 3 hours.
There is no method to cancel an order.
If you don't wish to use an order, discard its id and do not capture it.
To change to a server-side integration for order creation and capture, follow the Set up standard payments guide and make 2 routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. Both routes should return only JSON data (no HTML or text). Inside the 2nd route, when the capture API is successful you should store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id
, which is the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) immediately before forwarding your return JSON to the frontend caller.
Pair those 2 routes with the frontend approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
Upvotes: 1