Sample code for 30+ languages & platforms
B4X Requires Chilkat v11.7.0+

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 B4X Downloads

B4X
Dim success As Boolean = False

'  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
'  Supply a restricted sandbox key from merchant-controlled configuration.
Dim apiKey As String = "YOUR_STRIPE_TEST_KEY"

Dim curl As ChilkatHttpCurl
curl.Initialize("curl")
Dim cmd As ChilkatStringBuilder
cmd.Initialize
Dim json As ChilkatJsonObject
json.Initialize

Dim replaced As Int

Dim subscriptionId As String = "sub_FROM_ACCOUNT"

Dim itemId As String = "si_SELECTED_ITEM"

Dim priceId As String = "price_FROM_CATALOG"

Dim now As ChilkatDateTime
now.Initialize
now.SetFromCurrentSystemTime
Dim prorationDate As String = now.GetAsUnixTimeStr(False)

'  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}"
cmd.SetString("curl -X POST " & Chr(34) & "https://api.stripe.com/v1/invoices/create_preview" & Chr(34))
cmd.Append(" -u " & Chr(34) & "@KEY@:" & Chr(34))
cmd.Append(" -H " & Chr(34) & "Stripe-Version: 2026-10-28.endive" & Chr(34))
cmd.Append(" -d " & Chr(34) & "subscription=@SUB@" & Chr(34))
cmd.Append(" -d " & Chr(34) & "subscription_details[items][0][id]=@ITEM@" & Chr(34))
cmd.Append(" -d " & Chr(34) & "subscription_details[items][0][price]=@PRICE@" & Chr(34))
cmd.Append(" -d " & Chr(34) & "subscription_details[items][0][quantity]=5" & Chr(34))
cmd.Append(" -d " & Chr(34) & "subscription_details[proration_behavior]=create_prorations" & Chr(34))
cmd.Append(" -d " & Chr(34) & "subscription_details[proration_date]=@DATE@" & Chr(34))
replaced = cmd.Replace("@SUB@", subscriptionId)
replaced = cmd.Replace("@ITEM@", itemId)
replaced = cmd.Replace("@PRICE@", priceId)
replaced = cmd.Replace("@DATE@", prorationDate)
replaced = cmd.Replace("@KEY@", apiKey)
success = curl.DoYourThing(cmd.GetAsString)
If success <> True Then
    Log("No HTTP response. Chilkat failure code: " & curl.FailReason)
    Return
End If

success = curl.GetResponseJson(json)
If (curl.StatusCode <> 200) Or (success <> True) Then
    Log("Stripe HTTP " & curl.StatusCode & "  Request-Id: " & curl.GetResponseHeaderField("Request-Id"))
    If success = True Then
        Log(json.StringOf("error.message"))
    End If

    Return
End If


Log("total = " & json.StringOf("total"))
Log("currency = " & json.StringOf("currency"))

Log("Save this preview time with the selected changes: " & prorationDate)
Dim i As Int = 0
Do While (i < json.SizeOfArray("lines.data"))
    json.I = i
    If json.BoolOf("lines.data[i].parent.subscription_item_details.proration") = True Then
        Log(json.StringOf("lines.data[i].description") & "  " & json.StringOf("lines.data[i].amount"))
    End If

    i = i + 1
Loop
If json.BoolOf("lines.has_more") = True Then
    Log("Only the first page of preview lines is shown. The total covers all lines.")
End If