Search code examples
androidstripe-paymentsstripe-connect

How to generate token with bank account in stripe?


I integrated stripe in my android project. Now, I am generating token with card in stripe. That is working fine. But, I want to generate token with Bank Account. I searched in StackOverflow referred some of links. But, it doesn't worked for me. Is there is any way to generate stripe token with bank account in android?

The following code I used. But, it not worked.

        Stripe.apiKey = "sk_test_...";

        Map<String, Object> tokenParams = new HashMap<String, Object>();
        Map<String, Object> bank_accountParams = new HashMap<String, Object>();
        bank_accountParams.put("country", "US");
        bank_accountParams.put("currency", "usd");
        bank_accountParams.put("account_holder_name", "Jane Austen");
        bank_accountParams.put("account_holder_type", "individual");
        bank_accountParams.put("routing_number", "11000000");
        bank_accountParams.put("account_number", "000123456789");
        tokenParams.put("bank_account", bank_accountParams);

        try {
            Token s = Token.create(tokenParams);
            Log.d("Token",s.getId());
            tokens = s.getId();
        } catch (AuthenticationException e) {
            showAlertMessage("",e.getMessage());
        } catch (CardException e) {
            showAlertMessage("",e.getMessage());
        } catch (APIException e) {
            showAlertMessage("",e.getMessage());
        } catch (InvalidRequestException e) {
            showAlertMessage("", e.getMessage());
        } catch (APIConnectionException e) {
            showAlertMessage("",e.getMessage());
        }

Solution

  • According to the new docs you need to add following line to gradle build:

    compile 'com.stripe:stripe-android:4.0.1'
    

    check for the latest version at this link

    Then use the following code snippet:

    Stripe stripe = new Stripe(this);
    stripe.setDefaultPublishableKey("your_publishable_key");
    BankAccount bankAccount = new BankAccount("accountNumber","countryCode","currency","routingNumber");
    stripe.createBankAccountToken(bankAccount, new TokenCallback() {
        @Override
        public void onError(Exception error) {
            Log.e("Stripe Error",error.getMessage());
        }
    
        @Override
        public void onSuccess(com.stripe.android.model.Token token) {
            Log.e("Bank Token", token.getId());
        }
    });
    

    This should work like charm.