#jojilede
1 messages ยท Page 1 of 1 (latest)
does adding interval like this works?:
trial_period_days: 31,
interval: 4,
interval_unit: 'month'
}
Taking a look now
Can you be more specific about what you're trying to do? I'm not sure what "set the checkout.session subscription below in 4 months" means.
I want to just simply add a limit to the subscription to 4 cycle ๐
just to give a background:
" 4 cycle " what does this mean?
this is a long term property rental, and the use case above is I want to charge the user the initial payment(the ONE-TIME PRICE ID above) and the subscription that will end on their checkout date.
sample use case:
- Booking Date: now
- Check-in: Jan 15, 2023
- Check-out: June 14, 2023
we will charge the customer "now" for the cycle of Jan 15-Feb 14 and limit the subscription cycle to the remaining 4months (Feb - June)
This will set the billing cycle to charge every 4 months.
Oh I see.
So yeah, I think if you set the trial period to the number of days between the time of payment and the time of check-in, then they will not be charged for the Subscription, but you will have their payment details to charge when the subscription's trial is over.
Let me test on my end to make sure. I'll circle back to you in a few minutes
but that is already fixed on that code
what i need now is how to limit the subscription to the sample 4months.
Do you mean you want to cancel it at the 4 month mark?
yes ๐
Ahhhh! Okay, that's easy. I would recommend familiarizing yourself with this doc: https://stripe.com/docs/billing/subscriptions/cancel?dashboard-or-api=api
More specifically, you'll want to use cancel_at_period_end, which will cancel after 4 months when interval is set to 4 and interval_unit is set to month: https://stripe.com/docs/billing/subscriptions/cancel?dashboard-or-api=api#cancel-at-end-of-cycle
ah
so I will attach this to the webhook?
haha! That's exactly what I'm lookng for. Thank you so much!
Btw, may I know how will my code looks like now?
line_items: [
{
price: 'price_XXX',//ONE-TIME PRICE ID
quantity: 1,
},
{
price: 'price_XXX',//SUBSCRIPTION PRICE ID
quantity: 1,
},
],
mode: 'subscription',
success_url: `${req.headers.origin}/?success=true`,
cancel_url: `${req.headers.origin}/?canceled=true`,
automatic_tax: {enabled: true},
payment_method_types: ['card'],
subscription_data: {
trial_period_days: 31,
interval: 4,
interval_unit: 'month'
}
});
is that ok?
then on webhook I can just add:
case '[EVENT_NAME_FOR_SUBSCRIPTION_STARTED]':
stripe.subscriptions.update(event.object.subscription.id, {cancel_at_period_end: true});
also, how will this work now? will this work differently than what you said here?
That looks right to me. Now it will create the Subscription and (upon creation) the webhook will fire. Your server receives the webhook and then makes another API call to set cancel_at_period_end: true
Looks good to me
thanks, is the event.object.subscription.id correct?
Well I can just log it also from the webhook but it seems I still have to create it that's why I asked haha
or can I just do on the webhook:
case '[EVENT_NAME_FOR_SUBSCRIPTION_STARTED]':
stripe.subscriptions.update(event.object.subscription.id, {cancel_at: [FUTURE_DATE]});
I think it should be event.data.object.id
yeah, thanks ๐