15

I have been trying to get Stripe checkout working with Cordova iOs 4.2.0 and am having no luck. The last Cordova iOs version this works with is 3.9.2. To test I made an empty hello world cordova app and added this code for stripe (tested on ios 9 and 10):

<script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="xxxxxxx"
    data-amount="999"
    data-name="Oki Technologies Inc"
    data-description="Widget"
    data-locale="auto"
    data-currency="cad">

Now it works perfectly on Cordova ios 3.9.2, but on 4.0.0+ it just has an empty iframe with a dark overlay. I think its trying to open the popup in a new tab like the mobile web, instead of as a popup like it is supposed to do on the app. I'm hoping there's a useragent or something I can spoof to get this to work as it works perfectly on android web/cordova as well as iphone on the web. Is there any way to get this working?

I made a test repo here that someone can clone to test https://github.com/HockeyCommunity/stripe

Amrit Kahlon
  • 1,286
  • 1
  • 18
  • 38
  • Might be a bug caused by some change on the Cordova side. Have you checked the console to see if any errors come through? The only thought that comes to me is that cordova might block external resources from certain access as a security measure. – 16patsle Feb 11 '17 at 14:39
  • @16patsle yea there's no errrors, I'm pretty sure something is being blocked. I was hoping there was way around it by possibly spoofing a different user agent string but I haven't found anything yet. Its a shame because for iOS, I'm still running cordova ios 3.9.2 – Amrit Kahlon Feb 14 '17 at 22:08
  • 1
    I would guess you would have to use an In-App Browser to load unsecure resources, triggered by a button or something in your main app – 16patsle Feb 15 '17 at 10:16
  • @16patsle ah interesting idea, I will give it a shot – Amrit Kahlon Feb 15 '17 at 19:53
  • I've taken a look at the code in your repo and I can't really seem to find any other possible reason. When I've got more time I will try to run it myself. – 16patsle Feb 16 '17 at 11:01
  • Had a quick run in the ios simulator, but can't seem to get any further than you. Will try more later. – 16patsle Feb 16 '17 at 11:09
  • Works fine if I run it in a regular browser with a server. – 16patsle Feb 16 '17 at 11:12
  • Yea the issue is with cordova – Amrit Kahlon Feb 16 '17 at 22:26
  • Tried in Safari in Simulator and yes, I think the error might be that it tries to open a new window. In that case the in-app browser plugin should work, as it is "defined to be a drop-in replacement for the window.open() function". – 16patsle Feb 18 '17 at 17:01
  • I tried to see if it would work by just assigning it to window.open, but couldn't see any difference. Might be worth a try to use the debug version of the stripe script in case that makes it log errors to the console. – 16patsle Feb 18 '17 at 17:03

1 Answers1

13

I was banging my head against the wall for days looking for a solution to this. Solution was to add the following two lines to my config.xml file:

<access origin="*" /> <allow-navigation href="https://*.stripe.com/*" />

Hope this helps!

EDIT: Updated solution with suggestion from @TateThurston

adlondon
  • 156
  • 2
  • 6