#inderjeet-subscriptions
1 messages · Page 1 of 1 (latest)
Hello
I want to downgrade the plan at the end of the period so what i have to do for this.
hi! well the most flexible way to do that is to use SubscriptionSchedules https://stripe.com/docs/billing/subscriptions/subscription-schedules . You can schedule changes to the subscription, like changing the plan at the end of the current cycle.
$subSchedule = $stripe->subscriptionSchedules->update(
$subscription->id,
[
'end_behavior' => 'release',
'phases' => [
[
'items' => [
[
'price' => $currentPriceId,
'quantity' => 1,
],
],
'start_date' => $startPeriodDate,
'end_date' => $endPeriodDate,
],
[
'items' => [
[
'price' => $priceId,
'quantity' => 1,
],
],
'start_date' => $endPeriodDate
],
],
]
);
I am using the above code let me clear one thing i 'm passing the downgrade plan price id and startdate then how it will take subscription billing cycle ?
that would change from $currentPriceId to $priceId at the time $endPeriodDate , so yes, that seems correct for what you want
I have one more question suppose i have click on downgrade plan button today. but i want to downgrade the plan at the billing cycle then how i will update the downgrade plan in database. i think in this situation i have to use** Webhook** for update downgrade plan in the database. Am i right?
@glossy peak Are you there ?
yes
so yes, you would listen to webhooks I think
you can listen to the customer.subscription.updated event
that happens when the subscription cycles and switches to the new plan, at that point you can sync your database
What webhook event, i have to use for cancel subscription time therefore i have to sync with database.
customer.subscription.deleted
Thank you, @glossy peak Is it possible to access webhook at localhost ?
you can use our stripe-cli tool to forward webhooks to a local server during development; https://stripe.com/docs/stripe-cli/webhooks