Rust Requires Chilkat v11.7.0+
Rust
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 Rust Downloads
let mut success = false;
// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
let api_key = "YOUR_STRIPE_TEST_KEY".to_string();
let curl = chilkat::HttpCurl::new();
let cmd = chilkat::StringBuilder::new();
let json = chilkat::JsonObject::new();
// Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
let from_time = "1790812800".to_string();
let until_time = "1793491200".to_string();
let selected_payout = "po_SELECTED_BANK_DEPOSIT".to_string();
let mut expected_amount = String::new();
let mut currency = String::new();
let page_suffix = chilkat::StringBuilder::new();
let mut more = true;
let mut cursor = String::new();
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"
let _ = cmd.set_string("curl -X GET \"https://api.stripe.com/v1/payouts?created%5Bgte%5D=@FROM@&created%5Blt%5D=@UNTIL@&limit=100@CURSOR@\"");
let _ = cmd.append(" -u \"@KEY@:\"");
let _ = cmd.append(" -H \"Stripe-Version: 2026-10-28.endive\"");
let _ = cmd.replace("@CURSOR@", &page_suffix.get_as_string().unwrap_or_default());
let _ = cmd.replace("@FROM@", &from_time);
let _ = cmd.replace("@UNTIL@", &until_time);
let _ = cmd.replace("@KEY@", &api_key);
success = curl.do_your_thing(&cmd.get_as_string().unwrap_or_default()).is_ok();
if !success {
println!("No HTTP response. Chilkat failure code: {}", curl.fail_reason());
return;
}
success = curl.get_response_json(&json).is_ok();
if (curl.status_code() != 200) || (!success) {
println!("Stripe HTTP {} Request-Id: {}", curl.status_code(), curl.get_response_header_field("Request-Id").unwrap_or_default());
if success {
println!("{}", json.string_of("error.message").unwrap_or_default());
}
return;
}
let mut i = 0;
let count = json.size_of_array("data");
while i < count {
json.set_i(i);
println!("{} | {} | {} | {}", json.string_of("data[i].id").unwrap_or_default(), json.string_of("data[i].amount").unwrap_or_default(), json.string_of("data[i].currency").unwrap_or_default(), json.string_of("data[i].reconciliation_status").unwrap_or_default());
if json.string_of("data[i].id").unwrap_or_default() == selected_payout {
if (!json.bool_of("data[i].automatic")) || (json.string_of("data[i].reconciliation_status").unwrap_or_default() != "completed") {
println!("Select an automatic payout with completed reconciliation.");
return;
}
expected_amount = json.string_of("data[i].amount").unwrap_or_default();
currency = json.string_of("data[i].currency").unwrap_or_default();
}
i = i + 1;
}
more = json.bool_of("has_more");
if more {
let next = json.string_of("data[i].id").unwrap_or_default();
if (count < 1) || ((next == "") || (next == cursor)) {
println!("Invalid pagination cursor.");
return;
}
cursor = next.clone();
let _ = page_suffix.set_string("&starting_after=");
let _ = page_suffix.append(&cursor);
}
}
if expected_amount == "" {
println!("The selected payout was not in this date range.");
return;
}
let mut total_net = 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.
let number = chilkat::StringBuilder::new();
let page_suffix_txn = chilkat::StringBuilder::new();
let mut more_txn = true;
let mut cursor_txn = String::new();
while more_txn {
// 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"
let _ = cmd.set_string("curl -X GET \"https://api.stripe.com/v1/balance_transactions?payout=@PAYOUT@&limit=100@CURSOR@\"");
let _ = cmd.append(" -u \"@KEY@:\"");
let _ = cmd.append(" -H \"Stripe-Version: 2026-10-28.endive\"");
let _ = cmd.replace("@CURSOR@", &page_suffix_txn.get_as_string().unwrap_or_default());
let _ = cmd.replace("@PAYOUT@", &selected_payout);
let _ = cmd.replace("@KEY@", &api_key);
success = curl.do_your_thing(&cmd.get_as_string().unwrap_or_default()).is_ok();
if !success {
println!("No HTTP response. Chilkat failure code: {}", curl.fail_reason());
return;
}
success = curl.get_response_json(&json).is_ok();
if (curl.status_code() != 200) || (!success) {
println!("Stripe HTTP {} Request-Id: {}", curl.status_code(), curl.get_response_header_field("Request-Id").unwrap_or_default());
if success {
println!("{}", json.string_of("error.message").unwrap_or_default());
}
return;
}
let mut i_txn = 0;
let count_txn = json.size_of_array("data");
while i_txn < count_txn {
json.set_i(i_txn);
println!("{} {}", json.string_of("data[i].id").unwrap_or_default(), json.string_of("data[i].net").unwrap_or_default());
if json.string_of("data[i].currency").unwrap_or_default() != currency {
println!("Currency mismatch.");
return;
}
// Exclude the bank withdrawal itself if it appears in this batch.
if json.string_of("data[i].source").unwrap_or_default() != selected_payout {
let net_text = json.string_of("data[i].net").unwrap_or_default();
let entry_net = json.int_of("data[i].net");
number.set_int_value(entry_net);
if number.get_as_string().unwrap_or_default() != net_text {
println!("Entry exceeds the supported int range: {}", net_text);
return;
}
if entry_net > 0 {
if total_net > (2147483647 - entry_net) {
println!("Total exceeds the supported int range.");
return;
}
}
if entry_net < 0 {
if total_net < ((0 - 2147483647) - (entry_net + 1)) {
println!("Total exceeds the supported int range.");
return;
}
}
total_net = total_net + entry_net;
}
i_txn = i_txn + 1;
}
more_txn = json.bool_of("has_more");
if more_txn {
let next_txn = json.string_of("data[i].id").unwrap_or_default();
if (count_txn < 1) || ((next_txn == "") || (next_txn == cursor_txn)) {
println!("Invalid pagination cursor.");
return;
}
cursor_txn = next_txn.clone();
let _ = page_suffix_txn.set_string("&starting_after=");
let _ = page_suffix_txn.append(&cursor_txn);
}
}
number.set_int_value(total_net);
println!("Settlement net: {} Bank payout: {} {}", total_net, expected_amount, currency);
if number.get_as_string().unwrap_or_default() == expected_amount {
println!("Payout reconciled.");
} else {
println!("Investigate the difference.");
}