Sample code for 30+ languages & platforms
Unicode C Requires Chilkat v11.7.0+

Stripe: Create a Stripe Customer for an Existing Billing Account

See more Stripe Examples

Create a Stripe Customer for a local billing account. Send its internal reference in metadata and read the customer ID to save with that account.

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;
    const wchar_t *operationId;
    HCkHttpCurlW curl;
    HCkStringBuilderW cmd;
    HCkJsonObjectW json;
    int replaced;
    HCkStringBuilderW businessName;
    HCkStringBuilderW email;
    const wchar_t *accountRef;
    const wchar_t *customerId;

    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";
    //  Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
    operationId = L"YOUR_SAVED_OPERATION_UUID";

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

    //  For an account already linked to Stripe, reuse its saved customer ID.

    businessName = CkStringBuilderW_Create();
    CkStringBuilderW_SetString(businessName,L"Acme & Sons");

    email = CkStringBuilderW_Create();
    CkStringBuilderW_SetString(email,L"billing+east@example.com");

    accountRef = L"ACME-1042";

    //  curl -X POST "https://api.stripe.com/v1/customers" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive" \
    //    -H "Idempotency-Key: {operationId}-customer" \
    //    -d "name={businessName}" \
    //    -d "email={email}" \
    //    -d "metadata[account_ref]={accountRef}"
    CkStringBuilderW_SetString(cmd,L"curl -X POST \"https://api.stripe.com/v1/customers\"");
    CkStringBuilderW_Append(cmd,L" -u \"@KEY@:\"");
    CkStringBuilderW_Append(cmd,L" -H \"Stripe-Version: 2026-10-28.endive\"");
    CkStringBuilderW_Append(cmd,L" -H \"Idempotency-Key: @OP@-customer\"");
    CkStringBuilderW_Append(cmd,L" -d \"name=@NAME@\"");
    CkStringBuilderW_Append(cmd,L" -d \"email=@EMAIL@\"");
    CkStringBuilderW_Append(cmd,L" -d \"metadata[account_ref]=@REF@\"");
    replaced = CkStringBuilderW_Replace(cmd,L"@NAME@",CkStringBuilderW_getEncoded(businessName,L"url_rfc3986",L"utf-8"));
    replaced = CkStringBuilderW_Replace(cmd,L"@EMAIL@",CkStringBuilderW_getEncoded(email,L"url_rfc3986",L"utf-8"));
    replaced = CkStringBuilderW_Replace(cmd,L"@REF@",accountRef);
    replaced = CkStringBuilderW_Replace(cmd,L"@OP@",operationId);
    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(businessName);
        CkStringBuilderW_Dispose(email);
        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(businessName);
        CkStringBuilderW_Dispose(email);
        return;
    }

    //  Save this string on the existing billing account after a successful create.
    customerId = CkJsonObjectW_stringOf(json,L"id");
    wprintf(L"Stripe customer: %s\n",customerId);


    CkHttpCurlW_Dispose(curl);
    CkStringBuilderW_Dispose(cmd);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(businessName);
    CkStringBuilderW_Dispose(email);

    }