Sample code for 30+ languages & platforms
Swift Requires Chilkat v11.7.0+

Stripe: Review a customer's subscriptions

See more Stripe Examples

List a customer's subscriptions and inspect their items, prices, and seat counts.

Stripe documentation and cURL example

Chilkat Swift Downloads

Swift

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"

    let pageSuffix = CkoStringBuilder()!
    var more: Bool = true
    var cursor: String? = ""
    while (more == true) {
        //  curl -X GET "https://api.stripe.com/v1/subscriptions?customer={customerId}&status=all&limit=100" \
        //    -u "$STRIPE_API_KEY:" \
        //    -H "Stripe-Version: 2026-10-28.endive"
        cmd.setString(value: "curl -X GET \"https://api.stripe.com/v1/subscriptions?customer=@ID@&status=all&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: "@ID@", 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].status")!)")
            var j: Int = 0
            while (j < json.size(ofArray: "data[i].items.data").intValue) {
                json.j = j
                print("  Item \(json.string(of: "data[i].items.data[j].id")!)  price \(json.string(of: "data[i].items.data[j].price.id")!)  quantity \(json.string(of: "data[i].items.data[j].quantity")!)")
                j = j + 1
            }

            if json.bool(of: "data[i].items.has_more") == true {
                print("Additional items are available via /v1/subscription_items for this subscription.")
            }

            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)
        }

    }


}