Lua Requires Chilkat v11.7.0+
Lua
Stripe: Show available and pending balances by currency
See more Stripe Examples
Read the available and pending account balances for every currency returned by Stripe.
Stripe documentation and cURL example
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Requires an unlocked Chilkat bundle. See Global Unlock Sample.
-- Supply a restricted sandbox key from merchant-controlled configuration.
local apiKey = "YOUR_STRIPE_TEST_KEY"
local curl = chilkat.HttpCurl.new()
local cmd = chilkat.StringBuilder.new()
local json = chilkat.JsonObject.new()
-- curl -X GET "https://api.stripe.com/v1/balance" \
-- -u "$STRIPE_API_KEY:" \
-- -H "Stripe-Version: 2026-10-28.endive"
cmd:set_string("curl -X GET \"https://api.stripe.com/v1/balance\"")
cmd:append(" -u \"@KEY@:\"")
cmd:append(" -H \"Stripe-Version: 2026-10-28.endive\"")
local replaced = cmd:replace("@KEY@", apiKey)
local success = curl:do_your_thing(cmd:get_as_string())
if not success then
print("No HTTP response. Chilkat failure code: " .. curl.fail_reason)
return
end
success = curl:get_response_json(json)
if (curl.status_code ~= 200) or (not success) then
print("Stripe HTTP " .. curl.status_code .. " Request-Id: " .. curl:get_response_header_field("Request-Id"))
if success then
print(json:string_of("error.message"))
end
return
end
-- Amounts are integer minor units. Read them as text to preserve large balances.
local availableIndex = 0
while availableIndex < json:size_of_array("available") do
json.i = availableIndex
print("available: " .. json:string_of("available[i].amount") .. " " .. json:string_of("available[i].currency"))
availableIndex = availableIndex + 1
end
local pendingIndex = 0
while pendingIndex < json:size_of_array("pending") do
json.i = pendingIndex
print("pending: " .. json:string_of("pending[i].amount") .. " " .. json:string_of("pending[i].currency"))
pendingIndex = pendingIndex + 1
end