#ajivrajani_code

1 messages ยท Page 1 of 1 (latest)

dawn pathBOT
#

๐Ÿ‘‹ 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/1265746433752170526

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

blazing tulipBOT
#

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.

restive jay
#

Hey there

#

Can you share the Subscription ID that you tested with?

pine urchin
#

Absolutely

#

sub_1PgAItIp6MB4p4mqF6BCOwRb

#

Here's what I want to do:
Jan 2, 2024: Start subscription with priceID p1
Schedule updating the priceID to p2 when the subscription renews on Jan 2, 2025

restive jay
#

When you update a Subscription schedule you need to pass in the current phase as phase 0

pine urchin
#

Ah no, apologies. This is the new subscription I was testing with.

#

Here's how I am creating a schedule:

    schedule, err := sc.sClient.SubscriptionSchedules.New(&stripe.SubscriptionScheduleParams{
        FromSubscription: stripe.String(req.SubscriptionID),
    })
    if err != nil {
        return nil, errors.Wrapf(err, "creating new subscription schedule for subscriptionID: %s", req.SubscriptionID)
    }

    // Update the schedule with new phase
    params := &stripe.SubscriptionScheduleParams{
        Phases: []*stripe.SubscriptionSchedulePhaseParams{
            // Phase 0: this is the existing subscription phase
            {
                Items: []*stripe.SubscriptionSchedulePhaseItemParams{
                    {
                        Price:    stripe.String(schedule.Phases[0].Items[0].Price.ID),
                        Quantity: stripe.Int64(schedule.Phases[0].Items[0].Quantity),
                    },
                },
                StartDate: stripe.Int64(schedule.Phases[0].StartDate),
                EndDate:   stripe.Int64(schedule.Phases[0].EndDate),
            },
            // Phase 1: this is the new schedule phase
            {
                Items: []*stripe.SubscriptionSchedulePhaseItemParams{
                    {
                        Price: stripe.String(req.PriceID),
                        // the quantity of the new phase remains the same as the ongoing subscription
                        Quantity: stripe.Int64(schedule.Phases[0].Items[0].Quantity),
                    },
                },
            },
        },
    }
#

Note that I am creating phase 0 with ongoing subscription parameters (price and quantity)

restive jay
#

Okay well can you provide me the Subscription ID where you correctly set the Subscription Schedule and you didn't see it release after it completed all of its phases?

pine urchin
#

Sure! Give me ~3 minutes to set it up.

#

Alright here's the subscription with the attached schedule: sub_1PgAItIp6MB4p4mqF6BCOwRb
Do you want me to advnace the clock on this before you check things on your end?

restive jay
#

Yep

pine urchin
#

On it ๐Ÿซก

#

I advanced the clock by a year to July 25, 2025 | 12:14 PM PDT (a year from now)

restive jay
#

Ah the Schedule is still active until all of its phases complete. Your phase 1 has iterations: 1 meaning it will last a year as well.

#

Maybe that is the confusion

#

If you advance another year then you should see the schedule release

pine urchin
#

I see I see. Is there something I can do make the phase 1 essentially last for an instant long enough to switch the priceID to p2?

pine urchin
#

Effectively I want to change the priceID at the time of renewal. Having a phase attached even after a renewal makes it difficult to "update" subscriptions. Updates like quantity changes....

#

Right! So I can just put end_date as Jan 2, 2025 + 1 minute?

restive jay
#

Yep that should work

pine urchin
#

Interesting. Thank you!

Would you say this is an idiomatic approach of achieving what I described?

restive jay
#

Yeah it's a fine way to go.

pine urchin
#

Gotcha, thank you so much. I appreciate your help! ๐Ÿ™ Have a wonderful day!