Swift Requires Chilkat v11.7.0+
Swift
Stripe: Show available and pending balances by currency
See more Stripe Examples
Read the available and pending account balances for every currency returned by Stripe.
Stripe documentation and cURL example
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
var apiKey: String? = "YOUR_STRIPE_TEST_KEY"
let curl = CkoHttpCurl()!
let cmd = CkoStringBuilder()!
let json = CkoJsonObject()!
var replaced: Int
// curl -X GET "https://api.stripe.com/v1/balance" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive"
cmd.setString(value: "curl -X GET \"https://api.stripe.com/v1/balance\"")
cmd.append(value: " -u \"@KEY@:\"")
cmd.append(value: " -H \"Stripe-Version: 2026-10-28.endive\"")
replaced = cmd.replace(value: "@KEY@", replacement: apiKey).intValue
success = curl.doYourThing(targetCurl: cmd.getAsString())
if success != true {
print("No HTTP response. Chilkat failure code: \(curl.failReason.intValue)")
return
}
success = curl.getResponseJson(json: json)
if (curl.statusCode.intValue != 200) || (success != true) {
print("Stripe HTTP \(curl.statusCode.intValue) Request-Id: \(curl.getResponseHeaderField(name: "Request-Id")!)")
if success == true {
print("\(json.string(of: "error.message")!)")
}
return
}
// Amounts are integer minor units. Read them as text to preserve large balances.
var availableIndex: Int = 0
while (availableIndex < json.size(ofArray: "available").intValue) {
json.i = availableIndex
print("available: \(json.string(of: "available[i].amount")!) \(json.string(of: "available[i].currency")!)")
availableIndex = availableIndex + 1
}
var pendingIndex: Int = 0
while (pendingIndex < json.size(ofArray: "pending").intValue) {
json.i = pendingIndex
print("pending: \(json.string(of: "pending[i].amount")!) \(json.string(of: "pending[i].currency")!)")
pendingIndex = pendingIndex + 1
}
}