boomerdigital / solidus_avatax_certified

Improve your Solidus store's sales tax decision automation with Avalara AvaTax
BSD 3-Clause "New" or "Revised" License
9 stars 44 forks source link

Limit itemCode to 50 characters #127

Open ericsaupe opened 5 years ago

ericsaupe commented 5 years ago

While investigating an issue with our tax responses coming back as bad we received this in the response. We should limit the itemCode field to 50 characters as requested. We should also look into any other fields that have limits.

{
    "error" => {
           "code" => "ModelStateInvalid",
        "message" => "Field 'itemCode' has an invalid length.",
         "target" => "HttpRequest",
        "details" => [
            [0] {
                       "code" => "MaxStringLengthError",
                     "number" => 14,
                    "message" => "Field 'itemCode' has an invalid length.",
                "description" => "Field 'itemCode' must be no more than 50 characters in length.",
                  "faultCode" => "Client",
                   "helpLink" => "http://developer.avalara.com/avatax/errors/MaxStringLengthError",
                   "severity" => "Error"
            }
        ]
    }
}

Affected lines

dhonig commented 5 years ago

Interesting to know what field you used that was longer than 50 chars? Is it safe to limit this to substr(0,49) or do we need to do something else?

ericsaupe commented 5 years ago

For us it was the shipping_method.name. We display the name on the frontend so it allows editing more easily than having it hard coded. Changing to shipping_method.internal_name would have resolved it for us but may still not for others. I used truncate in the patch for our site but that can interfere with items that may be set specifically in AvaTax that are taxing based on itemCode instead of relying on the category.

I think substr or truncate are fine the issue is just to get it down to 50 characters to be in compliance of their API.