PayPal智能结帐按钮容易受到攻击吗?

问题描述

我正在制作一个电子商务网站,该网站应使用Smart Checkout按钮允许Paypal付款。 我担心的是每个人都可以卷曲我的网站,获取原始的HTML + js页面并编辑购买单位值。一旦他们完成了可以运行网页的工作,就会执行js代码,并使用伪造的值呈现按钮,并且他们可以伪造付款(用更少的钱)。 真的吗?还有没有使用Smart Button(没有REST API)的解决方案?

我将无法手动创建按钮,因为会有许多不同用户出售的文章

paypal.Buttons({

        // Set up the transaction
        createOrder: function(data,actions) {

            var o = actions.order.create({
                purchase_units: [{
                    amount: {
                        value: '30.99' //Can users change this ?
                    },payee: {
                      email_address: 'sb-qloys3515897@business.example.com'//email of the sellers
                    }
                }]
            })

            return o;
        },// Finalize the transaction
        onApprove: function(data,actions) {
            console.log(details);
            return actions.order.capture().then(function(details) {
                // Show a success message to the buyer
                //alert('Transaction completed by ' + details.payer.name.given_name + '!');
                alert(details);
            });
        }


    }).render('#paypal-button-container');

解决方法

如果仅使用客户端代码,则可以,任何人都可以在浏览器中直接编辑该客户端代码,并支付您希望的金额,从0.01美元到数万美元。

如果这种情况与您有关,那么仅客户端集成对于您来说显然太简单了,您应该使用服务器来实现所需的验证。

在服务器上创建两条路由,一条用于“设置交易”,另一条用于“捕获交易”,documented here.

然后用您的PayPal按钮呼叫这两条路线;这是最好的演示代码:https://developer.paypal.com/demo/checkout/#/pattern/server