#Admiral-sub-sched-cancel
1 messages ยท Page 1 of 1 (latest)
Hi ๐ can you elaborate on what doesn't work about that approach in your testing? It looks like that update to the Subscription Schedule would result in it automatically canceling the underlying Subscription at the end of the only phase.
Hm, actually, there might not be enough contents inside of phases to avoid an error.
sorry this is the complete function:
$schedule = $stripe->subscriptionSchedules->create([
'from_subscription' => $subscriptionId,
]);
$stripe->subscriptionSchedules->update($schedule->id, [
'phases' => [
[
'items' => [
[
'price' => $itemPrice,
'quantity' => $itemQuantity,
],
],
'iterations' => 1
],
],
'end_behavior' => 'cancel'
]);
however, after one day free trial, when a one year subscription starts, I don't see on stripe "cancelled at" like what I have for my other products like below:
in above screenshot for my other product, as you see I can see it get cancelled at the end of one year.
Are you using a Subscription for that one as well, or are you setting cancel_at on the Subscription object? We aren't as familiar with how the dashboard represents this as we focus more on the API side of things in this forum.
If you run your Subscription Schedule through its full lifecycle using a Test Clock:
https://stripe.com/docs/billing/testing/test-clocks
does the Subscription get cancelled at the end of the year?
Admiral-sub-sched-cancel
I didn't set any "cancel_at" on the subscription object and I'm using a subscription for that one as well. however, the subscription keeps renewing after one year. I don't want to bill user after one year
Can you provide me with the IDs of Subscriptions from your testing that aren't working as you're expecting so I can take a closer look at exactly what is happening?
sub_1NfkmxCmp8xvPA29MDuUTAdX
I don't see any Subscription Schedule associated with that Subscription, nor do I see any changes being made to it after it was created. What did you try to do with this Subscription?
so I want the user to have 1 day free trial, followed with one year, and that's it, I don't want it to renew after one year. but this will be renewed after one year.
Understood, and where are you running into problems accomplishing that? From what I'm seeing it doesn't look like the code you shared above was run for the Subscription you referenced. Did you try to run the code and encounter an error?
The code you have looks like it would accomplish what you're after, except as written right now I believe it will drop the trial period if you run that code while the trial is still active.
so what do you suggest ? would you please help me?
how can I modify the schedule code
To preserve the trial you will want to check the trial_end value that is set on the Subscription Schedule's current phase when you create the Subscription Schedule, and you will want to pass that value into phases.trial_end when you update the Subscription Schedule:
https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-phases-trial_end
Overall Subscription Schedules do sound like a good fit for what you're trying to accomplish. I would strongly recommend leveraging test clocks to be able to quickly run your test Subscriptions and Schedules through their full lifecycle so you can see exactly how they'll behave. Let me know if any questions come up while you're testing your code.
another question please, should I set trial_end to the date after my trial is finished? I don't know how to set it.
You should set trial_end to the same timestamp that it was previously set to when you created the Subscription with the trial period. That value is already there when you create the Subscription Schedule, but you need to pass it again when you update the Subscription Schedule or the request will unset the value.
After you create the Subscription Schedule from the Subscription, can you log out the full contents of the Subscription Schedule? You should see a value populated for phases[0].trial_end, but let me know if you don't.
thanks a lot let me try it out and reach out again in case I didn't see. thanks Toby you've been a great help ๐
Any time, we're always happy to help!