Skip to content

feat(iso/country): add ISO 3166-1 numeric ↔ alpha-2 mapping#205

Open
lei-wego wants to merge 1 commit into
mainfrom
PAY-2143-iso3166-numeric
Open

feat(iso/country): add ISO 3166-1 numeric ↔ alpha-2 mapping#205
lei-wego wants to merge 1 commit into
mainfrom
PAY-2143-iso3166-numeric

Conversation

@lei-wego
Copy link
Copy Markdown
Collaborator

@lei-wego lei-wego commented May 22, 2026

Summary

Adds country.FromNumeric / country.Numeric helpers to the existing iso/country package, sharing the canonical alpha-2 constant table.

Why

Some upstream providers — most immediately Juspay's /cardbins endpoint — report country as ISO 3166-1 numeric (e.g. 356 for India, sometimes without leading zero like 76 for 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.
  • Single source of truth: numericToAlpha2 map covers all 249 ISO 3166-1 codes; the inverse table is built at init.

Test plan

  • Unit tests for FromNumeric — happy path (12 countries), zero-padding (76BR), whitespace, empty, non-numeric, too long, unknown code
  • Unit tests for Numeric — happy path, case-insensitive, whitespace, unknown
  • Round-trip test across all 249 codes (FromNumeric(Numeric(a2)) == a2)
  • Existing iso/country constants untouched — no risk to current consumers

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant