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

Delphi DLL
var
success: Boolean;
apiKey: PWideChar;
curl: HCkHttpCurl;
cmd: HCkStringBuilder;
json: HCkJsonObject;
replaced: Integer;
subscriptionId: PWideChar;
itemId: PWideChar;
priceId: PWideChar;
now: HCkDateTime;
prorationDate: PWideChar;
i: Integer;

begin
success := False;

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

curl := CkHttpCurl_Create();
cmd := CkStringBuilder_Create();
json := CkJsonObject_Create();

subscriptionId := 'sub_FROM_ACCOUNT';

itemId := 'si_SELECTED_ITEM';

priceId := 'price_FROM_CATALOG';

now := CkDateTime_Create();
CkDateTime_SetFromCurrentSystemTime(now);
prorationDate := CkDateTime__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}"
CkStringBuilder_SetString(cmd,'curl -X POST "https://api.stripe.com/v1/invoices/create_preview"');
CkStringBuilder_Append(cmd,' -u "@KEY@:"');
CkStringBuilder_Append(cmd,' -H "Stripe-Version: 2026-10-28.endive"');
CkStringBuilder_Append(cmd,' -d "subscription=@SUB@"');
CkStringBuilder_Append(cmd,' -d "subscription_details[items][0][id]=@ITEM@"');
CkStringBuilder_Append(cmd,' -d "subscription_details[items][0][price]=@PRICE@"');
CkStringBuilder_Append(cmd,' -d "subscription_details[items][0][quantity]=5"');
CkStringBuilder_Append(cmd,' -d "subscription_details[proration_behavior]=create_prorations"');
CkStringBuilder_Append(cmd,' -d "subscription_details[proration_date]=@DATE@"');
replaced := CkStringBuilder_Replace(cmd,'@SUB@',subscriptionId);
replaced := CkStringBuilder_Replace(cmd,'@ITEM@',itemId);
replaced := CkStringBuilder_Replace(cmd,'@PRICE@',priceId);
replaced := CkStringBuilder_Replace(cmd,'@DATE@',prorationDate);
replaced := CkStringBuilder_Replace(cmd,'@KEY@',apiKey);
success := CkHttpCurl_DoYourThing(curl,CkStringBuilder__getAsString(cmd));
if (success <> True) then
  begin
    Memo1.Lines.Add('No HTTP response. Chilkat failure code: ' + IntToStr(CkHttpCurl_getFailReason(curl)));
    Exit;
  end;
success := CkHttpCurl_GetResponseJson(curl,json);
if ((CkHttpCurl_getStatusCode(curl) <> 200) or (success <> True)) then
  begin
    Memo1.Lines.Add('Stripe HTTP ' + IntToStr(CkHttpCurl_getStatusCode(curl)) + '  Request-Id: ' + CkHttpCurl__getResponseHeaderField(curl,'Request-Id'));
    if (success = True) then
      begin
        Memo1.Lines.Add(CkJsonObject__stringOf(json,'error.message'));
      end;
    Exit;
  end;

Memo1.Lines.Add('total = ' + CkJsonObject__stringOf(json,'total'));
Memo1.Lines.Add('currency = ' + CkJsonObject__stringOf(json,'currency'));

Memo1.Lines.Add('Save this preview time with the selected changes: ' + prorationDate);
i := 0;
while (i < CkJsonObject_SizeOfArray(json,'lines.data')) do
  begin
    CkJsonObject_putI(json,i);
    if (CkJsonObject_BoolOf(json,'lines.data[i].parent.subscription_item_details.proration') = True) then
      begin
        Memo1.Lines.Add(CkJsonObject__stringOf(json,'lines.data[i].description') + '  ' + CkJsonObject__stringOf(json,'lines.data[i].amount'));
      end;
    i := i + 1;
  end;

if (CkJsonObject_BoolOf(json,'lines.has_more') = True) then
  begin
    Memo1.Lines.Add('Only the first page of preview lines is shown. The total covers all lines.');
  end;

CkHttpCurl_Dispose(curl);
CkStringBuilder_Dispose(cmd);
CkJsonObject_Dispose(json);
CkDateTime_Dispose(now);