#Jonas Reif-subs-schedule

1 messages · Page 1 of 1 (latest)

crimson spindle
#

You'd have a schedule with a phases field that mirrors the 3 month schedule you want, and then set end_behaviour: 'cancel'

gleaming fern
#

So first I have to create a schedule like this:

subscription = "our created subscription"
schedule = Stripe::SubscriptionSchedule.create({
  from_subscription: subscription.id
})

And then in a next api call I update this like

Stripe::SubscriptionSchedule.update(
schedule.id,
  {
phases: [
    {
      items: [
        {
          price: subscription.price.id,
          quantity: 1,
        },
      ],
      iterations: 3,
    },
  ],
},
)

```
#

Is that correct like this?

crimson spindle
#

OOO, why must you create a subscription initially then the schedule?

gleaming fern
#

ah sorry

Stripe::SubscriptionSchedule.update(
schedule.id,
  {
end_behavior: 'cancel'
phases: [
    {
      items: [
        {
          price: subscription.price.id,
          quantity: 1,
        },
      ],
      iterations: 3,
    },
  ],
},
)

```
#

Because we are using stripe checkout and there you cannot create Subscription Schedules

crimson spindle
gleaming fern
#

Thanks for the clocks link. Never tried it but will try it now...

crimson spindle
#

Helps test these real world scenarios in warp speed 😄

sick valveBOT
#

This thread has been archived. If you need help with anything else please ask in #dev-help or contact Stripe Support: https://support.stripe.com/contact

gleaming fern
#

Hi again,
Thanks for reopening...

I tried to create the schedule from the subscription.

As response I get following:

#

So there is already a "phase" with an enddate.

#

When I now call:

Stripe::SubscriptionSchedule.update(
schedule.id,
  {
end_behavior: 'cancel',
phases: [
    {
      items: [
        {
          price: subscription.price.id,
          quantity: 1,
        },
      ],
      iterations: 3,
    },
  ],
},
)
#

Then I get following error:

{
  "error": {
    "message": "The subscription schedule update is missing at least one phase with a `start_date` to anchor end dates to.",
    "type": "invalid_request_error"
  }
}
#

What am I doing wrong?

#

I also tried to add a star_date to this phase, but then I get

((Status 400) (Request req_xNdMpo0mZT4PNK) You can not modify the start date of the current phase.
still pecan
gleaming fern
#

mhm let me try

#

I'm not sure how I could update the current phase

still pecan
#

As far as I know I don't think you can make much changes to the current phase except for ending it.
Let's step back a bit, what are you actually trying to do/update?

gleaming fern
#

ok.

We have a Stripe Checkout for a monthly subscription. Whenever a user make a subscription we want to end it automatically after 3 month (It should be a kind of installment payment)

First idea was to use cancel_at.
So whenever we get a webhook that the subscription was created, we set the cancel_at date to 3 month from now.

But the problem is by using the cancel_at the user is still able to cancel the the subscription after e.g. 1 month in the customer portal. And the user also does not see the "cancel_at" date in the customer portal... (we have also normal subscriptions, so hiding the cancel button completly is also not an option)

#

Thats how the customer portal looks like:

#

So even the subscription is cancelled you see a "Cancel" button and that the subscription will be renewed in one month....

#

Thats why the second idea was to use the Subscription Schedule.
So whenever the user is making the subscription we want to create a Subscription Schedule to cancel the subscription after 3 month

#

So the main question is:
How could I generate such a Subscription Schedule which cancels the subscription after 3 month from an existing subscription

#

Hope its clearer now? 🙂

tribal vortex
#

Hello, hanzo had to step out but I can help here. Does a subscription on a schedule have a clearer UI in the portal? I would think that it would also not show the cancel date there

gleaming fern
#

Hi Pompey,
I dont know. Thats what I also want to try.

But at least the cancel button is not there (according to docs)

tribal vortex
#

Gotcha. Looking in to how to do this for an existing subscription

gleaming fern
#

Thanks

tribal vortex
#

And to get it to cancel after three months, you would want to set the subscription's end_behavior to cancel and update the first phrase of the subscription to only last 3 iterations 'iterations': 12,

#

So I think you'd need to make one API call to create the schedule from the subscription and one to update the schedule to add the cancelation info

gleaming fern
#

Yes I think thats what we already have discussed above:

First API call would be:

subscription = "our created subscription"
schedule = Stripe::SubscriptionSchedule.create({
  from_subscription: subscription.id
})
#

But how does the second api call look like?

tribal vortex
#

You would be setting the end_behavior and passing in a modified version of your one phase to the phases parameter. My test code is in Python but here is what that looks like if it gives you a better idea:

    phase = schedule.phases.data[0]
    phase.iterations = 3
    schedule = stripe.SubscriptionSchedule.modify(
        schedule.id,
        end_behavior='cancel'
        phases=[
            phase
        ]
    )```
#

You don't actually need to re-use the same phase object, I just like to as it makes things easier

gleaming fern
#

ok thanks.
I will try it now 🙂

#

Ok thats the final code:

schedule = Stripe::SubscriptionSchedule.create({
      from_subscription: request.result.subscription[:external_id]
    })

    phase = schedule.phases[0]
    phase.end_date = nil
    phase.iterations = 3
    Stripe::SubscriptionSchedule.update(
      schedule.id,
      {
        end_behavior: "cancel",
        phases: [
          phase.to_hash
        ]
      }
    )
#

The cancel button is gone.
But I think still a missleading translation😦

tribal vortex
#

What does the translation say?

#

Unfortunately I don't think you can customize that string. You can update the description on your subscription but that text might not be prominent enough to communicate what you are looking to communicate

gleaming fern
#

Sth like
"Company XY has specified/set an update of your plan for the 24. September 2022."

#

mhm let me check that

gleaming fern
#

I'm still trying it out