Java Requires Chilkat v11.7.0+
Java
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 Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.HttpCurl;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
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";
HttpCurl curl = new HttpCurl();
StringBuilder cmd = new StringBuilder();
JsonObject json = new JsonObject();
int replaced = 0;
// 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 = "";
StringBuilder pageSuffix = new StringBuilder();
boolean more = true;
String 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 (ChilkatException e) {
System.out.println("No HTTP response. Chilkat failure code: " + curl.getFailReason());
return;
}
try {
curl.getResponseJson(json);
success = true;
} catch (ChilkatException e) {
success = false;
}
if ((curl.getStatusCode() != 200) || (!success)) {
System.out.println("Stripe HTTP " + curl.getStatusCode() + " Request-Id: " + curl.getResponseHeaderField("Request-Id"));
if (success) {
System.out.println(json.stringOf("error.message"));
}
return;
}
int i = 0;
int count = json.sizeOfArray("data");
while (i < count) {
json.setI(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").equals(selectedPayout)) {
if ((!json.boolOf("data[i].automatic")) || (!"completed".equals(json.stringOf("data[i].reconciliation_status")))) {
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) {
String next = json.stringOf("data[i].id");
if ((count < 1) || (("".equals(next)) || (next.equals(cursor)))) {
System.out.println("Invalid pagination cursor.");
return;
}
cursor = next;
pageSuffix.setString("&starting_after=");
pageSuffix.append(cursor);
}
}
if ("".equals(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.
StringBuilder number = new StringBuilder();
StringBuilder pageSuffixTxn = new StringBuilder();
boolean moreTxn = true;
String 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 (ChilkatException e) {
System.out.println("No HTTP response. Chilkat failure code: " + curl.getFailReason());
return;
}
try {
curl.getResponseJson(json);
success = true;
} catch (ChilkatException e) {
success = false;
}
if ((curl.getStatusCode() != 200) || (!success)) {
System.out.println("Stripe HTTP " + curl.getStatusCode() + " Request-Id: " + curl.getResponseHeaderField("Request-Id"));
if (success) {
System.out.println(json.stringOf("error.message"));
}
return;
}
int iTxn = 0;
int countTxn = json.sizeOfArray("data");
while (iTxn < countTxn) {
json.setI(iTxn);
System.out.println(json.stringOf("data[i].id") + " " + json.stringOf("data[i].net"));
if (!json.stringOf("data[i].currency").equals(currency)) {
System.out.println("Currency mismatch.");
return;
}
// Exclude the bank withdrawal itself if it appears in this batch.
if (!json.stringOf("data[i].source").equals(selectedPayout)) {
String netText = json.stringOf("data[i].net");
int entryNet = json.intOf("data[i].net");
number.setIntValue(entryNet);
if (!number.getAsString().equals(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) {
String nextTxn = json.stringOf("data[i].id");
if ((countTxn < 1) || (("".equals(nextTxn)) || (nextTxn.equals(cursorTxn)))) {
System.out.println("Invalid pagination cursor.");
return;
}
cursorTxn = nextTxn;
pageSuffixTxn.setString("&starting_after=");
pageSuffixTxn.append(cursorTxn);
}
}
number.setIntValue(totalNet);
System.out.println("Settlement net: " + totalNet + " Bank payout: " + expectedAmount + " " + currency);
if (number.getAsString().equals(expectedAmount)) {
System.out.println("Payout reconciled.");
} else {
System.out.println("Investigate the difference.");
}
}
}