Swift Stripe: Retrieve a Balance Transaction

Back to Index

Retrieves the balance transaction with the given ID.

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

CURL Command

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

Swift Example


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

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

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

    var id: String?
    var object: 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 i: Int
    var count_i: Int

    id = jsonResponse.StringOf("id")
    object = jsonResponse.StringOf("object")
    amount = jsonResponse.IntOf("amount").integerValue
    available_on = jsonResponse.IntOf("available_on").integerValue
    created = jsonResponse.IntOf("created").integerValue
    currency = jsonResponse.StringOf("currency")
    description = jsonResponse.IsNullOf("description")
    exchange_rate = jsonResponse.IsNullOf("exchange_rate")
    fee = jsonResponse.IntOf("fee").integerValue
    net = jsonResponse.IntOf("net").integerValue
    source = jsonResponse.StringOf("source")
    status = jsonResponse.StringOf("status")
    type = jsonResponse.StringOf("type")
    i = 0
    count_i = jsonResponse.SizeOfArray("fee_details").integerValue
    while i < count_i {
        jsonResponse.I = i
        i = i + 1
    }


}

Sample JSON Response Body

{
  "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"
}