SQL Server 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

SQL Server Example

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --  URL: https://api.stripe.com/v1/tokens
    DECLARE @bTls int
    SELECT @bTls = 1
    DECLARE @port int
    SELECT @port = 443
    DECLARE @bAutoReconnect int
    SELECT @bAutoReconnect = 1
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'api.stripe.com', STR(@port), STR(@bTls), STR(@bAutoReconnect)
    IF STR(@success) <> 1
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
        PRINT 'ConnectFailReason: ' + @iTmp0
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    EXEC sp_OAMethod @rest, 'SetAuthBasic', @success OUT, 'STRIPE_SECRET_KEY', ''

    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'bank_account[country]', 'US'
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'bank_account[currency]', 'usd'
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'bank_account[account_holder_name]', 'Chloe White'
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'bank_account[account_holder_type]', 'individual'
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'bank_account[routing_number]', '110000000'
    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'bank_account[account_number]', '000123456789'

    DECLARE @strResponseBody nvarchar(4000)
    EXEC sp_OAMethod @rest, 'FullRequestFormUrlEncoded', @strResponseBody OUT, 'POST', '/v1/tokens'
    EXEC sp_OAGetProperty @rest, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    DECLARE @jsonResponse int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jsonResponse OUT

    EXEC sp_OAMethod @jsonResponse, 'Load', @success OUT, @strResponseBody

    DECLARE @id nvarchar(4000)

    DECLARE @object nvarchar(4000)

    DECLARE @bank_accountId nvarchar(4000)

    DECLARE @bank_accountObject nvarchar(4000)

    DECLARE @bank_accountAccount_holder_name nvarchar(4000)

    DECLARE @bank_accountAccount_holder_type nvarchar(4000)

    DECLARE @bank_accountBank_name nvarchar(4000)

    DECLARE @bank_accountCountry nvarchar(4000)

    DECLARE @bank_accountCurrency nvarchar(4000)

    DECLARE @bank_accountFingerprint nvarchar(4000)

    DECLARE @bank_accountLast4 nvarchar(4000)

    DECLARE @bank_accountRouting_number nvarchar(4000)

    DECLARE @bank_accountStatus nvarchar(4000)

    DECLARE @client_ip int

    DECLARE @created int

    DECLARE @livemode int

    DECLARE @type nvarchar(4000)

    DECLARE @used int

    EXEC sp_OAMethod @jsonResponse, 'StringOf', @id OUT, 'id'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @object OUT, 'object'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @bank_accountId OUT, 'bank_account.id'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @bank_accountObject OUT, 'bank_account.object'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @bank_accountAccount_holder_name OUT, 'bank_account.account_holder_name'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @bank_accountAccount_holder_type OUT, 'bank_account.account_holder_type'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @bank_accountBank_name OUT, 'bank_account.bank_name'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @bank_accountCountry OUT, 'bank_account.country'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @bank_accountCurrency OUT, 'bank_account.currency'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @bank_accountFingerprint OUT, 'bank_account.fingerprint'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @bank_accountLast4 OUT, 'bank_account.last4'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @bank_accountRouting_number OUT, 'bank_account.routing_number'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @bank_accountStatus OUT, 'bank_account.status'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @client_ip OUT, 'client_ip'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @created OUT, 'created'
    EXEC sp_OAMethod @jsonResponse, 'BoolOf', @livemode OUT, 'livemode'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @type OUT, 'type'
    EXEC sp_OAMethod @jsonResponse, 'BoolOf', @used OUT, 'used'

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @jsonResponse


END
GO

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
}