Sample code for 30+ languages & platforms
PowerShell 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 PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

#  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
#  Supply a restricted sandbox key from merchant-controlled configuration.
$apiKey = "YOUR_STRIPE_TEST_KEY"

$curl = New-Object Chilkat.HttpCurl
$cmd = New-Object Chilkat.StringBuilder
$json = New-Object Chilkat.JsonObject

#  Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
$fromTime = "1790812800"
$untilTime = "1793491200"

$selectedPayout = "po_SELECTED_BANK_DEPOSIT"

$expectedAmount = ""
$currency = ""

$pageSuffix = New-Object Chilkat.StringBuilder
$more = $true
$cursor = ""
while (($more -eq $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 -ne $true) {
        $("No HTTP response. Chilkat failure code: " + $curl.FailReason)
        exit
    }

    $success = $curl.GetResponseJson($json)
    if (($curl.StatusCode -ne 200) -or ($success -ne $true)) {
        $("Stripe HTTP " + $curl.StatusCode + "  Request-Id: " + $curl.GetResponseHeaderField("Request-Id"))
        if ($success -eq $true) {
            $($json.StringOf("error.message"))
        }

        exit
    }

    $i = 0
    $count = $json.SizeOfArray("data")
    while (($i -lt $count)) {
        $json.I = $i
        $($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") -eq $selectedPayout) {
            if (($json.BoolOf("data[i].automatic") -ne $true) -or ($json.StringOf("data[i].reconciliation_status") -ne "completed")) {
                $("Select an automatic payout with completed reconciliation.")
                exit
            }

            $expectedAmount = $json.StringOf("data[i].amount")
            $currency = $json.StringOf("data[i].currency")
        }

        $i = $i + 1
    }

    $more = $json.BoolOf("has_more")
    if ($more -eq $true) {
        $next = $json.StringOf("data[i].id")
        if (($count -lt 1) -or ($next -eq "") -or ($next -eq $cursor)) {
            $("Invalid pagination cursor.")
            exit
        }

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

}

if ($expectedAmount -eq "") {
    $("The selected payout was not in this date range.")
    exit
}

$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.
$number = New-Object Chilkat.StringBuilder

$pageSuffixTxn = New-Object Chilkat.StringBuilder
$moreTxn = $true
$cursorTxn = ""
while (($moreTxn -eq $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 -ne $true) {
        $("No HTTP response. Chilkat failure code: " + $curl.FailReason)
        exit
    }

    $success = $curl.GetResponseJson($json)
    if (($curl.StatusCode -ne 200) -or ($success -ne $true)) {
        $("Stripe HTTP " + $curl.StatusCode + "  Request-Id: " + $curl.GetResponseHeaderField("Request-Id"))
        if ($success -eq $true) {
            $($json.StringOf("error.message"))
        }

        exit
    }

    $iTxn = 0
    $countTxn = $json.SizeOfArray("data")
    while (($iTxn -lt $countTxn)) {
        $json.I = $iTxn
        $($json.StringOf("data[i].id") + "  " + $json.StringOf("data[i].net"))
        if ($json.StringOf("data[i].currency") -ne $currency) {
            $("Currency mismatch.")
            exit
        }

        #  Exclude the bank withdrawal itself if it appears in this batch.
        if ($json.StringOf("data[i].source") -ne $selectedPayout) {
            $netText = $json.StringOf("data[i].net")
            $entryNet = $json.IntOf("data[i].net")
            $number.IntValue = $entryNet
            if ($number.GetAsString() -ne $netText) {
                $("Entry exceeds the supported int range: " + $netText)
                exit
            }

            if ($entryNet -gt 0) {
                if ($totalNet -gt (2147483647 - $entryNet)) {
                    $("Total exceeds the supported int range.")
                    exit
                }

            }

            if ($entryNet -lt 0) {
                if ($totalNet -lt ((0 - 2147483647) - ($entryNet + 1))) {
                    $("Total exceeds the supported int range.")
                    exit
                }

            }

            $totalNet = $totalNet + $entryNet
        }

        $iTxn = $iTxn + 1
    }

    $moreTxn = $json.BoolOf("has_more")
    if ($moreTxn -eq $true) {
        $nextTxn = $json.StringOf("data[i].id")
        if (($countTxn -lt 1) -or ($nextTxn -eq "") -or ($nextTxn -eq $cursorTxn)) {
            $("Invalid pagination cursor.")
            exit
        }

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

}

$number.IntValue = $totalNet
$("Settlement net: " + $totalNet + "  Bank payout: " + $expectedAmount + " " + $currency)
if ($number.GetAsString() -eq $expectedAmount) {
    $("Payout reconciled.")
}
else {
    $("Investigate the difference.")
}