我一直在使用Stripe和PayPal PHP API来实现付款。对我来说,使用JS API还是一个谜。因此,以Braintree Sofort / Klarna的这段代码为例:
function createLocalPaymentClickListener(type) {
return function (event) {
event.preventDefault();
localPaymentInstance.startPayment({
paymentType: type,
amount: '10.67'
...
}
};
}
10.67
的金额是通过Javascript设置的,在用户单击Sofort付款按钮后,我无法确认此金额,因为打开了叠加层,然后大部分付款由PayPal / Klarna处理。仅返回付款令牌。对此有所了解的用户可以轻松地操纵该金额并支付他/她自己设置的其他金额。
如何确定此金额不能更改?
您是对的,通过更简单的客户端集成,恶意客户端通常可以更改其批准的数量。除了切换到服务器端集成方案之外,没有其他方法可以防止这种情况,在该方案中,金额是在对支付网关的API调用中设置的。
但是,客户设置他们要批准的金额不一定是问题。例如,使用Braintree,实际捕获(在客户批准之后)发生在您的服务器上。因此,如果金额或任何其他详细信息有误,您可以在此前后丢弃付款,而不进行任何实际上会产生交易的捕获。
选项1:即使用户修改金额,也要遵循此机制
验证交易参考:https://developer.paypal.com/docs/checkout/integrate/
服务器端
Set up your server to make calls to PayPal
Set up your server to receive a call from the client with the order ID
Call PayPal to get the transaction details
Handle any errors from the call
Validate the transaction details are as expected
// 5. Validate the transaction details are as expected
if (details.purchase_units[0].amount.value !== '5.77') {
return response.send(400);
}
Save the transaction in your database
Return a successful response to the client
选项2:查看是否可以加密数据https://www.paypal.com/cgi-bin/webscr?cmd=p/xcl/rec/ewp-techview-outside
具有页面重定向机制,并防止用户查看金额。在不同页面上发送数据时,请使用上面建议的加密机制]
[注意,永远不要信任来自客户端的数据。这就是为什么我们也有服务器端的验证码...即使我们有客户端验证码,用户也可以通过它。