#mathan-billing

1 messages ยท Page 1 of 1 (latest)

small tapir
#

hello! i'm afraid i don't understand the term 1-to-1 billing, can you elaborate more perhaps?

errant cargo
#

i mean invoice creation only on every month 1st date!

small tapir
#

you want the subscription renewal to happen on the first of the month?

errant cargo
#

yes

#

only cycles between 1st date to next 1st date

#

if two plans are subscribed in between that dates i need one invoice on 1st date

small tapir
#

To set the subscription renewal to the first of the month, you would use the billing_cycle_anchor : https://stripe.com/docs/billing/subscriptions/billing-cycle#new-subscriptions

If you have two plans, then you should include both of them on the same subscription in order to receive only one invoice. However, different plans can only be combined on the same subscription only if they have the same billing interval e.g. Plan A : monthly and Plan B : monthly.

errant cargo
#

if the base amount is 500$ for 30 days but I changed my plan in 2 days then the previous subscription bill will be like this (500%30)x2 ?

#

when using 'proration_behavior' => 'create_prorations', !

small tapir
#

it's more complex than that. Stripe prorates to the second. We have one line for crediting the unused time for the old plan from day 3 to 30, and another line to charge the remaining time from day 3 to day 30 for the new plan

#

i suggest you just try it out, it'll be easier for you to understand when you see the generated invoice

errant cargo
#

Okay, but in my scenerio, I need to generate invoices for the day based, if the base is 600 I used 15 days I need to collect 300 for 15 days ?

dense nova
#

๐Ÿ‘‹ stepping in and catching up

#

I am afraid we don't support day-based calculation. It's seconds based calculation like my colleague stated

#

I would suggest you test it our using Test mode + Test clock and check the generated proration Invoice

errant cargo
#

Okay

#

seconds based means?

dense nova
#

base on seconds

errant cargo
#

okay how it works?

#

how it calculates billing? any examples?

dense nova
#

It's pretty much as my colleague mentioned here

Stripe prorates to the second. We have one line for crediting the unused time for the old plan from day 3 to 30, and another line to charge the remaining time from day 3 to day 30 for the new plan
Mean you calculate (how many seconds) from day 3 to 30 of the unused time, then (how many seconds) from day 3 to 30 that will be used in the new plan

#

Testing and seeing in a concrete Invoice would explain better, really

errant cargo
#

Okay nice

#

if the base amount is 500$ for 30 days but I changed my plan in 2 days then the previous subscription bill will be like this (500%30)x2 ?
when using 'proration_behavior' => 'create_prorations', ! any chance to do this scenario?

dense nova
#

Your formula looks confusing to me. My understand is if you change the base from, ie $500, to $600, in day 2, it will be Y - X, with X and Y are smth like:
Unused on old price: X = ($500/30) * (30-2)
Left for new price: Y = ($600/30) * (30-2)

Not to mention again this is illustrated by days, but in real word it will be calculated by seconds

errant cargo
#

Left for new price: Y = ($600/30) * (30-2) it is new plan ?

#

($500/30) * (30-2) 30-2 i did not understand

dense nova
#

30 days - 2 days

#

If you start at day 1, still has 30 days ahead. On days 3 you surpassed 2 days but still have 28 days ahead

errant cargo
#

so we calculate ($500/30) * 2 its right because we used 2days and changing new plan

dense nova
#

no, we calculate the unused time for old price, then the supposed to use time for new price. That's why it's calculated on 30-2

errant cargo
#

but the old bill is calculated only for 2 days correct?

dense nova
#

yes

#

It's like 2 days for old price then 28 days for new price

errant cargo
#

$this->stripeSubscriptionPlan = \Stripe\Subscription::update(stripe_subscription_id, [ 'billing_cycle_anchor' => 'now', 'proration_behavior' => 'create_prorations', 'items' => [ [ 'id' => $subscription->items->data[0]->id, 'price' => plan_stripe_id, ], ], ]); is correct for this scenrio

#

billing_cycle_anchor will not be correct right?

dense nova
#

not sure why you are resetting billing_cycle_anchor to now. It will move the cycle to current time immediately

errant cargo
#

What's the correct way to do this? pl tell me in my scenerio 1st date to 1stdate billing

dense nova
#

I think first remove the billing_cycle_anchor, since you wouldn't want to change the billing cycle

errant cargo
#

