PHP Requires Chilkat v11.7.0+
PHP
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 PHP Downloads
<?php
use Chilkat2\HttpCurl;
use Chilkat2\JsonObject;
use Chilkat2\StringBuilder;
$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 = new HttpCurl();
$cmd = new StringBuilder();
$json = new JsonObject();
$replaced = 0;
// Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
$fromTime = '1790812800';
$untilTime = '1793491200';
$selectedPayout = 'po_SELECTED_BANK_DEPOSIT';
$expectedAmount = '';
$currency = '';
$pageSuffix = new StringBuilder();
$more = true;
$cursor = '';
while ($more) {
// 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);
try {
$curl->DoYourThing($cmd->GetAsString());
} catch (\Chilkat2\Exception $e) {
echo 'No HTTP response. Chilkat failure code: ', $curl->FailReason, "\n";
exit;
}
try {
$curl->GetResponseJson($json);
$success = true;
} catch (\Chilkat2\Exception $e) {
$success = false;
}
if (($curl->StatusCode != 200) || (!$success)) {
echo 'Stripe HTTP ', $curl->StatusCode, ' Request-Id: ', $curl->GetResponseHeaderField('Request-Id'), "\n";
if ($success) {
echo $json->StringOf('error.message'), "\n";
}
exit;
}
$i = 0;
$count = $json->SizeOfArray('data');
while ($i < $count) {
$json->I = $i;
echo $json->StringOf('data[i].id'), ' | ', $json->StringOf('data[i].amount'), ' | ', $json->StringOf('data[i].currency'), ' | ', $json->StringOf('data[i].reconciliation_status'), "\n";
if ($json->StringOf('data[i].id') === $selectedPayout) {
if ((!$json->BoolOf('data[i].automatic')) || ($json->StringOf('data[i].reconciliation_status') !== 'completed')) {
echo "Select an automatic payout with completed reconciliation.\n";
exit;
}
$expectedAmount = $json->StringOf('data[i].amount');
$currency = $json->StringOf('data[i].currency');
}
$i = $i + 1;
}
$more = $json->BoolOf('has_more');
if ($more) {
$next = $json->StringOf('data[i].id');
if (($count < 1) || (($next === '') || ($next === $cursor))) {
echo "Invalid pagination cursor.\n";
exit;
}
$cursor = $next;
$pageSuffix->SetString('&starting_after=');
$pageSuffix->Append($cursor);
}
}
if ($expectedAmount === '') {
echo "The selected payout was not in this date range.\n";
exit;
}
$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 = new StringBuilder();
$pageSuffixTxn = new StringBuilder();
$moreTxn = true;
$cursorTxn = '';
while ($moreTxn) {
// 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);
try {
$curl->DoYourThing($cmd->GetAsString());
} catch (\Chilkat2\Exception $e) {
echo 'No HTTP response. Chilkat failure code: ', $curl->FailReason, "\n";
exit;
}
try {
$curl->GetResponseJson($json);
$success = true;
} catch (\Chilkat2\Exception $e) {
$success = false;
}
if (($curl->StatusCode != 200) || (!$success)) {
echo 'Stripe HTTP ', $curl->StatusCode, ' Request-Id: ', $curl->GetResponseHeaderField('Request-Id'), "\n";
if ($success) {
echo $json->StringOf('error.message'), "\n";
}
exit;
}
$iTxn = 0;
$countTxn = $json->SizeOfArray('data');
while ($iTxn < $countTxn) {
$json->I = $iTxn;
echo $json->StringOf('data[i].id'), ' ', $json->StringOf('data[i].net'), "\n";
if ($json->StringOf('data[i].currency') !== $currency) {
echo "Currency mismatch.\n";
exit;
}
// Exclude the bank withdrawal itself if it appears in this batch.
if ($json->StringOf('data[i].source') !== $selectedPayout) {
$netText = $json->StringOf('data[i].net');
$entryNet = $json->IntOf('data[i].net');
$number->IntValue = $entryNet;
if ($number->GetAsString() !== $netText) {
echo 'Entry exceeds the supported int range: ', $netText, "\n";
exit;
}
if ($entryNet > 0) {
if ($totalNet > (2147483647 - $entryNet)) {
echo "Total exceeds the supported int range.\n";
exit;
}
}
if ($entryNet < 0) {
if ($totalNet < ((0 - 2147483647) - ($entryNet + 1))) {
echo "Total exceeds the supported int range.\n";
exit;
}
}
$totalNet = $totalNet + $entryNet;
}
$iTxn = $iTxn + 1;
}
$moreTxn = $json->BoolOf('has_more');
if ($moreTxn) {
$nextTxn = $json->StringOf('data[i].id');
if (($countTxn < 1) || (($nextTxn === '') || ($nextTxn === $cursorTxn))) {
echo "Invalid pagination cursor.\n";
exit;
}
$cursorTxn = $nextTxn;
$pageSuffixTxn->SetString('&starting_after=');
$pageSuffixTxn->Append($cursorTxn);
}
}
$number->IntValue = $totalNet;
echo 'Settlement net: ', $totalNet, ' Bank payout: ', $expectedAmount, ' ', $currency, "\n";
if ($number->GetAsString() === $expectedAmount) {
echo "Payout reconciled.\n";
} else {
echo "Investigate the difference.\n";
}