#mobileengagement | subscription update

1 messages · Page 1 of 1 (latest)

warm escarpBOT
balmy lintel
#

Its important that metered billing is still calculated at the end of the month based on the previous subscription.
[09:44]
Billing runs from the 1st to the last day of the month

summer plank
#

Hi there, only usage-based pricing will be billed at the next of billing cycle, so the workaround is to use usage-based pricing for all your prices and you need to report the usage before the end of the billing cycle.

balmy lintel
#

What I am trying to do is UPDATE the current subscription and for that update to take place on the 1st of next month. Is this possible. OR do I have to cancel the existing subscription and start a new one (on free trial) till months end. Confused

#

I have read how to change a subscription immediately but not with a delay

#

To clarify Flat Rate and Volume where paid at the beginning of the current month. Glad to hear that metered billing wont change. Makes sense. But I still can't work out the best way to upgrade the fixed costs of the plan to start at the beginning of the next billing period. Any ideas

sick minnow
#

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

balmy lintel
#

checking

#

So let me confirm my understanding.

#

$stripe->subscriptions->update(
'sub_1MdVI12eZvKYlo2CkV5lqolI',
['metadata' => ['order_id' => '6735']]
);

#

This would add the order id to the existing meta data or replace the meta data as an example

#

Likewise, if I give a list of items, does this replace the current items

#

Then I used proration_behavior = none

#

And thats it?

sick minnow
sick minnow
balmy lintel
#

I am using the following code but getting several errors

#

$result = $stripe->subscriptions->update(
[
$subscriptionid,
'items' =>
[
[
'price' => $plan,
'quantity' => 1,
],
[
'price' => $excess,
],
[
'price' => $certificates,
'quantity' => $certificatecount,
],
],
'proration_behavior' => 'none',
'metadata' => ["subscription" => $description,"clientid" => $clientid,"certificates" => $certificatecount],
]
);

#

Warning: trim() expects parameter 1 to be string, array given in /var/www/html/webcontent/webfiles/html/admin.save.social/public/manage/stripe/vendor/stripe/stripe-php/lib/Service/AbstractService.php on line 96

Warning: urlencode() expects parameter 1 to be string, array given in /var/www/html/webcontent/webfiles/html/admin.save.social/public/manage/stripe/vendor/stripe/stripe-php/lib/Service/AbstractService.php on line 103

Fatal error: Uncaught (Status 404) Unrecognized request URL (POST: /v1/subscriptions/). If you are trying to list objects, remove the trailing slash. If you are trying to retrieve an object, make sure you passed a valid (non-empty) identifier in your code. Please see https://stripe.com/docs or we can help at https://support.stripe.com/. thrown in /var/www/html/webcontent/webfiles/html/admin.save.social/public/manage/stripe/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38

#

The structure is identical to the format used on the original subscription

#

$subscriptionid is a string

sick minnow
#

Warning: trim() expects parameter 1 to be string, array given in /var/www/html/webcontent/webfiles/html/admin.save.social/public/manage/stripe/vendor/stripe/stripe-php/lib/Service/AbstractService.php on line 96

Warning: urlencode() expects parameter 1 to be string, array given in /var/www/html/webcontent/webfiles/html/admin.save.social/public/manage/stripe/vendor/stripe/stripe-php/lib/Service/AbstractService.php on line 103
Those are warnings..

#

You are not passing the subscription Id in your request.

#
$stripe->subscriptions->update(
  'sub_123',
  [....]
);
balmy lintel
#

