简体   繁体   English

PayPal API 上下文结帐的错误

[英]Bug with PayPal API context checkout

I have a problem with PayPal Express Checkout integration : https://developer.paypal.com/docs/classic/express-checkout/in-context/javascript_advanced_settings/#color我对 PayPal Express Checkout 集成有问题: https : //developer.paypal.com/docs/classic/express-checkout/in-context/javascript_advanced_settings/#color

If I close the pop-up before it loads completely, the pop-up won't show up anymore until I refresh!如果我在弹出窗口完全加载之前关闭它,在我刷新之前,弹出窗口将不再显示!

This does occur on all browsers.这确实发生在所有浏览器上。 The error on Chrome console is: Chrome 控制台上的错误是:

ppxo_paypal_legacy_gettoken_initxo Object
print @ logger.js:65

Here is my code :这是我的代码:

window.paypalCheckoutReady = function() {
            paypal.checkout.setup("{$PayPal_in_context_checkout_merchant_id}", {
                environment: {if $PAYPAL_SANDBOX}"sandbox"{else}"production"{/if},
                click: function(event) {
                    event.preventDefault();

                    paypal.checkout.initXO();
                    updateFormDatas();
                    var str = '';
                    if($('.paypal_payment_form input[name="id_product"]').length > 0)
                        str += '&id_product='+$('.paypal_payment_form input[name="id_product"]').val();
                    if($('.paypal_payment_form input[name="quantity"]').length > 0)
                        str += '&quantity='+$('.paypal_payment_form input[name="quantity"]').val();
                    if($('.paypal_payment_form input[name="id_p_attr"]').length > 0)
                        str += '&id_p_attr='+$('.paypal_payment_form input[name="id_p_attr"]').val();

                    $.support.cors = true;
                    $.ajax({
                        url: "{$base_dir_ssl}modules/paypal/express_checkout/payment.php",
                        type: "GET",
                        data: '&ajax=1&onlytoken=1&express_checkout='+$('input[name="express_checkout"]').val()+'&current_shop_url='+$('input[name="current_shop_url"]').val()+'&bn='+$('input[name="bn"]').val()+str,   
                        async: true,
                        crossDomain: true,


                        success: function (token) {
                            var url = paypal.checkout.urlPrefix +token;

                            paypal.checkout.startFlow(url);
                        },
                        error: function (responseData, textStatus, errorThrown) {
                            alert("Error in ajax post"+responseData.statusText);

                            paypal.checkout.closeFlow();
                        }
                    });
                },

                buttons: [
  {
    container: 'paypal_process_payment',
    type: 'checkout',
    color: 'blue',
    size: 'small',
    shape: 'pill'
  },
  {
    container: 'payment_paypal_express_checkout',
    type: 'checkout',
    color: 'gold',
    size: 'small',
    shape: 'pill'
  }
]
            });
        };

I ran into the same issue,我遇到了同样的问题,

After looking into the source code, it turns out that when paypal.checkout.initXO();查看源代码后,发现当paypal.checkout.initXO(); the paypal.checkout.startFlow function is wrapped in a once function, which means you can only call startFlow once. paypal.checkout.startFlow函数被包裹在一个函数中,这意味着你只能调用 startFlow 一次。 and paypal.checkout.initXO is overwritten to show a warning in the console.并且paypal.checkout.initXO被覆盖以在控制台中显示警告。

Inside, paypal.checkout.closeFlow there is a call to paypal.checkout.reset which is important to resetting these functions.在内部, paypal.checkout.closeFlow有一个对paypal.checkout.reset的调用,这对于重置这些功能很重要。

The problem was happening when the user clicks the close button too early, where the startFlow promise wasn't being resolved (which means when the user closes the modal it will redirect to the canceled url) nor the paypal.checkout.closeFlow catch wasn't being hit either.问题发生在用户过早点击关闭按钮时,startFlow 承诺没有得到解决(这意味着当用户关闭模式时,它将重定向到取消的 url),也没有paypal.checkout.closeFlow catch 是'也没有被击中。

I was able to resolve the issue, by keeping track of how many times the user clicked the button, if it was more than once, I called paypal.checkout.closeFlow (which will reset) before paypal.checkout.initXO();我能够解决这个问题,通过跟踪用户点击按钮的次数,如果它不止一次,我在paypal.checkout.initXO();之前调用了paypal.checkout.closeFlow (它将重置paypal.checkout.initXO();

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

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