#ajivrajani_code

1 messages ยท Page 1 of 1 (latest)

vivid zodiacBOT
#

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

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

queen compass
#

Hi there

dire condor
#

Hi! ๐Ÿ‘‹

#

Here's what I did to create a subscription 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. But what about other subscription properties? 
            {
                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),
                    },
                },
            },
        },
    }
queen compass
#

No, not exactly. You'll need to split this up into two requests: Create a Schedule from an existing Subscription, then update the newly-created Schedule to add a second phase

dire condor
#

Right - that's exactly what I did ^

queen compass
#

Which properties are you referring to exactly? Can you share the Subscription ID or the Schedule ID?

dire condor
#

When I "update" the newly created subscription, I am required to "build" phase 0 (pertaining to ongoing subscription) once again.

queen compass
#

Right, since you need to pass any current and future phases when updating a Schedule

dire condor
#

What about properties like "collect tax automatically", "collection methods" that were set on the original subscription? Will they be lost when I "redefine" this phase 0?

queen compass
#

Do you have a Subscription ID I can review? I'll test on my end with a similarly-created Subscription

dire condor
#

Sure! Give me a minute please, I will re-create that subscription and share the ID with you

#

SubscriptionID: sub_1PfqbeIp6MB4p4mql98YWvMb
Note: Tax collection = true, payment method = send_invoice and I've set a custom footer description on the subscription

#

In my phase [1], I want to change the priceID only

#

Wrong thread?

queen compass
celest violet
#

I'm sorry, I was just looking for the answer because I contacted the support team and did not receive any response

queen compass
#

@dire condor I see you created this via the Dashboard. Was this just for testing purposes or do you intend to create these via the Dashboard in live mode?

dire condor
#

Ah, this was only for testing purpose. Do you need me to create one using the API?

#

Everything is API driven in the live mode. Curious though - should that make any difference?

queen compass
#

It shouldn't but just wanted to make sure we're testing in the same way

dire condor
#

Gotcha. For now let's stick to dashboards if you don't mind - that way I can create/edit the subscriptions quickly.

vivid zodiacBOT
#

@celest violet looks like you're in the wrong place, this thread is for someone else's question.

Note that posting inappropriate messages in other people's threads is against the rules. No worries if this was just an honest mistake, but anyone who violates the rules multiple times will be removed from this server.

celest violet
#

I'm sorry

queen compass
#

Sorry, still testing this out

#

I'll need to test via the API. Creating a Schedule and adding a phase via the Dashboard keeps all previously-configured properties on the original Subscription so this isn't necessarily the best test

dire condor
#

Hmm I see. Makes sense, thank you. Let me know if you need any help from me. Appreciate your help ๐Ÿ™

queen compass
#

yep!

dire condor
#

Another question @queen compass :
Let's say I created the subscription -> created a new schedule with phase 0 and phase 1.

Now let's I want to update the quantity of ongoing subscription from 10 to 20.

Can I do that with subscription update API? Or do I need to call a combination of subscription update + schedule update APIs so that the phases (that will kick after a year) will also have quantity = 20 (updated amount)?

I've asked two separate questions. We can talk about this one after we figure out the first part.

queen compass
#

Okay, it's sufficient to pass just the Price on the first/current phase and the second phase when updating the Schedule. The previously-set automatic tax and collection method remain unchanged on the Subscription

dire condor
#

Ah okay, so similar to what I originally mentioned - that's good news. Thanks for confirming!

queen compass
#

As for your other question

#

Once a Subscription is managed by a Schedule, you should only update the Schedule going forward. You can update quantity on a phase

dire condor
#

So IIUC, if I want to update the quantity on an ongoing subscription immediately, I will have to iterate through all the phases of the attached schedule and update their quantities. Is that right?

queen compass
#

update the quantity on an ongoing subscription immediately
What do you mean by this exactly? Let's say a customer is upgrading from a quantity of 1 to a quantity of 10. If their Subscription is already managed by a Schedule and that Schedule has multiple phases that still use a quantity of 1, you will need to update the Schedule and ensure that each phase uses a quantity of 10 instead

dire condor
#

I meant I want to update the quantity now as opposed to scheduling this quantity update

dire condor
queen compass
dire condor
#

I wish this was simplified under the hood where I would just need to update the ongoing subscription ๐Ÿ˜ž Oh well - that would defeat the purpose of a schedule I guess. Thanks for your help and patience today, I really appreciate it.

I will test this and start a new thread if needed.

Have a wonderful rest of your day!