Sample code for 30+ languages & platforms
Xbase++ 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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL cApiKey
LOCAL oCurl
LOCAL oCmd
LOCAL oJson
LOCAL nReplaced
LOCAL cInvoiceId
LOCAL oPageSuffix
LOCAL nMore
LOCAL cCursor
LOCAL i
LOCAL nCount
LOCAL cNext

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

cInvoiceId := "in_FROM_BILLING_RECORD"

oPageSuffix := CreateObject("Chilkat.StringBuilder")
nMore := 1
cCursor := ""
DO WHILE (nMore == 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"
    oCmd:SetString('curl -X GET "https://api.stripe.com/v1/invoice_payments?invoice=@ID@&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("@ID@", cInvoiceId)
    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].status") + " | " + oJson:StringOf("data[i].amount_paid") + " | " + oJson:StringOf("data[i].currency") + " | " + oJson:StringOf("data[i].payment.type")
        IF (oJson:StringOf("data[i].payment.type") == "payment_intent")
            ? "  PaymentIntent: " + oJson:StringOf("data[i].payment.payment_intent")
        ENDIF

        IF (oJson:StringOf("data[i].payment.type") == "charge")
            ? "  Charge: " + oJson:StringOf("data[i].payment.charge")
        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

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

oCurl:destroy()
oCmd:destroy()
oJson:destroy()
oPageSuffix:destroy()