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

Delphi DLL
var
success: Boolean;
apiKey: PWideChar;
curl: HCkHttpCurl;
cmd: HCkStringBuilder;
json: HCkJsonObject;
replaced: Integer;
invoiceId: PWideChar;
pageSuffix: HCkStringBuilder;
more: Boolean;
cursor: PWideChar;
i: Integer;
count: Integer;
next: 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';

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

invoiceId := 'in_FROM_BILLING_RECORD';

pageSuffix := CkStringBuilder_Create();
more := True;
cursor := '';
while (more = True) do
  begin
    //  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"');
    replaced := CkStringBuilder_Replace(cmd,'@CURSOR@',CkStringBuilder__getAsString(pageSuffix));
    replaced := CkStringBuilder_Replace(cmd,'@ID@',invoiceId);
    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;

    i := 0;
    count := CkJsonObject_SizeOfArray(json,'data');
    while (i < count) do
      begin
        CkJsonObject_putI(json,i);
        Memo1.Lines.Add(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
          begin
            Memo1.Lines.Add('  PaymentIntent: ' + CkJsonObject__stringOf(json,'data[i].payment.payment_intent'));
          end;
        if (CkJsonObject__stringOf(json,'data[i].payment.type') = 'charge') then
          begin
            Memo1.Lines.Add('  Charge: ' + CkJsonObject__stringOf(json,'data[i].payment.charge'));
          end;
        i := i + 1;
      end;

    more := CkJsonObject_BoolOf(json,'has_more');
    if (more = True) then
      begin
        next := CkJsonObject__stringOf(json,'data[i].id');
        if ((count < 1) or (next = '') or (next = cursor)) then
          begin
            Memo1.Lines.Add('Invalid pagination cursor.');
            Exit;
          end;
        cursor := next;
        CkStringBuilder_SetString(pageSuffix,'&starting_after=');
        CkStringBuilder_Append(pageSuffix,cursor);
      end;
  end;

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

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