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 <C_CkHttpCurlW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    BOOL success;
    const wchar_t *apiKey;
    HCkHttpCurlW curl;
    HCkStringBuilderW cmd;
    HCkJsonObjectW json;
    int replaced;
    const wchar_t *invoiceId;
    HCkStringBuilderW pageSuffix;
    BOOL more;
    const wchar_t *cursor;
    int i;
    int count;
    const wchar_t *next;

    success = FALSE;

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

    curl = CkHttpCurlW_Create();
    cmd = CkStringBuilderW_Create();
    json = CkJsonObjectW_Create();

    invoiceId = L"in_FROM_BILLING_RECORD";

    pageSuffix = CkStringBuilderW_Create();
    more = TRUE;
    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"
        CkStringBuilderW_SetString(cmd,L"curl -X GET \"https://api.stripe.com/v1/invoice_payments?invoice=@ID@&limit=100@CURSOR@\"");
        CkStringBuilderW_Append(cmd,L" -u \"@KEY@:\"");
        CkStringBuilderW_Append(cmd,L" -H \"Stripe-Version: 2026-10-28.endive\"");
        replaced = CkStringBuilderW_Replace(cmd,L"@CURSOR@",CkStringBuilderW_getAsString(pageSuffix));
        replaced = CkStringBuilderW_Replace(cmd,L"@ID@",invoiceId);
        replaced = CkStringBuilderW_Replace(cmd,L"@KEY@",apiKey);
        success = CkHttpCurlW_DoYourThing(curl,CkStringBuilderW_getAsString(cmd));
        if (success != TRUE) {
            wprintf(L"No HTTP response. Chilkat failure code: %d\n",CkHttpCurlW_getFailReason(curl));
            CkHttpCurlW_Dispose(curl);
            CkStringBuilderW_Dispose(cmd);
            CkJsonObjectW_Dispose(json);
            CkStringBuilderW_Dispose(pageSuffix);
            return;
        }

        success = CkHttpCurlW_GetResponseJson(curl,json);
        if ((CkHttpCurlW_getStatusCode(curl) != 200) || (success != TRUE)) {
            wprintf(L"Stripe HTTP %d  Request-Id: %s\n",CkHttpCurlW_getStatusCode(curl),CkHttpCurlW_getResponseHeaderField(curl,L"Request-Id"));
            if (success == TRUE) {
                wprintf(L"%s\n",CkJsonObjectW_stringOf(json,L"error.message"));
            }

            CkHttpCurlW_Dispose(curl);
            CkStringBuilderW_Dispose(cmd);
            CkJsonObjectW_Dispose(json);
            CkStringBuilderW_Dispose(pageSuffix);
            return;
        }

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

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

            i = i + 1;
        }

        more = CkJsonObjectW_BoolOf(json,L"has_more");
        if (more == TRUE) {
            next = CkJsonObjectW_stringOf(json,L"data[i].id");
            if ((count < 1) || (next == L"") || (next == cursor)) {
                wprintf(L"Invalid pagination cursor.\n");
                CkHttpCurlW_Dispose(curl);
                CkStringBuilderW_Dispose(cmd);
                CkJsonObjectW_Dispose(json);
                CkStringBuilderW_Dispose(pageSuffix);
                return;
            }

            cursor = next;
            CkStringBuilderW_SetString(pageSuffix,L"&starting_after=");
            CkStringBuilderW_Append(pageSuffix,cursor);
        }

    }

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


    CkHttpCurlW_Dispose(curl);
    CkStringBuilderW_Dispose(cmd);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(pageSuffix);

    }