#Mathankumar

1 messages ยท Page 1 of 1 (latest)

vocal merlinBOT
frigid arch
obtuse root
#

$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?

frigid arch
#

Yup, the subscription ID will remain the same

obtuse root
#

'from_subscription' = 'sub_mkwemwek' its right form?

frigid arch
#

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

obtuse root
#

Okay thanks for the info ๐Ÿค

frigid arch
#

No problem! Happy to help ๐Ÿ˜„

obtuse root
#

from_subscription , start_date is same?

frigid arch
#

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'

obtuse root
#

meaning of iterations in subscription_schedule i dont understand in stripe ?

#

pls give me a simple explenation?

frigid arch
#

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.

obtuse root
#

if I need that plan for the next cycle only then I don't need to specify that right?

frigid arch
#

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

obtuse root
#

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, ], ], ]);

frigid arch
#

Yup, you should create the subscription schedule with only from_subscription, then update the phases in subscription schedule.

obtuse root
#

create with from subscription and again updating the plan to that subscription schedule.?

somber stump
#

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.

obtuse root
#

`$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?

somber stump
#

Yes

obtuse root
#

I faced this error The subscription schedule update is missing at least one phase with a start_date to anchor end dates to. !

somber stump
#

you need to specify a start_date for the phase

obtuse root
#

inside the phase??

#

can I specify the start_date like the end date of the current subscription right?

obtuse root
#

??

somber stump
#

Can you share with me the ID of the created subscription schedule?

obtuse root
#

sub_sched_1LjcqmSF6Qh6F24i5e6XQWWB

#

i created like this

#

$subscriptionSchedules = $this->stripeKey->subscriptionSchedules->create([
'from_subscription' => $this->model->stripe_subscription_id,
]);

somber stump
#

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.

obtuse root
#

whee i can add that start date ?

somber stump
obtuse root
#

` $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 !

somber stump
#

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,
                        ],
                    ],
                ]
obtuse root
#

this error was acquired **You can not modify the start date of the current phase. ** !

somber stump
#

You should include the current phase of the subscription schedule in the phases array together with the new phase.

obtuse root
#

I don't understand, what is current phase?

somber stump
#

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,
                        ],
                    ],
                ]
...```
obtuse root
#

Invalid object in file /home/mathankumar/Documents/projects/success-api/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38

#

errors acquired

somber stump
#

Can you share with me the request ID?

obtuse root
#

req_d4nBX4VLlgaIkC

tropic prism
#

Hey! Taking over for my colleague. Let me catch up.

obtuse root
#

okay ?

obtuse root
somber stump
#

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?

obtuse root
#

` $this->stripeKey->subscriptionSchedules->update(
'sub_sched_1LjcqmSF6Qh6F24i5e6XQWWB',
[
'phases' => [
$subscriptionSchedule->phases[0],

                    [
                        'start_date' => $subscription->current_period_end,

                        'items' => [
                            [
                            'price' => $plan->stripe_id,
                            ],
                        ],
                        'iterations' => 1,
                    ],
                ],
            ]
          );`
tropic prism
#

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,
    ],
  ],
]);

obtuse root
#

how can specify the subscription_id

tropic prism
obtuse root
#

where i can specify? from_subscription

tropic prism
#

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
]);
obtuse root
#

error **You cannot set customer if from_subscription is set. in file **

tropic prism
obtuse root
#

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!

tropic prism
obtuse root
#

how to delete the subscription shedule?

gloomy socket
#

๐Ÿ‘‹ taking over for my colleague. Let me catch up.

obtuse root
gloomy socket
#

or do you want it to stop the subscription

obtuse root
#

I just want to remove the schedule only?

gloomy socket
#
#

when you cancel a schedule the subscription will be cancelled as well

#

when you release it the subscription would still be ongoing