okay, In my scenerio, I need to make an invoice only on the 1st date of every month not the plan end date. is this code is correct after removing the billing_cycle_anchor ?

dense nova
#

It's still hard to tell, because monthly is different than 30 days which you mentioned before

#

If plan_stripe_id is monthly then yes, looks good

errant cargo
#

yes plan_stripe_id is monthly !

#

but its show next invoice on 17th?

#

when using this code

#

$this->stripeSubscriptionPlan = \Stripe\Subscription::update($this->model->stripe_subscription_id, [ 'proration_behavior' => 'create_prorations', 'items' => [ [ 'id' => $subscription->items->data[0]->id, 'price' => $plan->stripe_id, ], ], ]);

dense nova
#

You can click on that Subscription to see its Upcoming Invoice detail

errant cargo
#

also same data

dense nova
#

Scroll down, check the Upcoming Invoice

errant cargo
dense nova
#

Ok, what is your old price and what is your new price?

#

easier, let me know the request id (req_xxx) that you updated the Subscription

errant cargo
#

request_id => req_0CP38zQfkcZhOh

#

old price = 100, new price = 500

dense nova
#

So you created this Sub on 2022-08-17 06:03:22 +0000 then update its item to new plan on 2022-08-17 06:10:36 +0000 , after that you updated again to the same new plan which has no effect

#

And because the time different on first and second request is too small, it doesn't make much impact

errant cargo
#

but next invoice date will be 1st but it shows 17th

dense nova
#

Because the Sub was first created with billing cycle = 17th. Do you want to also change the billing cycle to 1st?

errant cargo
#

yes , whenever the subscription starts i need to make invoice on next month 1st date

#

like, every month first date, if there 1 or 2 or etc subscription made that total billing in that 1st date invoice

dense nova
#

So why don't you specify billing_cycle_anchor on the first request when you created the Subscription?

#

The POST /v1/subscription request

errant cargo
#

ok but I need to give an exact date in billing_cycle_anchor, but I need every month's 1st date dynamically is it work?

dense nova
#

Yes, just give the exact timestamps for next month 1st 00:00:00. Then it will step up by one month, in UTC time

#

Let me warn you that typically 00:00:00 is not a good idea because:

  • It's a rush hour in Stripe when a lot of other Subscription trying to renew, so you can see delay
  • There are timezone issues, because the clock only jump monthly on UTC time
errant cargo
#

okay it will work for every month?

dense nova
#

Taking all advices above, yes, for every month forward on the anchor

#

Hi @errant cargo I am stepping down for the day. If you have other questions, please ask in the channel

errant cargo
#

ine minute

#

'billing_cycle_anchor' => '00:00:00',
it correct way?

dense nova
#

no

#

you need an unix timestamp

errant cargo
#

okay but how can convert this 00:00:00

celest totem
#

Well you'd input the date and time into that site @dense nova linked and it'll return the epoch timestamp (which is what our API expects)

#

For example, midnight today

errant cargo
#

i need to put next month first date right but is it work every month

#

its enough to create one time when i create subscription

celest totem
#

It would depend on the interval set on the Price object(s). But assuming a 1 month interval then yes setting the billing_cycle_anchor to a midnight timestamp with renew each month on the same day & time

errant cargo
#

how can i set billing_cycle_anchor = ?

celest totem
#

Depends on how you're integrating?

errant cargo
#

i just need to make an invoice every month 1st date that's all any ideas for billing_cycle_anchor = !

celest totem
#

As stated, it depends on how you're integrating. Are you using Checkout? Elements?

errant cargo
#

no, it's auto-detection right I just need to make an invoice every month on 1st date if the subscription ends before or at that time

celest totem
#

Right, but how are you creating the subscription?

errant cargo
#

$stripeSubscriptionPlan = $stripe->subscriptions->create([ 'customer' => $stripeCustomer->id, 'items' => [ ['price' => $plan->stripe_id], ], ]);

#

what i need to add in this code for my scenerio?

celest totem
errant cargo
#

its one tome or every time?

hallow orbit
#

๐Ÿ‘‹ Taking over this thread

#

It'll be one-time

errant cargo
#

when I change the next plan (updating subscription) I don't need to add billing_cycle_anchor right?

hallow orbit
#

Yup, it's not needed

errant cargo
#

okay great but my question is what I put in billing_cycle_anchor in my scenerio ?

hallow orbit