Dynamically update trial durationsVersion bêta privée
Update trial durations in response to changes made during checkout.
Private preview
This feature is in private preview. Request access to dynamic trial updates.
Learn how to dynamically update trial durations on subscription Checkout Sessions.
Use cases 
- Dynamic trial management: Add or remove trials based on promotional conditions or customer actions.
- Extend trials for upsells: Offer longer trial periods when customers upgrade to higher-tier plans (for example. 7 days for monthly gets extended to 14 days for yearly).
Set up SDKServer-side
Use our official libraries to access the Stripe API from your application:
Update server SDKServer-side
To use this beta, first update your SDK to use the private preview API version and the checkout_
beta version header.
Dynamically update trial durationsServer-side
Create a new endpoint on your server to update the trial duration for a yearly upsell on the Checkout Session. You call this from the frontend in a later step.
Conseil en matière de sécurité
Client-side code runs in an environment fully controlled by the user. A malicious user can bypass your client-side validation, intercept, and modify requests, or even create entirely new requests to your server.
When designing the endpoint, we recommend the following:
- Design endpoints for specific customer interactions instead of making them overly generic (for example, “extend trial for yearly upgrade” rather than a general “update” action). Specific endpoints help keep the purpose clear and make validation logic easier to write and maintain.
- Avoid passing Session data directly from the client to your endpoint. Malicious clients can modify request data, making it an unreliable source for determining the Checkout Session state. Instead, pass the session ID to your server and use it to securely retrieve the data from Stripe’s API.
You can update trial durations using either:
trial_
: An integer that represents the number of days for the trial period, or empty string to remove the trialperiod_ days trial_
: A Unix timestamp that represents when the trial should end, or empty string to remove the trialend
Keep in mind the following:
- The
trial_
andperiod_ days trial_
parameters are mutually exclusive. You can only specify one of them in a single update request.end - When removing a trial, use the same field that it was set with. A trial set with
trial_
can only be removed withperiod_ days trial_
, and a trial set withperiod_ days: "" trial_
can only be removed withend trial_
.end: ""
Test the integration
Test your integration to ensure trial duration updates work correctly:
- Create a subscription Checkout Session with an initial trial period.
- Trigger your server endpoint by interacting with the UI element you created.
- Verify the trial duration is updated correctly in the Checkout Session.
- Complete the checkout to ensure the subscription is created with the correct trial settings.
Remarque
When testing, use Stripe’s test mode to avoid creating live subscriptions. You can verify the trial duration changes by inspecting the Checkout Session object or the created subscription.
Common testing scenarios
- Trial extension: Start with a 7-day trial, extend to 14 days, and verify the change is reflected in the UI and session object.
- Remove existing trial: Start with a 7-day trial, remove it, and verify the change is reflected in the UI and session object. Remove the trial using the same field that it was set with.
- Error handling: Test invalid requests to ensure your error handling works correctly.