Swift Stripe: Create a Bank Account

Back to Index

Creates a new bank account object.

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

CURL Command

curl https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources \
   -u STRIPE_SECRET_KEY: \
   -d source=btok_1BnETKGswQrCoh0X43GQEzjM \
   -X POST

Swift Example


func chilkatTest() {
    let rest = CkoRest()
    var success: Bool

    //  URL: https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources
    var bTls: Bool = true
    var port: Int = 443
    var bAutoReconnect: Bool = true
    success = rest.Connect("api.stripe.com", port: port, tls: bTls, autoReconnect: bAutoReconnect)
    if success != true {
        print("ConnectFailReason: \(rest.ConnectFailReason.integerValue)")
        print("\(rest.LastErrorText)")
        return
    }

    rest.SetAuthBasic("STRIPE_SECRET_KEY", password: "")

    rest.AddQueryParam("source", value: "btok_1BnETKGswQrCoh0X43GQEzjM")

    var strResponseBody: String? = rest.FullRequestFormUrlEncoded("POST", uriPath: "/v1/customers/cus_CBbg3iRMzWBjoe/sources")
    if rest.LastMethodSuccess != true {
        print("\(rest.LastErrorText)")
        return
    }

    let jsonResponse = CkoJsonObject()
    jsonResponse.Load(strResponseBody)

    var id: String?
    var object: String?
    var account: String?
    var account_holder_name: String?
    var account_holder_type: String?
    var bank_name: String?
    var country: String?
    var currency: String?
    var default_for_currency: Bool
    var fingerprint: String?
    var last4: String?
    var routing_number: String?
    var status: String?
    var customer: String?

    id = jsonResponse.StringOf("id")
    object = jsonResponse.StringOf("object")
    account = jsonResponse.StringOf("account")
    account_holder_name = jsonResponse.StringOf("account_holder_name")
    account_holder_type = jsonResponse.StringOf("account_holder_type")
    bank_name = jsonResponse.StringOf("bank_name")
    country = jsonResponse.StringOf("country")
    currency = jsonResponse.StringOf("currency")
    default_for_currency = jsonResponse.BoolOf("default_for_currency")
    fingerprint = jsonResponse.StringOf("fingerprint")
    last4 = jsonResponse.StringOf("last4")
    routing_number = jsonResponse.StringOf("routing_number")
    status = jsonResponse.StringOf("status")
    customer = jsonResponse.StringOf("customer")

}

Sample JSON Response Body

{
  "id": "ba_1BnETKGswQrCoh0XzgjB3t99",
  "object": "bank_account",
  "account": "acct_18qpKxGswQrCoh0X",
  "account_holder_name": "Jane Austen",
  "account_holder_type": "individual",
  "bank_name": "STRIPE TEST BANK",
  "country": "US",
  "currency": "usd",
  "default_for_currency": false,
  "fingerprint": "L2j4aSuWk1MZMDZ5",
  "last4": "6789",
  "metadata": {},
  "routing_number": "110000000",
  "status": "new",
  "customer": "cus_CBbg3iRMzWBjoe"
}