Payments: fixed price for eu
This commit is contained in:
parent
ab3a38d8a0
commit
0338a029e8
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user