#sergixel04
1 messages · Page 1 of 1 (latest)
Hello sergixel04, we'll be with you shortly! Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
• sergixel04, 3 days ago, 62 messages
• sergixel04, 4 days ago, 11 messages
Hello! What is inaccurate? Can you share the req_xxx ID
Yes! The req is req_bdebLayk2UNlhM
I send the code too.
Stripe::setApiKey(config('app.stripe_secret'));
$user = User::find(auth()->id());
$subscription = $user->subscription('main');
$quantity = $subscription->quantity;
$proration_date = time();
$subscription = \Stripe\Subscription::retrieve($subscription->stripe_id);
$items = [
[
'id' => $subscription->items->data[0]->id,
'quantity' => 3
],
];
$invoice = \Stripe\Invoice::upcoming([
'customer' => $user->stripe_id,
'subscription' => $subscription['id'],
'subscription_items' => $items,
// 'subscription_proration_date' => $proration_date,
]);
return [$invoice];
I have a current active subscription in Test mode.
If quantity is 3, the amount due is correct according the dashboard. The pricing model is tiered graduated pricing.
First seat = 20€
2+ seats = +10€
In this case is working fine with quantity at 3, let me a sec
{
"object": "invoice",
"account_country": "ES",
"account_name": "XXXXX",
"account_tax_ids": null,
"amount_due": 4840,
"amount_paid": 0,
"amount_remaining": 4840,
"amount_shipping": 0,
"application": null,
"application_fee_amount": null,
"attempt_count": 0,
"attempted": false,
}
The problem becomes when I want to retrieve an upcoming invoice with one extra item, to tell the user what he's gonna pay for.
So, if I set quantity at 4. I would expect
20€ + 10€ * 3 = 50€ + taxes = 60,5€ amount due
Stripe::setApiKey(config('app.stripe_secret'));
$user = User::find(auth()->id());
$subscription = $user->subscription('main');
$quantity = $subscription->quantity;
$proration_date = time();
$subscription = \Stripe\Subscription::retrieve($subscription->stripe_id);
$items = [
[
'id' => $subscription->items->data[0]->id,
'quantity' => 4
],
];
$invoice = \Stripe\Invoice::upcoming([
'customer' => $user->stripe_id,
'subscription' => $subscription['id'],
'subscription_items' => $items,
// 'subscription_proration_date' => $proration_date,
]);
return [$invoice];
Let's put 4 at quantity
"object": "invoice",
"account_country": "ES",
"account_name": "XXXXX
",
"account_tax_ids": null,
"amount_due": 7144,
"amount_paid": 0,
"amount_remaining": 7144,
"amount_shipping": 0,
"application": null,
"application_fee_amount": null,
"attempt_count": 0,
"attempted": false,
"automatic_tax": {
"enabled": false,
"status": null
},
And the output is 7144 instead of 6050
I don't understand where is the mistake
Can you sahre the req_xxx where you sent quantity: 4? req_bdebLayk2UNlhM is for 3
Here it is req_L1ej9fDsJwHBEh
Can you share the lines field from the response?
Yep, it's prorating (crediting) for the unused time on the 3 quantity and then billing 4 quantity at the remaining time up until the existing billing cycle timestamp
and that's correct the amount due?
Well, it depends on what your intention is. If you want to bill the full amount for 4 seats upfront you'll need to use subscription_proration_behavior: 'none'
Perfect, I understand will try it. And for example, if I would like to calculate the prorations the customer would pay today, how can I do that?
Well the invoice preview you already have includes the prorations
But 7144 amount due isnt what the customer would pay due to prorations
that's what I dont understnad, how to catch the amount of prorations that the client would pay in that exact moment
for adding a extra account. Life cycle is monthly, so if the subscription renewal is today. And he adds a seat (updating the subscription), the prorations should be 10€ + taxes
I have tested that funcionality, and that's how it works, it works fine, but in the JSON upconming invoice I don't understand how to catch that value
👋 taking over for my colleague. Let me catch up.
thank you tarzan
this will take a minute, please bear with me
sure thank you!
would you mind trying again but this time passing in a proration_date?
Of course, I send you the output
sorry it's susbcription_proration_date
also I have to define some subscription_proration_behaviour? or iss not neccesary?
Perfect, thank you! do you know what should I put on subscription_proration_behaviour?
always_invoice?
it depends on what you're trying to do
$invoice = \Stripe\Invoice::upcoming([
'customer' => $user->stripe_id,
'subscription' => $subscription['id'],
'subscription_items' => $items,
'subscription_proration_date' => $proration_date,
'subscription_proration_behavior' => 'always_invoice'
]);
The objective would be calculate the amount due that the client is going to pay in that exact time
yes but how do you want to handle prorations?
do you want to calculate them or ignore them?
ok let's take a step back from the code
would you mind giving me an example in numbers of what you're expecting to happen when you do the change?
I would like to only calculate the total of prorations, for example.
A user adds an extra account, the information would be:
Total due today: 10,21€ (prorations calculation)
As of October 28, 2023 (next upcoming invoice date)
Subscription with {quantity} businesses: {total_excluding_taxes}€ per month
Estimated taxes: {total_taxes}€ per month
Total subscription: {amount_due}€
Payment method information
I wouldn't need to show the user all proration operation's math
Total due today: 10,21€ (prorations calculation)
how did you get to that
I wouldn't need to show the user all proration operation's math
but I need to see it 😛 in order to understand how you got to that calculation so I can help you out
10,21
is that €10 + tax?
so just the added quantity?
yes, 10,21 would be the total amount due. Wait I send you the output
if that's the case then you're not calculating prorations
prorations means that the customer would pay for the quantities based on the time of usage
Yes, I need to charge them in order to avoid that the user can subscribe and use the benefits without paying, and the day before the subscription renewal is charged, he cancels the subscription and doesn't pay
Currently is working the charge of prorations, the problem is to show the user before the payment
These are the lines
then you're just ignoring the prorations
I want to activate prorations and charge prorations. But in the frontend I want to show the user only the total amount due based on the time of usage
I want to activate prorations and charge prorations.
what you're suggesting is not called prorations
let me give you a simple example
I have a recurring price of $10 per month
my customer subscribed to 3 units
I created the subscription on Oct 1st
and it's a monthly subscription
so let's say we're on. the 15th of Oct
and the customer decides to add a 4th unit
they already paid $30 upfront
if we're calculating prorations
you will have an "unused time" line of: 30/2 = -15
and a new line for the new quantity of: 40/2 = 20
and the generated invoice if you don't want to change the billing_cycle_anchor would be -15 + 20 = 5
this means they will be charged a full amount of 30 + 5 = 35 for the first cycle
Hi there 👋 jumping in as my teammate needs to step away soon. Please feel free to take your time reviewing, I'll be happy to help clear up any remaining questions.
Alright, I think I have understood. Yes, I had that problem which prorations were being charged when the next cycle starts
But I've changed subscription_proration_behavior to always_invoice to avoid that. And charge those $5 of prorations when the increase the subscription's quantity to 1 more
which one is the filed where I can get the next upcoming invoice date?
is 'created'?
Thank you so much @sturdy thunder resolved the prorations thank you