Stripe Connect Android

2020-07-07 11:37发布

问题:

I am building an android app which pays someone. I explored Stripe Connect and it has an API and flow for website which requires displaying a stripe connect button and also needs a re-direct uri.

However, I can not find anything on for Android which allows to show a connect button and prompt user to create or connect a stripe account natively on Android device. Should I use a webview to do this or is there some more elegant way to do this?

回答1:

As far as I know, there're no native SDK for mobile stripe connect. I did the webview route for android. Was trivial, but I agree that I wished there're a more elegant solution to this.

For those who are wondering on how to do this (since I can't find any doc out there), here you go:

  1. Create a button that will open a new intent with a web view.

  2. The webview should load the oauth/authorize endpoint ("https://connect.stripe.com/oauth/authorize?response_type=code&client_id=[YOUR_API_KEY]&scope=read_write"). Do not forget to enable javascript on your webview.

  3. Once the form in webview is filled, Stripe will redirect to the redirect_url you provided with the authorization code if the authorization is successful. Have your web service parse that authorization code.

  4. Have your service make a post to stripe oauth/token with providing grant_type, client_id, code, and client_secret.

  5. Stripe will then respond back with the token (auth credentials) that you needed. Store that for later use & you're pretty much done.



回答2:

I know this is quite an old one but, After investing my 2 days and trying, searching a lot of techniques to create stripe account in android platform I found Stripe API which solves my problem...

Firstly, here is the jar file you have to include in your project. Then you have to initialize key provided you at the dashboard

Stripe.apiKey = "sk_test_xxxxxxxxxxxxxxxxxxxxxxxx";
RequestOptions requestOptions = RequestOptions.builder()
                                 .setApiKey("sk_test_xxxxxxxxxxxxxxxxxxxxxxxx").build();
Map<String, Object> accountParams = new HashMap<String, Object>();
   accountParams.put("managed", false);
   accountParams.put("country", "US");
   accountParams.put("email", "some@email.com");
  1. To create an account use create() method for Account class with there parameter create link

    try {
       Account create = Account.create(accountParams, null);
    } catch (AuthenticationException e) {
       e.printStackTrace();
    } 
    
  2. Then to retrieve account detail pass account id to retrieve() method

    try {
       Account detail = Account.retrieve("acct_xxxxxxxxxxxxxx", null);
    } catch (AuthenticationException e) {
       e.printStackTrace();
    } 
    

You can find more at Stripe Android API, and yes please do correct me if I am wrong..

Exception you need to catch AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException