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

Tcl

load ./chilkat.dll

set success 0

#  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
#  Supply a restricted sandbox key from merchant-controlled configuration.
set apiKey "YOUR_STRIPE_TEST_KEY"

set curl [new_CkHttpCurl]

set cmd [new_CkStringBuilder]

set json [new_CkJsonObject]

set subscriptionId "sub_FROM_ACCOUNT"

set itemId "si_SELECTED_ITEM"

set priceId "price_FROM_CATALOG"

set now [new_CkDateTime]

CkDateTime_SetFromCurrentSystemTime $now
set prorationDate [CkDateTime_getAsUnixTimeStr $now 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}"
CkStringBuilder_SetString $cmd "curl -X POST \"https://api.stripe.com/v1/invoices/create_preview\""
CkStringBuilder_Append $cmd " -u \"@KEY@:\""
CkStringBuilder_Append $cmd " -H \"Stripe-Version: 2026-10-28.endive\""
CkStringBuilder_Append $cmd " -d \"subscription=@SUB@\""
CkStringBuilder_Append $cmd " -d \"subscription_details[items][0][id]=@ITEM@\""
CkStringBuilder_Append $cmd " -d \"subscription_details[items][0][price]=@PRICE@\""
CkStringBuilder_Append $cmd " -d \"subscription_details[items][0][quantity]=5\""
CkStringBuilder_Append $cmd " -d \"subscription_details[proration_behavior]=create_prorations\""
CkStringBuilder_Append $cmd " -d \"subscription_details[proration_date]=@DATE@\""
set replaced [CkStringBuilder_Replace $cmd "@SUB@" $subscriptionId]
set replaced [CkStringBuilder_Replace $cmd "@ITEM@" $itemId]
set replaced [CkStringBuilder_Replace $cmd "@PRICE@" $priceId]
set replaced [CkStringBuilder_Replace $cmd "@DATE@" $prorationDate]
set replaced [CkStringBuilder_Replace $cmd "@KEY@" $apiKey]
set success [CkHttpCurl_DoYourThing $curl [CkStringBuilder_getAsString $cmd]]
if {$success != 1} then {
    puts "No HTTP response. Chilkat failure code: [CkHttpCurl_get_FailReason $curl]"
    delete_CkHttpCurl $curl
    delete_CkStringBuilder $cmd
    delete_CkJsonObject $json
    delete_CkDateTime $now
    exit
}

set success [CkHttpCurl_GetResponseJson $curl $json]
if {expr [[CkHttpCurl_get_StatusCode $curl] != 200]  ||  [$success != 1]} then {
    puts "Stripe HTTP [CkHttpCurl_get_StatusCode $curl]  Request-Id: [CkHttpCurl_getResponseHeaderField $curl Request-Id]"
    if {$success == 1} then {
        puts [CkJsonObject_stringOf $json error.message]
    }

    delete_CkHttpCurl $curl
    delete_CkStringBuilder $cmd
    delete_CkJsonObject $json
    delete_CkDateTime $now
    exit
}

puts "total = [CkJsonObject_stringOf $json total]"
puts "currency = [CkJsonObject_stringOf $json currency]"

puts "Save this preview time with the selected changes: $prorationDate"
set i 0
while {$i < [CkJsonObject_SizeOfArray $json "lines.data"]} {
    CkJsonObject_put_I $json $i
    if {[CkJsonObject_BoolOf $json "lines.data[i].parent.subscription_item_details.proration"] == 1} then {
        puts [CkJsonObject_stringOf $json {lines.data[i].description}]  [CkJsonObject_stringOf $json {lines.data[i].amount}]
    }

    set i [expr $i + 1]
}
if {[CkJsonObject_BoolOf $json "lines.has_more"] == 1} then {
    puts "Only the first page of preview lines is shown. The total covers all lines."
}


delete_CkHttpCurl $curl
delete_CkStringBuilder $cmd
delete_CkJsonObject $json
delete_CkDateTime $now