Swift Stripe: List Balance History

Back to Index

Returns a list of transactions that have contributed to the Stripe account balance (e.g., charges, transfers, and so forth). The transactions are returned in sorted order, with the most recent transactions appearing first.

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

CURL Command

curl https://api.stripe.com/v1/balance/history?limit=3 \
   -u STRIPE_SECRET_KEY: \
   -G

Swift Example


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

    //  URL: https://api.stripe.com/v1/balance/history?limit=3
    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/history?limit=3", sb: sbResponseBody)
    if success != true {
        print("\(rest.LastErrorText)")
        return
    }

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

    var object: String?
    var url: String?
    var has_more: Bool
    var i: Int
    var count_i: Int
    var id: String?
    var amount: Int
    var available_on: Int
    var created: Int
    var currency: String?
    var description: Bool
    var exchange_rate: Bool
    var fee: Int
    var net: Int
    var source: String?
    var status: String?
    var type: String?
    var j: Int
    var count_j: Int

    object = jsonResponse.StringOf("object")
    url = jsonResponse.StringOf("url")
    has_more = jsonResponse.BoolOf("has_more")
    i = 0
    count_i = jsonResponse.SizeOfArray("data").integerValue
    while i < count_i {
        jsonResponse.I = i
        id = jsonResponse.StringOf("data[i].id")
        object = jsonResponse.StringOf("data[i].object")
        amount = jsonResponse.IntOf("data[i].amount").integerValue
        available_on = jsonResponse.IntOf("data[i].available_on").integerValue
        created = jsonResponse.IntOf("data[i].created").integerValue
        currency = jsonResponse.StringOf("data[i].currency")
        description = jsonResponse.IsNullOf("data[i].description")
        exchange_rate = jsonResponse.IsNullOf("data[i].exchange_rate")
        fee = jsonResponse.IntOf("data[i].fee").integerValue
        net = jsonResponse.IntOf("data[i].net").integerValue
        source = jsonResponse.StringOf("data[i].source")
        status = jsonResponse.StringOf("data[i].status")
        type = jsonResponse.StringOf("data[i].type")
        j = 0
        count_j = jsonResponse.SizeOfArray("data[i].fee_details").integerValue
        while j < count_j {
            jsonResponse.J = j
            j = j + 1
        }

        i = i + 1
    }


}

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/balance/history",
  "has_more": false,
  "data": [
    {
      "id": "txn_1BnETJGswQrCoh0XxO2tGYr7",
      "object": "balance_transaction",
      "amount": 100,
      "available_on": 1516662781,
      "created": 1516662781,
      "currency": "usd",
      "description": null,
      "exchange_rate": null,
      "fee": 0,
      "fee_details": [
      ],
      "net": 100,
      "source": "ch_1BnETJGswQrCoh0XTs0EERBj",
      "status": "pending",
      "type": "charge"
    }
  ]
}