Payments: fixed price for eu

This commit is contained in:
pavelbannov 2023-05-15 19:30:14 +03:00
parent ab3a38d8a0
commit 0338a029e8
3 changed files with 49 additions and 32 deletions

View File

@ -34,6 +34,7 @@ public class IPGeolocationInfo
public string TimezoneName { get; set; }
public IPAddress IPStart { get; set; }
public IPAddress IPEnd { get; set; }
public string Continent { get; set; }
public static readonly IPGeolocationInfo Default = new IPGeolocationInfo

View File

@ -49,10 +49,30 @@ public class RegionHelper
public RegionInfo GetCurrentRegionInfo(IDictionary<string, Dictionary<string, decimal>> priceInfo = null)
{
var defaultRegion = GetDefaultRegionInfo();
var geoinfo = _geolocationHelper.GetIPGeolocationFromHttpContext();
var countryCode = _httpContextAccessor.HttpContext?.Request.Query["country"];
var currentRegion = GetRegionInfo(countryCode) ?? FindRegionInfo();
var currentRegion = GetRegionInfo(countryCode);
if (currentRegion == null)
{
if (geoinfo != null)
{
currentRegion = GetRegionInfo(geoinfo.Key);
}
if (currentRegion == null)
{
var tenant = _tenantManager.GetCurrentTenant(false);
if (tenant != null)
{
var owner = _userManager.GetUsers(tenant.OwnerId);
var culture = string.IsNullOrEmpty(owner.CultureName) ? tenant.GetCulture() : owner.GetCulture();
currentRegion = GetRegionInfo(culture.Name);
}
}
}
if (currentRegion != null && !currentRegion.Name.Equals(defaultRegion.Name))
{
@ -62,6 +82,11 @@ public class RegionHelper
{
return currentRegion;
}
if (geoinfo != null && !string.IsNullOrEmpty(geoinfo.Continent) && geoinfo.Continent == "EU")
{
return GetRegionInfo("ES");
}
}
return defaultRegion;
@ -74,45 +99,35 @@ public class RegionHelper
public string GetCurrencyFromRequest()
{
var regionInfo = GetDefaultRegionInfo();
var defaultRegion = GetDefaultRegionInfo();
var geoinfo = _geolocationHelper.GetIPGeolocationFromHttpContext();
if (!string.IsNullOrEmpty(geoinfo.Key))
{
try
{
regionInfo = new RegionInfo(geoinfo.Key);
var currentRegion = new RegionInfo(geoinfo.Key);
if (currentRegion != null && !currentRegion.Name.Equals(defaultRegion.Name))
{
var priceInfo = _tenantManager.GetProductPriceInfo();
if (priceInfo.Values.Any(value => value.ContainsKey(currentRegion.ISOCurrencySymbol)))
{
return currentRegion.ISOCurrencySymbol;
}
if (!string.IsNullOrEmpty(geoinfo.Continent) && geoinfo.Continent == "EU")
{
return "EUR";
}
}
}
catch (Exception)
{
}
}
return regionInfo.ISOCurrencySymbol;
}
private RegionInfo FindRegionInfo()
{
RegionInfo regionInfo = null;
var geoinfo = _geolocationHelper.GetIPGeolocationFromHttpContext();
if (geoinfo != null)
{
regionInfo = GetRegionInfo(geoinfo.Key);
}
if (regionInfo == null)
{
var tenant = _tenantManager.GetCurrentTenant(false);
if (tenant != null)
{
var owner = _userManager.GetUsers(tenant.OwnerId);
var culture = string.IsNullOrEmpty(owner.CultureName) ? tenant.GetCulture() : owner.GetCulture();
regionInfo = GetRegionInfo(culture.Name);
}
}
return regionInfo;
return defaultRegion.ISOCurrencySymbol;
}
private RegionInfo GetRegionInfo(string isoTwoLetterCountryCode)

View File

@ -79,7 +79,8 @@ public class GeolocationHelper
IPStart = new IPAddress(r.IPStart),
Key = r.Country,
TimezoneOffset = r.TimezoneOffset,
TimezoneName = r.TimezoneName
TimezoneName = r.TimezoneName,
Continent = r.Continent
})
.FirstOrDefault();
@ -104,7 +105,7 @@ public class GeolocationHelper
{
var ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress;
if (ip != IPAddress.Loopback)
if (!ip.Equals(IPAddress.Loopback))
{
_logger.DebugRemoteIpAddress(ip.ToString());
@ -114,4 +115,4 @@ public class GeolocationHelper
return IPGeolocationInfo.Default;
}
}
}