#NEWJOSSY

1 messages ยท Page 1 of 1 (latest)

midnight talonBOT
dawn badger
#

Hello there )

vernal notch
dawn badger
#

Yeah but it will cancel subscription immediately

#

I want subscription to be canceled on the next payment date and when the next phase of schedule will be active

vernal notch
#

Not sure I understand exactly your use case ? you mean once the next invoice is paid, you want to cancel the subscription regardless if the Subscription Schedule ends or not ? or you want to wait until all subscription_schedule's phases to end then cancel the subscription ?

dawn badger
#

Okay let me explain more detailed

#

User requested to change billing cycle from monthly to annual. I have implemented that using Stripe Schedules

#

If user requested this change, his subscription is managed by scheduler now, and I cannot use Subscription API with property.
SubscriptionUpdateOptions options = new() { CancelAtPeriodEnd = true };

If I'll use Cancel for Scheduler, subscription will be immediately canceled and the next invoice for new annual subscription will be cancelled too. What I want is to cancel current monthly subscription at the date when invoice for new annual subscription should be paid. Here is my code for reference how I update billing cycle for customer from Monthly Standard subscription to Annual Standard subscription.

#

`SubscriptionScheduleCreateOptions createOptions = new()
{
FromSubscription = oldSubscription.Id,
};

        SubscriptionScheduleService service = new SubscriptionScheduleService();
        var schedule = await service.CreateAsync(createOptions);

        SubscriptionScheduleUpdateOptions updateOptions = new SubscriptionScheduleUpdateOptions
        {
            Phases = new List<SubscriptionSchedulePhaseOptions>
            {
                new SubscriptionSchedulePhaseOptions
                {
                    Iterations = 1,
                    StartDate = schedule.CurrentPhase.StartDate,
                    Items = new List<SubscriptionSchedulePhaseItemOptions>
                    {
                        new SubscriptionSchedulePhaseItemOptions { Price = oldSubscription.Items.Data[0].Price.Id },
                    },
                },
                new SubscriptionSchedulePhaseOptions
                {
                    Items = new List<SubscriptionSchedulePhaseItemOptions>
                    {
                        new SubscriptionSchedulePhaseItemOptions { Price = newSubscriptionPriceId },
                    },
                },
            },
        };

        await service.UpdateAsync(schedule.Id, updateOptions);`
vernal notch
#

Thanks for sharing these details.

What I want is to cancel current monthly subscription at the date when invoice for new annual subscription should be paid
I don't understand what you want to cancel? the existing Subscription is converted to a Subscription Scheduler. There'll be no new monthly invoices once the new annual Subscription is in place. The Subscription Schedule is just a wrapper to your existing Subscription. So you should just manipulate the new subscription scheduler.

dawn badger
#

Here is the result of canceled schedule

#

And here is the result of cancelling subscription via Subscription API

#

The second one cancels at May 4

#

When the first one cancels at the same moment when schedule was canceled

#

The second one is still active until May 4

#

I want the same behavior for schedule

vernal notch
dawn badger
#

That are separate API calls

#

I need to update the scheduler, but how can I update phase?

vernal notch
dawn badger
#

How do i specify exact phase for edit ?

vernal notch
#

When doing phase update, you need to pass all phases (including the current one).

midnight talonBOT
soft iron
#

๐Ÿ‘‹ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!

dawn badger
#

Ok, I have now trouble with dates

#

id of request
req_Lb8DzzmQJoP0Oz

soft iron
#

the second phase has the same start_date and end_date

#

end_date: "1683201568"
start_date: "1683201568"

dawn badger
#

Ok I've added one second

#

And what will happen after 4-th of May ?

soft iron
#

why do you need a 1sec cycle?

#

what are you trying to achieve?

dawn badger
#

result like this

soft iron
#

I'm not sure I understand

#

would you mind explaining

dawn badger
#

I want to cancel current user subscription on the next payment date. Like it's done with Subscription API

#

In Subscription API we have CancelAtPeriodEnd = true, is there any similar property in Subscription Scheduler ?

woven drift
#

Hi ๐Ÿ‘‹ when you mention Subscription Scheduler, are you referring to our Subscription Schedules?
If so, then you have those cancel the associated Subscription at the end of their lifecycle by setting the end_behavior to release:
https://stripe.com/docs/api/subscription_schedules/update?lang=node#update_subscription_schedule-end_behavior