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

Xbase++
LOCAL nSuccess
LOCAL cApiKey
LOCAL cOperationId
LOCAL oCurl
LOCAL oCmd
LOCAL oJson
LOCAL nReplaced
LOCAL cPaymentIntent

nSuccess := 0

//  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
//  Supply a restricted sandbox key from merchant-controlled configuration.
cApiKey := "YOUR_STRIPE_TEST_KEY"
//  Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
cOperationId := "YOUR_SAVED_OPERATION_UUID"

oCurl := CreateObject("Chilkat.HttpCurl")
oCmd := CreateObject("Chilkat.StringBuilder")
oJson := CreateObject("Chilkat.JsonObject")

cPaymentIntent := "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"
oCmd:SetString('curl -X POST "https://api.stripe.com/v1/refunds"')
oCmd:Append(' -u "@KEY@:"')
oCmd:Append(' -H "Stripe-Version: 2026-10-28.endive"')
oCmd:Append(' -H "Idempotency-Key: @OP@-refund"')
oCmd:Append(' -d "payment_intent=@PAYMENT@"')
oCmd:Append(' -d "amount=500"')
nReplaced := oCmd:Replace("@PAYMENT@", cPaymentIntent)
nReplaced := oCmd:Replace("@OP@", cOperationId)
nReplaced := oCmd:Replace("@KEY@", cApiKey)
nSuccess := oCurl:DoYourThing(oCmd:GetAsString())
IF (nSuccess != 1)
    ? "No HTTP response. Chilkat failure code: " + Str(oCurl:FailReason)
    oCurl:destroy()
    oCmd:destroy()
    oJson:destroy()
    RETURN
ENDIF

nSuccess := oCurl:GetResponseJson(oJson)
IF ((oCurl:StatusCode != 200) .OR. (nSuccess != 1))
    ? "Stripe HTTP " + Str(oCurl:StatusCode) + "  Request-Id: " + oCurl:GetResponseHeaderField("Request-Id")
    IF (nSuccess == 1)
        ? oJson:StringOf("error.message")
    ENDIF

    oCurl:destroy()
    oCmd:destroy()
    oJson:destroy()
    RETURN
ENDIF

? "id = " + oJson:StringOf("id")
? "status = " + oJson:StringOf("status")
? "amount = " + oJson:StringOf("amount")
? "currency = " + oJson:StringOf("currency")

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

oCurl:destroy()
oCmd:destroy()
oJson:destroy()