lob-php icon indicating copy to clipboard operation
lob-php copied to clipboard

Exception Handling Issue during International Address Verification

Open mrnevisane opened this issue 2 years ago • 1 comments

Summary

We encountered an InvalidArgumentException while utilizing your SDK to verify an international address:

Failed to send a postcard using Lob: “Invalid value 'Housenumber/Building' for 'coverage', must be one of 'SUBBUILDING', 'HOUSENUMBER/BUILDING', 'STREET', 'LOCALITY', 'SPARSE'”.

Expected Behavior

In this case, the exception should not be thrown since the response from the Lob service is Housenumber/Building, whereas the SDK expects it to be in uppercase as HOUSENUMBER/BUILDING. It's worth noting that PHP's in_array method is case-sensitive.

image

Current Behavior

The SDK is throwing an exception, as mentioned before, when attempting to verify an international address.

Possible Solution

To address the issue, there are two potential solutions:

  1. Modify the response from the Lob service to send the coverage in uppercase to match the SDK's expectations.
  2. Alternatively, you can modify the SDK code by adding strtoupper($coverage) as the first parameter of the in_array method.

Steps to Reproduce

Using a simple code like this, leads to same error:

$verificationApi = new IntlVerificationsApi($this->config);
$verificationWritable = new IntlVerificationWritable([
    'recipient' => $recipientFullname,
    'primary_line' => $address->addressLine1,
    'secondary_line' => $address->addressLine2,
    'city' => $address->city,
    'state' => $address->state,
    'postal_code' => $address->postalCode,
    'country' => $address->country->code,
]);

$verification = $verificationApi->verifySingle($verificationWritable);

Context (Environment)

Version: 4.2.0

mrnevisane avatar Jul 18 '23 09:07 mrnevisane

I can confirm: I have similar issues:

Invalid value 'Housenumber/Building' for 'coverage', must be one of 'SUBBUILDING', 'HOUSENUMBER/BUILDING', 'STREET', 'LOCALITY', 'SPARSE'

and

Invalid value 'Subbuilding' for 'coverage', must be one of 'SUBBUILDING', 'HOUSENUMBER/BUILDING', 'STREET', 'LOCALITY', 'SPARSE'

Exception message is confusing

Example of API response:

{
    "id": "intl_ver_bf83dde51d4d738acd4a",
    "recipient": "John Zorn",
    "primary_line": "THE UNIVERSITY OF MELBOURNE, THOMAS CHERRY BUILDING, LEVEL 1",
    "secondary_line": "",
    "last_line": "MELBOURNE VIC 3010",
    "country": "AU",
    "coverage": "Subbuilding",
    "deliverability": "deliverable_missing_info",
    "status": "2",
    "components": {
        "primary_number": "",
        "building": "",
        "street_name": "THE UNIVERSITY OF MELBOURNE, THOMAS CHERRY BUILDING, LEVEL 1",
        "locality": "",
        "city": "MELBOURNE",
        "state": "VIC",
        "postal_code": "3010"
    },
    "object": "intl_verification"
}

Please note to the "coverage": "Subbuilding" part - it has a wrong case (should be SUBBUILDING)

But \OpenAPI\Client\Model\IntlVerification::getCoverageAllowableValues returns uppercase options only:

image

And similar issue with \OpenAPI\Client\Model\IntlVerification::setStatus method: API uses numeric values (1, 2, 3, 4), but this method accepts only string values prefixed by LV: image

I'll create a PR to solve both issues

UPD: Sorry, it's not possible to fix \OpenAPI\Client\Model\IntlVerification::setStatus on this library level: when this method accept a numeric string (e.g. 1), we don't how to properly prefix the string because there are few possible prefixes (LV, LF, LM, LU. see the screenshot above). So, the only solution is to fix server response or lose IntlVerification validation in setCoverage and setStatus methods

version: v4.2.3 (latest)

alies-dev avatar Oct 17 '23 14:10 alies-dev