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

PowerBuilder
integer li_rc
long li_Success
string ls_ApiKey
oleobject loo_Curl
oleobject loo_Cmd
oleobject loo_Json
long li_Replaced
string ls_FromTime
string ls_UntilTime
string ls_SelectedPayout
string ls_ExpectedAmount
string ls_Currency
oleobject loo_PageSuffix
long li_More
string ls_Cursor
long i
long li_Count
string ls_Next
long li_TotalNet
oleobject loo_Number
oleobject loo_PageSuffixTxn
long li_MoreTxn
string ls_CursorTxn
long li_ITxn
long li_CountTxn
string ls_NetText
long li_EntryNet
string ls_NextTxn

li_Success = 0

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

loo_Curl = create oleobject
li_rc = loo_Curl.ConnectToNewObject("Chilkat.HttpCurl")
if li_rc < 0 then
    destroy loo_Curl
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Cmd = create oleobject
li_rc = loo_Cmd.ConnectToNewObject("Chilkat.StringBuilder")

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

//  Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
ls_FromTime = "1790812800"
ls_UntilTime = "1793491200"

ls_SelectedPayout = "po_SELECTED_BANK_DEPOSIT"

ls_ExpectedAmount = ""
ls_Currency = ""

loo_PageSuffix = create oleobject
li_rc = loo_PageSuffix.ConnectToNewObject("Chilkat.StringBuilder")

