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

Rust
let mut success = false;

// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
let api_key = "YOUR_STRIPE_TEST_KEY".to_string();

let curl = chilkat::HttpCurl::new();
let cmd = chilkat::StringBuilder::new();
let json = chilkat::JsonObject::new();

let subscription_id = "sub_FROM_ACCOUNT".to_string();

let item_id = "si_SELECTED_ITEM".to_string();

let price_id = "price_FROM_CATALOG".to_string();

let now = chilkat::DateTime::new();
let _ = now.set_from_current_system_time();
let proration_date = now.get_as_unix_time_str(false).unwrap_or_default();

// 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}"
let _ = cmd.set_string("curl -X POST \"https://api.stripe.com/v1/invoices/create_preview\"");
let _ = cmd.append(" -u \"@KEY@:\"");
let _ = cmd.append(" -H \"Stripe-Version: 2026-10-28.endive\"");
let _ = cmd.append(" -d \"subscription=@SUB@\"");
let _ = cmd.append(" -d \"subscription_details[items][0][id]=@ITEM@\"");
let _ = cmd.append(" -d \"subscription_details[items][0][price]=@PRICE@\"");
let _ = cmd.append(" -d \"subscription_details[items][0][quantity]=5\"");
let _ = cmd.append(" -d \"subscription_details[proration_behavior]=create_prorations\"");
let _ = cmd.append(" -d \"subscription_details[proration_date]=@DATE@\"");
let _ = cmd.replace("@SUB@", &subscription_id);
let _ = cmd.replace("@ITEM@", &item_id);
let _ = cmd.replace("@PRICE@", &price_id);
let _ = cmd.replace("@DATE@", &proration_date);
let _ = cmd.replace("@KEY@", &api_key);
success = curl.do_your_thing(&cmd.get_as_string().unwrap_or_default()).is_ok();
if !success {
    println!("No HTTP response. Chilkat failure code: {}", curl.fail_reason());
    return;
}

success = curl.get_response_json(&json).is_ok();
if (curl.status_code() != 200) || (!success) {
    println!("Stripe HTTP {}  Request-Id: {}", curl.status_code(), curl.get_response_header_field("Request-Id").unwrap_or_default());
    if success {
        println!("{}", json.string_of("error.message").unwrap_or_default());
    }

    return;
}

println!("total = {}", json.string_of("total").unwrap_or_default());
println!("currency = {}", json.string_of("currency").unwrap_or_default());

println!("Save this preview time with the selected changes: {}", proration_date);
let mut i = 0;
while i < json.size_of_array("lines.data") {
    json.set_i(i);
    if json.bool_of("lines.data[i].parent.subscription_item_details.proration") {
        println!("{}  {}", json.string_of("lines.data[i].description").unwrap_or_default(), json.string_of("lines.data[i].amount").unwrap_or_default());
    }

    i = i + 1;
}

if json.bool_of("lines.has_more") {
    println!("Only the first page of preview lines is shown. The total covers all lines.");
}