Java Stripe: Create a Bank Account Token

Back to Index

Creates a single use token that wraps the details of a bank account. This token can be used in place of a bank account dictionary with any API method.

Documentation: https://stripe.com/docs/api/curl#create_bank_account_token

CURL Command

curl https://api.stripe.com/v1/tokens \
   -u STRIPE_SECRET_KEY: \
   -d bank_account[country]=US \
   -d bank_account[currency]=usd \
   -d bank_account[account_holder_name]="Chloe White" \
   -d bank_account[account_holder_type]=individual \
   -d bank_account[routing_number]=110000000 \
   -d bank_account[account_number]=000123456789 \
   -X POST

Java Example

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://api.stripe.com/v1/tokens
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("api.stripe.com",port,bTls,bAutoReconnect);
    if (success != true) {
        System.out.println("ConnectFailReason: " + rest.get_ConnectFailReason());
        System.out.println(rest.lastErrorText());
        return;
        }

    rest.SetAuthBasic("STRIPE_SECRET_KEY","");

    rest.AddQueryParam("bank_account[country]","US");
    rest.AddQueryParam("bank_account[currency]","usd");
    rest.AddQueryParam("bank_account[account_holder_name]","Chloe White");
    rest.AddQueryParam("bank_account[account_holder_type]","individual");
    rest.AddQueryParam("bank_account[routing_number]","110000000");
    rest.AddQueryParam("bank_account[account_number]","000123456789");

    String strResponseBody = rest.fullRequestFormUrlEncoded("POST","/v1/tokens");
    if (rest.get_LastMethodSuccess() != true) {
        System.out.println(rest.lastErrorText());
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    jsonResponse.Load(strResponseBody);

    String id;
    String object;
    String bank_accountId;
    String bank_accountObject;
    String bank_accountAccount_holder_name;
    String bank_accountAccount_holder_type;
    String bank_accountBank_name;
    String bank_accountCountry;
    String bank_accountCurrency;
    String bank_accountFingerprint;
    String bank_accountLast4;
    String bank_accountRouting_number;
    String bank_accountStatus;
    boolean client_ip;
    int created;
    boolean livemode;
    String type;
    boolean used;

    id = jsonResponse.stringOf("id");
    object = jsonResponse.stringOf("object");
    bank_accountId = jsonResponse.stringOf("bank_account.id");
    bank_accountObject = jsonResponse.stringOf("bank_account.object");
    bank_accountAccount_holder_name = jsonResponse.stringOf("bank_account.account_holder_name");
    bank_accountAccount_holder_type = jsonResponse.stringOf("bank_account.account_holder_type");
    bank_accountBank_name = jsonResponse.stringOf("bank_account.bank_name");
    bank_accountCountry = jsonResponse.stringOf("bank_account.country");
    bank_accountCurrency = jsonResponse.stringOf("bank_account.currency");
    bank_accountFingerprint = jsonResponse.stringOf("bank_account.fingerprint");
    bank_accountLast4 = jsonResponse.stringOf("bank_account.last4");
    bank_accountRouting_number = jsonResponse.stringOf("bank_account.routing_number");
    bank_accountStatus = jsonResponse.stringOf("bank_account.status");
    client_ip = jsonResponse.IsNullOf("client_ip");
    created = jsonResponse.IntOf("created");
    livemode = jsonResponse.BoolOf("livemode");
    type = jsonResponse.stringOf("type");
    used = jsonResponse.BoolOf("used");
  }
}

Sample JSON Response Body

{
  "id": "btok_1BnETKGswQrCoh0X86abg4gM",
  "object": "token",
  "bank_account": {
    "id": "ba_1BnETKGswQrCoh0XptCSwzal",
    "object": "bank_account",
    "account_holder_name": "Jane Austen",
    "account_holder_type": "individual",
    "bank_name": "STRIPE TEST BANK",
    "country": "US",
    "currency": "usd",
    "fingerprint": "L2j4aSuWk1MZMDZ5",
    "last4": "6789",
    "routing_number": "110000000",
    "status": "new"
  },
  "client_ip": null,
  "created": 1516662782,
  "livemode": false,
  "type": "bank_account",
  "used": false
}