Passer au contenu principal
POST
/
subscriptions
/
{subscription_id}
/
change-plan
JavaScript
import DodoPayments from 'dodopayments';

const client = new DodoPayments({
  bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
});

await client.subscriptions.changePlan('subscription_id', {
  product_id: 'product_id',
  proration_billing_mode: 'prorated_immediately',
  quantity: 0,
});

Modifications de plan programmées

Utilisez le paramètre effective_at pour contrôler quand le changement de plan prend effet :
ValeurComportement
immediatelyAppliquer le changement de plan immédiatement. C’est l’option par défaut.
next_billing_dateProgrammer le changement pour la prochaine date de facturation. Le client conserve l’accès à son plan actuel jusqu’à la fin de la période de facturation.
Les modifications de plan programmées sont idéales pour les déclassements — les clients conservent les avantages de leur plan actuel jusqu’à la fin de la période de facturation, puis passent automatiquement au nouveau plan.
Pour annuler une modification de plan programmée avant qu’elle ne prenne effet, utilisez le point de terminaison Annuler la modification de plan programmée.

Gestion des échecs de paiement

Utilisez le paramètre on_payment_failure pour contrôler ce qui se passe en cas d’échec du paiement du changement de plan :
ValeurComportement
prevent_changeConserver l’abonnement sur le plan actuel jusqu’à la réussite du paiement. Le changement de plan reste en attente.
apply_changeAppliquer le changement de plan immédiatement, quel que soit le résultat du paiement. C’est l’option par défaut.
Si on_payment_failure n’est pas spécifié, le comportement par défaut dépend du paramètre de niveau entreprise configuré dans le tableau de bord.

Codes de réduction

Vous pouvez appliquer un code de réduction lors du changement de plan en transmettant le paramètre discount_code.
ScénarioComportement
discount_code fourniValide et applique la réduction au nouveau plan.
discount_code non fourni, réduction existante avec preserve_on_plan_change=trueLa réduction existante est conservée si elle s’applique au nouveau produit.
discount_code non fourni, aucune réduction conservableAucune réduction appliquée.
Utilisez des codes de réduction lors des changements de plan pour offrir des tarifs promotionnels sur les améliorations, ou transmettez un code lorsque vous passez les clients à un nouveau niveau de plan.
Utilisez prevent_change pour les mises à niveau critiques où vous souhaitez garantir le paiement avant d’accorder l’accès aux fonctionnalités premium.

Autorisations

Authorization
string
header
requis

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Paramètres de chemin

subscription_id
string
requis

Subscription Id

Corps

application/json
product_id
string
requis

Unique identifier of the product to subscribe to

proration_billing_mode
enum<string>
requis

Proration Billing Mode

Options disponibles:
prorated_immediately,
full_immediately,
difference_immediately,
do_not_bill
quantity
integer<int32>
requis

Number of units to subscribe for. Must be at least 1.

Plage requise: x >= 0
addons
Attach Addon Request · object[] | null

Addons for the new plan. Note : Leaving this empty would remove any existing addons

discount_code
string | null

Optional 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_at
enum<string>

When to apply the plan change.

  • immediately (default): Apply the plan change right away
  • next_billing_date: Schedule the change for the next billing date
Options disponibles:
immediately,
next_billing_date
metadata
object

Metadata for the payment. If not passed, the metadata of the subscription will be taken

on_payment_failure
null | enum<string>

Controls behavior when the plan change payment fails.

  • prevent_change: Keep subscription on current plan until payment succeeds
  • apply_change (default): Apply plan change immediately regardless of payment outcome

If not specified, uses the business-level default setting.

Options disponibles:
prevent_change,
apply_change

Réponse

Subscription plan changed. If on_payment_failure=prevent_change, the plan change is pending until payment succeeds.

Last modified on April 20, 2026