#cho_best-practices
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/1229894857569472594
đ 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.
- cho_best-practices, 55 minutes ago, 24 messages
- cho_best-practices, 4 days ago, 31 messages
const updated_subscription = await stripe.subscriptions.update(
subscription_id,
{
trial_end: new_end_date_epoch,
proration_behavior: 'none',
}
)
Current phase is usually the one with index 0
ahh okay
why "usually" ?
I mean, I can test that in test mode with the time tool, but I'd like to know the caveat
Ah also the subscription schedule has current_phase param
https://docs.stripe.com/api/subscription_schedules/object#subscription_schedule_object-current_phase
ah, but current phase param just gives start and end epochs
I was actually about to use that and write logic gates to tell me the index with the epoch in btwn
but wanted to save myself the code bc it seemed very logical that you guys would have a solve
So can I move forward assuming index 0 is the current phse?
In my experience it is always index 0, just haven't tested it myself recently
99% sure. Would recommend testing it out just in case
okay!
ty
once again haha
Do you guys have a reference I can use to try and update this code?
maybe more docs that have examples?
I'm having to try and engineer around the fact that this phases array has multiple indexed items and also requires the items array when all I want is to extend the subscription time
Hi there! Stepping in for my teammate
We have some sample code for a few different Schedule use cases here: https://docs.stripe.com/billing/subscriptions/subscription-schedules/use-cases
I am looking all through the docs and I think I need to discuss if my approach is even correct
Originally, I opened a case and spoke to hanzo about updating subscriptions to extend the billing date
However we use subscription schedules, so I hit a wall
I want to push out the billing anchor date for a subscription schedule by X number of days essentially. We sell prescription medications so sometimes we need to push it out a week for the customer
I'm questioning what I am actually needing to change within the stripe object to achieve this
Would I need to add a trial to the current phase of the subscription schedule? Or do I change the start / end dates?
I think this is the sample you're looking for: https://docs.stripe.com/billing/subscriptions/subscription-schedules/use-cases#resetting-anchor
I recommend testing this out in test mode alongside test clocks so you can see what happens when the subscription cycles
ok ty
i see this is for 'create' , but would it apply to update?
Like, is there an equivalent to:
`const updated_subscription = await stripe.subscriptions.update(
subscription_id,
{
trial_end: new_end_date_epoch,
proration_behavior: 'none',
}
)
code for subscription schedules?`
You can update a Schedule, yes: https://docs.stripe.com/api/subscription_schedules/update
You'll want to update the phase
I see
I was running into some typescript issues with it requiring me to pass
the required items array
let me try once again
ok i got it
thank you very much
I did end up running into a lot of my own errors in learning the type of the Phase in the ScheduleUpdateParams, but very do-able
Sure thing!
thank you @round surge , and also thank you @timid breach
oh
I actually ran into the issue
hanzo was mistaken
index 0 is NOT the current phase
I guess there is no real way to know what is the current phase prior to checking with logic
Just to be clear, does this mean you advanced a test clock into a new phase but index 0 was still the old phase?
uhh yes
here were my steps
- made subscription schedule: phase 1 = 1 month, phase 2 = indefinite
- changed the renewal date to be 7 days in the future from now
- observed renewal date change
- pushed 32 days into the future to confirm anchor change
here is where the problem began:
5. attempted to change renewal date once more
6. got hit with the RequestError: "You can not update a phase that has already ended. Trying to update phase 0."
Do you have the Schedule ID?
Yep, that works too
sub_1P6HHRDyFtOu3ZuTU3No68e0
To be clear, Subscription Schedule ID doesn't change either even if the phase changes
can you confirm to me whether hanzo was mistaken and the phases will come identically to the test I conducted?
I am also under suspicion that it is returning the phases as-is since it is test-mode, but I'd like the confirmation
Hold on a second
okay, I just wanted to say i'm just very scared to be wrong in live here because we can't manually modify the subscription schedules since we don't have billing scale
Can you start this test over and, instead of taking an existing test mode subscription and adding a test clock to it, create a brand-new test clock then add a customer and a schedule + subscription there
uhh would it speed this up if I just
retrieved a live mode subscription
and checked the phases
I have 1 customer who is in phase 1 [0 indexed]
Sure, you can check the phases on a live mode subscription
{ "id": "sub_sched_1OrVSjDyFtOu3ZuT6ZIE7kQe", "object": "subscription_schedule", "application": null, "canceled_at": null, "completed_at": null, "created": 1709773773, "current_phase": { "end_date": 1715044173, "start_date": 1712452173 }, "customer": "cus_Pf3YKPYDPoVLmJ", "default_settings": { "application_fee_percent": null, "automatic_tax": { "enabled": false, "liability": null }, "billing_cycle_anchor": "automatic", "billing_thresholds": null, "collection_method": "charge_automatically", "default_payment_method": "pm_1OpjRRDyFtOu3ZuTgK3DBDh1", "default_source": null, "description": null, "invoice_settings": { "account_tax_ids": null, "days_until_due": null, "issuer": { "type": "self" } }, "on_behalf_of": null, "transfer_data": null }, "end_behavior": "release", "livemode": true, "metadata": { "orderId": "1317" }, "phases": [ { "add_invoice_items": [], "application_fee_percent": null, "billing_cycle_anchor": null, "billing_thresholds": null, "collection_method": null, "coupon": "nW8Pjgx0", "currency": "usd", "default_payment_method": null, "default_tax_rates": [], "description": "NAD+ Injection first-month subscription", "discounts": [ { "coupon": "nW8Pjgx0", "discount": null, "promotion_code": null } ], "end_date": 1712452173, "invoice_settings": null, "items": [ { "billing_thresholds": null, "discounts": [], "metadata": {}, "plan": "price_1OpOdFDyFtOu3ZuToP8CUeqF", "price": "price_1OpOdFDyFtOu3ZuToP8CUeqF", "quantity": 1, "tax_rates": [] } ], "metadata": {}, "on_behalf_of": null, "proration_behavior": "create_prorations", "start_date": 1709773773, "transfer_data": null, "trial_end": null }, { "add_invoice_items": [], "application_fee_percent": null, "billing_cycle_anchor": null, "billing_thresholds": null, "collection_method": null, "coupon": null, "currency": "usd", "default_payment_method": null, "default_tax_rates": [], "description": "NAD+ Injection subscription", "discounts": [], "end_date": 1715044173, "invoice_settings": null, "items": [ { "billing_thresholds": null, "discounts": [], "metadata": {}, "plan": "price_1OpOdFDyFtOu3ZuToP8CUeqF", "price": "price_1OpOdFDyFtOu3ZuToP8CUeqF", "quantity": 1, "tax_rates": [] } ], "metadata": {}, "on_behalf_of": null, "proration_behavior": "create_prorations", "start_date": 1712452173, "transfer_data": null, "trial_end": null } ], "released_at": null, "released_subscription": null, "renewal_interval": null, "status": "active", "subscription": "sub_1OrVSjDyFtOu3ZuTPdOW9yTA", "test_clock": null }
I just copy pasted the object here for reference
it seems that phase 0 is indeed just the first phase
I know mainly because the first phase of our subscriptions have a discount
Also, the end_date for phase 0 is 1712452173, which is in the past
Ha, no, I'm not that special. I converted it
additional question
for the end_date on the 2nd phase I see
my 2nd phase is supposed to be indefinite
did I do something wrong for an end_date to appear?
oh
it leaves the schedule
No, I don't think you did anything wrong here
this is heinous 
I just went to test mode and pushed my original test
another 1 month
and I found out that it just converts to a regular subscription
Ah, I see. Yeah, I see the subscription was released from the schedule
I think hanzo might have been mixed up and was thinking about updates made to schedules: https://docs.stripe.com/billing/subscriptions/subscription-schedules#updating
You have to pass the current and all future schedules so the current phase in that call is in index 0
if you can read epoch time and tell that's insane haha