DataFlex Requires Chilkat v11.7.0+
DataFlex
Stripe: Preview a plan or seat change
See more Stripe Examples
Preview a seat or plan change and display its proration lines, total, and the timestamp to retain with the quote.
Stripe documentation and cURL example
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
String sApiKey
Handle hoCurl
Handle hoCmd
Variant vJson
Handle hoJson
Integer iReplaced
String sSubscriptionId
String sItemId
String sPriceId
Handle hoNow
String sProrationDate
Integer i
String sTemp1
String sTemp2
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
Move "YOUR_STRIPE_TEST_KEY" To sApiKey
Get Create (RefClass(cComChilkatHttpCurl)) To hoCurl
If (Not(IsComObjectCreated(hoCurl))) Begin
Send CreateComObject of hoCurl
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoCmd
If (Not(IsComObjectCreated(hoCmd))) Begin
Send CreateComObject of hoCmd
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Move "sub_FROM_ACCOUNT" To sSubscriptionId
Move "si_SELECTED_ITEM" To sItemId
Move "price_FROM_CATALOG" To sPriceId
Get Create (RefClass(cComCkDateTime)) To hoNow
If (Not(IsComObjectCreated(hoNow))) Begin
Send CreateComObject of hoNow
End
Get ComSetFromCurrentSystemTime Of hoNow To iSuccess
Get ComGetAsUnixTimeStr Of hoNow False To sProrationDate
// curl -X POST "https://api.stripe.com/v1/invoices/create_preview" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive" \
// -d "subscription={subscriptionId}" \
// -d "subscription_details[items][0][id]={itemId}" \
// -d "subscription_details[items][0][price]={priceId}" \
// -d "subscription_details[items][0][quantity]=5" \
// -d "subscription_details[proration_behavior]=create_prorations" \
// -d "subscription_details[proration_date]={prorationDate}"
Get ComSetString Of hoCmd 'curl -X POST "https://api.stripe.com/v1/invoices/create_preview"' To iSuccess
Get ComAppend Of hoCmd ' -u "@KEY@:"' To iSuccess
Get ComAppend Of hoCmd ' -H "Stripe-Version: 2026-10-28.endive"' To iSuccess
Get ComAppend Of hoCmd ' -d "subscription=@SUB@"' To iSuccess
Get ComAppend Of hoCmd ' -d "subscription_details[items][0][id]=@ITEM@"' To iSuccess
Get ComAppend Of hoCmd ' -d "subscription_details[items][0][price]=@PRICE@"' To iSuccess
Get ComAppend Of hoCmd ' -d "subscription_details[items][0][quantity]=5"' To iSuccess
Get ComAppend Of hoCmd ' -d "subscription_details[proration_behavior]=create_prorations"' To iSuccess
Get ComAppend Of hoCmd ' -d "subscription_details[proration_date]=@DATE@"' To iSuccess
Get ComReplace Of hoCmd "@SUB@" sSubscriptionId To iReplaced
Get ComReplace Of hoCmd "@ITEM@" sItemId To iReplaced
Get ComReplace Of hoCmd "@PRICE@" sPriceId To iReplaced
Get ComReplace Of hoCmd "@DATE@" sProrationDate To iReplaced
Get ComReplace Of hoCmd "@KEY@" sApiKey To iReplaced
Get ComGetAsString Of hoCmd To sTemp1
Get ComDoYourThing Of hoCurl sTemp1 To iSuccess
If (iSuccess <> True) Begin
Get ComFailReason Of hoCurl To iTemp1
Showln "No HTTP response. Chilkat failure code: " iTemp1
Procedure_Return
End
Get pvComObject of hoJson to vJson
Get ComGetResponseJson Of hoCurl vJson To iSuccess
Get ComStatusCode Of hoCurl To iTemp1
If ((iTemp1 <> 200) Or (iSuccess <> True)) Begin
Get ComStatusCode Of hoCurl To iTemp1
Get ComGetResponseHeaderField Of hoCurl "Request-Id" To sTemp1
Showln "Stripe HTTP " iTemp1 " Request-Id: " sTemp1
If (iSuccess = True) Begin
Get ComStringOf Of hoJson "error.message" To sTemp1
Showln sTemp1
End
Procedure_Return
End
Get ComStringOf Of hoJson "total" To sTemp1
Showln "total = " sTemp1
Get ComStringOf Of hoJson "currency" To sTemp1
Showln "currency = " sTemp1
Showln "Save this preview time with the selected changes: " sProrationDate
Move 0 To i
While (i < (ComSizeOfArray(hoJson, "lines.data")))
Set ComI Of hoJson To i
Get ComBoolOf Of hoJson "lines.data[i].parent.subscription_item_details.proration" To bTemp1
If (bTemp1 = True) Begin
Get ComStringOf Of hoJson "lines.data[i].description" To sTemp1
Get ComStringOf Of hoJson "lines.data[i].amount" To sTemp2
Showln sTemp1 " " sTemp2
End
Move (i + 1) To i
Loop
Get ComBoolOf Of hoJson "lines.has_more" To bTemp1
If (bTemp1 = True) Begin
Showln "Only the first page of preview lines is shown. The total covers all lines."
End
End_Procedure