$result = $stripe->subscriptions->update(
[
$subscriptionid,
'items' =>
[

#

$subscriptionid is the subscriptionid and is a string

sick minnow
#

You should do this:

$result = $stripe->subscriptions->update(
   $subscriptionid,
 [
      
      'items' => 
      [
#

check the sample please

balmy lintel
#

Ah, subtle but true. Thanks for that. OK getting a new error

#

Fatal error: Uncaught (Status 400) (Request req_3oVncwkNIo1QA2) Cannot add multiple subscription items with the same plan: price_1Mb6plIvSjr3oTuQy37topnZ thrown in /var/www/html/webcontent/webfiles/html/admin.save.social/public/manage/stripe/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38

#

There are 3 parts to the subscription.

#

price_XXX

#

price_aaa

#

price_bbb

#

The format is the same as when the sub was created

#

I think what may be happening is we are ADDING ITEMS to the existing plan. Where we should be REPLACING ITEMS in the existing plan. What do you think? And what can we do? Thanks

sick minnow
#

Give couple of minutes while I check this please

sick minnow
#

mobileengagement | subscription update

balmy lintel
#

It seems the statement "I think what may be happening is we are ADDING ITEMS to the existing plan. Where we should be REPLACING ITEMS in the existing plan." is true. I am not recording the subscription item ids in my database so currently looking to see if I can. I think we then do 3 subscriptionItems updates

#

Specificaly "Update a subscription item"

#

Is there a better way

snow wolf
#

Hi! I'm taking over this thread.

#

Is your goal to change the price of an existing subscription (instead of adding a new price to the subscription)?

#

Notice that we place a price and an ID, to replace the existing price. If you forget to pass the ID, it will add a new price.

balmy lintel
#

we are 3 parts of the subscription

#

Plan : 1K PM, 3K PM, 6K PM and 12K PM / 10K PA, 30K PA, 60K PA, 120K PA

#

Certificates: £100 pm pr £1000 pa - First free, then subsequent are charged monthly / annually

#

Metered : Monthly Target or Annual Target

#

So its quite complicated

#

I want update the subscription to reflect these changes from the beginning of next month

#

So each option has its own price_id

#

Do I simply swap the current price and quantity with the new price and quantity for each subscription item

snow wolf
#

So the subscription has 3 price IDs, and you want to update all three at the same time?

balmy lintel
#

and the item id does not chnage

#

yes

snow wolf
#

Yes that's possible, you need to do something like this:

items: [{
    id: "si_xxx", // existing subscription item ID
    price: 'price_xxx', // new price ID
  },{
    id: "si_xxx", // existing subscription item ID
    price: 'price_xxx', // new price ID
  },{
    id: "si_xxx", // existing subscription item ID
    price: 'price_xxx', // new price ID
  }]

as covered here: https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#changing
however this will change the price of the subscription immediately, and not at the next billing period.

balmy lintel
#

Since we charge in advance and will use proration_behavior = none

#

Although the plan will change immediately there would be no impact until the next billing cycle?

#

Probably the only difference is that there metered rate would be based on say ANNUAL TARGET before they have paid for an annual subscription due on the 1st. I can live with that?

#

Is my assumption correct?

#

I am testing

#

$result = $stripe->subscriptions->update(
$subscriptionid,
[
'items' =>
[
[
'id' => $planid,
'price' => $plan,
'quantity' => 1,
],
[
'id' => $excessid,
'price' => $excess,
],
[
'id' => $certificateid,
'price' => $certificates,
'quantity' => $certificatecount,
],
],
'proration_behavior' => 'none',
'metadata' => ["subscription" => $description,"clientid" => $clientid,"certificates" => $certificatecount],
]

snow wolf
#

Since we charge in advance and will use proration_behavior = none
Although the plan will change immediately there would be no impact until the next billing cycle?
Yes I think so. But I recommend to test everything is test mode to make sure it works as expected.

balmy lintel
#

thanks

balmy lintel
#

Problems

#

$result = $stripe->subscriptions->update(
$subscriptionid,
[
'items' =>
[
[
'id' => $planid,
'price' => $plan,
'quantity' => 1,
],
[
'id' => $excessid,
'price' => $excess,
],
[
'id' => $certificatesid,
'price' => $certificates,
'quantity' => $certificatecount,
],
],
'billing_cycle_anchor' => 'unchanged',
'proration_behavior' => 'none',
'metadata' => ["subscription" => $description,"clientid" => $clientid,"certificates" => $certificatecount],
]
);

#

I get the error Fatal error: Uncaught (Status 400) (Request req_WXD5y6dyiCaECy) Changing plan intervals. There's no way to leave billing cycle unchanged. thrown in /var/www/html/webcontent/webfiles/html/admin.save.social/public/manage/stripe/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38

#

If I remove the billing_cycle_anchor from the code it charges the customer immediately

#

Please advise. Thanks

snow wolf
balmy lintel
#

I do not want to change the billing interval.I want it to stay the same. 1st of the month. All I want to change is the items

snow wolf
#

But the new price are changing the plan interval.

#

And when you change the plan interval, Stripe automatically change the billing cycle.

balmy lintel
#

OK let me run a quick test

snow wolf
#

This is mentioned in the link I shared earlier:

If both prices have the same billing periods—combination of interval and interval_count, the subscription retains the same billing dates. If the prices have different billing periods, the new price is billed at the new interval, starting on the day of the change.
https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#changing

#

So if you need to change the plan interval and also not charge the customer immediately, then the only option is to use Subscription Schedule.

balmy lintel
#

So are you saying the system is incapable of changing items and starting at the beginning of the declared billing cycle. Because i tried 'billing_cycle_anchor' => $billingtimestamp,
'proration_behavior' => 'none', and it didn't like it. I got this error

#

Fatal error: Uncaught (Status 400) (Request req_OYSE6TqOQyoG2M) When updating an existing subscription, billing_cycle_anchor must be either unset, 'now', or 'unchanged' thrown in /var/www/html/webcontent/webfiles/html/admin.save.social/public/manage/stripe/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38

sick minnow
balmy lintel
#

Wow talk about complicated. OK Plan B. Wouldn't it be easier to cancel the existing subscription and create a new one with a future start date and proration_behavior: none

sick minnow
#

yes that's an option too

balmy lintel
#

how do i set a subscription to cancel at the end of the current billing period

#

found it - thanks

balmy lintel
#

OK slightly different FYI. You update the current subscription with cancel_at_period_end
= true and add a new subscription to start at the beginning of the next billing period