Sample code for 30+ languages & platforms
PowerBuilder 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 PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
string ls_ApiKey
oleobject loo_Curl
oleobject loo_Cmd
oleobject loo_Json
long li_Replaced
string ls_CustomerId
oleobject loo_PageSuffix
long li_More
string ls_Cursor
long i
long li_Count
long j
string ls_Next

li_Success = 0

//  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
//  Supply a restricted sandbox key from merchant-controlled configuration.
ls_ApiKey = "YOUR_STRIPE_TEST_KEY"

loo_Curl = create oleobject
li_rc = loo_Curl.ConnectToNewObject("Chilkat.HttpCurl")
if li_rc < 0 then
    destroy loo_Curl
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Cmd = create oleobject
li_rc = loo_Cmd.ConnectToNewObject("Chilkat.StringBuilder")

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

ls_CustomerId = "cus_FROM_BILLING_ACCOUNT"

loo_PageSuffix = create oleobject
li_rc = loo_PageSuffix.ConnectToNewObject("Chilkat.StringBuilder")

li_More = 1
ls_Cursor = ""
do while (li_More = 1)
    //  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"
    loo_Cmd.SetString("curl -X GET ~"https://api.stripe.com/v1/subscriptions?customer=@ID@&status=all&limit=100@CURSOR@~"")
    loo_Cmd.Append(" -u ~"@KEY@:~"")
    loo_Cmd.Append(" -H ~"Stripe-Version: 2026-10-28.endive~"")
    li_Replaced = loo_Cmd.Replace("@CURSOR@",loo_PageSuffix.GetAsString())
    li_Replaced = loo_Cmd.Replace("@ID@",ls_CustomerId)
    li_Replaced = loo_Cmd.Replace("@KEY@",ls_ApiKey)
    li_Success = loo_Curl.DoYourThing(loo_Cmd.GetAsString())
    if li_Success <> 1 then
        Write-Debug "No HTTP response. Chilkat failure code: " + string(loo_Curl.FailReason)
        destroy loo_Curl
        destroy loo_Cmd
        destroy loo_Json
        destroy loo_PageSuffix
        return
    end if

    li_Success = loo_Curl.GetResponseJson(loo_Json)
    if (loo_Curl.StatusCode <> 200) OR (li_Success <> 1) then
        Write-Debug "Stripe HTTP " + string(loo_Curl.StatusCode) + "  Request-Id: " + loo_Curl.GetResponseHeaderField("Request-Id")
        if li_Success = 1 then
            Write-Debug loo_Json.StringOf("error.message")
        end if

        destroy loo_Curl
        destroy loo_Cmd
        destroy loo_Json
        destroy loo_PageSuffix
        return
    end if

    i = 0
    li_Count = loo_Json.SizeOfArray("data")
    do while (i < li_Count)
        loo_Json.I = i
        Write-Debug loo_Json.StringOf("data[i].id") + " | " + loo_Json.StringOf("data[i].status")
        j = 0
        do while (j < loo_Json.SizeOfArray("data[i].items.data"))
            loo_Json.J = j
            Write-Debug "  Item " + loo_Json.StringOf("data[i].items.data[j].id") + "  price " + loo_Json.StringOf("data[i].items.data[j].price.id") + "  quantity " + loo_Json.StringOf("data[i].items.data[j].quantity")
            j = j + 1
        loop
        if loo_Json.BoolOf("data[i].items.has_more") = 1 then
            Write-Debug "Additional items are available via /v1/subscription_items for this subscription."
        end if

        i = i + 1
    loop
    li_More = loo_Json.BoolOf("has_more")
    if li_More = 1 then
        ls_Next = loo_Json.StringOf("data[i].id")
        if (li_Count < 1) OR (ls_Next = "") OR (ls_Next = ls_Cursor) then
            Write-Debug "Invalid pagination cursor."
            destroy loo_Curl
            destroy loo_Cmd
            destroy loo_Json
            destroy loo_PageSuffix
            return
        end if

        ls_Cursor = ls_Next
        loo_PageSuffix.SetString("&starting_after=")
        loo_PageSuffix.Append(ls_Cursor)
    end if

loop


destroy loo_Curl
destroy loo_Cmd
destroy loo_Json
destroy loo_PageSuffix