Unicode C++ Requires Chilkat v11.7.0+
Unicode C++
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 Unicode C++ Downloads
#include <CkHttpCurlW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool success = false;
// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
const wchar_t *apiKey = L"YOUR_STRIPE_TEST_KEY";
CkHttpCurlW curl;
CkStringBuilderW cmd;
CkJsonObjectW json;
int replaced;
// Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
const wchar_t *fromTime = L"1790812800";
const wchar_t *untilTime = L"1793491200";
const wchar_t *selectedPayout = L"po_SELECTED_BANK_DEPOSIT";
const wchar_t *expectedAmount = L"";
const wchar_t *currency = L"";
CkStringBuilderW pageSuffix;
bool more = true;
const wchar_t *cursor = L"";
while ((more == true)) {
// 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(L"curl -X GET \"https://api.stripe.com/v1/payouts?created%5Bgte%5D=@FROM@&created%5Blt%5D=@UNTIL@&limit=100@CURSOR@\"");
cmd.Append(L" -u \"@KEY@:\"");
cmd.Append(L" -H \"Stripe-Version: 2026-10-28.endive\"");
replaced = cmd.Replace(L"@CURSOR@",pageSuffix.getAsString());
replaced = cmd.Replace(L"@FROM@",fromTime);
replaced = cmd.Replace(L"@UNTIL@",untilTime);
replaced = cmd.Replace(L"@KEY@",apiKey);
success = curl.DoYourThing(cmd.getAsString());
if (success != true) {
wprintf(L"No HTTP response. Chilkat failure code: %d\n",curl.get_FailReason());
return;
}
success = curl.GetResponseJson(json);
if ((curl.get_StatusCode() != 200) || (success != true)) {
wprintf(L"Stripe HTTP %d Request-Id: %s\n",curl.get_StatusCode(),curl.getResponseHeaderField(L"Request-Id"));
if (success == true) {
wprintf(L"%s\n",json.stringOf(L"error.message"));
}
return;
}
int i = 0;
int count = json.SizeOfArray(L"data");
while ((i < count)) {
json.put_I(i);
wprintf(L"%s | %s | %s | %s\n",json.stringOf(L"data[i].id"),json.stringOf(L"data[i].amount"),json.stringOf(L"data[i].currency"),json.stringOf(L"data[i].reconciliation_status"));
if (json.stringOf(L"data[i].id") == selectedPayout) {
if ((json.BoolOf(L"data[i].automatic") != true) || (json.stringOf(L"data[i].reconciliation_status") != L"completed")) {
wprintf(L"Select an automatic payout with completed reconciliation.\n");
return;
}
expectedAmount = json.stringOf(L"data[i].amount");
currency = json.stringOf(L"data[i].currency");
}
i = i + 1;
}
more = json.BoolOf(L"has_more");
if (more == true) {
const wchar_t *next = json.stringOf(L"data[i].id");
if ((count < 1) || (next == L"") || (next == cursor)) {
wprintf(L"Invalid pagination cursor.\n");
return;
}
cursor = next;
pageSuffix.SetString(L"&starting_after=");
pageSuffix.Append(cursor);
}
}
if (expectedAmount == L"") {
wprintf(L"The selected payout was not in this date range.\n");
return;
}
int 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.
CkStringBuilderW number;
CkStringBuilderW pageSuffixTxn;
bool moreTxn = true;
const wchar_t *cursorTxn = L"";
while ((moreTxn == true)) {
// 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(L"curl -X GET \"https://api.stripe.com/v1/balance_transactions?payout=@PAYOUT@&limit=100@CURSOR@\"");
cmd.Append(L" -u \"@KEY@:\"");
cmd.Append(L" -H \"Stripe-Version: 2026-10-28.endive\"");
replaced = cmd.Replace(L"@CURSOR@",pageSuffixTxn.getAsString());
replaced = cmd.Replace(L"@PAYOUT@",selectedPayout);
replaced = cmd.Replace(L"@KEY@",apiKey);
success = curl.DoYourThing(cmd.getAsString());
if (success != true) {
wprintf(L"No HTTP response. Chilkat failure code: %d\n",curl.get_FailReason());
return;
}
success = curl.GetResponseJson(json);
if ((curl.get_StatusCode() != 200) || (success != true)) {
wprintf(L"Stripe HTTP %d Request-Id: %s\n",curl.get_StatusCode(),curl.getResponseHeaderField(L"Request-Id"));
if (success == true) {
wprintf(L"%s\n",json.stringOf(L"error.message"));
}
return;
}
int iTxn = 0;
int countTxn = json.SizeOfArray(L"data");
while ((iTxn < countTxn)) {
json.put_I(iTxn);
wprintf(L"%s %s\n",json.stringOf(L"data[i].id"),json.stringOf(L"data[i].net"));
if (json.stringOf(L"data[i].currency") != currency) {
wprintf(L"Currency mismatch.\n");
return;
}
// Exclude the bank withdrawal itself if it appears in this batch.
if (json.stringOf(L"data[i].source") != selectedPayout) {
const wchar_t *netText = json.stringOf(L"data[i].net");
int entryNet = json.IntOf(L"data[i].net");
number.put_IntValue(entryNet);
if (number.getAsString() != netText) {
wprintf(L"Entry exceeds the supported int range: %s\n",netText);
return;
}
if (entryNet > 0) {
if (totalNet > (2147483647 - entryNet)) {
wprintf(L"Total exceeds the supported int range.\n");
return;
}
}
if (entryNet < 0) {
if (totalNet < ((0 - 2147483647) - (entryNet + 1))) {
wprintf(L"Total exceeds the supported int range.\n");
return;
}
}
totalNet = totalNet + entryNet;
}
iTxn = iTxn + 1;
}
moreTxn = json.BoolOf(L"has_more");
if (moreTxn == true) {
const wchar_t *nextTxn = json.stringOf(L"data[i].id");
if ((countTxn < 1) || (nextTxn == L"") || (nextTxn == cursorTxn)) {
wprintf(L"Invalid pagination cursor.\n");
return;
}
cursorTxn = nextTxn;
pageSuffixTxn.SetString(L"&starting_after=");
pageSuffixTxn.Append(cursorTxn);
}
}
number.put_IntValue(totalNet);
wprintf(L"Settlement net: %d Bank payout: %s %s\n",totalNet,expectedAmount,currency);
if (number.getAsString() == expectedAmount) {
wprintf(L"Payout reconciled.\n");
}
else {
wprintf(L"Investigate the difference.\n");
}
}