Search code examples
paypal

Prevent Modification of PayPal Orders from JavaScript


I'm starting to integrate PayPal checkouts with a server workflow.

My basic need is to create an order on the server and ensure that the client can not modify it in any way. Because of this requirement, I have already ruled out using the "simple" JavaScript-only solution, and I'm instead going for a server integration, calling my own URL endpoints for creating and capturing orders.

However, I have found that the client can just ab-use the actions.order.patch() method to modify almost every aspect of the order, including the amount and the custom_id that I'm attaching to the purchase_item.

Basically, It looks like I have absolutely no guarantee on the order contents, even if I created it on the server, is this correct? In that case, it means I have to check each order's contents against the orders database of my application. It is possible, but I was hoping to not have to do that.

Any clues? How do you deal with this issue? Thanks!


Solution

  • If you are particularly concerned about this scenario of patching down the total or other details before capture, the only way to ensure it has not changed is to do a server-side ‘get details’ call before the capture and at least validate the total amount value, as well as any other field you’re concerned about.

    Otherwise, the usual general safety solution in ecommerce (for this as well as other potential issues that might crop up) is to simply capture and validate the total in the capture response. If the capture has a total you don't expect, issue an immediate refund or flag the occurrence for review before fulfilling anything.