C 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

C Example

#include <C_CkRest.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    const char *strResponseBody;
    HCkJsonObject jsonResponse;
    const char *id;
    const char *object;
    const char *bank_accountId;
    const char *bank_accountObject;
    const char *bank_accountAccount_holder_name;
    const char *bank_accountAccount_holder_type;
    const char *bank_accountBank_name;
    const char *bank_accountCountry;
    const char *bank_accountCurrency;
    const char *bank_accountFingerprint;
    const char *bank_accountLast4;
    const char *bank_accountRouting_number;
    const char *bank_accountStatus;
    BOOL client_ip;
    int created;
    BOOL livemode;
    const char *type;
    BOOL used;

    rest = CkRest_Create();

    //  URL: https://api.stripe.com/v1/tokens
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    CkRest_SetAuthBasic(rest,"STRIPE_SECRET_KEY","");

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

    strResponseBody = CkRest_fullRequestFormUrlEncoded(rest,"POST","/v1/tokens");
    if (CkRest_getLastMethodSuccess(rest) != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    jsonResponse = CkJsonObject_Create();
    CkJsonObject_Load(jsonResponse,strResponseBody);

    id = CkJsonObject_stringOf(jsonResponse,"id");
    object = CkJsonObject_stringOf(jsonResponse,"object");
    bank_accountId = CkJsonObject_stringOf(jsonResponse,"bank_account.id");
    bank_accountObject = CkJsonObject_stringOf(jsonResponse,"bank_account.object");
    bank_accountAccount_holder_name = CkJsonObject_stringOf(jsonResponse,"bank_account.account_holder_name");
    bank_accountAccount_holder_type = CkJsonObject_stringOf(jsonResponse,"bank_account.account_holder_type");
    bank_accountBank_name = CkJsonObject_stringOf(jsonResponse,"bank_account.bank_name");
    bank_accountCountry = CkJsonObject_stringOf(jsonResponse,"bank_account.country");
    bank_accountCurrency = CkJsonObject_stringOf(jsonResponse,"bank_account.currency");
    bank_accountFingerprint = CkJsonObject_stringOf(jsonResponse,"bank_account.fingerprint");
    bank_accountLast4 = CkJsonObject_stringOf(jsonResponse,"bank_account.last4");
    bank_accountRouting_number = CkJsonObject_stringOf(jsonResponse,"bank_account.routing_number");
    bank_accountStatus = CkJsonObject_stringOf(jsonResponse,"bank_account.status");
    client_ip = CkJsonObject_IsNullOf(jsonResponse,"client_ip");
    created = CkJsonObject_IntOf(jsonResponse,"created");
    livemode = CkJsonObject_BoolOf(jsonResponse,"livemode");
    type = CkJsonObject_stringOf(jsonResponse,"type");
    used = CkJsonObject_BoolOf(jsonResponse,"used");


    CkRest_Dispose(rest);
    CkJsonObject_Dispose(jsonResponse);

    }

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
}