Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Handling Issue during International Address Verification #172

Open
mrnevisane opened this issue Jul 18, 2023 · 1 comment
Open

Comments

@mrnevisane
Copy link

mrnevisane commented Jul 18, 2023

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

@alies-dev
Copy link

alies-dev commented Oct 17, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants