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

在PayPal和Stripe中使用Javascript设置付款金额,javascript,paypal,braintree,Javascript,Paypal,Braintree,我一直在使用Stripe和PayPal PHP API来实现支付。对我来说,使用JSAPI仍然有点神秘。以Braintree Sofort/Klarna中的这段代码为例: function createLocalPaymentClickListener(type) { return function (event) { event.preventDefault(); localPaymentInstance.startPayment({

我一直在使用Stripe和PayPal PHP API来实现支付。对我来说,使用JSAPI仍然有点神秘。以Braintree Sofort/Klarna中的这段代码为例:

function createLocalPaymentClickListener(type) {
    return function (event) {
        event.preventDefault();

        localPaymentInstance.startPayment({
              paymentType: type,
              amount: '10.67'
            ...
        }
    };
}
10.67
的金额是通过Javascript设置的,在用户单击Sofort payment按钮后,我无法确认该金额,因为会打开一个覆盖,大部分付款由PayPal/Klarna处理。只返回一个支付令牌。对这一点稍有了解的用户可以轻松地操纵此金额并支付他/她自己设定的不同金额


如何确保该金额不能更改?

您是对的,通过更简单的客户端集成,恶意客户端通常可以更改他们将要批准的金额。除了切换到更服务器端的集成方案之外,没有其他方法可以防止这种情况,在这种方案中,金额是在对支付网关的API调用中设置的

然而,客户设置他们将批准的金额并不一定是个问题。以Braintree为例,实际捕获(在客户机批准后)发生在您的服务器上。因此,如果金额或任何其他细节有误,您可以立即放弃付款,而不进行任何实际创建交易的捕获。

选项1: 即使用户修改金额,也要遵循此机制

验证事务参考:

服务器端

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: 看看是否可以加密数据

设置页面重定向机制,防止用户查看金额。在跨不同页面发送数据时,请使用上面建议的加密机制

一般注意,永远不要信任来自客户端的数据。。这就是为什么我们还有服务器端验证。。。即使我们有客户端的权限,用户也可以绕过它