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

Visual FoxPro
LOCAL lnSuccess
LOCAL lcApiKey
LOCAL loCurl
LOCAL loCmd
LOCAL loJson
LOCAL lnReplaced
LOCAL lcInvoiceId
LOCAL loPageSuffix
LOCAL lnMore
LOCAL lcCursor
LOCAL i
LOCAL lnCount
LOCAL lcNext

lnSuccess = 0

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

loCurl = CreateObject('Chilkat.HttpCurl')
loCmd = CreateObject('Chilkat.StringBuilder')
loJson = CreateObject('Chilkat.JsonObject')

lcInvoiceId = "in_FROM_BILLING_RECORD"

loPageSuffix = CreateObject('Chilkat.StringBuilder')
lnMore = 1
lcCursor = ""
DO WHILE (lnMore = 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"
    loCmd.SetString('curl -X GET "https://api.stripe.com/v1/invoice_payments?invoice=@ID@&limit=100@CURSOR@"')
    loCmd.Append(' -u "@KEY@:"')
    loCmd.Append(' -H "Stripe-Version: 2026-10-28.endive"')
    lnReplaced = loCmd.Replace("@CURSOR@",loPageSuffix.GetAsString())
    lnReplaced = loCmd.Replace("@ID@",lcInvoiceId)
    lnReplaced = loCmd.Replace("@KEY@",lcApiKey)
    lnSuccess = loCurl.DoYourThing(loCmd.GetAsString())
    IF (lnSuccess <> 1) THEN
        ? "No HTTP response. Chilkat failure code: " + STR(loCurl.FailReason)
        RELEASE loCurl
        RELEASE loCmd
        RELEASE loJson
        RELEASE loPageSuffix
        CANCEL
    ENDIF

    lnSuccess = loCurl.GetResponseJson(loJson)
    IF ((loCurl.StatusCode <> 200) OR (lnSuccess <> 1)) THEN
        ? "Stripe HTTP " + STR(loCurl.StatusCode) + "  Request-Id: " + loCurl.GetResponseHeaderField("Request-Id")
        IF (lnSuccess = 1) THEN
            ? loJson.StringOf("error.message")
        ENDIF

        RELEASE loCurl
        RELEASE loCmd
        RELEASE loJson
        RELEASE loPageSuffix
        CANCEL
    ENDIF

    i = 0
    lnCount = loJson.SizeOfArray("data")
    DO WHILE (i < lnCount)
        loJson.I = i
        ? loJson.StringOf("data[i].id") + " | " + loJson.StringOf("data[i].status") + " | " + loJson.StringOf("data[i].amount_paid") + " | " + loJson.StringOf("data[i].currency") + " | " + loJson.StringOf("data[i].payment.type")
        IF (loJson.StringOf("data[i].payment.type") = "payment_intent") THEN
            ? "  PaymentIntent: " + loJson.StringOf("data[i].payment.payment_intent")
        ENDIF

        IF (loJson.StringOf("data[i].payment.type") = "charge") THEN
            ? "  Charge: " + loJson.StringOf("data[i].payment.charge")
        ENDIF

        i = i + 1
    ENDDO
    lnMore = loJson.BoolOf("has_more")
    IF (lnMore = 1) THEN
        lcNext = loJson.StringOf("data[i].id")
        IF ((lnCount < 1) OR (lcNext = "") OR (lcNext = lcCursor)) THEN
            ? "Invalid pagination cursor."
            RELEASE loCurl
            RELEASE loCmd
            RELEASE loJson
            RELEASE loPageSuffix
            CANCEL
        ENDIF

        lcCursor = lcNext
        loPageSuffix.SetString("&starting_after=")
        loPageSuffix.Append(lcCursor)
    ENDIF

ENDDO

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

RELEASE loCurl
RELEASE loCmd
RELEASE loJson
RELEASE loPageSuffix