Change Subscription Plan

Preview the effects of a subscription plan change before committing to it.

Request

use dodopayments_rust::{
    models::UpdateSubscriptionPlanReq, to_pretty_json, DodoPaymentsClientBuilder,
};

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("DODO_API_KEY")?;

    let client = DodoPaymentsClientBuilder::new()
        .bearer_token(&api_key)
        .enviroment("test_mode")
        .build()?;

    let subscription_id = "sub_xxxxxxxxxx";

    let resp = client
        .subscriptions()
        .id(subscription_id)
        .change_plan()
        .body(UpdateSubscriptionPlanReq {
            product_id: "prod_xxxxxxxxxx".to_string(),
            ..Default::default()
        })
        .send()
        .await?;

    println!("{}", to_pretty_json(&resp)?);

    Ok(())
}

Path Parameters

ParameterTypeDescription
subscription_idstringSubscription Id

Body

FieldTypeDescription
addonsobjectAddons for the new plan. Note : Leaving this empty would remove any existing addons
discount_codeobjectOptional discount code to apply to the new plan. If provided, validates and applies the discount to the plan change. If not provided and the subscription has an existing discount with preserve_on_plan_change=true, the existing discount will be preserved (if applicable to the new product).
effective_atEffectiveAtWhen to apply the plan change. - immediately (default): Apply the plan change right away - next_billing_date: Schedule the change for the next billing date
metadataobject
on_payment_failureobject
product_idstringUnique identifier of the product to subscribe to
proration_billing_modeProrationBillingModeProration Billing Mode
quantityintegerNumber of units to subscribe for. Must be at least 1.

Responses

200 Status

FieldTypeDescription
immediate_chargeImmediateCharge
new_planSubscriptionResponse

Preview of subscription plan change

500 Status

Something went wrong :(