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

Delphi DLL
var
success: Boolean;
apiKey: PWideChar;
operationId: PWideChar;
curl: HCkHttpCurl;
cmd: HCkStringBuilder;
json: HCkJsonObject;
replaced: Integer;
paymentIntent: PWideChar;

begin
success := False;

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

curl := CkHttpCurl_Create();
cmd := CkStringBuilder_Create();
json := CkJsonObject_Create();

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"');
replaced := CkStringBuilder_Replace(cmd,'@PAYMENT@',paymentIntent);
replaced := CkStringBuilder_Replace(cmd,'@OP@',operationId);
replaced := CkStringBuilder_Replace(cmd,'@KEY@',apiKey);
success := CkHttpCurl_DoYourThing(curl,CkStringBuilder__getAsString(cmd));
if (success <> True) then
  begin
    Memo1.Lines.Add('No HTTP response. Chilkat failure code: ' + IntToStr(CkHttpCurl_getFailReason(curl)));
    Exit;
  end;
success := CkHttpCurl_GetResponseJson(curl,json);
if ((CkHttpCurl_getStatusCode(curl) <> 200) or (success <> True)) then
  begin
    Memo1.Lines.Add('Stripe HTTP ' + IntToStr(CkHttpCurl_getStatusCode(curl)) + '  Request-Id: ' + CkHttpCurl__getResponseHeaderField(curl,'Request-Id'));
    if (success = True) then
      begin
        Memo1.Lines.Add(CkJsonObject__stringOf(json,'error.message'));
      end;
    Exit;
  end;

Memo1.Lines.Add('id = ' + CkJsonObject__stringOf(json,'id'));
Memo1.Lines.Add('status = ' + CkJsonObject__stringOf(json,'status'));
Memo1.Lines.Add('amount = ' + CkJsonObject__stringOf(json,'amount'));
Memo1.Lines.Add('currency = ' + CkJsonObject__stringOf(json,'currency'));

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

CkHttpCurl_Dispose(curl);
CkStringBuilder_Dispose(cmd);
CkJsonObject_Dispose(json);