#verox_api
1 messages Ā· Page 1 of 1 (latest)
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.
- verox_api, 4 days ago, 22 messages
- verox_subscription-retries, 4 days ago, 9 messages
š Welcome to your new thread!
ā²ļø We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
ā±ļø We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
š This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1238526577738780685
š Have more to share? Add more details, code, screenshots, videos, etc. below.
$invoice = Cashier::stripe()->invoices->upcoming([
'customer' => $user->stripe_id,
'subscription' => $subscription->id,
'subscription_details' => [
'items' => [
[
'price_data' => [
'unit_amount' => $currentPrice,
'currency' => $user->currency,
'recurring' => [
'interval' => $request->input('period', $server->period) === 'monthly' ? 'month' : 'year'
],
'product' => ...
]
]
],
'proration_date' => Carbon::now()->timestamp,
]
]);
The subscription I provided has an upcoming invoice of 4.79⬠and $currentPrice is logged to be 4.79⬠as well.
But if I get $invoice->amount, I get 12.99ā¬.
Can you share one of your upcomign invoice request IDs and the exact output you're getting back from the API?
Yes, sure.
Here you go: req_SfzaTjTCAyf3fA
Thanks! Give me a few minutes to take a look
Of course, thanks for your help.
Is your goal just to have an Invoice that charges for the proration? If so, I thihnk you need to be setting subscription_proration_behavior: always_invoice. This'll give you that upcoming invoice that would be immediately charged for if you were to add this subscription item.
No, I just want Stripe to calculate the upcoming price, so my customers know much an upgrade would increase the price for the upcoming invoice.
I actually don't need the invoice at all. I just need to know how much the price would be with and without prorations.
The reason we're showing you something clsoe to 12.99 is because we're adding up the 4.80 price your subscription already has, the 4.78 price you're newly adding, AND the proration for adding the 4.78 mid cycle
What was the number you were hoping to see instead?
Actually only 4.78ā¬.
So how do I get the actual price?
I want it to be the price, which WOULD be charged, IF the user would upgrade to another price.
What price what I have to pass?
Gotcha - then you have to change your request to pass in the existing Subscription Item ID si_Q4lrIaDAK8WEVv in subscription_items.id (https://docs.stripe.com/api/invoices/upcoming#upcoming_invoice-subscription_items-id) and also disable prorations by passing in subscription_proration_behavior: none
Alright, I'll try that. See you in a minute.
Em, but that's not actually what I wanted. Let's say the subscription charges 10$ a month and I halfway upgrade my subscription to 20$, the half of 20$ would be $10. So Stripe should return me 20$ for the upcoming price.
Ah, so you didn't actually want just the 4.78
In this case I do, because 4.78 to 4.78 isn't an upgrade, so just 4.78 should be returned.
But if I were to upgrade from 4.78 to 5, 5.22 should be returned.
Of course only if the upgrade was made immediately after creation. Because if the upgrade happened mid-subscription, the upgrade costs would be lower.
Gotcha - so you need to still pass si_Q4lrIaDAK8WEVv as the ID, but remove subscription_proration_behavior
Ah, alright. And how do I pass the upgraded price?
You can still pass in subscription_details.items.price_data - you just need to also pass in subscription_details.items.id
Ah, okay. I'll try that.
Alright, I did it like you said:
$item = $subscription->items->data[0];
$invoice = Cashier::stripe()->invoices->upcoming([
'customer' => $user->stripe_id,
'subscription' => $subscription->id,
'subscription_details' => [
'items' => [
[
'price_data' => [
'unit_amount' => $currentPrice,
'currency' => $user->currency,
'recurring' => [
'interval' => $request->input('period', $server->period) === 'monthly' ? 'month' : 'year'
],
'product' => config('cashier.products.server')
]
],
[
'id' => $item->id,
]
],
'proration_date' => Carbon::now()->timestamp,
]
]);
and it now return "1298", so 12.98ā¬.
You need to do this:
$item = $subscription->items->data[0];
$invoice = Cashier::stripe()->invoices->upcoming([
'customer' => $user->stripe_id,
'subscription' => $subscription->id,
'subscription_details' => [
'items' => [
[
'id' => $item->id,
'price_data' => [
'unit_amount' => $currentPrice,
'currency' => $user->currency,
'recurring' => [
'interval' => $request->input('period', $server->period) === 'monthly' ? 'month' : 'year'
],
'product' => config('cashier.products.server')
]
],
],
'proration_date' => Carbon::now()->timestamp,
]
]);
(note that I moved where you're setting id )
Alright, looks better. Does it make sense that it shows 4.76⬠now?
That sounds about right to me, but I'd need to see the full output you're getting back from the API to be sure
I have created another subscription for 9,18: sub_1PEx74Bxo62JExo20oog7DhW
But it displays 9,19 as upcoming price. Why's that?
Here's the request: req_SfzaTjTCAyf3fA
Sorry, wrong one.
I meant this one: req_jJqv7dg9tSPy4z
Oh wait, no I know why. This is so dumb.
Thanks a lot for your help. The other problem is my fault.
You resolved my issue. Thanks a lot!
š happy to help!