#codeninja-proration

1 messages · Page 1 of 1 (latest)

short moss
#

You can prevent it happens by specifying proration_behavior = none

grand stratus
#

Hi thanks for your response, we did try that but unfortunately still happening

#

Here is our sample code

$subscription = \Stripe\Subscription::create([
'customer' => $stripe_customer_id,
'items' => [
[
'plan' => $planID
],
],

'proration_behavior' => 'none',
'cancel_at_period_end' => true,
'expand' => ['latest_invoice.payment_intent'],
'payment_behavior' => 'error_if_incomplete',
'metadata' => []
]);

short moss
#

This is a Subscription create. Where do you see it's still prorated?

#

I would be happy to look at some example Subscription Id

grand stratus
#

Sure let me just check

grand stratus
#

Hey sorry for the late response I was checking the logs. Here is the Id

sub_1KJC9nFf1GyfQkaKHwpl7uTk

short moss
#

Taking a look

#

what change did you make to let this Sub end on Jul 17?

grand stratus
#

I think thats manual cancellation requested by customer

short moss
#

by customer portal? maybe?

grand stratus
#

Yup

#

Looking at our code above, that is correct right?

short moss
#

Yeah I can see it's prorated. Still don't have an idea why. My colleague will be here soon to continue assisting you

cosmic hornet
#

Hi! I'm taking over this thread.

#

I think this is expected because proration isn't a mode or setting. Instead it's an option that you choose on each API call that you make, and the default value is on.

grand stratus
#

Hi @tranquil yarrow , have you seen our code? Is there something we need to change or add?

#

$subscription = \Stripe\Subscription::create([
'customer' => $stripe_customer_id,
'items' => [
[
'plan' => $planID
],
],

'proration_behavior' => 'none',
'cancel_at_period_end' => true,
'expand' => ['latest_invoice.payment_intent'],
'payment_behavior' => 'error_if_incomplete',
'metadata' => []
]);

#

Btw thanks @short moss

cosmic hornet
#

Sorry if I wasn't clear! This code is correct. But every time you make an update to the subscription, you would need to pass proration_behavior: none to not have any proration.

grand stratus
#

But every time you make an update to the subscription, you would need to pass proration_behavior: none to not have any proration.

We are not doing any Subscription update using API so all of our Subscription proration_behavior is set to none

cosmic hornet
#

Let me try to explain this differently: proration_behavior isn't a mode that you set once and is automatically applied to all subscription udpates.** It's an option** that needs to be passed every time the subscription is updated, and if not set the default value is on. When using the customer portal you cannot change how the API call is made, so by default it will have proration_behavior: on.

#

If you want to cancel the subscription you have two choice:

  • Cancel the subscription immediately, which will generate proration no matter what
  • Cancel the subscription at the end of the period, which will never generate proration
grand stratus
#

So proration only generates when cancelling a subscription?

#

Or updating subscription as you have mentioned, just to make it clear

#

..but some of our subscription cancelled at the end of the period, and still generates proration

cosmic hornet
#

..but some of our subscription cancelled at the end of the period, and still generates proration
Can you share the subscription IDs? Also did you use the setting "cancel at the end of the billing period" (or used the cancel_at_period_end parameter when using the API)

grand stratus
#

Yup we used cancel_at_period_end = true

cosmic hornet
#

Can you share the subscription IDs where you saw proration with cancel_at_period_end = true?

grand stratus
#

sub_1K6IZMFf1GyfQkaKQInskyXg
sub_1KJC9nFf1GyfQkaKHwpl7uTk
sub_1Jst6cFf1GyfQkaKjRX1ElT8

cosmic hornet
#

Thanks!

#

So you are not using cancel_at_period_end

#

To not get proration we recommend using cancel_at_period_end.
Otherwise, if you have to use cancel_at, then you need to compute the exact timestamp of when the subscription's billing cycle for that period would end. Even being off by a few seconds would cause proration

grand stratus
#

You mean we can just replace cancel_at with cancel_at_period_end is that correct ?

cosmic hornet
#

Yes, cancel_at_period_end: true means the subscription will automatically cancel at the end of the period with no proration.

grand stratus
#

Okies I think thats it for now, will update our code and will monitor

#

Thanks for the informative discussion, appreciate your time!