B4X Requires Chilkat v11.7.0+
B4X
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 B4X Downloads
Dim success As Boolean = False
' Requires an unlocked Chilkat bundle. See Global Unlock Sample.
' Supply a restricted sandbox key from merchant-controlled configuration.
Dim apiKey As String = "YOUR_STRIPE_TEST_KEY"
Dim curl As ChilkatHttpCurl
curl.Initialize("curl")
Dim cmd As ChilkatStringBuilder
cmd.Initialize
Dim json As ChilkatJsonObject
json.Initialize
Dim replaced As Int
' Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
Dim fromTime As String = "1790812800"
Dim untilTime As String = "1793491200"
Dim selectedPayout As String = "po_SELECTED_BANK_DEPOSIT"
Dim expectedAmount As String = ""
Dim currency As String = ""
Dim pageSuffix As ChilkatStringBuilder
pageSuffix.Initialize
Dim more As Boolean = True
Dim cursor As String = ""
Do 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 " & Chr(34) & "https://api.stripe.com/v1/payouts?created%5Bgte%5D=@FROM@&created%5Blt%5D=@UNTIL@&limit=100@CURSOR@" & Chr(34))
cmd.Append(" -u " & Chr(34) & "@KEY@:" & Chr(34))
cmd.Append(" -H " & Chr(34) & "Stripe-Version: 2026-10-28.endive" & Chr(34))
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 Then
Log("No HTTP response. Chilkat failure code: " & curl.FailReason)
Return
End If
success = curl.GetResponseJson(json)
If (curl.StatusCode <> 200) Or (success <> True) Then
Log("Stripe HTTP " & curl.StatusCode & " Request-Id: " & curl.GetResponseHeaderField("Request-Id"))
If success = True Then
Log(json.StringOf("error.message"))
End If
Return
End If
Dim i As Int = 0
Dim count As Int = json.SizeOfArray("data")
Do While (i < count)
json.I = i
Log(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") = selectedPayout Then
If (json.BoolOf("data[i].automatic") <> True) Or (json.StringOf("data[i].reconciliation_status") <> "completed") Then
Log("Select an automatic payout with completed reconciliation.")
Return
End If
expectedAmount = json.StringOf("data[i].amount")
currency = json.StringOf("data[i].currency")
End If
i = i + 1
Loop
more = json.BoolOf("has_more")
If more = True Then
Dim next As String = json.StringOf("data[i].id")
If (count < 1) Or (next = "") Or (next = cursor) Then
Log("Invalid pagination cursor.")
Return
End If
cursor = next
pageSuffix.SetString("&starting_after=")
pageSuffix.Append(cursor)
End If
Loop
If expectedAmount = "" Then
Log("The selected payout was not in this date range.")
Return
End If
Dim totalNet As Int = 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.
Dim number As ChilkatStringBuilder
number.Initialize
Dim pageSuffixTxn As ChilkatStringBuilder
pageSuffixTxn.Initialize
Dim moreTxn As Boolean = True
Dim cursorTxn As String = ""
Do 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 " & Chr(34) & "https://api.stripe.com/v1/balance_transactions?payout=@PAYOUT@&limit=100@CURSOR@" & Chr(34))
cmd.Append(" -u " & Chr(34) & "@KEY@:" & Chr(34))
cmd.Append(" -H " & Chr(34) & "Stripe-Version: 2026-10-28.endive" & Chr(34))
replaced = cmd.Replace("@CURSOR@", pageSuffixTxn.GetAsString)
replaced = cmd.Replace("@PAYOUT@", selectedPayout)
replaced = cmd.Replace("@KEY@", apiKey)
success = curl.DoYourThing(cmd.GetAsString)
If success <> True Then
Log("No HTTP response. Chilkat failure code: " & curl.FailReason)
Return
End If
success = curl.GetResponseJson(json)
If (curl.StatusCode <> 200) Or (success <> True) Then
Log("Stripe HTTP " & curl.StatusCode & " Request-Id: " & curl.GetResponseHeaderField("Request-Id"))
If success = True Then
Log(json.StringOf("error.message"))
End If
Return
End If
Dim iTxn As Int = 0
Dim countTxn As Int = json.SizeOfArray("data")
Do While (iTxn < countTxn)
json.I = iTxn
Log(json.StringOf("data[i].id") & " " & json.StringOf("data[i].net"))
If json.StringOf("data[i].currency") <> currency Then
Log("Currency mismatch.")
Return
End If
' Exclude the bank withdrawal itself if it appears in this batch.
If json.StringOf("data[i].source") <> selectedPayout Then
Dim netText As String = json.StringOf("data[i].net")
Dim entryNet As Int = json.IntOf("data[i].net")
number.IntValue = entryNet
If number.GetAsString <> netText Then
Log("Entry exceeds the supported int range: " & netText)
Return
End If
If entryNet > 0 Then
If totalNet > (2147483647 - entryNet) Then
Log("Total exceeds the supported int range.")
Return
End If
End If
If entryNet < 0 Then
If totalNet < ((0 - 2147483647) - (entryNet + 1)) Then
Log("Total exceeds the supported int range.")
Return
End If
End If
totalNet = totalNet + entryNet
End If
iTxn = iTxn + 1
Loop
moreTxn = json.BoolOf("has_more")
If moreTxn = True Then
Dim nextTxn As String = json.StringOf("data[i].id")
If (countTxn < 1) Or (nextTxn = "") Or (nextTxn = cursorTxn) Then
Log("Invalid pagination cursor.")
Return
End If
cursorTxn = nextTxn
pageSuffixTxn.SetString("&starting_after=")
pageSuffixTxn.Append(cursorTxn)
End If
Loop
number.IntValue = totalNet
Log("Settlement net: " & totalNet & " Bank payout: " & expectedAmount & " " & currency)
If number.GetAsString = expectedAmount Then
Log("Payout reconciled.")
Else
Log("Investigate the difference.")
End If