AutoIt Requires Chilkat v11.7.0+
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; Requires an unlocked Chilkat bundle. See Global Unlock Sample.
; Supply a restricted sandbox key from merchant-controlled configuration.
Local $sApiKey = "YOUR_STRIPE_TEST_KEY"
$oCurl = ObjCreate("Chilkat.HttpCurl")
$oCmd = ObjCreate("Chilkat.StringBuilder")
$oJson = ObjCreate("Chilkat.JsonObject")
Local $iReplaced
; Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
Local $sFromTime = "1790812800"
Local $sUntilTime = "1793491200"
Local $selectedPayout = "po_SELECTED_BANK_DEPOSIT"
Local $sExpectedAmount = ""
Local $sCurrency = ""
$oPageSuffix = ObjCreate("Chilkat.StringBuilder")
Local $bMore = True
Local $sCursor = ""
While ($bMore = 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"
$oCmd.SetString("curl -X GET ""https://api.stripe.com/v1/payouts?created%5Bgte%5D=@FROM@&created%5Blt%5D=@UNTIL@&limit=100@CURSOR@""")
$oCmd.Append(" -u ""@KEY@:""")
$oCmd.Append(" -H ""Stripe-Version: 2026-10-28.endive""")
$iReplaced = $oCmd.Replace("@CURSOR@",$oPageSuffix.GetAsString())
$iReplaced = $oCmd.Replace("@FROM@",$sFromTime)
$iReplaced = $oCmd.Replace("@UNTIL@",$sUntilTime)
$iReplaced = $oCmd.Replace("@KEY@",$sApiKey)
$bSuccess = $oCurl.DoYourThing($oCmd.GetAsString())
If ($bSuccess <> True) Then
ConsoleWrite("No HTTP response. Chilkat failure code: " & $oCurl.FailReason & @CRLF)
Exit
EndIf
$bSuccess = $oCurl.GetResponseJson($oJson)
If (($oCurl.StatusCode <> 200) Or ($bSuccess <> True)) Then
ConsoleWrite("Stripe HTTP " & $oCurl.StatusCode & " Request-Id: " & $oCurl.GetResponseHeaderField("Request-Id") & @CRLF)
If ($bSuccess = True) Then
ConsoleWrite($oJson.StringOf("error.message") & @CRLF)
EndIf
Exit
EndIf
Local $i = 0
Local $iCount = $oJson.SizeOfArray("data")
While ($i < $iCount)
$oJson.I = $i
ConsoleWrite($oJson.StringOf("data[i].id") & " | " & $oJson.StringOf("data[i].amount") & " | " & $oJson.StringOf("data[i].currency") & " | " & $oJson.StringOf("data[i].reconciliation_status") & @CRLF)
If ($oJson.StringOf("data[i].id") = $selectedPayout) Then
If (($oJson.BoolOf("data[i].automatic") <> True) Or ($oJson.StringOf("data[i].reconciliation_status") <> "completed")) Then
ConsoleWrite("Select an automatic payout with completed reconciliation." & @CRLF)
Exit
EndIf
$sExpectedAmount = $oJson.StringOf("data[i].amount")
$sCurrency = $oJson.StringOf("data[i].currency")
EndIf
$i = $i + 1
Wend
$bMore = $oJson.BoolOf("has_more")
If ($bMore = True) Then
Local $sNext = $oJson.StringOf("data[i].id")
If (($iCount < 1) Or ($sNext = "") Or ($sNext = $sCursor)) Then
ConsoleWrite("Invalid pagination cursor." & @CRLF)
Exit
EndIf
$sCursor = $sNext
$oPageSuffix.SetString("&starting_after=")
$oPageSuffix.Append($sCursor)
EndIf
Wend
If ($sExpectedAmount = "") Then
ConsoleWrite("The selected payout was not in this date range." & @CRLF)
Exit
EndIf
Local $iTotalNet = 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.
$oNumber = ObjCreate("Chilkat.StringBuilder")
$oPageSuffixTxn = ObjCreate("Chilkat.StringBuilder")
Local $bMoreTxn = True
Local $sCursorTxn = ""
While ($bMoreTxn = 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"
$oCmd.SetString("curl -X GET ""https://api.stripe.com/v1/balance_transactions?payout=@PAYOUT@&limit=100@CURSOR@""")
$oCmd.Append(" -u ""@KEY@:""")
$oCmd.Append(" -H ""Stripe-Version: 2026-10-28.endive""")
$iReplaced = $oCmd.Replace("@CURSOR@",$oPageSuffixTxn.GetAsString())
$iReplaced = $oCmd.Replace("@PAYOUT@",$selectedPayout)
$iReplaced = $oCmd.Replace("@KEY@",$sApiKey)
$bSuccess = $oCurl.DoYourThing($oCmd.GetAsString())
If ($bSuccess <> True) Then
ConsoleWrite("No HTTP response. Chilkat failure code: " & $oCurl.FailReason & @CRLF)
Exit
EndIf
$bSuccess = $oCurl.GetResponseJson($oJson)
If (($oCurl.StatusCode <> 200) Or ($bSuccess <> True)) Then
ConsoleWrite("Stripe HTTP " & $oCurl.StatusCode & " Request-Id: " & $oCurl.GetResponseHeaderField("Request-Id") & @CRLF)
If ($bSuccess = True) Then
ConsoleWrite($oJson.StringOf("error.message") & @CRLF)
EndIf
Exit
EndIf
Local $iTxn = 0
Local $iCountTxn = $oJson.SizeOfArray("data")
While ($iTxn < $iCountTxn)
$oJson.I = $iTxn
ConsoleWrite($oJson.StringOf("data[i].id") & " " & $oJson.StringOf("data[i].net") & @CRLF)
If ($oJson.StringOf("data[i].currency") <> $sCurrency) Then
ConsoleWrite("Currency mismatch." & @CRLF)
Exit
EndIf
; Exclude the bank withdrawal itself if it appears in this batch.
If ($oJson.StringOf("data[i].source") <> $selectedPayout) Then
Local $sNetText = $oJson.StringOf("data[i].net")
Local $iEntryNet = $oJson.IntOf("data[i].net")
$oNumber.IntValue = $iEntryNet
If ($oNumber.GetAsString() <> $sNetText) Then
ConsoleWrite("Entry exceeds the supported int range: " & $sNetText & @CRLF)
Exit
EndIf
If ($iEntryNet > 0) Then
If ($iTotalNet > (2147483647 - $iEntryNet)) Then
ConsoleWrite("Total exceeds the supported int range." & @CRLF)
Exit
EndIf
EndIf
If ($iEntryNet < 0) Then
If ($iTotalNet < ((0 - 2147483647) - ($iEntryNet + 1))) Then
ConsoleWrite("Total exceeds the supported int range." & @CRLF)
Exit
EndIf
EndIf
$iTotalNet = $iTotalNet + $iEntryNet
EndIf
$iTxn = $iTxn + 1
Wend
$bMoreTxn = $oJson.BoolOf("has_more")
If ($bMoreTxn = True) Then
Local $sNextTxn = $oJson.StringOf("data[i].id")
If (($iCountTxn < 1) Or ($sNextTxn = "") Or ($sNextTxn = $sCursorTxn)) Then
ConsoleWrite("Invalid pagination cursor." & @CRLF)
Exit
EndIf
$sCursorTxn = $sNextTxn
$oPageSuffixTxn.SetString("&starting_after=")
$oPageSuffixTxn.Append($sCursorTxn)
EndIf
Wend
$oNumber.IntValue = $iTotalNet
ConsoleWrite("Settlement net: " & $iTotalNet & " Bank payout: " & $sExpectedAmount & " " & $sCurrency & @CRLF)
If ($oNumber.GetAsString() = $sExpectedAmount) Then
ConsoleWrite("Payout reconciled." & @CRLF)
Else
ConsoleWrite("Investigate the difference." & @CRLF)
EndIf