Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe Connect in Ionic Cordova - Can't redirect back to application

Framework: Ionic Cordova

API: Stripe Connect (allows users to send payments to each other).

The registration process for getting payments is through Stripe Connects own external window. When registering for Stripe Connect it uses a Redirect URI, (which is set in the settings of my Stripe account) to go back to the screen you came from with an authentication code. This works in browser (because Redirect URI is set to localhost or an IP), but the actual running application on a phone doesn't, because the application doesn't have a URL. So it shows a "site is not accessible/doesn't exist" browser error message.

I currently use open the Stripe Connect registration screen by using:

  var link = "https://connect.stripe.com/oauth/authorize?response_type=code&client_id=MYCLIENTID&scope=read_write";

    window.open(link, '_blank', 'location=no');
  • I've asked Stripe support for help, but they have no solution for this.

  • I've tried using the Custom URL Scheme for giving the application a URL - but Stripe only allow "Http://" URL's, and not CoolAppName//:, as the Custom URL Scheme gives.

  • Please do not get confused by this one: If I run "ionic run -l" in cmd, and then use the given URL as Redirect URI, it actually redirects back with the authentication code on phone as well. BUT, erases every information stored in application, so it "forgets" what user is logged in. Of course this solution will only work locally as well.

Any suggestion is appreciated.

Thanks in advance.

like image 593
Rad Avatar asked Apr 22 '16 14:04

Rad


1 Answers

You can use any url you want, what you have to do is to listen for the loadstart event and check if it's loading that url to know if the redirection was ok

First install inAppBrowser plugin if you haven't done it already cordova plugin add cordova-plugin-inappbrowser

and use window.cordova.InAppBrowser.open instead of window.open (the API changed long time ago)

Your code should be something like this:

var link = "https://connect.stripe.com/oauth/authorize?response_type=code&client_id=MYCLIENTID&scope=read_write";

var browserRef = window.cordova.InAppBrowser.open(link, '_blank', 'location=no');

browserRef.addEventListener('loadstart', function(event) {
    if((event.url).indexOf(yourRedirectUri) === 0) {
        //Loaded the redirect url
    }
});

Where yourRedirectUri is the url you used on stripe

like image 60
jcesarmobile Avatar answered Sep 27 '22 02:09

jcesarmobile