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

Stripe: Identify the payment for a paid invoice

See more Stripe Examples

List the payments allocated to an invoice and identify a paid charge or PaymentIntent for refund.

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 invoiceId "in_FROM_BILLING_RECORD"

set pageSuffix [new_CkStringBuilder]

set more 1
set cursor ""
while {$more == 1} {
    #  curl -X GET "https://api.stripe.com/v1/invoice_payments?invoice={invoiceId}&limit=100" \
    #    -u "$STRIPE_API_KEY:" \
    #    -H "Stripe-Version: 2026-10-28.endive"
    CkStringBuilder_SetString $cmd "curl -X GET \"https://api.stripe.com/v1/invoice_payments?invoice=@ID@&limit=100@CURSOR@\""
    CkStringBuilder_Append $cmd " -u \"@KEY@:\""
    CkStringBuilder_Append $cmd " -H \"Stripe-Version: 2026-10-28.endive\""
    set replaced [CkStringBuilder_Replace $cmd "@CURSOR@" [CkStringBuilder_getAsString $pageSuffix]]
    set replaced [CkStringBuilder_Replace $cmd "@ID@" $invoiceId]
    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_CkStringBuilder $pageSuffix
        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_CkStringBuilder $pageSuffix
        exit
    }

    set i 0
    set count [CkJsonObject_SizeOfArray $json "data"]
    while {$i < $count} {
        CkJsonObject_put_I $json $i
        puts [CkJsonObject_stringOf $json {data[i].id}] | [CkJsonObject_stringOf $json {data[i].status}] | [CkJsonObject_stringOf $json {data[i].amount_paid}] | [CkJsonObject_stringOf $json {data[i].currency}] | [CkJsonObject_stringOf $json {data[i].payment.type}]
        if {[CkJsonObject_stringOf $json "data[i].payment.type"] == "payment_intent"} then {
            puts "  PaymentIntent: [CkJsonObject_stringOf $json {data[i].payment.payment_intent}]"
        }

        if {[CkJsonObject_stringOf $json "data[i].payment.type"] == "charge"} then {
            puts "  Charge: [CkJsonObject_stringOf $json {data[i].payment.charge}]"
        }

        set i [expr $i + 1]
    }
    set more [CkJsonObject_BoolOf $json "has_more"]
    if {$more == 1} then {
        set next [CkJsonObject_stringOf $json "data[i].id"]
        if {expr [$count < 1]  ||  [expr [$next == ""]  ||  [$next == $cursor]]} then {
            puts "Invalid pagination cursor."
            delete_CkHttpCurl $curl
            delete_CkStringBuilder $cmd
            delete_CkJsonObject $json
            delete_CkStringBuilder $pageSuffix
            exit
        }

        set cursor $next
        CkStringBuilder_SetString $pageSuffix "&starting_after="
        CkStringBuilder_Append $pageSuffix $cursor
    }

}

#  Select the paid allocation belonging to the order before issuing its refund.

delete_CkHttpCurl $curl
delete_CkStringBuilder $cmd
delete_CkJsonObject $json
delete_CkStringBuilder $pageSuffix