li_More = 1
ls_Cursor = ""
do while (li_More = 1)
    //  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"
    loo_Cmd.SetString("curl -X GET ~"https://api.stripe.com/v1/payouts?created%5Bgte%5D=@FROM@&created%5Blt%5D=@UNTIL@&limit=100@CURSOR@~"")
    loo_Cmd.Append(" -u ~"@KEY@:~"")
    loo_Cmd.Append(" -H ~"Stripe-Version: 2026-10-28.endive~"")
    li_Replaced = loo_Cmd.Replace("@CURSOR@",loo_PageSuffix.GetAsString())
    li_Replaced = loo_Cmd.Replace("@FROM@",ls_FromTime)
    li_Replaced = loo_Cmd.Replace("@UNTIL@",ls_UntilTime)
    li_Replaced = loo_Cmd.Replace("@KEY@",ls_ApiKey)
    li_Success = loo_Curl.DoYourThing(loo_Cmd.GetAsString())
    if li_Success <> 1 then
        Write-Debug "No HTTP response. Chilkat failure code: " + string(loo_Curl.FailReason)
        destroy loo_Curl
        destroy loo_Cmd
        destroy loo_Json
        destroy loo_PageSuffix
        return
    end if

    li_Success = loo_Curl.GetResponseJson(loo_Json)
    if (loo_Curl.StatusCode <> 200) OR (li_Success <> 1) then
        Write-Debug "Stripe HTTP " + string(loo_Curl.StatusCode) + "  Request-Id: " + loo_Curl.GetResponseHeaderField("Request-Id")
        if li_Success = 1 then
            Write-Debug loo_Json.StringOf("error.message")
        end if

        destroy loo_Curl
        destroy loo_Cmd
        destroy loo_Json
        destroy loo_PageSuffix
        return
    end if

    i = 0
    li_Count = loo_Json.SizeOfArray("data")
    do while (i < li_Count)
        loo_Json.I = i
        Write-Debug loo_Json.StringOf("data[i].id") + " | " + loo_Json.StringOf("data[i].amount") + " | " + loo_Json.StringOf("data[i].currency") + " | " + loo_Json.StringOf("data[i].reconciliation_status")
        if loo_Json.StringOf("data[i].id") = ls_SelectedPayout then
            if (loo_Json.BoolOf("data[i].automatic") <> 1) OR (loo_Json.StringOf("data[i].reconciliation_status") <> "completed") then
                Write-Debug "Select an automatic payout with completed reconciliation."
                destroy loo_Curl
                destroy loo_Cmd
                destroy loo_Json
                destroy loo_PageSuffix
                return
            end if

            ls_ExpectedAmount = loo_Json.StringOf("data[i].amount")
            ls_Currency = loo_Json.StringOf("data[i].currency")
        end if

        i = i + 1
    loop
    li_More = loo_Json.BoolOf("has_more")
    if li_More = 1 then
        ls_Next = loo_Json.StringOf("data[i].id")
        if (li_Count < 1) OR (ls_Next = "") OR (ls_Next = ls_Cursor) then
            Write-Debug "Invalid pagination cursor."
            destroy loo_Curl
            destroy loo_Cmd
            destroy loo_Json
            destroy loo_PageSuffix
            return
        end if

        ls_Cursor = ls_Next
        loo_PageSuffix.SetString("&starting_after=")
        loo_PageSuffix.Append(ls_Cursor)
    end if

loop

if ls_ExpectedAmount = "" then
    Write-Debug "The selected payout was not in this date range."
    destroy loo_Curl
    destroy loo_Cmd
    destroy loo_Json
    destroy loo_PageSuffix
    return
end if

li_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.
loo_Number = create oleobject
li_rc = loo_Number.ConnectToNewObject("Chilkat.StringBuilder")

loo_PageSuffixTxn = create oleobject
li_rc = loo_PageSuffixTxn.ConnectToNewObject("Chilkat.StringBuilder")

li_MoreTxn = 1
ls_CursorTxn = ""
do while (li_MoreTxn = 1)
    //  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"
    loo_Cmd.SetString("curl -X GET ~"https://api.stripe.com/v1/balance_transactions?payout=@PAYOUT@&limit=100@CURSOR@~"")
    loo_Cmd.Append(" -u ~"@KEY@:~"")
    loo_Cmd.Append(" -H ~"Stripe-Version: 2026-10-28.endive~"")
    li_Replaced = loo_Cmd.Replace("@CURSOR@",loo_PageSuffixTxn.GetAsString())
    li_Replaced = loo_Cmd.Replace("@PAYOUT@",ls_SelectedPayout)
    li_Replaced = loo_Cmd.Replace("@KEY@",ls_ApiKey)
    li_Success = loo_Curl.DoYourThing(loo_Cmd.GetAsString())
    if li_Success <> 1 then
        Write-Debug "No HTTP response. Chilkat failure code: " + string(loo_Curl.FailReason)
        destroy loo_Curl
        destroy loo_Cmd
        destroy loo_Json
        destroy loo_PageSuffix
        destroy loo_Number
        destroy loo_PageSuffixTxn
        return
    end if

    li_Success = loo_Curl.GetResponseJson(loo_Json)
    if (loo_Curl.StatusCode <> 200) OR (li_Success <> 1) then
        Write-Debug "Stripe HTTP " + string(loo_Curl.StatusCode) + "  Request-Id: " + loo_Curl.GetResponseHeaderField("Request-Id")
        if li_Success = 1 then
            Write-Debug loo_Json.StringOf("error.message")
        end if

        destroy loo_Curl
        destroy loo_Cmd
        destroy loo_Json
        destroy loo_PageSuffix
        destroy loo_Number
        destroy loo_PageSuffixTxn
        return
    end if

    li_ITxn = 0
    li_CountTxn = loo_Json.SizeOfArray("data")
    do while (li_ITxn < li_CountTxn)
        loo_Json.I = li_ITxn
        Write-Debug loo_Json.StringOf("data[i].id") + "  " + loo_Json.StringOf("data[i].net")
        if loo_Json.StringOf("data[i].currency") <> ls_Currency then
            Write-Debug "Currency mismatch."
            destroy loo_Curl
            destroy loo_Cmd
            destroy loo_Json
            destroy loo_PageSuffix
            destroy loo_Number
            destroy loo_PageSuffixTxn
            return
        end if

        //  Exclude the bank withdrawal itself if it appears in this batch.
        if loo_Json.StringOf("data[i].source") <> ls_SelectedPayout then
            ls_NetText = loo_Json.StringOf("data[i].net")
            li_EntryNet = loo_Json.IntOf("data[i].net")
            loo_Number.IntValue = li_EntryNet
            if loo_Number.GetAsString() <> ls_NetText then
                Write-Debug "Entry exceeds the supported int range: " + ls_NetText
                destroy loo_Curl
                destroy loo_Cmd
                destroy loo_Json
                destroy loo_PageSuffix
                destroy loo_Number
                destroy loo_PageSuffixTxn
                return
            end if

            if li_EntryNet > 0 then
                if li_TotalNet > (2147483647 - li_EntryNet) then
                    Write-Debug "Total exceeds the supported int range."
                    destroy loo_Curl
                    destroy loo_Cmd
                    destroy loo_Json
                    destroy loo_PageSuffix
                    destroy loo_Number
                    destroy loo_PageSuffixTxn
                    return
                end if

            end if

            if li_EntryNet < 0 then
                if li_TotalNet < ((0 - 2147483647) - (li_EntryNet + 1)) then
                    Write-Debug "Total exceeds the supported int range."
                    destroy loo_Curl
                    destroy loo_Cmd
                    destroy loo_Json
                    destroy loo_PageSuffix
                    destroy loo_Number
                    destroy loo_PageSuffixTxn
                    return
                end if

            end if

            li_TotalNet = li_TotalNet + li_EntryNet
        end if

        li_ITxn = li_ITxn + 1
    loop
    li_MoreTxn = loo_Json.BoolOf("has_more")
    if li_MoreTxn = 1 then
        ls_NextTxn = loo_Json.StringOf("data[i].id")
        if (li_CountTxn < 1) OR (ls_NextTxn = "") OR (ls_NextTxn = ls_CursorTxn) then
            Write-Debug "Invalid pagination cursor."
            destroy loo_Curl
            destroy loo_Cmd
            destroy loo_Json
            destroy loo_PageSuffix
            destroy loo_Number
            destroy loo_PageSuffixTxn
            return
        end if

        ls_CursorTxn = ls_NextTxn
        loo_PageSuffixTxn.SetString("&starting_after=")
        loo_PageSuffixTxn.Append(ls_CursorTxn)
    end if

loop

loo_Number.IntValue = li_TotalNet
Write-Debug "Settlement net: " + string(li_TotalNet) + "  Bank payout: " + ls_ExpectedAmount + " " + ls_Currency
if loo_Number.GetAsString() = ls_ExpectedAmount then
    Write-Debug "Payout reconciled."
else
    Write-Debug "Investigate the difference."
end if



destroy loo_Curl
destroy loo_Cmd
destroy loo_Json
destroy loo_PageSuffix
destroy loo_Number
destroy loo_PageSuffixTxn