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

Unicode C++
#include <CkHttpCurlW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpCurlW curl;
    CkStringBuilderW cmd;
    CkJsonObjectW json;

    int replaced;

    const wchar_t *invoiceId = L"in_FROM_BILLING_RECORD";

    CkStringBuilderW pageSuffix;
    bool more = true;
    const wchar_t *cursor = L"";
    while ((more == true)) {
        //  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.SetString(L"curl -X GET \"https://api.stripe.com/v1/invoice_payments?invoice=@ID@&limit=100@CURSOR@\"");
        cmd.Append(L" -u \"@KEY@:\"");
        cmd.Append(L" -H \"Stripe-Version: 2026-10-28.endive\"");
        replaced = cmd.Replace(L"@CURSOR@",pageSuffix.getAsString());
        replaced = cmd.Replace(L"@ID@",invoiceId);
        replaced = cmd.Replace(L"@KEY@",apiKey);
        success = curl.DoYourThing(cmd.getAsString());
        if (success != true) {
            wprintf(L"No HTTP response. Chilkat failure code: %d\n",curl.get_FailReason());
            return;
        }

        success = curl.GetResponseJson(json);
        if ((curl.get_StatusCode() != 200) || (success != true)) {
            wprintf(L"Stripe HTTP %d  Request-Id: %s\n",curl.get_StatusCode(),curl.getResponseHeaderField(L"Request-Id"));
            if (success == true) {
                wprintf(L"%s\n",json.stringOf(L"error.message"));
            }

            return;
        }

        int i = 0;
        int count = json.SizeOfArray(L"data");
        while ((i < count)) {
            json.put_I(i);
            wprintf(L"%s | %s | %s | %s | %s\n",json.stringOf(L"data[i].id"),json.stringOf(L"data[i].status"),json.stringOf(L"data[i].amount_paid"),json.stringOf(L"data[i].currency")
                ,json.stringOf(L"data[i].payment.type"));
            if (json.stringOf(L"data[i].payment.type") == L"payment_intent") {
                wprintf(L"  PaymentIntent: %s\n",json.stringOf(L"data[i].payment.payment_intent"));
            }

            if (json.stringOf(L"data[i].payment.type") == L"charge") {
                wprintf(L"  Charge: %s\n",json.stringOf(L"data[i].payment.charge"));
            }

            i = i + 1;
        }

        more = json.BoolOf(L"has_more");
        if (more == true) {
            const wchar_t *next = json.stringOf(L"data[i].id");
            if ((count < 1) || (next == L"") || (next == cursor)) {
                wprintf(L"Invalid pagination cursor.\n");
                return;
            }

            cursor = next;
            pageSuffix.SetString(L"&starting_after=");
            pageSuffix.Append(cursor);
        }

    }

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