#essakrishnachaitanya - Checkout Subscription duration
1 messages · Page 1 of 1 (latest)
Hello, good question. Checking in to whether Checkout can set this automatically
It looks like Checkout can't specify this from the start but you can listen to the checkout.session.succeeded event or the customer.subscription.created event and update the subscription's cancel_at timestamp to tell stripe when to end the subscription.
can you please send me sample example of checkout.session.succeeded and customer.subscription.created event in javascript
We have a guide on handling them but I am not seeing example values, checking if we have that... https://stripe.com/docs/payments/checkout/fulfill-orders#create-event-handler
It looks like we don't but you can see how an event object is structured here[1] and how the checkout object on it will look here[2]
[1] https://stripe.com/docs/api/events/object
[2] https://stripe.com/docs/api/checkout/sessions/object
How to create a subscription schedule with iterations on stripe checkout..?
Unfortunately Checkout cannot create a subscription schedule by itself. To use a schedule like this, you can listen to those same webhook events and create a schedule from an existing subscription https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription
okay from plain javascript how to create a schedule subscription..?
That doc has a snippet for how to make that call in Node.js
from_subscription: 'sub_GB98WOvaRAWPl6'
});```
okay our requirement is we need to create a subscription for user for a specified duration in javascript
Makes sense, in your scenario, that would mean that you create the Checkout Session, listen for the appropriate webhook, and then when you get that webhook you can either:
- Calculate when you want the subscription to end and make and API call to set the
cancels_attimestamp on your subscriptions - Make an API call to create a subscription schedule from the subscription that your Checkout Session created and then another API call to set how many
iterationsyou want the subscription to last for