C# Requires Chilkat v11.7.0+
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 C# Downloads
bool success = false;
// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
string apiKey = "YOUR_STRIPE_TEST_KEY";
Chilkat.HttpCurl curl = new Chilkat.HttpCurl();
Chilkat.StringBuilder cmd = new Chilkat.StringBuilder();
Chilkat.JsonObject json = new Chilkat.JsonObject();
int replaced;
// Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
string fromTime = "1790812800";
string untilTime = "1793491200";
string selectedPayout = "po_SELECTED_BANK_DEPOSIT";
string expectedAmount = "";
string currency = "";
Chilkat.StringBuilder pageSuffix = new Chilkat.StringBuilder();
bool more = true;
string cursor = "";
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("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 != true) {
Debug.WriteLine("No HTTP response. Chilkat failure code: " + Convert.ToString(curl.FailReason));
return;
}
success = curl.GetResponseJson(json);
if ((curl.StatusCode != 200) || (success != true)) {
Debug.WriteLine("Stripe HTTP " + Convert.ToString(curl.StatusCode) + " Request-Id: " + curl.GetResponseHeaderField("Request-Id"));
if (success == true) {
Debug.WriteLine(json.StringOf("error.message"));
}
return;
}
int i = 0;
int count = json.SizeOfArray("data");
while ((i < count)) {
json.I = i;
Debug.WriteLine(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) {
if ((json.BoolOf("data[i].automatic") != true) || (json.StringOf("data[i].reconciliation_status") != "completed")) {
Debug.WriteLine("Select an automatic payout with completed reconciliation.");
return;
}
expectedAmount = json.StringOf("data[i].amount");
currency = json.StringOf("data[i].currency");
}
i = i + 1;
}
more = json.BoolOf("has_more");
if (more == true) {
string next = json.StringOf("data[i].id");
if ((count < 1) || (next == "") || (next == cursor)) {
Debug.WriteLine("Invalid pagination cursor.");
return;
}
cursor = next;
pageSuffix.SetString("&starting_after=");
pageSuffix.Append(cursor);
}
}
if (expectedAmount == "") {
Debug.WriteLine("The selected payout was not in this date range.");
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.
Chilkat.StringBuilder number = new Chilkat.StringBuilder();
Chilkat.StringBuilder pageSuffixTxn = new Chilkat.StringBuilder();
bool moreTxn = true;
string cursorTxn = "";
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("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 != true) {
Debug.WriteLine("No HTTP response. Chilkat failure code: " + Convert.ToString(curl.FailReason));
return;
}
success = curl.GetResponseJson(json);
if ((curl.StatusCode != 200) || (success != true)) {
Debug.WriteLine("Stripe HTTP " + Convert.ToString(curl.StatusCode) + " Request-Id: " + curl.GetResponseHeaderField("Request-Id"));
if (success == true) {
Debug.WriteLine(json.StringOf("error.message"));
}
return;
}
int iTxn = 0;
int countTxn = json.SizeOfArray("data");
while ((iTxn < countTxn)) {
json.I = iTxn;
Debug.WriteLine(json.StringOf("data[i].id") + " " + json.StringOf("data[i].net"));
if (json.StringOf("data[i].currency") != currency) {
Debug.WriteLine("Currency mismatch.");
return;
}
// Exclude the bank withdrawal itself if it appears in this batch.
if (json.StringOf("data[i].source") != selectedPayout) {
string netText = json.StringOf("data[i].net");
int entryNet = json.IntOf("data[i].net");
number.IntValue = entryNet;
if (number.GetAsString() != netText) {
Debug.WriteLine("Entry exceeds the supported int range: " + netText);
return;
}
if (entryNet > 0) {
if (totalNet > (2147483647 - entryNet)) {
Debug.WriteLine("Total exceeds the supported int range.");
return;
}
}
if (entryNet < 0) {
if (totalNet < ((0 - 2147483647) - (entryNet + 1))) {
Debug.WriteLine("Total exceeds the supported int range.");
return;
}
}
totalNet = totalNet + entryNet;
}
iTxn = iTxn + 1;
}
moreTxn = json.BoolOf("has_more");
if (moreTxn == true) {
string nextTxn = json.StringOf("data[i].id");
if ((countTxn < 1) || (nextTxn == "") || (nextTxn == cursorTxn)) {
Debug.WriteLine("Invalid pagination cursor.");
return;
}
cursorTxn = nextTxn;
pageSuffixTxn.SetString("&starting_after=");
pageSuffixTxn.Append(cursorTxn);
}
}
number.IntValue = totalNet;
Debug.WriteLine("Settlement net: " + Convert.ToString(totalNet) + " Bank payout: " + expectedAmount + " " + currency);
if (number.GetAsString() == expectedAmount) {
Debug.WriteLine("Payout reconciled.");
}
else {
Debug.WriteLine("Investigate the difference.");
}