Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • seanrock 153 posts 330 karma points
    Jul 24, 2020 @ 11:00

    3 char ISO country codes

    Hi Matt

    It seems we can only specify the 2 char country code? The payment gateway we are working with requires the 3 char code.

    I can do a lookup as we're only targeting UK at the moment and then possibly USA soon after. But I can see it being a problem for global sites.

  • Matt Brailsford 2807 posts 14331 karma points MVP 7x c-trib
    Jul 24, 2020 @ 14:19
    Matt Brailsford

    Hi Sean,

    I think in this case I would suggest you do the conversion in the payment provider as allowing the stored code to be changeable could have adverse effects on code that expects it in the 2 letter format (ie, I think consistency is more beneficial than flexibility here).

    With that being the case you have 2 options really. Store a hard coded lookup table of 2 to 3 letter ISO3166 codes. Or potentially look at using CultureInfo to do it dynamically

    public string ConvertTwoLetterNameToThreeLetterName(string name)
        if (name.Length != 2)
            throw new ArgumentException("name must be two letters.");
        name = name.ToUpper();
        var cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
        foreach (var culture in cultures)
            var region = new RegionInfo(culture.LCID);
            if (region.TwoLetterISORegionName.ToUpper() == name)
                return region.ThreeLetterISORegionName;
        return null;

    This is modified from a stack overflow post which has some good other alternatives too


Please Sign in or register to post replies

Write your reply to: