PureBasic Requires Chilkat v11.7.0+
PureBasic
Stripe: Start a subscription billed by invoice
See more Stripe Examples
Start an invoice-billed subscription for an existing customer, using a recurring price and 30-day payment terms.
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"
; Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
operationId.s = "YOUR_SAVED_OPERATION_UUID"
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"
priceId.s = "price_FROM_CATALOG"
; Choose a recurring price. The customer pays the invoice under the agreed terms.
; curl -X POST "https://api.stripe.com/v1/subscriptions" \
; -u "$STRIPE_API_KEY:" \
; -H "Stripe-Version: 2026-10-28.endive" \
; -H "Idempotency-Key: {operationId}-subscription" \
; -d "customer={customerId}" \
; -d "items[0][price]={priceId}" \
; -d "items[0][quantity]=3" \
; -d "collection_method=send_invoice" \
; -d "days_until_due=30"
CkStringBuilder::ckSetString(cmd,"curl -X POST " + Chr(34) + "https://api.stripe.com/v1/subscriptions" + 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))
CkStringBuilder::ckAppend(cmd," -H " + Chr(34) + "Idempotency-Key: @OP@-subscription" + Chr(34))
CkStringBuilder::ckAppend(cmd," -d " + Chr(34) + "customer=@CUSTOMER@" + Chr(34))
CkStringBuilder::ckAppend(cmd," -d " + Chr(34) + "items[0][price]=@PRICE@" + Chr(34))
CkStringBuilder::ckAppend(cmd," -d " + Chr(34) + "items[0][quantity]=3" + Chr(34))
CkStringBuilder::ckAppend(cmd," -d " + Chr(34) + "collection_method=send_invoice" + Chr(34))
CkStringBuilder::ckAppend(cmd," -d " + Chr(34) + "days_until_due=30" + Chr(34))
replaced = CkStringBuilder::ckReplace(cmd,"@CUSTOMER@",customerId)
replaced = CkStringBuilder::ckReplace(cmd,"@PRICE@",priceId)
replaced = CkStringBuilder::ckReplace(cmd,"@OP@",operationId)
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)
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)
ProcedureReturn
EndIf
Debug "id = " + CkJsonObject::ckStringOf(json,"id")
Debug "status = " + CkJsonObject::ckStringOf(json,"status")
Debug "latest_invoice = " + CkJsonObject::ckStringOf(json,"latest_invoice")
; Save the subscription and invoice IDs. Read payment status from the invoice.
CkHttpCurl::ckDispose(curl)
CkStringBuilder::ckDispose(cmd)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure