Sample code for 30+ languages & platforms
C++ Requires Chilkat v11.7.0+

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

C++
#include <CkHttpCurl.h>
#include <CkStringBuilder.h>
#include <CkJsonObject.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 char *apiKey = "YOUR_STRIPE_TEST_KEY";

    CkHttpCurl curl;
    CkStringBuilder cmd;
    CkJsonObject json;

    int replaced;

    //  Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
    const char *fromTime = "1790812800";
    const char *untilTime = "1793491200";

    const char *selectedPayout = "po_SELECTED_BANK_DEPOSIT";

    const char *expectedAmount = "";
    const char *currency = "";

    CkStringBuilder pageSuffix;
    bool more = true;
    const char *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) {
            std::cout << "No HTTP response. Chilkat failure code: " << curl.get_FailReason() << "\r\n";
            return;
        }

        success = curl.GetResponseJson(json);
        if ((curl.get_StatusCode() != 200) || (success != true)) {
            std::cout << "Stripe HTTP " << curl.get_StatusCode() << "  Request-Id: " << curl.getResponseHeaderField("Request-Id") << "\r\n";
            if (success == true) {
                std::cout << json.stringOf("error.message") << "\r\n";
            }

            return;
        }

        int i = 0;
        int count = json.SizeOfArray("data");
        while ((i < count)) {
            json.put_I(i);
            std::cout << json.stringOf("data[i].id") << " | " << json.stringOf("data[i].amount") << " | " << json.stringOf("data[i].currency") << " | " << json.stringOf("data[i].reconciliation_status") << "\r\n";
            if (json.stringOf("data[i].id") == selectedPayout) {
                if ((json.BoolOf("data[i].automatic") != true) || (json.stringOf("data[i].reconciliation_status") != "completed")) {
                    std::cout << "Select an automatic payout with completed reconciliation." << "\r\n";
                    return;
                }

                expectedAmount = json.stringOf("data[i].amount");
                currency = json.stringOf("data[i].currency");
            }

            i = i + 1;
        }

        more = json.BoolOf("has_more");
        if (more == true) {
            const char *next = json.stringOf("data[i].id");
            if ((count < 1) || (next == "") || (next == cursor)) {
                std::cout << "Invalid pagination cursor." << "\r\n";
                return;
            }

            cursor = next;
            pageSuffix.SetString("&starting_after=");
            pageSuffix.Append(cursor);
        }

    }

    if (expectedAmount == "") {
        std::cout << "The selected payout was not in this date range." << "\r\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.
    CkStringBuilder number;

    CkStringBuilder pageSuffixTxn;
    bool moreTxn = true;
    const char *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) {
            std::cout << "No HTTP response. Chilkat failure code: " << curl.get_FailReason() << "\r\n";
            return;
        }

        success = curl.GetResponseJson(json);
        if ((curl.get_StatusCode() != 200) || (success != true)) {
            std::cout << "Stripe HTTP " << curl.get_StatusCode() << "  Request-Id: " << curl.getResponseHeaderField("Request-Id") << "\r\n";
            if (success == true) {
                std::cout << json.stringOf("error.message") << "\r\n";
            }

            return;
        }

        int iTxn = 0;
        int countTxn = json.SizeOfArray("data");
        while ((iTxn < countTxn)) {
            json.put_I(iTxn);
            std::cout << json.stringOf("data[i].id") << "  " << json.stringOf("data[i].net") << "\r\n";
            if (json.stringOf("data[i].currency") != currency) {
                std::cout << "Currency mismatch." << "\r\n";
                return;
            }

            //  Exclude the bank withdrawal itself if it appears in this batch.
            if (json.stringOf("data[i].source") != selectedPayout) {
                const char *netText = json.stringOf("data[i].net");
                int entryNet = json.IntOf("data[i].net");
                number.put_IntValue(entryNet);
                if (number.getAsString() != netText) {
                    std::cout << "Entry exceeds the supported int range: " << netText << "\r\n";
                    return;
                }

                if (entryNet > 0) {
                    if (totalNet > (2147483647 - entryNet)) {
                        std::cout << "Total exceeds the supported int range." << "\r\n";
                        return;
                    }

                }

                if (entryNet < 0) {
                    if (totalNet < ((0 - 2147483647) - (entryNet + 1))) {
                        std::cout << "Total exceeds the supported int range." << "\r\n";
                        return;
                    }

                }

                totalNet = totalNet + entryNet;
            }

            iTxn = iTxn + 1;
        }

        moreTxn = json.BoolOf("has_more");
        if (moreTxn == true) {
            const char *nextTxn = json.stringOf("data[i].id");
            if ((countTxn < 1) || (nextTxn == "") || (nextTxn == cursorTxn)) {
                std::cout << "Invalid pagination cursor." << "\r\n";
                return;
            }

            cursorTxn = nextTxn;
            pageSuffixTxn.SetString("&starting_after=");
            pageSuffixTxn.Append(cursorTxn);
        }

    }

    number.put_IntValue(totalNet);
    std::cout << "Settlement net: " << totalNet << "  Bank payout: " << expectedAmount << " " << currency << "\r\n";
    if (number.getAsString() == expectedAmount) {
        std::cout << "Payout reconciled." << "\r\n";
    }
    else {
        std::cout << "Investigate the difference." << "\r\n";
    }
    }