x First time here? Check out the FAQ
  • Avatar677posts1185karma

    ISO 3166-1 numeric codes

    Simon Dingley started this topic September 26, 2011 @ 05:32 , this topic was edited at: Monday, September 26, 2011 7:37 PM, Go directly to the topic solution

    Finishing up the first stages of the HSBC Payment Provider and I need to pass through the numeric country code to the service which is currently not available through the API or as far as I can tell the .Net Framework, only the alpha codes. 

    Looking for advice on the best way to implement this since I am sure they will not be the only payment provider using this method of country identification?

    Thanks, Simon


  • Replies

  • Avatar1607posts2123karma
    Comment with ID: 90532
    Søren Spelling Lund posted this reply September 26, 2011 @ 06:04

    I had a similar challenge when I did our license store. I ended up doing an extension method for country, which maps country codes from a lookup structure. 


  • Avatar677posts1185karma
    Comment with ID: 90533
    Simon Dingley posted this reply September 26, 2011 @ 06:22

    Something you're willing to share? Is this something that may be included OOTB in the future?

    Thanks, Simon


  • Søren Spelling Lund posted this reply September 26, 2011 @ 07:37

    In my case my requirement was slightly different: I needed to figure out whether any given ISO code belongs to the EU, but the idea is the same.

    Here the extension I did:

    public static string GetCountryCode(this Country country)
    {
    	IDictionary<string, string> countryCodesInEu = new Dictionary<string, string>
    		{
    			{"Denmark", "DK"},
    			{"Austria", "AT"},
    			{"Belgium", "BG"},
    			{"Cyprus", "CY"},
    			{"Switzerland", "CZ"},
    			{"Germany", "DE"},
    			{"Estonia", "EE"},
    			{"Spain", "ES"},
    			{"Finland", "FI"},
    			{"France", "FR"},
    			{"United Kingdom", "GB"},
    			{"Greece", "GR"},
    			{"Hungary", "HU"},
    			{"Ireland", "IE"},
    			{"Italy", "IT"},
    			{"Luxembourg", "LU"},
    			{"Latvia", "LV"},
    			{"Malta", "MT"},
    			{"Netherlands", "NL"},
    			{"Poland", "PL"},
    			{"Portugal", "PT"},
    			{"Romania", "RO"},
    			{"Sweden", "SE"},
    			{"Solvenia", "SI"},
    			{"Solvakia", "SK"},
    		};
    	
    	if (countryCodesInEu.Keys.Contains(country.Name))
    		return countryCodesInEu[country.Name];
    
    	return null;
    }

Please login or Sign up To post replies