Lua Requires Chilkat v11.7.0+
Lua
Stripe: Identify the payment for a paid invoice
See more Stripe Examples
List the payments allocated to an invoice and identify a paid charge or PaymentIntent for refund.
Stripe documentation and cURL example
Chilkat Lua Downloads
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 invoiceId = "in_FROM_BILLING_RECORD"
local pageSuffix = chilkat.StringBuilder.new()
local more = true
local cursor = ""
while more do
-- curl -X GET "https://api.stripe.com/v1/invoice_payments?invoice={invoiceId}&limit=100" \
-- -u "$STRIPE_API_KEY:" \
-- -H "Stripe-Version: 2026-10-28.endive"
cmd:set_string("curl -X GET \"https://api.stripe.com/v1/invoice_payments?invoice=@ID@&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("@ID@", invoiceId)
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].status") .. " | " .. json:string_of("data[i].amount_paid") .. " | " .. json:string_of("data[i].currency") .. " | " .. json:string_of("data[i].payment.type"))
if json:string_of("data[i].payment.type") == "payment_intent" then
print(" PaymentIntent: " .. json:string_of("data[i].payment.payment_intent"))
end
if json:string_of("data[i].payment.type") == "charge" then
print(" Charge: " .. json:string_of("data[i].payment.charge"))
end
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
-- Select the paid allocation belonging to the order before issuing its refund.