Xbase++ Requires Chilkat v11.7.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL cApiKey
LOCAL oCurl
LOCAL oCmd
LOCAL oJson
LOCAL nReplaced
LOCAL cFromTime
LOCAL cUntilTime
LOCAL cSelectedPayout
LOCAL cExpectedAmount
LOCAL cCurrency
LOCAL oPageSuffix
LOCAL nMore
LOCAL cCursor
LOCAL i
LOCAL nCount
LOCAL cNext
LOCAL nTotalNet
LOCAL oNumber
LOCAL oPageSuffixTxn
LOCAL nMoreTxn
LOCAL cCursorTxn
LOCAL nITxn
LOCAL nCountTxn
LOCAL cNetText
LOCAL nEntryNet
LOCAL cNextTxn
nSuccess := 0
// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
cApiKey := "YOUR_STRIPE_TEST_KEY"
oCurl := CreateObject("Chilkat.HttpCurl")
oCmd := CreateObject("Chilkat.StringBuilder")
oJson := CreateObject("Chilkat.JsonObject")
// Example UTC interval: 1 October 2026 inclusive through 1 November exclusive.
cFromTime := "1790812800"
cUntilTime := "1793491200"
cSelectedPayout := "po_SELECTED_BANK_DEPOSIT"
cExpectedAmount := ""
cCurrency := ""
oPageSuffix := CreateObject("Chilkat.StringBuilder")
nMore := 1
cCursor := ""
DO WHILE (nMore == 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"
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"')
nReplaced := oCmd:Replace("@CURSOR@", oPageSuffix:GetAsString())
nReplaced := oCmd:Replace("@FROM@", cFromTime)
nReplaced := oCmd:Replace("@UNTIL@", cUntilTime)
nReplaced := oCmd:Replace("@KEY@", cApiKey)
nSuccess := oCurl:DoYourThing(oCmd:GetAsString())
IF (nSuccess != 1)
? "No HTTP response. Chilkat failure code: " + Str(oCurl:FailReason)
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
RETURN
ENDIF
nSuccess := oCurl:GetResponseJson(oJson)
IF ((oCurl:StatusCode != 200) .OR. (nSuccess != 1))
? "Stripe HTTP " + Str(oCurl:StatusCode) + " Request-Id: " + oCurl:GetResponseHeaderField("Request-Id")
IF (nSuccess == 1)
? oJson:StringOf("error.message")
ENDIF
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
RETURN
ENDIF
i := 0
nCount := oJson:SizeOfArray("data")
DO WHILE (i < nCount)
oJson:I := i
? oJson:StringOf("data[i].id") + " | " + oJson:StringOf("data[i].amount") + " | " + oJson:StringOf("data[i].currency") + " | " + oJson:StringOf("data[i].reconciliation_status")
IF (oJson:StringOf("data[i].id") == cSelectedPayout)
IF ((oJson:BoolOf("data[i].automatic") != 1) .OR. (oJson:StringOf("data[i].reconciliation_status") != "completed"))
? "Select an automatic payout with completed reconciliation."
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
RETURN
ENDIF
cExpectedAmount := oJson:StringOf("data[i].amount")
cCurrency := oJson:StringOf("data[i].currency")
ENDIF
i := i + 1
ENDDO
nMore := oJson:BoolOf("has_more")
IF (nMore == 1)
cNext := oJson:StringOf("data[i].id")
IF ((nCount < 1) .OR. (cNext == "") .OR. (cNext == cCursor))
? "Invalid pagination cursor."
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
RETURN
ENDIF
cCursor := cNext
oPageSuffix:SetString("&starting_after=")
oPageSuffix:Append(cCursor)
ENDIF
ENDDO
IF (cExpectedAmount == "")
? "The selected payout was not in this date range."
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
RETURN
ENDIF
nTotalNet := 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 := CreateObject("Chilkat.StringBuilder")
oPageSuffixTxn := CreateObject("Chilkat.StringBuilder")
nMoreTxn := 1
cCursorTxn := ""
DO WHILE (nMoreTxn == 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"
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"')
nReplaced := oCmd:Replace("@CURSOR@", oPageSuffixTxn:GetAsString())
nReplaced := oCmd:Replace("@PAYOUT@", cSelectedPayout)
nReplaced := oCmd:Replace("@KEY@", cApiKey)
nSuccess := oCurl:DoYourThing(oCmd:GetAsString())
IF (nSuccess != 1)
? "No HTTP response. Chilkat failure code: " + Str(oCurl:FailReason)
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
oNumber:destroy()
oPageSuffixTxn:destroy()
RETURN
ENDIF
nSuccess := oCurl:GetResponseJson(oJson)
IF ((oCurl:StatusCode != 200) .OR. (nSuccess != 1))
? "Stripe HTTP " + Str(oCurl:StatusCode) + " Request-Id: " + oCurl:GetResponseHeaderField("Request-Id")
IF (nSuccess == 1)
? oJson:StringOf("error.message")
ENDIF
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
oNumber:destroy()
oPageSuffixTxn:destroy()
RETURN
ENDIF
nITxn := 0
nCountTxn := oJson:SizeOfArray("data")
DO WHILE (nITxn < nCountTxn)
oJson:I := nITxn
? oJson:StringOf("data[i].id") + " " + oJson:StringOf("data[i].net")
IF (oJson:StringOf("data[i].currency") != cCurrency)
? "Currency mismatch."
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
oNumber:destroy()
oPageSuffixTxn:destroy()
RETURN
ENDIF
// Exclude the bank withdrawal itself if it appears in this batch.
IF (oJson:StringOf("data[i].source") != cSelectedPayout)
cNetText := oJson:StringOf("data[i].net")
nEntryNet := oJson:IntOf("data[i].net")
oNumber:IntValue := nEntryNet
IF (oNumber:GetAsString() != cNetText)
? "Entry exceeds the supported int range: " + cNetText
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
oNumber:destroy()
oPageSuffixTxn:destroy()
RETURN
ENDIF
IF (nEntryNet > 0)
IF (nTotalNet > (2147483647 - nEntryNet))
? "Total exceeds the supported int range."
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
oNumber:destroy()
oPageSuffixTxn:destroy()
RETURN
ENDIF
ENDIF
IF (nEntryNet < 0)
IF (nTotalNet < ((0 - 2147483647) - (nEntryNet + 1)))
? "Total exceeds the supported int range."
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
oNumber:destroy()
oPageSuffixTxn:destroy()
RETURN
ENDIF
ENDIF
nTotalNet := nTotalNet + nEntryNet
ENDIF
nITxn := nITxn + 1
ENDDO
nMoreTxn := oJson:BoolOf("has_more")
IF (nMoreTxn == 1)
cNextTxn := oJson:StringOf("data[i].id")
IF ((nCountTxn < 1) .OR. (cNextTxn == "") .OR. (cNextTxn == cCursorTxn))
? "Invalid pagination cursor."
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
oNumber:destroy()
oPageSuffixTxn:destroy()
RETURN
ENDIF
cCursorTxn := cNextTxn
oPageSuffixTxn:SetString("&starting_after=")
oPageSuffixTxn:Append(cCursorTxn)
ENDIF
ENDDO
oNumber:IntValue := nTotalNet
? "Settlement net: " + Str(nTotalNet) + " Bank payout: " + cExpectedAmount + " " + cCurrency
IF (oNumber:GetAsString() == cExpectedAmount)
? "Payout reconciled."
ELSE
? "Investigate the difference."
ENDIF
oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()
oNumber:destroy()
oPageSuffixTxn:destroy()