#naveed-web3auth_sub-schedule-release
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1389172416093098088
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- naveed-web3auth_best-practices, 1 hour ago, 45 messages
- naveed-web3auth_best-practices, 6 days ago, 67 messages
Is it possible to set a subscription to downgrade at the end of the month and release the schedule immediately when it occurs?
Yes
Basically subscription schedule remains for one month before finally being released but i want it to be immediate because that allows me to delete some resources on my application db and keep things in sync
You would create a Schedule with 2 phases. The first phase lasts 1 month is whatever the full price is and then the second phase is the downgrade is. This will also last 1 iteration and then release.
what i have encountered is that at the end of the month the subscription gets downgraded, but because it is now on phase 2 the subscription shcedule is still there
but from my pov the downgrade has already completed
so the release should happen at that point
but what happens instead is that release happens at the end of phase 2
so if i am scheduled to be downgraded on 1st July, i expect that I am downgraded and the sub schedule is released
but what happens is the sub schedule is only released at the end of july
This is what needs to happen in terms of the Sub Schedule. You need to have a new phase to capture what the sub is changing to. My question is, if the sub schedule is releasing, why does it matter?
Basically direct updates to subscriptions while a sub schedule exists causes additional phases to be added to the existing sub schedule object
technically a user can also downgrade again before sub schedule is fully released
because on 1st July they are downgraded
so after that point they can downgrade again
i feel like i would rather create a new subs schedule than edit the existing one
phases := constructSubscriptionSchedulePhaseParams(schedule.Phases)
phases = append(phases, &stripe.SubscriptionSchedulePhaseParams{
Items: subscriptionSchedulePhaseDowngradeItems,
Metadata: map[string]string{
"downgrade_plan": string(newPlan),
},
})
My downgrade logic looks like this atm, it appends to the existing phases
In that case you can trigger an immediate release after the downgrade using the API directly: https://docs.stripe.com/api/subscription_schedules/release
How can I know when to trigger this?
From what I know the subscription_schedule.updated event does not fire on phase transition
You would listen for the webhook event customer.subscription.updated and check to see if the price downgraded
hmmm
Because the Subscription object still gets changed
thats right
from your pov though u are saying its not too necessary to care about released state eh
let me see if i can design around that
Well you raise a good point about additional changes triggering new phases
So if that is something you wanted to avoid releasing immediately would help
in the midst of an upcoming downgrade, i have handled the case of preventing user from performing an upgrade by telling them to cancel first,
But once downgrade is completed they should now be able to upgrade/downgrade as they please. But the sub schedule at this point has not yet released.
If they upgrade the existing sub, schedule is updated automatically with the upgrade phase,
for downgrade, i would add to the existing subschedule a future downgrade phase
So if you release the Sub Schedule after you recieve the customer.subscription.updated event indicating the scheduled downgrade has taken place, that would allow you to make changes without creating a new phase
yes, that's exactly right
maybe i will have to inspect previous attributes and compare the price items to detect that it was a downgrade
The previus_attributes are what makes the .updated events so useful since they tell you what the previous values were along with the current state of the object.
Is it that price lookup keys are present in customer.subscription.updated whereas it is not present in schedule.updated?
You could use the subscription_schedule.updated if that is easier for you https://docs.stripe.com/api/events/types#event_types-subscription_schedule.updated
I just find the Subscription object easier to use, personally
as mentioned i cant rely on subscription_schedule.updated because it does not fire on phase transition
and i found that it did not contain information on price lookup keys
Yes, that is something we are actively working on.
So my recommendation to use custmer.subscription.updated still holds
Yes thus far I think this is the most elegant solution thank you,
I will try to evaluate between the pros and cons of keeping sub schedule auto released by stripe (being delayed by a month more than id like) vs manual release on downgrade success
I think it would depend on how much engineering it would take to build an automated process to trigger the release in response to the downgrade vs the impact of restricting when customers can make changes to their subscriptions
But ultimately that is up to how your business operates