#verox_api

1 messages Ā· Page 1 of 1 (latest)

zinc whaleBOT
sweet adderBOT
#

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.

zinc whaleBOT
#

šŸ‘‹ 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.

worn atlas
#
$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€.

woeful narwhal
#

Can you share one of your upcomign invoice request IDs and the exact output you're getting back from the API?

worn atlas
#

Yes, sure.

woeful narwhal
#

Thanks! Give me a few minutes to take a look

worn atlas
#

Of course, thanks for your help.

woeful narwhal
#

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.

worn atlas
#

I actually don't need the invoice at all. I just need to know how much the price would be with and without prorations.

woeful narwhal
#

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?

worn atlas
#

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?

woeful narwhal
worn atlas
#

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.

woeful narwhal
#

Ah, so you didn't actually want just the 4.78

worn atlas
#

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.

woeful narwhal
#

Gotcha - so you need to still pass si_Q4lrIaDAK8WEVv as the ID, but remove subscription_proration_behavior

worn atlas
#

Ah, alright. And how do I pass the upgraded price?

woeful narwhal
#

You can still pass in subscription_details.items.price_data - you just need to also pass in subscription_details.items.id

worn atlas
#

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€.

woeful narwhal
#

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 )

worn atlas
#

Alright, looks better. Does it make sense that it shows 4.76€ now?

woeful narwhal
#

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

worn atlas
#

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!

woeful narwhal
#

šŸ‘ happy to help!