blitzen12
blitzen12

Reputation: 1390

generate bank account token using android from stripe

I am integrating stripe on my android project. I know that you can generate stripetoken for card using this.

Card card = new Card("4242424242424242", "12", "2014", "123");

Stripe stripe = new Stripe("pk_test_6pRNASCoBOKtIshFeQd4XMUh");
stripe.createToken(
    card,
    new TokenCallback() {
        public void onSuccess(Token token) {
            // Send token to your server
        }
        public void onError(Exception error) {
            // Show localized error message
            Toast.makeText(getContext(),
              error.getLocalizedString(getContext()),
              Toast.LENGTH_LONG
            ).show();
        }
    }
)

I am using their stripe-android library from github

So How can I generate stripeToken for BankAccount?

I can't seem to find any example on google about this.

Thank you!

Upvotes: 2

Views: 2848

Answers (4)

Sohaib Khalid
Sohaib Khalid

Reputation: 69

You can create using this code.

  Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2";

  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());
  } 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());
  }

Upvotes: 2

Moktahid Al Faisal
Moktahid Al Faisal

Reputation: 910

hi simply try below code with ur stripe api key

Stripe stripe = new Stripe(this, "YOUR API KEY");

        BankAccount bankAccount = new BankAccount("000123456789","US","usd","110000000");
        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());
            }
        });

Upvotes: 0

Rahul Sharma
Rahul Sharma

Reputation: 2893

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.

Upvotes: 0

rfunduk
rfunduk

Reputation: 30442

There isn't a way to have customers pay directly from a bank account, so there's no API to create a payment token using bank details. Maybe you're thinking of the 'Marketplaces' product which let's you setup recipients with bank details and make transfers to them (eg, to pay out earnings).

Upvotes: 1

Related Questions