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

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
string ls_ApiKey
oleobject loo_Curl
oleobject loo_Cmd
oleobject loo_Json
long li_Replaced
string ls_InvoiceId
oleobject loo_PageSuffix
long li_More
string ls_Cursor
long i
long li_Count
string ls_Next

li_Success = 0

//  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
//  Supply a restricted sandbox key from merchant-controlled configuration.
ls_ApiKey = "YOUR_STRIPE_TEST_KEY"

loo_Curl = create oleobject
li_rc = loo_Curl.ConnectToNewObject("Chilkat.HttpCurl")
if li_rc < 0 then
    destroy loo_Curl
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Cmd = create oleobject
li_rc = loo_Cmd.ConnectToNewObject("Chilkat.StringBuilder")

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

ls_InvoiceId = "in_FROM_BILLING_RECORD"

loo_PageSuffix = create oleobject
li_rc = loo_PageSuffix.ConnectToNewObject("Chilkat.StringBuilder")

li_More = 1
ls_Cursor = ""
do while (li_More = 1)
    //  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"
    loo_Cmd.SetString("curl -X GET ~"https://api.stripe.com/v1/invoice_payments?invoice=@ID@&limit=100@CURSOR@~"")
    loo_Cmd.Append(" -u ~"@KEY@:~"")
    loo_Cmd.Append(" -H ~"Stripe-Version: 2026-10-28.endive~"")
    li_Replaced = loo_Cmd.Replace("@CURSOR@",loo_PageSuffix.GetAsString())
    li_Replaced = loo_Cmd.Replace("@ID@",ls_InvoiceId)
    li_Replaced = loo_Cmd.Replace("@KEY@",ls_ApiKey)
    li_Success = loo_Curl.DoYourThing(loo_Cmd.GetAsString())
    if li_Success <> 1 then
        Write-Debug "No HTTP response. Chilkat failure code: " + string(loo_Curl.FailReason)
        destroy loo_Curl
        destroy loo_Cmd
        destroy loo_Json
        destroy loo_PageSuffix
        return
    end if

    li_Success = loo_Curl.GetResponseJson(loo_Json)
    if (loo_Curl.StatusCode <> 200) OR (li_Success <> 1) then
        Write-Debug "Stripe HTTP " + string(loo_Curl.StatusCode) + "  Request-Id: " + loo_Curl.GetResponseHeaderField("Request-Id")
        if li_Success = 1 then
            Write-Debug loo_Json.StringOf("error.message")
        end if

        destroy loo_Curl
        destroy loo_Cmd
        destroy loo_Json
        destroy loo_PageSuffix
        return
    end if

    i = 0
    li_Count = loo_Json.SizeOfArray("data")
    do while (i < li_Count)
        loo_Json.I = i
        Write-Debug loo_Json.StringOf("data[i].id") + " | " + loo_Json.StringOf("data[i].status") + " | " + loo_Json.StringOf("data[i].amount_paid") + " | " + loo_Json.StringOf("data[i].currency") + " | " + loo_Json.StringOf("data[i].payment.type")
        if loo_Json.StringOf("data[i].payment.type") = "payment_intent" then
            Write-Debug "  PaymentIntent: " + loo_Json.StringOf("data[i].payment.payment_intent")
        end if

        if loo_Json.StringOf("data[i].payment.type") = "charge" then
            Write-Debug "  Charge: " + loo_Json.StringOf("data[i].payment.charge")
        end if

        i = i + 1
    loop
    li_More = loo_Json.BoolOf("has_more")
    if li_More = 1 then
        ls_Next = loo_Json.StringOf("data[i].id")
        if (li_Count < 1) OR (ls_Next = "") OR (ls_Next = ls_Cursor) then
            Write-Debug "Invalid pagination cursor."
            destroy loo_Curl
            destroy loo_Cmd
            destroy loo_Json
            destroy loo_PageSuffix
            return
        end if

        ls_Cursor = ls_Next
        loo_PageSuffix.SetString("&starting_after=")
        loo_PageSuffix.Append(ls_Cursor)
    end if

loop

//  Select the paid allocation belonging to the order before issuing its refund.


destroy loo_Curl
destroy loo_Cmd
destroy loo_Json
destroy loo_PageSuffix