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

Stripe: Show available and pending balances by currency

See more Stripe Examples

Read the available and pending account balances for every currency returned by Stripe.

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]

#  curl -X GET "https://api.stripe.com/v1/balance" \
#    -u "$STRIPE_API_KEY:" \
#    -H "Stripe-Version: 2026-10-28.endive"
CkStringBuilder_SetString $cmd "curl -X GET \"https://api.stripe.com/v1/balance\""
CkStringBuilder_Append $cmd " -u \"@KEY@:\""
CkStringBuilder_Append $cmd " -H \"Stripe-Version: 2026-10-28.endive\""
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
    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
    exit
}

#  Amounts are integer minor units. Read them as text to preserve large balances.

set availableIndex 0
while {$availableIndex < [CkJsonObject_SizeOfArray $json "available"]} {
    CkJsonObject_put_I $json $availableIndex
    puts "available: [CkJsonObject_stringOf $json {available[i].amount}] [CkJsonObject_stringOf $json {available[i].currency}]"
    set availableIndex [expr $availableIndex + 1]
}

set pendingIndex 0
while {$pendingIndex < [CkJsonObject_SizeOfArray $json "pending"]} {
    CkJsonObject_put_I $json $pendingIndex
    puts "pending: [CkJsonObject_stringOf $json {pending[i].amount}] [CkJsonObject_stringOf $json {pending[i].currency}]"
    set pendingIndex [expr $pendingIndex + 1]
}

delete_CkHttpCurl $curl
delete_CkStringBuilder $cmd
delete_CkJsonObject $json