Sample code for 30+ languages & platforms
Xojo Plugin 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 Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

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

Dim curl As New Chilkat.HttpCurl
Dim cmd As New Chilkat.StringBuilder
Dim json As New Chilkat.JsonObject

Dim replaced As Int32

Dim subscriptionId As String
subscriptionId = "sub_FROM_ACCOUNT"

Dim itemId As String
itemId = "si_SELECTED_ITEM"

Dim priceId As String
priceId = "price_FROM_CATALOG"

Dim now As New Chilkat.CkDateTime
success = now.SetFromCurrentSystemTime()
Dim prorationDate As String
prorationDate = 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}"
success = cmd.SetString("curl -X POST ""https://api.stripe.com/v1/invoices/create_preview""")
success = cmd.Append(" -u ""@KEY@:""")
success = cmd.Append(" -H ""Stripe-Version: 2026-10-28.endive""")
success = cmd.Append(" -d ""subscription=@SUB@""")
success = cmd.Append(" -d ""subscription_details[items][0][id]=@ITEM@""")
success = cmd.Append(" -d ""subscription_details[items][0][price]=@PRICE@""")
success = cmd.Append(" -d ""subscription_details[items][0][quantity]=5""")
success = cmd.Append(" -d ""subscription_details[proration_behavior]=create_prorations""")
success = cmd.Append(" -d ""subscription_details[proration_date]=@DATE@""")
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
    System.DebugLog("No HTTP response. Chilkat failure code: " + Str(curl.FailReason))
    Return
End If

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

    Return
End If

System.DebugLog("total = " + json.StringOf("total"))
System.DebugLog("currency = " + json.StringOf("currency"))

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

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