#mtanzi - invoice update
1 messages ยท Page 1 of 1 (latest)
Hello! Just starting a thread for you -- I'll review and respond as soon as I can ๐
Can you please share the request ID that errors? https://stripe.com/docs/api/request_ids
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
What are you trying to update?
hey @unborn knoll thanks to taking the case.. the req_id is req_5cbyBrNbeweQSa
I am updating a draft invoice to set the tax_rates for each line item when is present, otherwise it will fall back to "" to remove the tax_rate
This appears to be an empty request: https://dashboard.stripe.com/logs/req_5cbyBrNbeweQSa
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
What do you expect it to include?
from the code I would expect to see something like
Stripe::InvoiceItem.update('il_1KqkDtJfYi7qv89iXIu7nBlU', { tax_rates: ["txr_1KqgnSJfYi7qv89i4UOmQVRC"] })
Is that the code that produced this request?
how can I reproduce that specific error by calling Stripe::InvoiceItem.update ?
If I pass an empty body it does not fail
> Stripe::InvoiceItem.update('il_1KqkDtJfYi7qv89iXIu7nBlU', { })
=> #<Stripe::InvoiceItem:0x3e594 id=ii_1KqkDtJfYi7qv89iRd3wH7gw> JSON: {
"id": "ii_1KqkDtJfYi7qv89iRd3wH7gw",
"object": "invoiceitem",
"amount": 500,
"currency": "usd",
"customer": "cus_LXpV6EHO9oPUnr",
"date": 1650486841,
"description": "test",
"discountable": true,
"discounts": [],
"invoice": "in_1KqkCqJfYi7qv89ibMDlwEXU",
"livemode": false,
"metadata": {},
"period": {"end":1650486841,"start":1650486841},
"plan": null,
"price": {"id":"price_1Jn1rdJfYi7qv89ihqCL60d0","object":"price","active":true,"billing_scheme":"per_unit","created":1634825005,"currency":"usd","livemode":false,"lookup_key":null,"metadata":{"type":"overage"},"nickname":"test","product":"prod_xxx","recurring":null,"tax_behavior":"unspecified","tiers_mode":null,"transform_quantity":null,"type":"one_time","unit_amount":50,"unit_amount_decimal":"50"},
"proration": false,
"quantity": 10,
"subscription": null,
"tax_rates": [],
"test_clock": null,
"unit_amount": 50,
"unit_amount_decimal": "50"
}
yes.. well the code is more like
Stripe::InvoiceItem.update(invoice_item_id, { tax_rates: (tax_rates || "") })
tax_rates can either be an array of tax_rate ids or nil
Let me see if I can reproduce, hang on...
Hm, can't reproduce. I've tried several variations, but I can't get the error you're seeing. ๐ค
same here... I have been trying to reproduce that error for 2 days!
What happens if you use the ii_123 id instead of the il_123 id?
ii_1KqkDtJfYi7qv89iRd3wH7gw
let me try
Stripe::InvalidRequestError: No such Invoice Item: 'ii_1KqkDtJfYi7qv89iXIu7nBlU'(livemode=false)
it doesn't find the item
the id is different, not just the prefix
right..
using that id you sent me it works like with the initial ID
passing the empty body {} it still doesn't fail
what confuses me is also the error message:
When passing an invoice's line item id, you may only update tax_ratesordiscounts``
in that call I only pass tax_rates, not discounts
I was able to reproduce! One sec...
The key is passing in an empty array, like this:
invoiceItem = Stripe::InvoiceItem.update('il_1Kjq4WLieeNbcBYs8YhLFnNo', {
tax_rates: []
},)
I was trying with an ii_ object initially, but then someone on my team pointed out the mismatch, and trying that variation with an il_ object got me the same error.
This also produces the same error:
tax_rates = []
invoiceItem = Stripe::InvoiceItem.update('il_1Kjq4WLieeNbcBYs8YhLFnNo', {
tax_rates: (tax_rates || "")
},)
with
Stripe::InvoiceItem.update('il_1KqkDtJfYi7qv89iXIu7nBlU', { tax_rates: [] })
or
Stripe::InvoiceItem.update('ii_1KqkDtJfYi7qv89iRd3wH7gw', {tax_rates: []})
The call success in both cases without changing nothing
๐ค
I am doing those test in the Stripe test environment now
Also, how would I get an InvoiceItem id from the Invoice object? I only see LineItem ids?
do I need first to retrieve the InvoiceItem?
Stripe::InvoiceItem.retrieve('il_1KqkDtJfYi7qv89iXIu7nBlU')
This is how I'm reproducing:
interesting... are you in test mode or in prod mode?
Test mode.
The il_ IDs are found on the Invoice itself, in the lines.data array of objects.
I am not sure why here is not failing..
Am I doing something wrong?
> tax_rates = []
[]
> invoiceItem = Stripe::InvoiceItem.update('il_1KqkDtJfYi7qv89iXIu7nBlU', {
tax_rates: (tax_rates || "")
})
=> #<Stripe::InvoiceItem:0x3e6d4 id=ii_1KqkDtJfYi7qv89iRd3wH7gw> JSON: {...}
does the subscription associated to your invoice have a discount applied?
maybe let's do a step back...
how did you create the draft invoice used for this test?
I created mine from the Dashboard
I just grabbed the first il_ object I could find associated with a draft Invoice.
I have a lot of draft Invoices on my test account. I don't think the type of Invoice would matter here though.
so I don't get why in my test is not failing, i am also using a il_
anyway... to solve the issue and avoid that error to happen you are saying that I should use always the ii_ ids instead of il_?
Sorry I am also conscious that I am taking a lot of your time... I really appreciate all the help with this! ๐โโ๏ธ
No worries, I'm here to help!
To avoid this issue you should avoid passing an empty array to tax_rates.
Right now your logic considers an empty array a perfectly valid thing to pass along, but you should refactor to do exactly what you want when there's an empty array.
To clarify, though, you can't reproduce with exactly this code? Stripe::InvoiceItem.update('il_1KqkDtJfYi7qv89iXIu7nBlU', { tax_rates: [] })
Thanks! I will give a deeper look why we have an empty array there... but this is definitely a great lead !
No
that returns the Stripe::InvoiceItem object
Can you give me the request ID for that successful request?
#<Stripe::InvoiceItem:0x3e724 id=ii_1KqkDtJfYi7qv89iRd3wH7gw> JSON: {...}
I'd like to make sure I'm not doing something differently.
Hm. Do you have the Invoice ID associated with il_1KqjmPJfYi7qv89ik74qGCNq?
in_1KqkCqJfYi7qv89ibMDlwEXU
That's the one for il_1KqkDtJfYi7qv89iXIu7nBlU. ๐
mmm... yes sorry that's the one I have the one associated to the line item il_1KqkDtJfYi7qv89iXIu7nBlU
I can't find the il_1KqjmPJfYi7qv89ik74qGCNq
Hm, I can't seem to find that Invoice either. Do you have the ii_ ID associated with it, or any other details?
for the il_1KqkDtJfYi7qv89iXIu7nBlU yes...
for il_1KqjmPJfYi7qv89ik74qGCNq I can't find anything associate ๐ฆ
where the il_1KqjmPJfYi7qv89ik74qGCNq come from?
It would have to have come from an Invoice. Let me see if I can find it another way...
where did you find the il_1KqjmPJfYi7qv89ik74qGCNq id ?
That's from the original request you asked about: https://dashboard.stripe.com/logs/req_5cbyBrNbeweQSa
ah ok... that request was prod data
I have an invoice ID for a different call but that fails with the same error: in_1KqhyyJfYi7qv89iZ8xiNYNF
Looking...
Nothing is jumping out at me as far as why you're getting this error on some Invoice Line Items and not others, but I do believe the root cause is the empty body, which is caused by passing in an empty array for the value.
What is your intent with these requests? Like what are you trying to actually update?
I think your finding is actually the way to solve this mystery...
The porpose for this call is to update the taxrate with the most recent at the time of the call.. however if the user doesn't have the the billing information we would just pass ""
I believe that the code upstream that calculate the taxrates return empty array instead of nil and that is the error you were able to reproduce
it bugs me not been able to reproduce it myself but I will try that route to try solving this problem ๐
Thanks a lot for the debugging session! it helped! ๐
No problem! I think your approach sounds good and should solve the issue for you.
Thanks again! have a good rest of the day/evening