Hi,
I have a weird issue where upcoming invoices return invalid tax IDs. It's rare, but it happens often enough that I am worried I misunderstand something in the Stripe API.
This is my Go code to get the upcoming invoice
in, err := invoice.Upcoming(newInvoice)
if err != nil {
return nil, fmt.Errorf("failed to get upcoming invoice: %w", err)
}
if len(in.Lines.Data) == 0 {
return nil, fmt.Errorf(`no lines in invoice for customer id %s`, customerID)
}
invoiceLine := in.Lines.Data[len(in.Lines.Data)-1]
I then use this invoiceLine to work out if there is any tax on the price.
if invoiceLine.TaxAmounts != nil && len(invoiceLine.TaxAmounts) > 0 {
taxRates := invoiceLine.TaxAmounts[0]
tr, err := taxrate.Get(
taxRates.TaxRate.ID,
nil,
)
if err != nil {
zap.S().Errorw("failed to get tax rate",
zap.String("customer_id", customerID),
zap.String("tax_id", taxRates.TaxRate.ID),
zap.String("tax_display_name", taxRates.TaxRate.DisplayName),
zap.String("tax_country", taxRates.TaxRate.Country),
zap.Error(err),
)
return &preview, nil
}
I am, however, seeing this taxrate.Get fail every now and then with an error like this.
{
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"status": 404,
"message": "No such tax rate: 'txr_1NscVlL7Q22muElKO1Xi7UNg'",
"param": "tax_rate",
"request_id": "req_3dPgfwhFSB3cCg",
"request_log_url": "https://dashboard.stripe.com/logs/req_3dPgfwhFSB3cCg?t=1695262862",
"type": "invalid_request_error"
}
Am I doing something wrong? I expect any txr returned on the invoice preview to be lookup able via the API, but this isn't the case.