Delphi ActiveX Requires Chilkat v11.7.0+
Delphi ActiveX
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 ActiveX Downloads
var
success: Integer;
apiKey: WideString;
curl: TChilkatHttpCurl;
cmd: TChilkatStringBuilder;
json: TChilkatJsonObject;
replaced: Integer;
fromTime: WideString;
untilTime: WideString;
selectedPayout: WideString;
expectedAmount: WideString;
currency: WideString;
pageSuffix: TChilkatStringBuilder;
more: Integer;
cursor: WideString;
i: Integer;
count: Integer;
next: WideString;
totalNet: Integer;
number: TChilkatStringBuilder;
pageSuffixTxn: TChilkatStringBuilder;
moreTxn: Integer;
cursorTxn: WideString;
iTxn: Integer;
countTxn: Integer;
netText: WideString;
entryNet: Integer;
nextTxn: WideString;
begin
success := 0;
// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
apiKey := 'YOUR_STRIPE_TEST_KEY';
curl := TChilkatHttpCurl.Create(Self);
cmd := TChilkatStringBuilder.Create(Self);
json := TChilkatJsonObject.Create(Self);
// Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
fromTime := '1790812800';
untilTime := '1793491200';
selectedPayout := 'po_SELECTED_BANK_DEPOSIT';
expectedAmount := '';
currency := '';
pageSuffix := TChilkatStringBuilder.Create(Self);
more := 1;
cursor := '';
while (more = 1) 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"
cmd.SetString('curl -X GET "https://api.stripe.com/v1/payouts?created%5Bgte%5D=@FROM@&created%5Blt%5D=@UNTIL@&limit=100@CURSOR@"');
cmd.Append(' -u "@KEY@:"');
cmd.Append(' -H "Stripe-Version: 2026-10-28.endive"');
replaced := cmd.Replace('@CURSOR@',pageSuffix.GetAsString());
replaced := cmd.Replace('@FROM@',fromTime);
replaced := cmd.Replace('@UNTIL@',untilTime);
replaced := cmd.Replace('@KEY@',apiKey);
success := curl.DoYourThing(cmd.GetAsString());
if (success <> 1) then
begin
Memo1.Lines.Add('No HTTP response. Chilkat failure code: ' + IntToStr(curl.FailReason));
Exit;
end;
success := curl.GetResponseJson(json.ControlInterface);
if ((curl.StatusCode <> 200) or (success <> 1)) then
begin
Memo1.Lines.Add('Stripe HTTP ' + IntToStr(curl.StatusCode) + ' Request-Id: ' + curl.GetResponseHeaderField('Request-Id'));
if (success = 1) then
begin
Memo1.Lines.Add(json.StringOf('error.message'));
end;
Exit;
end;
i := 0;
count := json.SizeOfArray('data');
while (i < count) do
begin
json.I := i;
Memo1.Lines.Add(json.StringOf('data[i].id') + ' | ' + json.StringOf('data[i].amount') + ' | ' + json.StringOf('data[i].currency') + ' | ' + json.StringOf('data[i].reconciliation_status'));
if (json.StringOf('data[i].id') = selectedPayout) then
begin
if ((json.BoolOf('data[i].automatic') <> 1) or (json.StringOf('data[i].reconciliation_status') <> 'completed')) then
begin
Memo1.Lines.Add('Select an automatic payout with completed reconciliation.');
Exit;
end;
expectedAmount := json.StringOf('data[i].amount');
currency := json.StringOf('data[i].currency');
end;
i := i + 1;
end;
more := json.BoolOf('has_more');
if (more = 1) then
begin
next := json.StringOf('data[i].id');
if ((count < 1) or (next = '') or (next = cursor)) then
begin
Memo1.Lines.Add('Invalid pagination cursor.');
Exit;
end;
cursor := next;
pageSuffix.SetString('&starting_after=');
pageSuffix.Append(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 := TChilkatStringBuilder.Create(Self);
pageSuffixTxn := TChilkatStringBuilder.Create(Self);
moreTxn := 1;
cursorTxn := '';
while (moreTxn = 1) 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"
cmd.SetString('curl -X GET "https://api.stripe.com/v1/balance_transactions?payout=@PAYOUT@&limit=100@CURSOR@"');
cmd.Append(' -u "@KEY@:"');
cmd.Append(' -H "Stripe-Version: 2026-10-28.endive"');
replaced := cmd.Replace('@CURSOR@',pageSuffixTxn.GetAsString());
replaced := cmd.Replace('@PAYOUT@',selectedPayout);
replaced := cmd.Replace('@KEY@',apiKey);
success := curl.DoYourThing(cmd.GetAsString());
if (success <> 1) then
begin
Memo1.Lines.Add('No HTTP response. Chilkat failure code: ' + IntToStr(curl.FailReason));
Exit;
end;
success := curl.GetResponseJson(json.ControlInterface);
if ((curl.StatusCode <> 200) or (success <> 1)) then
begin
Memo1.Lines.Add('Stripe HTTP ' + IntToStr(curl.StatusCode) + ' Request-Id: ' + curl.GetResponseHeaderField('Request-Id'));
if (success = 1) then
begin
Memo1.Lines.Add(json.StringOf('error.message'));
end;
Exit;
end;
iTxn := 0;
countTxn := json.SizeOfArray('data');
while (iTxn < countTxn) do
begin
json.I := iTxn;
Memo1.Lines.Add(json.StringOf('data[i].id') + ' ' + json.StringOf('data[i].net'));
if (json.StringOf('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 (json.StringOf('data[i].source') <> selectedPayout) then
begin
netText := json.StringOf('data[i].net');
entryNet := json.IntOf('data[i].net');
number.IntValue := entryNet;
if (number.GetAsString() <> 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 := json.BoolOf('has_more');
if (moreTxn = 1) then
begin
nextTxn := json.StringOf('data[i].id');
if ((countTxn < 1) or (nextTxn = '') or (nextTxn = cursorTxn)) then
begin
Memo1.Lines.Add('Invalid pagination cursor.');
Exit;
end;
cursorTxn := nextTxn;
pageSuffixTxn.SetString('&starting_after=');
pageSuffixTxn.Append(cursorTxn);
end;
end;
number.IntValue := totalNet;
Memo1.Lines.Add('Settlement net: ' + IntToStr(totalNet) + ' Bank payout: ' + expectedAmount + ' ' + currency);
if (number.GetAsString() = expectedAmount) then
begin
Memo1.Lines.Add('Payout reconciled.');
end
else
begin
Memo1.Lines.Add('Investigate the difference.');
end;