CkJava Requires Chilkat v11.7.0+
CkJava
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 CkJava Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean 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";
CkHttpCurl curl = new CkHttpCurl();
CkStringBuilder cmd = new CkStringBuilder();
CkJsonObject json = new CkJsonObject();
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 = "";
CkStringBuilder pageSuffix = new CkStringBuilder();
boolean 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) {
System.out.println("No HTTP response. Chilkat failure code: " + curl.get_FailReason());
return;
}
success = curl.GetResponseJson(json);
if ((curl.get_StatusCode() != 200) || (success != true)) {
System.out.println("Stripe HTTP " + curl.get_StatusCode() + " Request-Id: " + curl.getResponseHeaderField("Request-Id"));
if (success == true) {
System.out.println(json.stringOf("error.message"));
}
return;
}
int i = 0;
int count = json.SizeOfArray("data");
while ((i < count)) {
json.put_I(i);
System.out.println(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")) {
System.out.println("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)) {
System.out.println("Invalid pagination cursor.");
return;
}
cursor = next;
pageSuffix.SetString("&starting_after=");
pageSuffix.Append(cursor);
}
}
if (expectedAmount == "") {
System.out.println("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.
CkStringBuilder number = new CkStringBuilder();
CkStringBuilder pageSuffixTxn = new CkStringBuilder();
boolean 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) {
System.out.println("No HTTP response. Chilkat failure code: " + curl.get_FailReason());
return;
}
success = curl.GetResponseJson(json);
if ((curl.get_StatusCode() != 200) || (success != true)) {
System.out.println("Stripe HTTP " + curl.get_StatusCode() + " Request-Id: " + curl.getResponseHeaderField("Request-Id"));
if (success == true) {
System.out.println(json.stringOf("error.message"));
}
return;
}
int iTxn = 0;
int countTxn = json.SizeOfArray("data");
while ((iTxn < countTxn)) {
json.put_I(iTxn);
System.out.println(json.stringOf("data[i].id") + " " + json.stringOf("data[i].net"));
if (json.stringOf("data[i].currency") != currency) {
System.out.println("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.put_IntValue(entryNet);
if (number.getAsString() != netText) {
System.out.println("Entry exceeds the supported int range: " + netText);
return;
}
if (entryNet > 0) {
if (totalNet > (2147483647 - entryNet)) {
System.out.println("Total exceeds the supported int range.");
return;
}
}
if (entryNet < 0) {
if (totalNet < ((0 - 2147483647) - (entryNet+1))) {
System.out.println("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)) {
System.out.println("Invalid pagination cursor.");
return;
}
cursorTxn = nextTxn;
pageSuffixTxn.SetString("&starting_after=");
pageSuffixTxn.Append(cursorTxn);
}
}
number.put_IntValue(totalNet);
System.out.println("Settlement net: " + totalNet + " Bank payout: " + expectedAmount + " " + currency);
if (number.getAsString() == expectedAmount) {
System.out.println("Payout reconciled.");
}
else {
System.out.println("Investigate the difference.");
}
}
}