PayPal lightbox won't open in iPhone safari/web app; 'win.location' undefined

前提是你 提交于 2019-12-21 02:58:10

问题


(works fine in Chrome on the iPhone)

I get this error:

TypeError: 'undefined' is not an object (evaluating 'win.location') in dg.js line 3

And the lightbox does not open.

The code in question inside PayPal's dg.js is:

startFlow: function (url) {
    var win = that._render();
    if (win.location) {
        win.location = url;
    } else {
        win.src = url;
    }
}

So does mobile Safari not understand that._render()? How do I get around this?

If it matters, I'm using Adaptive Payments, calling it like so:

var dg = new PAYPAL.apps.DGFlow({
    trigger: null, 
    expType: 'light'
});
dg.startFlow('https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=' +data.paykey);

I don't have any problems getting the payKey & the entire payflow works on desktops and in mobile browsers other than Safari (it works on desktop Safari). It also does not work when our site is run as an iOS web app, which I assume is just a shell for Safari anyway.


回答1:


I can explain why you are seeing this error. Safari on iOS only allows a window to be opened as a result of a user click/touch event.

The DGFlow._render() function executes:

window.open('', "PPDG");

which returns null if triggered by anything other than a user click/touch event.

I am guessing you are issuing an XMLHttpRequest to generate a PayRequest/PayKey on the server and then in the onsuccess callback you are calling DGFlow.startFlow().

The solution is two split the process into two steps:

  1. When the user is ready to checkout, issue the call to the server to generate the pay key.
  2. Then, present the user with a button to Checkout with PayPal and when that is clicked, call DGFlow.startFlow()



回答2:


Found a couple of ways to get around this...location.replace with the PayPal URL or using your own lightbox. I used easybox.

// Replace
dg.startFlow('https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=' +data.paykey);

// with
var RUNNING_AS_WEB_APP = (window.navigator.standalone == true ? true : false);
if (RUNNING_AS_WEB_APP === false) {
    dg.startFlow('https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=' +data.paykey);
} else {
    location.replace('https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=' +data.paykey);
    // Or, lightbox option: 
    // $.easybox([{url: 'https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=' +data.paykey, width: 320, height: 480}]);
} 



回答3:


Try using the mini browser experience where expType=mini. Seems to work better than the lightbox on mobile devices.

Adaptive Payments without modal box or popups?



来源:https://stackoverflow.com/questions/17216172/paypal-lightbox-wont-open-in-iphone-safari-web-app-win-location-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!