#nickdnk_unexpected
1 messages · Page 1 of 1 (latest)
👋 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/1405241481777778830
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
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.
- nickdnk_api, 1 hour ago, 17 messages
Hi, we document this here: https://docs.stripe.com/billing/taxes/tax-rates#rounding
Are you referring to this in_1RrEoXL7ilRdQXxEbYWh3kyc?
But I tried both of those methods
Im no longer at my computer so I can’t see the invoice you posted, but you can see the sub ID I provided
Regardless of how you round it internally, presenting 25% of 153.85 on the invoice as 38.47 isn’t right. Only ceiling rounding would give that result, which seems odd.
The reason why I need to confirm is that the invoice I shared shows 38.96 EUR in tax.
Uhh
So it seems like we're looking at 2 different invoices and I need to be help me confirm the one you're seeing
I will get back to you in like 10-15 minutes
I'm trying to help, and if we're looking at different things it is not going to be productive
Sure
I just don’t know where you got that from the sub I linked
Im on the phone right now, I’ll message you in a bit
Maybe I was looking at upcoming invoice for the sub
Sounds good!
Yea Im just looking at sub_1RiOVFL7ilRdQXxEOSybAFRj under upcoming invoice
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
The first item for -42.19x.25 = -10.55 (10.5775)
The next item for 175x.25 = 43.75 (43.75)
The next item for 5.50x.25 = 1.38 (1.375)
The next item for 17.50x.25= 4.38 (3.75)
You all those and get 38.96: in_1RrEoXL7ilRdQXxEbYWh3kyc as expected.
Oh, you're looking in the Dashboard for the upcoming invoice?
im looking at this yes
I did what you did here for that one and I get 38.46. If I don't round them off at all to ints before I sum them, I get 38.4615
public static function calculateTaxForValueWithDiscount(float $cost, float $taxPercentage, float $discount): float
{
if (!$taxPercentage) {
return 0;
}
$discount = ($discount ? $cost * ($discount / 100) : 0);
return ($taxPercentage / 100) * ($cost - $discount);
}
and then:
$user = SomeClass::calculateTaxForValueWithDiscount(1750, 25, 22.3);
$members = SomeClass::calculateTaxForValueWithDiscount(550, 25, 22.3);
$identity = SomeClass::calculateTaxForValueWithDiscount(17500, 25, 22.3);
echo $user + $members + $identity; // = 3846.15
I've tried in various different ways and I can't seem to get 38.47 except if I essentially ceil the result
am I just bad at math?
If I round off every line I still get 38.4625
Just to clarify that I tried both
The discount is applied to the entire Invoice. When they do that, apply the discount on each Invoice Items. We calculated a one-cent difference in the amount of the applied discount for this specific Invoice Item.
Let me try to break down the math manually
Yeah I don’t know how to convert that explanation to code
I guess I could try calculating the non-rounded cost (with discount) for each item, sum that instead of the rounded total, then use that for the tax basis
Hi there 👋 jumping in as my teammate needs to step away soon. Out of curiosity, if you create a preivew of the next Invoice for this Subscription via the API, does it show the same tax amounts as the dashboard?
I'd hope so, but I trust it more if I can see it 😅 we don't know the dashboard super well in this forum, but I know it enough to know it doesn't always do things the same way.
So I'm trying to understand whether this is possibly a dashboard bug, or a math mixup somewhere. And the generation of the preview Invoice will give us more detailed views into the breakdowns of discounts and tax amounts per line item, which may give us the insight we're missing.
Alright. Let me see it I can do this
pretty big response
can't post it here
you have to download it
but it also says 38.47
Yup, and all the individual tax_amounts in the lines array sum up to that number 🤔
Am I crazy or are you also confused?
I'm still doing the math
alright
Hm, the numbers are all adding up for me when I used the tax_amounts.taxable_amounts from each line, and round at the line item level.
Are the line item amounts you're calculating after discounts aligning with those taxable_amounts?
let me check
They don't. If I do:
$discount = round($discount ? $cost * ($discount / 100) : 0);
I get 3903 discount amount for 17500, where the API says 3902. The unrounded value is 3902.5, so it seems I need to use a different rounding for that
RoundingMode::HalfTowardsZero seems to make it correct
but that's not the PHP default
and with so many to choose from and so many places where you can do the round-off, it becomes very hard to figure out
Wrong for the 550 value though, that gives me 123 and not 122 like the API, with that rounding mode
RoundingMode::TowardsZero gives both 122 and 3902 for the discounts, final result being 3846.5 which would round to 3847.
550 giving 122 and 17500 giving 3902, that is
How pressing is this? I have a suspicion of what is going on here, but it will take me a while to do the math and confirm.
Not at all, just confused
Just some working code here:
public static function calculateTaxForValueWithDiscount(float $cost, float $taxPercentage, float $discount): float
{
if (!$taxPercentage) {
return 0;
}
$discount = round($discount ? $cost * ($discount / 100) : 0, mode:RoundingMode::TowardsZero); // this rounding mode being the only one that seems to get it right in all 3 cases
return ($taxPercentage / 100) * ($cost - $discount);
}
and then:
$user = SomeClass::calculateTaxForValueWithDiscount(1750, 25, 22.3);
$members = SomeClass::calculateTaxForValueWithDiscount(550, 25, 22.3);
$identity = SomeClass::calculateTaxForValueWithDiscount(17500, 25, 22.3);
echo round($user + $members + $identity); // = 3847
I know the math for splitting fixed amount discounts applied to the Invoice level, across all of the Invoice Items is very finicky and not as intuitive as it feels like it should (with good reason, but that I only barely grasp).
I am not sure offhand if same logic is used for percentage based discounts like you used. I can step through the math and see if that lines up, but it will take me a bit.
but if I used RoundingMode::TowardsZero when I add them all together, I'd be at 3846 again
With that approach, we essentially know the total amount of the discount for the Invoice, then we split that amount across the items. That doesn't always line up to the same amount as if you just calculated the percentages directly, and the remainder of one invoice item impacts the calculations for the next.
Yea you can take your time, it's not really super important, I was just trying to get it right for our case
Cool, let me try to burn down some of these other threads, and I'll circle back when I can do that math with focus to make sure I don't mix things up.
Will do!
(I am working on ending up just as confused 😅 )
@crimson geyser sorry, I can't make sense of this either. This isn't lining up with any of the ways I know we round things (unless I'm mixing up my math and haven't spotted that yet).
It almost looks like we always round down, maybe until there is enough discount remainder to round up, but not in the way I'm used to seeing. I think this should be turned into a support case so we can 1) confirm with the right folks internally whether this calculation is as expected and 2) push to get any funky math going on there documented so this is easier to make sense of in the future.
https://support.stripe.com/?contact=true
Find help and support for Stripe. Our support site provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
Alright, I guess you’ll take over from here then.