umbraco / Umbraco.Commerce.Issues

18 stars 2 forks source link

Three-letter ISO 3166 Country Codes #279

Open bjarnef opened 3 years ago

bjarnef commented 3 years ago

Is your feature request related to a problem? Please describe. Currently we have access to two-letter ISO 3166 country codes, when fetching country via CountryService, e.g.

var country = order.ShippingInfo.CountryId.HasValue
                    ? Vendr.Services.CountryService.GetCountry(order.ShippingInfo.CountryId.Value)
                    : null;

var isoCode = country.Code; // Two-letter ISO 3166 country code

This is useful in some payment providers like Stripe: https://github.com/vendrhub/vendr-payment-provider-stripe/blob/dev/src/Vendr.PaymentProviders.Stripe/StripeCheckoutPaymentProvider.cs#L76

However some payment provider or maybe if working with integration with other third party system, there are use-cases where a three-letter ISO 3166 country code should be used, e.g. in DIBS Easy for consumer country (DNK instead of DK).

https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes

Describe the solution you'd like It would be great if we have access to three-letter ISO 3166 country codes on CountryReadOnly. Maybe also a dictionary like Iso4217.CurrencyCodes, e.g. Iso3166Country.CountryCodes or Iso3166.CountryCodes` which could be useful to work with when not directly dealing with CountryService.

For example just to verify a string is a valid ISO 3166 country code similar to this check we have in most payment providers:

// Ensure currency has valid ISO 4217 code
if (!Iso4217.CurrencyCodes.ContainsKey(currencyCode))
{
     throw new Exception("Currency must be a valid ISO 4217 currency code: " + currency.Name);
}

Currently I can use this workaround though:

var country = order.ShippingInfo.CountryId.HasValue
                    ? Vendr.Services.CountryService.GetCountry(order.ShippingInfo.CountryId.Value)
                    : null;

var region = country != null ? new RegionInfo(country.Code) : null;
var countryIsoCode = region?.ThreeLetterISORegionName; // Three-letter ISO 3166 country code
bjarnef commented 3 years ago

@mattbrailsford furhermore it could be useful with international country calling code (maybe as property on country or available in a collection) as some payment gateways deal with these: https://docs.checkout.com/resources/codes/country-codes

I found this nice overview: https://countrycode.org/