首页 > 解决方案 > 是否真的需要服务器端 Paypal 支付验证?

问题描述

简而言之,问题是是否需要服务器端的Paypal支付验证?

更长的故事,我有后端 Scala Play 和前端 Angular7,它们使用 Paypal 客户端 API 触发支付,使用以下客户端支付模式示例作为基线:

<!DOCTYPE html>
<head>
    <!-- Add meta tags for mobile and IE -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
    <!-- Set up a container element for the button -->
    <div id="paypal-button-container"></div>
    <!-- Include the PayPal JavaScript SDK -->
    <script src="https://www.paypal.com/sdk/js?client-id=sb&currency=USD"></script>
    <script>
        // Render the PayPal button into #paypal-button-container
        paypal.Buttons({
            // Set up the transaction
            createOrder: function(data, actions) {
                return actions.order.create({
                    purchase_units: [{
                        amount: {
                            value: '0.01'
                        }
                    }]
                });
            },
            // Finalize the transaction
            onApprove: function(data, actions) {
                // >>>>>>>>>>>>>>>>>>>> IS THIS NECESSARY? <<<<<<<<<<<<<<<<<<<<<<<<
                // use data.orderID to verify the payment on the server-side
                myPaypalPaymentRemoteAppServiceImpl.verifyPayment(data.orderID); 
                // add payment verification result code here

                return actions.order.capture().then(function(details) {
                    // Show a success message to the buyer
                    alert('Transaction completed by ' + details.payer.name.given_name + '!');
                });
            }
        }).render('#paypal-button-container');
    </script>
</body>

orderID那么问题是使用 Paypal REST API 在我的服务器端抓取并仔细检查付款确实成功完成并且付款金额确实是预期的(没有潜在的恶意客户端入侵)是否有意义可能会改变价格或尝试其他形式的破坏)。

标签: javascriptpaypalpaypal-sandbox

解决方案


推荐阅读