#cho_best-practices

1 messages ¡ Page 1 of 1 (latest)

sharp haloBOT
#

👋 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.

wintry dockBOT
#

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.

slate ember
#

const updated_subscription = await stripe.subscriptions.update(
subscription_id,
{
trial_end: new_end_date_epoch,
proration_behavior: 'none',
}
)

wintry dockBOT
timid breach
#

Current phase is usually the one with index 0

slate ember
#

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

sharp haloBOT
timid breach
slate ember
#

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?

timid breach
#

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

slate ember
#

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

round surge
#

Hi there! Stepping in for my teammate

slate ember
#

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?

round surge
#

I recommend testing this out in test mode alongside test clocks so you can see what happens when the subscription cycles

slate ember
#

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?`

round surge
slate ember
#

I see

#

I was running into some typescript issues with it requiring me to pass

#

the required items array

#

let me try once again

slate ember
#

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

round surge
#

Sure thing!

slate ember
#

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

round surge
#

Just to be clear, does this mean you advanced a test clock into a new phase but index 0 was still the old phase?

slate ember
#

uhh yes

#

here were my steps

#
  1. made subscription schedule: phase 1 = 1 month, phase 2 = indefinite
  2. changed the renewal date to be 7 days in the future from now
  3. observed renewal date change
  4. 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."

round surge
#

Do you have the Schedule ID?

slate ember
#

is sub Id okay?

#

since sub id does not change even if phase changes

round surge
#

Yep, that works too

slate ember
#

sub_1P6HHRDyFtOu3ZuTU3No68e0

round surge
#

To be clear, Subscription Schedule ID doesn't change either even if the phase changes

slate ember
#

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

round surge
#

Hold on a second

slate ember
#

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

round surge
#

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

slate ember
#

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]

round surge
#

Sure, you can check the phases on a live mode subscription

slate ember
#

{ "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

round surge
#

Also, the end_date for phase 0 is 1712452173, which is in the past

slate ember
#

WOW if you can read epoch time and tell that's insane haha

#

but true!

round surge
#

Ha, no, I'm not that special. I converted it

slate ember
#

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

round surge
#

No, I don't think you did anything wrong here

slate ember
#

this is heinous Aryan_laugh

#

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

round surge
#

Ah, I see. Yeah, I see the subscription was released from the schedule

slate ember
#

oh interesting

#

so it looks like to accomplish my original task

#

I have to

  1. Determine if it has a schedule
  2. if it is a schedule determine which phase it is on using the epoch times and the given parameters