#mtanzi - invoice update

1 messages ยท Page 1 of 1 (latest)

unborn knoll
#

Hello! Just starting a thread for you -- I'll review and respond as soon as I can ๐Ÿ™‚

#

What are you trying to update?

prime burrow
#

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

unborn knoll
#

What do you expect it to include?

prime burrow
#

from the code I would expect to see something like

Stripe::InvoiceItem.update('il_1KqkDtJfYi7qv89iXIu7nBlU', { tax_rates: ["txr_1KqgnSJfYi7qv89i4UOmQVRC"] })
lapis canopy
#

Is that the code that produced this request?

prime burrow
#

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"
}
prime burrow
lapis canopy
#

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. ๐Ÿค”

prime burrow
#

same here... I have been trying to reproduce that error for 2 days!

unborn knoll
#

What happens if you use the ii_123 id instead of the il_123 id?

#

ii_1KqkDtJfYi7qv89iRd3wH7gw

prime burrow
#

let me try

#

Stripe::InvalidRequestError: No such Invoice Item: 'ii_1KqkDtJfYi7qv89iXIu7nBlU'(livemode=false)

#

it doesn't find the item

unborn knoll
#

the id is different, not just the prefix

prime burrow
#

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

lapis canopy
#

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 || "")
},)
prime burrow
#

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')
lapis canopy
#

This is how I'm reproducing:

prime burrow
#

interesting... are you in test mode or in prod mode?

lapis canopy
#

Test mode.

#

The il_ IDs are found on the Invoice itself, in the lines.data array of objects.

prime burrow
#

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

lapis canopy
#

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.

prime burrow
#

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! ๐Ÿ™‡โ€โ™‚๏ธ

lapis canopy
#

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: [] })

prime burrow
#

Thanks! I will give a deeper look why we have an empty array there... but this is definitely a great lead !

prime burrow
#

that returns the Stripe::InvoiceItem object

lapis canopy
#

Can you give me the request ID for that successful request?

prime burrow
#

#<Stripe::InvoiceItem:0x3e724 id=ii_1KqkDtJfYi7qv89iRd3wH7gw> JSON: {...}

lapis canopy
#

I'd like to make sure I'm not doing something differently.

prime burrow
#

req_igDqkoyvt6Oadw

#

it has an empty body but it succeed

#

very odd

lapis canopy
#

Hm. Do you have the Invoice ID associated with il_1KqjmPJfYi7qv89ik74qGCNq?

prime burrow
#

in_1KqkCqJfYi7qv89ibMDlwEXU

lapis canopy
#

That's the one for il_1KqkDtJfYi7qv89iXIu7nBlU. ๐Ÿ™‚

prime burrow
#

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

lapis canopy
#

Hm, I can't seem to find that Invoice either. Do you have the ii_ ID associated with it, or any other details?

prime burrow
#

for the il_1KqkDtJfYi7qv89iXIu7nBlU yes...
for il_1KqjmPJfYi7qv89ik74qGCNq I can't find anything associate ๐Ÿ˜ฆ

#

where the il_1KqjmPJfYi7qv89ik74qGCNq come from?

lapis canopy
#

It would have to have come from an Invoice. Let me see if I can find it another way...

prime burrow
#

where did you find the il_1KqjmPJfYi7qv89ik74qGCNq id ?

lapis canopy
prime burrow
#

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

lapis canopy
#

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?

prime burrow
#

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! ๐Ÿ˜„

lapis canopy
#

No problem! I think your approach sounds good and should solve the issue for you.

prime burrow
#

Thanks again! have a good rest of the day/evening