Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.7.0+

Stripe: Review invoices and outstanding amounts

See more Stripe Examples

List open invoices for a billing account and show outstanding amounts, due dates, and invoice links.

Stripe documentation and cURL example

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local success = false

-- 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()

local replaced = 0

local customerId = "cus_FROM_BILLING_ACCOUNT"

-- Remove status=open to show all invoice states.

local pageSuffix = chilkat.StringBuilder.new()
local more = true
local cursor = ""
while more do
    -- curl -X GET "https://api.stripe.com/v1/invoices?customer={customerId}&status=open&limit=100" \
    --   -u "$STRIPE_API_KEY:" \
    --   -H "Stripe-Version: 2026-10-28.endive"
    cmd:set_string("curl -X GET \"https://api.stripe.com/v1/invoices?customer=@CUSTOMER@&status=open&limit=100@CURSOR@\"")
    cmd:append(" -u \"@KEY@:\"")
    cmd:append(" -H \"Stripe-Version: 2026-10-28.endive\"")
    replaced = cmd:replace("@CURSOR@", pageSuffix:get_as_string())
    replaced = cmd:replace("@CUSTOMER@", customerId)
    replaced = cmd:replace("@KEY@", apiKey)
    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

    local i = 0
    local count = json:size_of_array("data")
    while i < count do
        json.i = i
        print(json:string_of("data[i].id") .. " | " .. json:string_of("data[i].number") .. " | " .. json:string_of("data[i].status") .. " | " .. json:string_of("data[i].due_date") .. " | " .. json:string_of("data[i].amount_remaining") .. " | " .. json:string_of("data[i].currency") .. " | " .. json:string_of("data[i].hosted_invoice_url") .. " | " .. json:string_of("data[i].invoice_pdf"))
        i = i + 1
    end

    more = json:bool_of("has_more")
    if more then
        local next_ = json:string_of("data[i].id")
        if (count < 1) or ((next_ == "") or (next_ == cursor)) then
            print("Invalid pagination cursor.")
            return
        end

        cursor = next_
        pageSuffix:set_string("&starting_after=")
        pageSuffix:append(cursor)
    end
end