贝宝结帐 javascript 错误 - this20.getParentTemplate 不是函数

paypal checkout javascript error - this20.getParentTemplate is not a function

我正在将 paypal 快速结帐按钮实现到我开发的 wordpress 插件中。

我有一个编辑订单页面,其中有一个 "confirm order" 按钮,它是一个弹出模式消息,确认总支付金额,其中呈现结账按钮。

$("#mdp-order-button").click(function(e){
    e.preventDefault();
    mdp_render_confirm_modal();
});

function mdp_render_confirm_modal(){
    if (!$("#mdp_upload_image")[0].files[0]){
        alert("please upload an image first");
    }else{
        if(mdp_check_overlap()){
            alert("the block is either out of the grid or overlapped with other block, please place it again");
        }else{
            var current_block = $('.current_block');
            var cost = current_block.width() * current_block.height();
            $('#mdp-show-size').html("Your block is "+current_block.width()+"px X "+current_block.height()+"px");
            $('#mdp-show-cost').html("Total: "+cost);
            $('#mdp-modal').show();
            $('#mdp-close').click(function(){
                $('mdp-modal').hide();
            })
            mdp_render_paypal_button(cost)
        }
    }
}

function mdp_render_paypal_button(charge) {

    paypal.Button.render({

        env: 'sandbox', // Or 'sandbox'

        commit: true, // Show a 'Pay Now' button

        client: {
            sandbox:    'censored xxxxx'
        },

        payment: function() {
            return paypal.rest.payment.create(this.props.env, this.props.client, {
                transactions: [
                    {
                        amount: {
                            total:    charge,
                            currency: 'USD'
                        }
                    }
                ]
            });
        },

        onAuthorize: function(data, actions) {
            return actions.payment.execute().then(function(response) {
                console.log(response);
            });
        }
    }, '#paypal-button');
}

当我点击结帐按钮时,paypal window 弹出并立即关闭,控制台上显示错误

checkout.js:4225 ppxo_xc_ppcheckout_destroy Object {timestamp: 1494405598944, windowID: "53bb903148", pageID: "84e2908f4a", host: "www.sandbox.paypal.com", path: "/webapps/hermes/button"…}
checkout.js:2021 Uncaught Error: _this20.getParentTemplate is not a function
TypeError: _this20.getParentTemplate is not a function
    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:9346:40)
    at _loop2 (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1077:62)
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1107:29)
    at SyncPromise.then (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1125:18)
    at Function.syncPromiseTry [as try] (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1170:42)
    at DelegateComponent.openContainer (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:9342:55)
    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:8556:35)
    at _loop2 (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1077:62)
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1107:29)
    at SyncPromise.then (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1125:18)
    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:9346:40)
    at _loop2 (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1077:62)
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1107:29)
    at SyncPromise.then (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1125:18)
    at Function.syncPromiseTry [as try] (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1170:42)
    at DelegateComponent.openContainer (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:9342:55)
    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:8556:35)
    at _loop2 (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1077:62)
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1107:29)
    at SyncPromise.then (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1125:18)
    at Object._RECEIVE_MESSAGE_TYPE.(anonymous function) [as postrobot_message_response] (https://www.paypalobjects.com/api/checkout.js:2021:118)
    at receiveMessage (https://www.paypalobjects.com/api/checkout.js:1929:73)
    at messageListener (https://www.paypalobjects.com/api/checkout.js:1949:13)

我尝试在网上搜索,但没有找到类似的问题或文档,我真的不知道为什么会这样。

在此先感谢您的帮助,全站员

非常感谢@bluepnume 的帮助。

这是 wordpress 如何加载脚本的问题,默认情况下附加查询字符串 ?ver='current_wordpress_version' 到加载的脚本,已禁用它,现在它正在获取最新版本的checkout.js

而不仅仅是

wp_enqueue_script('paypal_checkout', 'https://www.paypalobjects.com/api/checkout.js');

现在

wp_enqueue_script('paypal_checkout', 'https://www.paypalobjects.com/api/checkout.js',array(),null);