#aaron_api
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/1386793442306166847
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
extra context:
https://dashboard.stripe.com/support/sco_SMR5u1n5kxZcW0
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Hello
When you say
We are wondering how that amount is created?
Are you referring to invoice amount, due amount or something else?
I see the invoice you've attached but could you specify the amount you're asking about?
More context would help be on the same page ๐
yup lemme get you the exact numbers
We are wanting to refund $60.00 + taxes on $60.00
The amount should be 6533 after all calculations are done which seems correct.
However the failure is happening on Stripes side with a error
```The sum of refunds, credit amount, and out of band amount ($65.33) must equal the credit note post_payment_amount ($65.32)
We previously asked about this undocumented field / response and your team got back to us saying that we needed to pass in the gross amount in the `lines[:amount]` param
Therefore, in the lines params we pass in
{
type: "invoice_line_item",
invoice_line_item: line_item.id,
amount: 7407 # this is the calculated gross amount of $60 before discounts.
tax_amounts: credit_note_tax_amounts,
net_amount_to_refund: to_stripe_integer(amount_to_refund)
}
When we hard code the amount to 7408 the preview works.
We are wondering how that calculation is handled on your side? and if there is a recommended way to find out the pre discount amount for a specified amount?
Hello, looking in to this. When you talked to our team before, was it on this channel or somewhere else? I am having trouble finding the other conversation
it was on this support thread https://dashboard.stripe.com/support/sco_SMR5u1n5kxZcW0
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 problem is that the calculation of getting the pre discount amount (7407) is one cent off from what stripe caculates as the pre discount amount
Gotcha, so the question is how to get that original amount. Is this 7407 amount on the invoice that you shared the ID of? I don't see anything with a ~7400 amount on it
I am reaching out to my colleagues for help looking in to this and will get back with what we can find
Still working on this. Thought we had the calculation down but are double checking some of our math.
thanks!
Gotcha, so the question is how to get that original amount. Is this 7407 amount on the invoice that you shared the ID of? I don't see anything with a ~7400 amount on it
No this is the amount that we want for a partial discount
but we need to derive the pre discount amount
- we want to refund $60 out of the $508.73 on the line item.
- there is a 10% subscription discount + 10% product level
- We need to find the pre discount amount of $60.00 which according to our caclulation is $74.07 however it is failing validation on stripe's side because stripe believes it is $74.08 which causes the post_payment_amount to be
$65.32in the error message above
if we hard code the amount as 7408 in the request, the request will be successful. however we do not know how to get to that number
Gotcha, and how are you calculating this amount currently?
net_amount_to_refund * line_item_full_amount / line_amount_after_discounts
- this seems to work for like 90% of the cases but every once in a while we get a 1 cent error
Thank you, and how are you calculating line_amount_after_discounts specifically?
we grab the full amount of the line and substract it by the discount_amounts on the line
another thing we tried was getting the ceiling of the calculation above and it gives some sort of weird error as well.
We eventually debugged and found out that the amount we calculate above is 1 cent different than what stripe expects it to be.
๐ taking over for my colleague who needs to step away. Give me a few minutes to catch up please!
thanks!
Okay, I understand how we're calculating 65.33
The first Invoice line item has both a 10% line item discount and a 10% group discount. The second Invoice line item has just the 10% group discount.
This appears to be the formula we're using:
3704 - 3704 * 0.1 - (3704 - 3704 * 0.1) * 0.1 + 3333 - 3333 * 0.1 + 120 + 135 + 11 + 120 + 135 + 11
yup that is what we calculated it as as well.
the error we get from stripe is The sum of refunds, credit amount, and out of band amount ($65.33) must equal the credit note post_payment_amount ($65.32)
post_payment_amount is coming from stripe and is calculating to $65.32 ๐ค
Nope, that's not it
https://dashboard.stripe.com/test/logs/req_aQLntzyf4DbFnJ
"The sum of refunds, credit amount, and out of band amount ($65.32) must equal the credit note post_payment_amount ($65.33)."
oh weird
65.33 is coming from Stripe
I think as long as we know how stripe caculates it I just need to replicate it on our side
Ah, I think I see what's going on. We're immediately rounding the discount amounts after multiplying
So, using order of operations, we're ending up with:
3704 - 370 - 333 + 3333 - 333 + 120 + 135 + 11 + 120 + 135 + 11 = 6533
If you round until the end:
3704 - 370.4 - 333.6 + 3333 - 333 + 120 + 135 + 11 + 120 + 135 + 11 = 6532
okay so I verified we are calculating 6533 correctly in our code.
we're still getting the same error ``` The sum of refunds, credit amount, and out of band amount ($65.33) must equal the credit note post_payment_amount ($65.32)
I think it means stripe is rounding at the end then?
Do you have a request ID for that credit note creation request?
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
"expand": {
"0": "tax_amounts.tax_rate"
},
"invoice": "in_1RdINiDAWTp2PXOww3zbsH1s",
"lines": {
"0": {
"amount": "7407",
"invoice_line_item": "il_1RdINiDAWTp2PXOw1WEqE1aB",
"tax_amounts": {
"0": {
"amount": "240",
"tax_rate": "txr_1ROjB9DAWTp2PXOwTgDRrY7E",
"taxable_amount": "6000"
},
"1": {
"amount": "270",
"tax_rate": "txr_1ROjB9DAWTp2PXOwzXolntD7",
"taxable_amount": "6000"
},
"2": {
"amount": "23",
"tax_rate": "txr_1ROjB9DAWTp2PXOwAqLqKR8j",
"taxable_amount": "6000"
}
},
"type": "invoice_line_item"
}
},
"memo": "test",
"metadata": {
"tax_amount_1": "240",
"tax_amount_2": "270",
"tax_amount_3": "23",
"tax_netsuite_id_1": "14956",
"tax_netsuite_id_2": "14956",
"tax_netsuite_id_3": "14956"
},
"refund_amount": "6533"
}
ah okay, this helps. Give me a min
thank you! really appreciate the help! ๐
pls note that the 7407 is the PRE discount amount that I was advised to submit as params for the API to work.
I notice that if I hardcode 7408, the preview and creation will be successful which leads me to believe it has something to do with how stripe calculates the pre discounted amount
Okay so we're doing:
7407 - 7407 * 0.1 - (7407 * 0.1) * 0.1 + 240 + 270 + 23
We're rounding at the discount calculation so:
7407 - 741 - 667 + 240 + 270 + 23 = 6532
oh interesting
hmm okay so I need to figure out how to get that amount then ๐ค
okay I'm really confused now
I figured out how to submit it as 6532
but the validation error changed again to
The sum of refunds, credit amount, and out of band amount ($65.32) must equal the credit note `post_payment_amount` ($65.31).
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
heres the new request
That URL doesn't quite help much since it's linking to a list view of requests, not a specific request. I'm looking into this one: https://dashboard.stripe.com/test/logs/req_NG0hIdwARNcXez
ah, I see the difference
The old request used amount 23 for txr_1ROjB9DAWTp2PXOwAqLqKR8j. The new request used amount 22 for txr_1ROjB9DAWTp2PXOwAqLqKR8j
old request: 7407 - 741 - 667 + 240 + 270 + 23 = 6532
new request: 7407 - 741 - 667 + 240 + 270 + 22 = 6531
hmm okay lemme check
okay so my question is -- how do we come to the value of 7407 - 741 - 667 if we want to refund 6000?
if you calculate that it ends up being 5999 not 6000
Taking a step back, why do you want to refund 6000 (+ tax)?
one of the requirements is to be able to be creating credit notes partially
Got it, so not for the total amount of an invoice line item
yup exactly.
it just happens that for some reason 60 gives this error
it seems like 99% of the time it works
except for 60, 51, 42 ๐คฏ
it looks like we are calcuating the total as 6000 + 240 + 270 + 23 = 5233
in the case of the tax changes
6000 + 240 + 270 + 22 = 6532
On stripes side it is calculating:
5999 + 240 + 270 + 23 = 5232
5999 + 240 + 270 + 23 = 5231
If you want to refund 6000 + tax, you should start with 7408
7408 - 7408 * 0.1 - (7408 - 7408 * 0.1) * 0.1 + 240 + 270 + 23
This would be
7408 - 741 - 667 + 240 + 270 + 23 = 6533
How are you calculating that?
net_amount_to_refund * line_item_full_amount / line_amount_after_discounts
so in this case, does net_amount_to_refund = 60? can you plug in the numbers you're using here to get to 7407?
yep
net_amount_to_refund = 6000
line_item_full_amount = 8900
line_amount_after_discounts = 7209
6000 * 8900 / 7209
= 7407
How are you calculating line_amount_after_discounts
Oh, I got it nevermind
It's 8900 - 890 - 801
yeup
so I think I understand what the problem is now
We pass in the amount as 7407 and stripe does the automatic reduction of the discounts that ends up being 5999 + tax = 6532
however on our side , the user enters 6000 and we expect it to add the tax which ends up being 6533
so the question is:
- how do we get 7408 from 6000 before discounts?
unless this is something on stripes end that can be fixed?
Likely not in the short term. I think what you're ultimately looking for here is the ability to pass a flat amount to refund while ignoring any discount amounts from the original Invoice
That way we don't do any additional calculation on our end for post_payment_amount
It might be clearer to see how net_amount_to_refund * line_item_full_amount / line_amount_after_discounts might not capture all scenarios if you try with some round numbers, e.g. an Invoice with a line item of 100, a line item discount of 10% and a group discount of 10%, then try to calculate a partial refund of $5
hmm okay is there any recommended path forward then?
I think you can play around with this a bit, especially with rounder numbers. You might have to introduce some conditionals when using the result of net_amount_to_refund * line_item_full_amount / line_amount_after_discounts to calculate the amount pre tax. If the amount doesn't equal what the user entered, adjust
alright sounds good! thank you so much for the help ๐
Thank you for going through this together!