I’ve been working with both the Stripe and PayPal PHP APIs to implement payments. Working with JS APIs is still a bit of a mystery for me. So just this snippet from Braintree Sofort/Klarna as an example:
function createLocalPaymentClickListener(type) {
return function (event) {
event.preventDefault();
localPaymentInstance.startPayment({
paymentType: type,
amount: '10.67'
...
}
};
}
The amount of 10.67
is set via Javascript and I have no way to confirm this amount after the user clicked the Sofort payment button, since an overlay is opened and most of the payment is handled by PayPal / Klarna then. Only a payment token is returned. A user who knows a bit about this could easily manipulate this amount and pay a different amount, that he/she sets himself.
How could I make sure that this amount cannot be changed?
2
Answers
You are right that with simpler client-side integrations, malicious clients can often change the amount they are going to approve. There is no guard against this other than switching over to a more server-side integration scheme, where the amount is set in an API call to the payment gateway.
However, clients setting the amount they are going to approve isn’t necessarily a problem. With Braintree for example, the actual capture (after client gives approval) happens on your server. And so if the amount or any other details are wrong, you can discard the payment right then and there, and not proceed with any capture that would actually create a transaction.
Option 1:
Even the user modifies the amount, follow this mechanism
Verify the transaction Ref: https://developer.paypal.com/docs/checkout/integrate/
Server side
Option 2 :
See whether you can encrypt the data
https://www.paypal.com/cgi-bin/webscr?cmd=p/xcl/rec/ewp-techview-outside
Have a page redirect mechansium and prevent users from viewing the amount. While sending data across different pages, use encryption mechanism as suggested above
General note, never trust data coming from client side.. Thats why we have server side valiations as well… even though we have client side valdiations in place, users can by pass it.