taxjar / taxjar-go

Sales Tax API Client for Go
https://developers.taxjar.com/api/reference/?go
MIT License
15 stars 5 forks source link

Handle API line item numeric strings in json.Unmarshal #20

Closed sethobey closed 2 years ago

sethobey commented 2 years ago

Context

Although the TaxJar API accepts line item IDs of type string, when a numeric string is encountered, the corresponding response line item ID is returned as an integer rather than the request body's type of string.

When this error was previously identified, the accepted resolution in PR #8 was to modify the underlying OrderLineItem struct to decode ID values as json.Number rather than string, since the JSON number literal type will accept numeric string values.

While this change addressed the API's potential internal modification of ID value types, it did not account for the possibility of special characters (or letters) being included in item identifiers as raised in Issue #16.

Description

If a type error is encountered when Unmarshal-ing transaction request JSON and that type error is due to a numeric line item ID in the API response, we will no longer return an error. This will still surface all other errors, including other type errors on this field.

Testing

WIth API key set in environment (live mode)

Screen Shot 2022-10-14 at 10 35 49 PM

Without API key set in environment

Screen Shot 2022-10-14 at 10 36 22 PM