Swift Stripe: Retrieve Balance

Back to Index

Retrieves the current account balance, based on the authentication that was used to make the request.

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

CURL Command

curl https://api.stripe.com/v1/balance \
   -u STRIPE_SECRET_KEY:

Swift Example


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

    //  URL: https://api.stripe.com/v1/balance
    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: "")

    let sbResponseBody = CkoStringBuilder()
    success = rest.FullRequestNoBodySb("GET", uriPath: "/v1/balance", sb: sbResponseBody)
    if success != true {
        print("\(rest.LastErrorText)")
        return
    }

    let jsonResponse = CkoJsonObject()
    jsonResponse.LoadSb(sbResponseBody)

    var object: String?
    var livemode: Bool
    var i: Int
    var count_i: Int
    var currency: String?
    var amount: Int
    var source_typesCard: Int

    object = jsonResponse.StringOf("object")
    livemode = jsonResponse.BoolOf("livemode")
    i = 0
    count_i = jsonResponse.SizeOfArray("available").integerValue
    while i < count_i {
        jsonResponse.I = i
        currency = jsonResponse.StringOf("available[i].currency")
        amount = jsonResponse.IntOf("available[i].amount").integerValue
        source_typesCard = jsonResponse.IntOf("available[i].source_types.card").integerValue
        i = i + 1
    }

    i = 0
    count_i = jsonResponse.SizeOfArray("pending").integerValue
    while i < count_i {
        jsonResponse.I = i
        currency = jsonResponse.StringOf("pending[i].currency")
        amount = jsonResponse.IntOf("pending[i].amount").integerValue
        source_typesCard = jsonResponse.IntOf("pending[i].source_types.card").integerValue
        i = i + 1
    }


}

Sample JSON Response Body

{
  "object": "balance",
  "available": [
    {
      "currency": "usd",
      "amount": 0,
      "source_types": {
        "card": 0
      }
    }
  ],
  "livemode": false,
  "pending": [
    {
      "currency": "usd",
      "amount": 0,
      "source_types": {
        "card": 0
      }
    }
  ]
}