#mathan-billing
1 messages ยท Page 1 of 1 (latest)
hello! i'm afraid i don't understand the term 1-to-1 billing, can you elaborate more perhaps?
i mean invoice creation only on every month 1st date!
you want the subscription renewal to happen on the first of the month?
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
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.
if you're not yet aware of test clocks : https://stripe.com/docs/billing/testing/test-clocks - this is useful for testing subscriptions
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', !
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
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 ?
๐ 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
base on seconds
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
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?
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
See this https://stripe.com/docs/api/subscriptions/update and try it yourself!
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Left for new price: Y = ($600/30) * (30-2) it is new plan ?
($500/30) * (30-2) 30-2 i did not understand
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
so we calculate ($500/30) * 2 its right because we used 2days and changing new plan
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
but the old bill is calculated only for 2 days correct?
$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?
not sure why you are resetting billing_cycle_anchor to now. It will move the cycle to current time immediately
What's the correct way to do this? pl tell me in my scenerio 1st date to 1stdate billing
I think first remove the billing_cycle_anchor, since you wouldn't want to change the billing cycle
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 ?
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
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, ], ], ]);
You can click on that Subscription to see its Upcoming Invoice detail
also same data
Scroll down, check the Upcoming Invoice
same
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
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
but next invoice date will be 1st but it shows 17th
Because the Sub was first created with billing cycle = 17th. Do you want to also change the billing cycle to 1st?
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
So why don't you specify billing_cycle_anchor on the first request when you created the Subscription?
The POST /v1/subscription request
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?
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
okay it will work for every month?
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
no
you need an unix timestamp
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I guess you can try it yourself by converting some value using this website: https://www.unixtimestamp.com/
Epoch and unix timestamp converter for developers. Date and time function syntax reference for various programming languages.
okay but how can convert this 00:00:00
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
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
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
how can i set billing_cycle_anchor = ?
Depends on how you're integrating?
i just need to make an invoice every month 1st date that's all any ideas for billing_cycle_anchor = !
As stated, it depends on how you're integrating. Are you using Checkout? Elements?
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
Right, but how are you creating the subscription?
$stripeSubscriptionPlan = $stripe->subscriptions->create([ 'customer' => $stripeCustomer->id, 'items' => [ ['price' => $plan->stripe_id], ], ]);
what i need to add in this code for my scenerio?
Pass billing_cycle_anchor with your epoch timestamp: https://stripe.com/docs/api/subscriptions/create?lang=php#create_subscription-billing_cycle_anchor
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
its one tome or every time?
when I change the next plan (updating subscription) I don't need to add billing_cycle_anchor right?
Yup, it's not needed
okay great but my question is what I put in billing_cycle_anchor in my scenerio ?
You can refer to the doc here about setting billing_cycle_anchor: https://stripe.com/docs/billing/subscriptions/billing-cycle