PureBasic Requires Chilkat v11.7.0+
PureBasic
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 PureBasic Downloads
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttpCurl.pb"
Procedure ChilkatExample()
success.i = 0
; Requires an unlocked Chilkat bundle. See Global Unlock Sample.
; Supply a restricted sandbox key from merchant-controlled configuration.
apiKey.s = "YOUR_STRIPE_TEST_KEY"
curl.i = CkHttpCurl::ckCreate()
If curl.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
cmd.i = CkStringBuilder::ckCreate()
If cmd.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
replaced.i
customerId.s = "cus_FROM_BILLING_ACCOUNT"
pageSuffix.i = CkStringBuilder::ckCreate()
If pageSuffix.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
more.i = 1
cursor.s = ""
While (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"
CkStringBuilder::ckSetString(cmd,"curl -X GET " + Chr(34) + "https://api.stripe.com/v1/subscriptions?customer=@ID@&status=all&limit=100@CURSOR@" + Chr(34))
CkStringBuilder::ckAppend(cmd," -u " + Chr(34) + "@KEY@:" + Chr(34))
CkStringBuilder::ckAppend(cmd," -H " + Chr(34) + "Stripe-Version: 2026-10-28.endive" + Chr(34))
replaced = CkStringBuilder::ckReplace(cmd,"@CURSOR@",CkStringBuilder::ckGetAsString(pageSuffix))
replaced = CkStringBuilder::ckReplace(cmd,"@ID@",customerId)
replaced = CkStringBuilder::ckReplace(cmd,"@KEY@",apiKey)
success = CkHttpCurl::ckDoYourThing(curl,CkStringBuilder::ckGetAsString(cmd))
If success <> 1
Debug "No HTTP response. Chilkat failure code: " + Str(CkHttpCurl::ckFailReason(curl))
CkHttpCurl::ckDispose(curl)
CkStringBuilder::ckDispose(cmd)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(pageSuffix)
ProcedureReturn
EndIf
success = CkHttpCurl::ckGetResponseJson(curl,json)
If (CkHttpCurl::ckStatusCode(curl) <> 200) OR (success <> 1)
Debug "Stripe HTTP " + Str(CkHttpCurl::ckStatusCode(curl)) + " Request-Id: " + CkHttpCurl::ckGetResponseHeaderField(curl,"Request-Id")
If success = 1
Debug CkJsonObject::ckStringOf(json,"error.message")
EndIf
CkHttpCurl::ckDispose(curl)
CkStringBuilder::ckDispose(cmd)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(pageSuffix)
ProcedureReturn
EndIf
i.i = 0
count.i = CkJsonObject::ckSizeOfArray(json,"data")
While (i < count)
CkJsonObject::setCkI(json, i)
Debug CkJsonObject::ckStringOf(json,"data[i].id") + " | " + CkJsonObject::ckStringOf(json,"data[i].status")
j.i = 0
While (j < CkJsonObject::ckSizeOfArray(json,"data[i].items.data"))
CkJsonObject::setCkJ(json, j)
Debug " Item " + CkJsonObject::ckStringOf(json,"data[i].items.data[j].id") + " price " + CkJsonObject::ckStringOf(json,"data[i].items.data[j].price.id") + " quantity " + CkJsonObject::ckStringOf(json,"data[i].items.data[j].quantity")
j = j + 1
Wend
If CkJsonObject::ckBoolOf(json,"data[i].items.has_more") = 1
Debug "Additional items are available via /v1/subscription_items for this subscription."
EndIf
i = i + 1
Wend
more = CkJsonObject::ckBoolOf(json,"has_more")
If more = 1
next.s = CkJsonObject::ckStringOf(json,"data[i].id")
If (count < 1) OR (next = "") OR (next = cursor)
Debug "Invalid pagination cursor."
CkHttpCurl::ckDispose(curl)
CkStringBuilder::ckDispose(cmd)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(pageSuffix)
ProcedureReturn
EndIf
cursor = next
CkStringBuilder::ckSetString(pageSuffix,"&starting_after=")
CkStringBuilder::ckAppend(pageSuffix,cursor)
EndIf
Wend
CkHttpCurl::ckDispose(curl)
CkStringBuilder::ckDispose(cmd)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(pageSuffix)
ProcedureReturn
EndProcedure