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

PureBasic
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttpCurl.pb"

Procedure ChilkatExample()

    success.i = 0

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

    curl.i = CkHttpCurl::ckCreate()
    If curl.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    cmd.i = CkStringBuilder::ckCreate()
    If cmd.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    replaced.i

    customerId.s = "cus_FROM_BILLING_ACCOUNT"

    ;  Remove status=open to show all invoice states.

    pageSuffix.i = CkStringBuilder::ckCreate()
    If pageSuffix.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    more.i = 1
    cursor.s = ""
    While (more = 1)
        ;  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"
        CkStringBuilder::ckSetString(cmd,"curl -X GET " + Chr(34) + "https://api.stripe.com/v1/invoices?customer=@CUSTOMER@&status=open&limit=100@CURSOR@" + Chr(34))
        CkStringBuilder::ckAppend(cmd," -u " + Chr(34) + "@KEY@:" + Chr(34))
        CkStringBuilder::ckAppend(cmd," -H " + Chr(34) + "Stripe-Version: 2026-10-28.endive" + Chr(34))
        replaced = CkStringBuilder::ckReplace(cmd,"@CURSOR@",CkStringBuilder::ckGetAsString(pageSuffix))
        replaced = CkStringBuilder::ckReplace(cmd,"@CUSTOMER@",customerId)
        replaced = CkStringBuilder::ckReplace(cmd,"@KEY@",apiKey)
        success = CkHttpCurl::ckDoYourThing(curl,CkStringBuilder::ckGetAsString(cmd))
        If success <> 1
            Debug "No HTTP response. Chilkat failure code: " + Str(CkHttpCurl::ckFailReason(curl))
            CkHttpCurl::ckDispose(curl)
            CkStringBuilder::ckDispose(cmd)
            CkJsonObject::ckDispose(json)
            CkStringBuilder::ckDispose(pageSuffix)
            ProcedureReturn
        EndIf

        success = CkHttpCurl::ckGetResponseJson(curl,json)
        If (CkHttpCurl::ckStatusCode(curl) <> 200) OR (success <> 1)
            Debug "Stripe HTTP " + Str(CkHttpCurl::ckStatusCode(curl)) + "  Request-Id: " + CkHttpCurl::ckGetResponseHeaderField(curl,"Request-Id")
            If success = 1
                Debug CkJsonObject::ckStringOf(json,"error.message")
            EndIf

            CkHttpCurl::ckDispose(curl)
            CkStringBuilder::ckDispose(cmd)
            CkJsonObject::ckDispose(json)
            CkStringBuilder::ckDispose(pageSuffix)
            ProcedureReturn
        EndIf

        i.i = 0
        count.i = CkJsonObject::ckSizeOfArray(json,"data")
        While (i < count)
            CkJsonObject::setCkI(json, i)
            Debug CkJsonObject::ckStringOf(json,"data[i].id") + " | " + CkJsonObject::ckStringOf(json,"data[i].number") + " | " + CkJsonObject::ckStringOf(json,"data[i].status") + " | " + CkJsonObject::ckStringOf(json,"data[i].due_date") + " | " + CkJsonObject::ckStringOf(json,"data[i].amount_remaining") + " | " + CkJsonObject::ckStringOf(json,"data[i].currency") + " | " + CkJsonObject::ckStringOf(json,"data[i].hosted_invoice_url") + " | " + CkJsonObject::ckStringOf(json,"data[i].invoice_pdf")
            i = i + 1
        Wend
        more = CkJsonObject::ckBoolOf(json,"has_more")
        If more = 1
            next.s = CkJsonObject::ckStringOf(json,"data[i].id")
            If (count < 1) OR (next = "") OR (next = cursor)
                Debug "Invalid pagination cursor."
                CkHttpCurl::ckDispose(curl)
                CkStringBuilder::ckDispose(cmd)
                CkJsonObject::ckDispose(json)
                CkStringBuilder::ckDispose(pageSuffix)
                ProcedureReturn
            EndIf

            cursor = next
            CkStringBuilder::ckSetString(pageSuffix,"&starting_after=")
            CkStringBuilder::ckAppend(pageSuffix,cursor)
        EndIf

    Wend


    CkHttpCurl::ckDispose(curl)
    CkStringBuilder::ckDispose(cmd)
    CkJsonObject::ckDispose(json)
    CkStringBuilder::ckDispose(pageSuffix)


    ProcedureReturn
EndProcedure