使用Javascript在PayPal和Stripe中设置的付款金额



我一直在使用 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

有一个页面重定向机制,并阻止用户查看金额。跨不同页面发送数据时,请使用上述建议的加密机制

一般说明,永远不要信任来自客户端的数据。这就是为什么我们也有服务器端评估的原因......即使我们有客户端验证,用户也可以通过它传递它。

最新更新