Swift Requires Chilkat v11.7.0+
Swift
Stripe: Review invoices and outstanding amounts
See more Stripe Examples
List open invoices for a billing account and show outstanding amounts, due dates, and invoice links.
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
var customerId: String? = "cus_FROM_BILLING_ACCOUNT"
// Remove status=open to show all invoice states.
let pageSuffix = CkoStringBuilder()!
var more: Bool = true
var cursor: String? = ""
while (more == true) {
// curl -X GET "https://api.stripe.com/v1/invoices?customer={customerId}&status=open&limit=100" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive"
cmd.setString(value: "curl -X GET \"https://api.stripe.com/v1/invoices?customer=@CUSTOMER@&status=open&limit=100@CURSOR@\"")
cmd.append(value: " -u \"@KEY@:\"")
cmd.append(value: " -H \"Stripe-Version: 2026-10-28.endive\"")
replaced = cmd.replace(value: "@CURSOR@", replacement: pageSuffix.getAsString()).intValue
replaced = cmd.replace(value: "@CUSTOMER@", replacement: customerId).intValue
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
}
var i: Int = 0
var count: Int = json.size(ofArray: "data").intValue
while (i < count) {
json.i = i
print("\(json.string(of: "data[i].id")!) | \(json.string(of: "data[i].number")!) | \(json.string(of: "data[i].status")!) | \(json.string(of: "data[i].due_date")!) | \(json.string(of: "data[i].amount_remaining")!) | \(json.string(of: "data[i].currency")!) | \(json.string(of: "data[i].hosted_invoice_url")!) | \(json.string(of: "data[i].invoice_pdf")!)")
i = i + 1
}
more = json.bool(of: "has_more")
if more == true {
var next: String? = json.string(of: "data[i].id")
if (count < 1) || (next == "") || (next == cursor) {
print("Invalid pagination cursor.")
return
}
cursor = next
pageSuffix.setString(value: "&starting_after=")
pageSuffix.append(value: cursor)
}
}
}