javascript - Paypal 取消功能

标签 javascript paypal

当用户取消 paypal 付款时,我试图将用户转到另一个页面。使用下面的脚本,它在没有 onCancel 函数的情况下也能正常工作,但是一旦我将其添加到 JS 中,paypal 按钮就会消失。

谁能看看代码并告诉我如何更正它。

提前致谢。

paypal.Button.render({

    // Set your environment

    env: 'sandbox', // sandbox | production

    // Specify the style of the button

    style: {
        label: 'checkout',
        size:  'medium',    // small | medium | large | responsive
        shape: 'pill',     // pill | rect
        color: 'silver'      // gold | blue | silver | black
    },

    // PayPal Client IDs - replace with your own
    // Create a PayPal app: https://developer.paypal.com/developer/applications/create

    client: {
        sandbox:    '<insert production client id>',
        production: '<insert production client id>'
    },


        // Show the buyer a 'Pay Now' button in the checkout flow
        commit: true,

    // Wait for the PayPal button to be clicked

    payment: function(data, actions) {

        // Make a client-side call to the REST api to create the payment

        return actions.payment.create({
            payment: {
                transactions: [
                    {
                        amount: { total: '1.09', currency: 'GBP' }
                    }
                ]
            },

            experience: {
                input_fields: {
                    no_shipping: 1
                }
            }
        });
    },

    // Wait for the payment to be authorized by the customer

    onAuthorize: function(data, actions) {

        // Execute the payment

        return actions.payment.execute().then(function() {
        window.location.href = "<direct to payment success page>";
        });
    }

            onCancel: function(data, actions) {
        // Show a cancel page or return to cart
    }

}, '#paypal-button-container');

最佳答案

您需要添加一个 , 来为每个附加项格式化 JSON 对象,例如 onCancel。请注意 onAuthorize 项的右大括号后的逗号。

},

        onCancel: function(data, actions) {
    // Show a cancel page or return to cart
}

关于javascript - Paypal 取消功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48157678/

相关文章:

java - Stripe : How do i know whether card is 3d secure and how to charge it

javascript - 运行 "pm2 start server --watch"但不是 "pm2 start server"时出现 CORS 错误。不存在 'Access-Control-Allow-Origin' header

javascript - 如何限制vue中NUMBER输入的最大数量?

javascript - 如何从 Kaizala API 获取 accessToken

paypal - 使用 Paypal IPN 识别唯一的配置文件

c# - 许多站点接受订单;一个 Paypal 账户

javascript - 'var a = b' 和 'this.a = b' 之间的区别

javascript - 如何等待异步函数返回?

paypal - 在现有和已执行的计费协议(protocol)中更改 Paypal 下一个付款日期?

api - paypal rest api 测试信用卡号码