surprisehighway / craft-avatax

Calculate and add sales tax to an order's base tax using Avalara's AvaTax service with Craft Commerce 5.
MIT License
7 stars 11 forks source link

Only consider an address valid if coordinates are returned #25

Closed benface closed 3 years ago

benface commented 3 years ago

When entering an invalid ZIP code (e.g. 99999), Avatax's address validation API responds with something like this:

{
    "address": {
        "textCase": "Mixed",
        "line1": "123 Pratt St",
        "city": "Durham",
        "region": "AK",
        "country": "US",
        "postalCode": "99999"
    },
    "validatedAddresses": [
        {
            "addressType": "UnknownAddressType",
            "line1": "123 Pratt St",
            "line2": "",
            "line3": "",
            "city": "Durham",
            "region": "AK",
            "country": "US",
            "postalCode": "99999"
        }
    ],
    "resolutionQuality": "External",
    "messages": [
        {
            "summary": "Address not geocoded.",
            "details": "Address cannot be geocoded.",
            "refersTo": "Address",
            "severity": "Error",
            "source": "Avalara.AvaTax.Common"
        },
        {
            "summary": "The city could not be determined.",
            "details": "The city could not be found or determined from postal code.",
            "refersTo": "Address.City",
            "severity": "Error",
            "source": "Avalara.AvaTax.Common"
        }
    ]
}

...which is currently considered valid by this plugin, but I don't think it should be. I'm suggesting changing the condition that determines whether an address is valid to require an entry in validatedAddresses AND have coordinates (latitude and longitude), instead of OR.