简体   繁体   English

Paypal取消功能

[英]Paypal on cancel funtion

I've trying to send a user to another page when they cancel the paypal payment. 当他们取消贝宝付款时,我试图将用户发送到另一个页面。 With the script below it works fine without the onCancel function, but as soon as I add the into the JS the paypal button disappears. 使用下面的脚本,它可以在没有onCancel函数的情况下正常工作,但是一旦将JS添加到JS中,贝宝按钮就会消失。

Could someone please have a look at the code and tell me how to correct it. 有人可以看一下代码,然后告诉我如何更正它。

Thanks in advance. 提前致谢。

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');

You need to add a , to format the JSON object for each additional item, like the onCancel. 您需要添加一个,以为每个其他项目(如onCancel)格式化JSON对象。 Note the comma immediately after the close curly bracket for the onAuthorize item. 请注意onAuthorize项的大括号后紧跟逗号。

},

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

Ususally you need to use both onCancel and onError 通常,您需要同时使用onCancel和onError

    onCancel: function(data, actions) {
      console.log("You are a bummer!");
    },

    onError: function(err) {
      console.log("PayPal is a bummer!");
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM