I'm about to integrate Paypal Express Checkout in an online food ordering system. My current view of the flow is the following:
SetExpressCheckout
is called, and the customer is redirected to Paypal with the token.DoExpressCheckoutPayment
is called and the payment is completed;That makes me wonder, is it ever possible that DoExpressCheckoutPayment
fails, and the funds cannot be taken for any reason? Because in my case, that would be too late to cancel the order which has already been sent to the restaurant.
Should I use PAYMENTACTION=Authorization
instead, and then capture/void the authorization? As the funds can be held for 3 days, while I just need a few minutes for decision, that looks a bit overkill.
Yes, a DoExpressCheckoutPayment API call can certainly fail.
What you should do is set PAYMENTACTION=Authorization in your SetExpressCheckout and DoExpressCheckoutPayment API call, and - once the restaurant has acknowledged the order - call the DoCapture API to capture the funds from the authorization.
Funds are honoured for 3 days, and an authorization is available up to 29 days.
Also; design to fail. Keep a fallback. Just in case the DoCapture does fail. It shouldn't, but you never know. So double-check that 'PAYMENTSTATUS' is 'Completed' and 'TRANSACTIONID' is not empty in the DoCapture API response.