PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
string ls_ApiKey
oleobject loo_Curl
oleobject loo_Cmd
oleobject loo_Json
long li_Replaced
string ls_SubscriptionId
string ls_ItemId
string ls_PriceId
oleobject loo_Now
string ls_ProrationDate
long i
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_SubscriptionId = "sub_FROM_ACCOUNT"
ls_ItemId = "si_SELECTED_ITEM"
ls_PriceId = "price_FROM_CATALOG"
loo_Now = create oleobject
li_rc = loo_Now.ConnectToNewObject("Chilkat.CkDateTime")
loo_Now.SetFromCurrentSystemTime()
ls_ProrationDate = loo_Now.GetAsUnixTimeStr(0)
// 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}"
loo_Cmd.SetString("curl -X POST ~"https://api.stripe.com/v1/invoices/create_preview~"")
loo_Cmd.Append(" -u ~"@KEY@:~"")
loo_Cmd.Append(" -H ~"Stripe-Version: 2026-10-28.endive~"")
loo_Cmd.Append(" -d ~"subscription=@SUB@~"")
loo_Cmd.Append(" -d ~"subscription_details[items][0][id]=@ITEM@~"")
loo_Cmd.Append(" -d ~"subscription_details[items][0][price]=@PRICE@~"")
loo_Cmd.Append(" -d ~"subscription_details[items][0][quantity]=5~"")
loo_Cmd.Append(" -d ~"subscription_details[proration_behavior]=create_prorations~"")
loo_Cmd.Append(" -d ~"subscription_details[proration_date]=@DATE@~"")
li_Replaced = loo_Cmd.Replace("@SUB@",ls_SubscriptionId)
li_Replaced = loo_Cmd.Replace("@ITEM@",ls_ItemId)
li_Replaced = loo_Cmd.Replace("@PRICE@",ls_PriceId)
li_Replaced = loo_Cmd.Replace("@DATE@",ls_ProrationDate)
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_Now
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_Now
return
end if
Write-Debug "total = " + loo_Json.StringOf("total")
Write-Debug "currency = " + loo_Json.StringOf("currency")
Write-Debug "Save this preview time with the selected changes: " + ls_ProrationDate
i = 0
do while (i < loo_Json.SizeOfArray("lines.data"))
loo_Json.I = i
if loo_Json.BoolOf("lines.data[i].parent.subscription_item_details.proration") = 1 then
Write-Debug loo_Json.StringOf("lines.data[i].description") + " " + loo_Json.StringOf("lines.data[i].amount")
end if
i = i + 1
loop
if loo_Json.BoolOf("lines.has_more") = 1 then
Write-Debug "Only the first page of preview lines is shown. The total covers all lines."
end if
destroy loo_Curl
destroy loo_Cmd
destroy loo_Json
destroy loo_Now