#Mathankumar
1 messages ยท Page 1 of 1 (latest)
Yup. This can be done by setting the existing subscription ID in from_subscription field in Subscription Schedule Create API: https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-from_subscription
For more detailed doc, you may refer to the doc here: https://stripe.com/docs/billing/subscriptions/subscription-schedules#managing
$stripe = new \Stripe\StripeClient(
'jj'
);
$stripe->subscriptionSchedules->create([
'customer' => 'cus_4QFK8XrieeBDYp',
'start_date' => 1664162332,
'end_behavior' => 'release',
'phases' => [
[
'items' => [
[
'price' => 'plan_JiX4v6L7JY0Vyt',
'quantity' => 1,
],
],
'iterations' => 12,
],
],
]);
'from_subscription' = 'sub_mkwemwek' right??
if i add this from_subscription next plan will continue in this same subscription_id right?
Yup, the subscription ID will remain the same
'from_subscription' = 'sub_mkwemwek' its right form?
Yes, it'll be 'from_subscription' => 'sub_xxx'
Please do not share your secret key in this server as the messages are public to everyone
Okay thanks for the info ๐ค
No problem! Happy to help ๐
from_subscription , start_date is same?
start_date refers to the timestamp when hen the subscription schedule starts.
It's up to your system to decide
If you wish to start the subscription schedule now, you can set start_date='now'
meaning of iterations in subscription_schedule i dont understand in stripe ?
pls give me a simple explenation?
iterations means how many cycles you want the plan to be. For example, if you want the monthly plan to last 4 months in this phase, then iterations will be set to 4.
if I need that plan for the next cycle only then I don't need to specify that right?
you can set the iterations to 1 and set end_behavioiur='release' to release the subscription schedule and the subscription will remain the same plan
I'd recommend testing it out with test clock in the test mode:
- subscription schedule use case: https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases
- test clock: https://stripe.com/docs/billing/testing/test-clocks
i got error ** You cannot set phases if from_subscription is set.**
for this code
$this->stripeKey->subscriptionSchedules->create([ 'end_behavior' => 'release', 'from_subscription' => $this->model->stripe_subscription_id, 'phases' => [ [ 'items' => [ [ 'price' => $plan->stripe_id, ], ], 'iterations' => 1, ], ], ]);
Yup, you should create the subscription schedule with only from_subscription, then update the phases in subscription schedule.
create with from subscription and again updating the plan to that subscription schedule.?
Hi @obtuse root I'm taking over
from_subscription and phases are mutually exclusive, so you should create a subscription schedule with from_subscription first, and then update it.
`$subscriptionSchedules = $this->stripeKey->subscriptionSchedules->create([
'end_behavior' => 'release',
'from_subscription' => $this->model->stripe_subscription_id,
]);
$this->stripeKey->subscriptionSchedules->update(
$subscriptionSchedules->id,
[
'end_behavior' => 'release',
'phases' => [
[
'items' => [
[
'price' => $plan->stripe_id,
],
],
'iterations' => 1,
],
],
]
);`
is right?
Yes
I faced this error The subscription schedule update is missing at least one phase with a start_date to anchor end dates to. !
you need to specify a start_date for the phase
inside the phase??
can I specify the start_date like the end date of the current subscription right?
??
Can you share with me the ID of the created subscription schedule?
sub_sched_1LjcqmSF6Qh6F24i5e6XQWWB
i created like this
$subscriptionSchedules = $this->stripeKey->subscriptionSchedules->create([
'from_subscription' => $this->model->stripe_subscription_id,
]);
Thanks, the end_date of one phase will always equal the start_date of the next phase, so you shall specify the start_date of the new phase that you wish to add in.
whee i can add that start date ?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
` $this->stripeKey->subscriptionSchedules->update(
'sub_sched_1LjcqmSF6Qh6F24i5e6XQWWB',
[
'phases' => [
'start_date' => $subscription->current_period_end,
[
'items' => [
[
'price' => $plan->stripe_id,
],
],
'iterations' => 1,
],
],
]
);`
error when i do this !
You should put start_date in the item of the phases, something like this
'phases' => [
[
'start_date' => $subscription->current_period_end,
'items' => [
[
'price' => $plan->stripe_id,
],
],
'iterations' => 1,
],
],
]
this error was acquired **You can not modify the start date of the current phase. ** !
You should include the current phase of the subscription schedule in the phases array together with the new phase.
I don't understand, what is current phase?
sub_sched_1LjcqmSF6Qh6F24i5e6XQWWB has one phase, so you should include this phase when update the subscription schedule
$subscriptionSchedule = $this->stripeKey->subscriptionSchedules->retrieve('sub_sched_1LjcqmSF6Qh6F24i5e6XQWWB', []);
$this->stripeKey->subscriptionSchedules->update(
'sub_sched_1LjcqmSF6Qh6F24i5e6XQWWB',
[
phases' => [
$subscriptionSchedule->phases[0],
[
'start_date' => $subscription->current_period_end,
'items' => [
[
'price' => $plan->stripe_id,
],
],
'iterations' => 1,
],
],
]
...```
Invalid object in file /home/mathankumar/Documents/projects/success-api/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
errors acquired
Can you share with me the request ID?
req_d4nBX4VLlgaIkC
Hey! Taking over for my colleague. Let me catch up.
okay ?
ans
Hi @obtuse root It seems like your request is passing a string instead of object
I'm not a PHP expert here, but can you edit your code and pass in the first phase as object instead of string?
but I don't pass any string, i did not know that error in my code
` $this->stripeKey->subscriptionSchedules->update(
'sub_sched_1LjcqmSF6Qh6F24i5e6XQWWB',
[
'phases' => [
$subscriptionSchedule->phases[0],
[
'start_date' => $subscription->current_period_end,
'items' => [
[
'price' => $plan->stripe_id,
],
],
'iterations' => 1,
],
],
]
);`
While analyzing your shared requestId, in fact as my colleague mentioned above, there is an issue when sending the request to Stripe API:
Here is what your app send to Stripe API:
https://dashboard.stripe.com/test/logs/req_d4nBX4VLlgaIkC
You can follow this guide, and make sure to use php language in order to have a complete example:
https://stripe.com/docs/billing/subscriptions/subscription-schedules#managing
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
\Stripe\Stripe::setApiKey('sk_test_1232');
\Stripe\SubscriptionSchedule::create([
'customer' => 'cus_123',
'start_date' => 'now',
'end_behavior' => 'release',
'phases' => [
[
'items' => [
[
'price' => 'price_123',
'quantity' => 1,
],
],
'iterations' => 12,
],
],
]);
how can specify the subscription_id
You need to specifu the field from_subscription
here is the full reference of the API using php:
https://stripe.com/docs/api/subscription_schedules/create?lang=php#create_subscription_schedule-from_subscription
where i can specify? from_subscription
at the same level of customer and start_date... something like:
\Stripe\SubscriptionSchedule::create([
'customer' => 'cus_123',
'start_date' => 'now',
'end_behavior' => 'release',
'from_subscription' => 'sub_1232' // don't set the customer with this
]);
error **You cannot set customer if from_subscription is set. in file **
The above request body, is just an example, feel free to update it with your own need basing on the API documentation
In API docs only basic code available i need this scenario what i do?
I tried from the morning but I did not get clarification!
Regarding your issue, here you are passing a php object to phases[0], which is $subscriptionSchedule->phases[0] you need to encode this before sending it to the API:
try use this php function json_encode:
https://www.php.net/manual/en/function.json-encode.php
how to delete the subscription shedule?
๐ taking over for my colleague. Let me catch up.
?
do you want to keep the subscription ongoing after you release the schedule?
or do you want it to stop the subscription
I just want to remove the schedule only?
Basically you can either cancel a schedule https://stripe.com/docs/api/subscription_schedules/cancel
or release the schedule https://stripe.com/docs/api/subscription_schedules/release
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
when you cancel a schedule the subscription will be cancelled as well
when you release it the subscription would still be ongoing