如何在成功的贝宝付款上发布表格?

西澳大学

我的 HTML 页面上有一个包含贝宝按钮和贝宝信用卡按钮的表单。这是一个简单的 HTML、JS 站点,而不是网络商店。成功付款后如何以编程方式发布表格?我的onApprove部分在下面不起作用。* 目前只设置了贝宝沙箱帐户。

paypal.Buttons({
            style: {
                layout: 'vertical',
                color: 'black',
                shape: 'rect',
                label: 'paypal',
                height: 45
            },
            createOrder: function (data, actions) {
                // This function sets up the details of the transaction, including the amount and line item details.
                return actions.order.create({
                    purchase_units: [{
                        amount: {
                            value: total
                        }
                    }]
                });
            },
            onApprove: function (data, actions) {
                // This function captures the funds from the transaction.
                return actions.order.capture().then(function (details) {
                    // This function shows a transaction success message to your buyer.
                    $('#orderForm').submit();
                });
            }
            //fundingSource: paypal.FUNDING.PAYPAL
        }).render('#paypal-button-container');
普雷斯顿PHX

在客户端之后actions.order.capture(),您不应发布表单或写入数据库或任何此类性质的内容。客户端集成不适用于该用例。如果您需要在服务器上发送或存储数据作为 PayPal 交易的一部分,您应该使用服务器端集成:


在您的服务器上创建两条路由,一条用于“创建订单”,另一条用于“捕获订单”,记录在此处这些路由应该只返回 JSON 数据(没有 HTML 或文本)。后者应该(成功时)在返回之前将付款详细信息存储在您的数据库中(特别purchase_units[0].payments.captures[0].id是 PayPal 交易 ID)

将这两条路线与以下审批流程配对:https : //developer.paypal.com/demo/checkout/#/pattern/server

如果需要向服务器传输数据,请在fetch; 不要使用表单帖子。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章