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

Stripe: Match an automatic bank payout to its transactions

See more Stripe Examples

Reconcile a selected automatic payout by comparing its amount with the sum of its settlement entries across all result pages.

Stripe documentation and cURL example

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
apiKey: PWideChar;
curl: HCkHttpCurl;
cmd: HCkStringBuilder;
json: HCkJsonObject;
replaced: Integer;
fromTime: PWideChar;
untilTime: PWideChar;
selectedPayout: PWideChar;
expectedAmount: PWideChar;
currency: PWideChar;
pageSuffix: HCkStringBuilder;
more: Boolean;
cursor: PWideChar;
i: Integer;
count: Integer;
next: PWideChar;
totalNet: Integer;
number: HCkStringBuilder;
pageSuffixTxn: HCkStringBuilder;
moreTxn: Boolean;
cursorTxn: PWideChar;
iTxn: Integer;
countTxn: Integer;
netText: PWideChar;
entryNet: Integer;
nextTxn: 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();

//  Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
fromTime := '1790812800';
untilTime := '1793491200';

selectedPayout := 'po_SELECTED_BANK_DEPOSIT';

expectedAmount := '';
currency := '';

pageSuffix := CkStringBuilder_Create();
more := True;
cursor := '';
while (more = True) do
  begin
    //  curl -X GET "https://api.stripe.com/v1/payouts?created%5Bgte%5D={fromTime}&created%5Blt%5D={untilTime}&limit=100" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive"
    CkStringBuilder_SetString(cmd,'curl -X GET "https://api.stripe.com/v1/payouts?created%5Bgte%5D=@FROM@&created%5Blt%5D=@UNTIL@&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,'@FROM@',fromTime);
    replaced := CkStringBuilder_Replace(cmd,'@UNTIL@',untilTime);
    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].amount') + ' | ' + CkJsonObject__stringOf(json,'data[i].currency')
             + ' | ' + CkJsonObject__stringOf(json,'data[i].reconciliation_status'));
        if (CkJsonObject__stringOf(json,'data[i].id') = selectedPayout) then
          begin
            if ((CkJsonObject_BoolOf(json,'data[i].automatic') <> True) or (CkJsonObject__stringOf(json,'data[i].reconciliation_status') <> 'completed')) then
              begin
                Memo1.Lines.Add('Select an automatic payout with completed reconciliation.');
                Exit;
              end;
            expectedAmount := CkJsonObject__stringOf(json,'data[i].amount');
            currency := CkJsonObject__stringOf(json,'data[i].currency');
          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;

if (expectedAmount = '') then
  begin
    Memo1.Lines.Add('The selected payout was not in this date range.');
    Exit;
  end;
totalNet := 0;
//  This portable example uses int for arithmetic. Reject an out-of-range entry
//  or sum before adding. A larger ledger can sum the exact strings using decimal arithmetic.
number := CkStringBuilder_Create();

pageSuffixTxn := CkStringBuilder_Create();
moreTxn := True;
cursorTxn := '';
while (moreTxn = True) do
  begin
    //  curl -X GET "https://api.stripe.com/v1/balance_transactions?payout={selectedPayout}&limit=100" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive"
    CkStringBuilder_SetString(cmd,'curl -X GET "https://api.stripe.com/v1/balance_transactions?payout=@PAYOUT@&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(pageSuffixTxn));
    replaced := CkStringBuilder_Replace(cmd,'@PAYOUT@',selectedPayout);
    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;

    iTxn := 0;
    countTxn := CkJsonObject_SizeOfArray(json,'data');
    while (iTxn < countTxn) do
      begin
        CkJsonObject_putI(json,iTxn);
        Memo1.Lines.Add(CkJsonObject__stringOf(json,'data[i].id') + '  ' + CkJsonObject__stringOf(json,'data[i].net'));
        if (CkJsonObject__stringOf(json,'data[i].currency') <> currency) then
          begin
            Memo1.Lines.Add('Currency mismatch.');
            Exit;
          end;
        //  Exclude the bank withdrawal itself if it appears in this batch.
        if (CkJsonObject__stringOf(json,'data[i].source') <> selectedPayout) then
          begin
            netText := CkJsonObject__stringOf(json,'data[i].net');
            entryNet := CkJsonObject_IntOf(json,'data[i].net');
            CkStringBuilder_putIntValue(number,entryNet);
            if (CkStringBuilder__getAsString(number) <> netText) then
              begin
                Memo1.Lines.Add('Entry exceeds the supported int range: ' + netText);
                Exit;
              end;
            if (entryNet > 0) then
              begin
                if (totalNet > (2147483647 - entryNet)) then
                  begin
                    Memo1.Lines.Add('Total exceeds the supported int range.');
                    Exit;
                  end;
              end;
            if (entryNet < 0) then
              begin
                if (totalNet < ((0 - 2147483647) - (entryNet + 1))) then
                  begin
                    Memo1.Lines.Add('Total exceeds the supported int range.');
                    Exit;
                  end;
              end;
            totalNet := totalNet + entryNet;
          end;
        iTxn := iTxn + 1;
      end;

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

CkStringBuilder_putIntValue(number,totalNet);
Memo1.Lines.Add('Settlement net: ' + IntToStr(totalNet) + '  Bank payout: ' + expectedAmount + ' ' + currency);
if (CkStringBuilder__getAsString(number) = expectedAmount) then
  begin
    Memo1.Lines.Add('Payout reconciled.');
  end
else
  begin
    Memo1.Lines.Add('Investigate the difference.');
  end;

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