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

Stripe: Issue a full or partial refund

See more Stripe Examples

Issue a partial refund against a selected payment, or refund the remaining amount by omitting the amount field.

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"
#  Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
set operationId "YOUR_SAVED_OPERATION_UUID"

set curl [new_CkHttpCurl]

set cmd [new_CkStringBuilder]

set json [new_CkJsonObject]

set paymentIntent "pi_FROM_SELECTED_PAYMENT"

#  The operator selected a partial refund of 500 minor units. Omit the amount field to refund the remaining balance. For a charge ID use charge= instead of payment_intent=.

#  curl -X POST "https://api.stripe.com/v1/refunds" \
#    -u "$STRIPE_API_KEY:" \
#    -H "Stripe-Version: 2026-10-28.endive" \
#    -H "Idempotency-Key: {operationId}-refund" \
#    -d "payment_intent={paymentIntent}" \
#    -d "amount=500"
CkStringBuilder_SetString $cmd "curl -X POST \"https://api.stripe.com/v1/refunds\""
CkStringBuilder_Append $cmd " -u \"@KEY@:\""
CkStringBuilder_Append $cmd " -H \"Stripe-Version: 2026-10-28.endive\""
CkStringBuilder_Append $cmd " -H \"Idempotency-Key: @OP@-refund\""
CkStringBuilder_Append $cmd " -d \"payment_intent=@PAYMENT@\""
CkStringBuilder_Append $cmd " -d \"amount=500\""
set replaced [CkStringBuilder_Replace $cmd "@PAYMENT@" $paymentIntent]
set replaced [CkStringBuilder_Replace $cmd "@OP@" $operationId]
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
}

puts "id = [CkJsonObject_stringOf $json id]"
puts "status = [CkJsonObject_stringOf $json status]"
puts "amount = [CkJsonObject_stringOf $json amount]"
puts "currency = [CkJsonObject_stringOf $json currency]"

#  Save this refund ID with the refund request for status checks.

delete_CkHttpCurl $curl
delete_CkStringBuilder $cmd
delete_CkJsonObject $json