2
votes

(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.

3

3 Answers

2
votes

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()
1
votes

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}]);
} 
1
votes

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?