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

Stripe: Preview a plan or seat change

See more Stripe Examples

Preview a seat or plan change and display its proration lines, total, and the timestamp to retain with the quote.

Stripe documentation and cURL example

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpCurlW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkDateTimeW.h>

void ChilkatSample(void)
    {
    BOOL success;
    const wchar_t *apiKey;
    HCkHttpCurlW curl;
    HCkStringBuilderW cmd;
    HCkJsonObjectW json;
    int replaced;
    const wchar_t *subscriptionId;
    const wchar_t *itemId;
    const wchar_t *priceId;
    HCkDateTimeW now;
    const wchar_t *prorationDate;
    int i;

    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();

    subscriptionId = L"sub_FROM_ACCOUNT";

    itemId = L"si_SELECTED_ITEM";

    priceId = L"price_FROM_CATALOG";

    now = CkDateTimeW_Create();
    CkDateTimeW_SetFromCurrentSystemTime(now);
    prorationDate = CkDateTimeW_getAsUnixTimeStr(now,FALSE);

    //  curl -X POST "https://api.stripe.com/v1/invoices/create_preview" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive" \
    //    -d "subscription={subscriptionId}" \
    //    -d "subscription_details[items][0][id]={itemId}" \
    //    -d "subscription_details[items][0][price]={priceId}" \
    //    -d "subscription_details[items][0][quantity]=5" \
    //    -d "subscription_details[proration_behavior]=create_prorations" \
    //    -d "subscription_details[proration_date]={prorationDate}"
    CkStringBuilderW_SetString(cmd,L"curl -X POST \"https://api.stripe.com/v1/invoices/create_preview\"");
    CkStringBuilderW_Append(cmd,L" -u \"@KEY@:\"");
    CkStringBuilderW_Append(cmd,L" -H \"Stripe-Version: 2026-10-28.endive\"");
    CkStringBuilderW_Append(cmd,L" -d \"subscription=@SUB@\"");
    CkStringBuilderW_Append(cmd,L" -d \"subscription_details[items][0][id]=@ITEM@\"");
    CkStringBuilderW_Append(cmd,L" -d \"subscription_details[items][0][price]=@PRICE@\"");
    CkStringBuilderW_Append(cmd,L" -d \"subscription_details[items][0][quantity]=5\"");
    CkStringBuilderW_Append(cmd,L" -d \"subscription_details[proration_behavior]=create_prorations\"");
    CkStringBuilderW_Append(cmd,L" -d \"subscription_details[proration_date]=@DATE@\"");
    replaced = CkStringBuilderW_Replace(cmd,L"@SUB@",subscriptionId);
    replaced = CkStringBuilderW_Replace(cmd,L"@ITEM@",itemId);
    replaced = CkStringBuilderW_Replace(cmd,L"@PRICE@",priceId);
    replaced = CkStringBuilderW_Replace(cmd,L"@DATE@",prorationDate);
    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);
        CkDateTimeW_Dispose(now);
        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);
        CkDateTimeW_Dispose(now);
        return;
    }

    wprintf(L"total = %s\n",CkJsonObjectW_stringOf(json,L"total"));
    wprintf(L"currency = %s\n",CkJsonObjectW_stringOf(json,L"currency"));

    wprintf(L"Save this preview time with the selected changes: %s\n",prorationDate);
    i = 0;
    while ((i < CkJsonObjectW_SizeOfArray(json,L"lines.data"))) {
        CkJsonObjectW_putI(json,i);
        if (CkJsonObjectW_BoolOf(json,L"lines.data[i].parent.subscription_item_details.proration") == TRUE) {
            wprintf(L"%s  %s\n",CkJsonObjectW_stringOf(json,L"lines.data[i].description"),CkJsonObjectW_stringOf(json,L"lines.data[i].amount"));
        }

        i = i + 1;
    }

    if (CkJsonObjectW_BoolOf(json,L"lines.has_more") == TRUE) {
        wprintf(L"Only the first page of preview lines is shown. The total covers all lines.\n");
    }



    CkHttpCurlW_Dispose(curl);
    CkStringBuilderW_Dispose(cmd);
    CkJsonObjectW_Dispose(json);
    CkDateTimeW_Dispose(now);

    }