feat(iso/country): add ISO 3166-1 numeric ↔ alpha-2 mapping#205
Open
lei-wego wants to merge 1 commit into
Open
feat(iso/country): add ISO 3166-1 numeric ↔ alpha-2 mapping#205lei-wego wants to merge 1 commit into
lei-wego wants to merge 1 commit into
Conversation
Some upstream providers (Juspay /cardbins) report country as ISO 3166-1 numeric code rather than alpha-2. Adds FromNumeric / Numeric helpers to the iso/country package, sharing the single alpha-2 constant table already defined there. Input normalisation accepts 1-3 digit input with or without leading zeros (Juspay returns "76" for Brazil, not "076"). Needed by PAY-2143 (Juspay BIN provider in payments service).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
country.FromNumeric/country.Numerichelpers to the existingiso/countrypackage, sharing the canonical alpha-2 constant table.Why
Some upstream providers — most immediately Juspay's
/cardbinsendpoint — report country as ISO 3166-1 numeric (e.g.356for India, sometimes without leading zero like76for Brazil). Our codebase standardises on alpha-2, so we need a single canonical converter rather than ad-hoc maps scattered across consumers.Required by PAY-2143 (Juspay BIN provider in the payments service).
What's new
country.FromNumeric(numeric string) (alpha2 string, found bool)— accepts"76","076"," 76 "interchangeably; returns("", false)for unknown / malformed input.country.Numeric(alpha2 string) (numeric string, found bool)— reverse lookup; case-insensitive on input; returns 3-digit zero-padded output.numericToAlpha2map covers all 249 ISO 3166-1 codes; the inverse table is built at init.Test plan
FromNumeric— happy path (12 countries), zero-padding (76→BR), whitespace, empty, non-numeric, too long, unknown codeNumeric— happy path, case-insensitive, whitespace, unknownFromNumeric(Numeric(a2)) == a2)iso/countryconstants untouched — no risk to current consumers