예제 #1
0
 public static Currency Get(eCurrencyCode currencyCodeCode)
 {
     if (CurrencyDictionary.ContainsKey(currencyCodeCode))
     {
         return(CurrencyDictionary[currencyCodeCode]);
     }
     return(null);
 }
예제 #2
0
        public async Task <APIExchangeRate> GetExchangeRate(eCurrencyCode Code, DateTime?AsOfDate = null)
        {
            if (!AsOfDate.HasValue)
            {
                AsOfDate = DateTime.Now;
            }

            var querystring = $"sourcecurrencycode={Code}&asofdate={AsOfDate.Value.ToString("yyyy-MM-dd")}";
            var response    = this.HttpService.GET($"{this.Config.BaseURL}company/{this.Config.CompanyId}/exchangerate", querystring, new Dictionary <string, string>
            {
                ["Accept"]        = "application/json",
                ["Content-Type"]  = "application/text",
                ["Authorization"] = $"Bearer {this.Config.AccessToken}"
            });

            // Unauthorized (401) - refresh token and try again
            if (!response.Success && response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                await this.RefreshToken();

                response = this.HttpService.GET($"{this.Config.BaseURL}company/{this.Config.CompanyId}/exchangerate", querystring, new Dictionary <string, string>
                {
                    ["Accept"]        = "application/json",
                    ["Content-Type"]  = "application/text",
                    ["Authorization"] = $"Bearer {this.Config.AccessToken}"
                });
            }

            if (!response.Success)
            {
                throw new APIException(this.ParseError(response.Content));
            }

            var modelSchema = new
            {
                ExchangeRate = new
                {
                    SourceCurrencyCode = string.Empty,
                    TargetCurrencyCode = string.Empty,
                    Rate     = 0.0F,
                    AsOfDate = string.Empty
                }
            };

            var responseData = JsonConvert.DeserializeAnonymousType(response.Content, modelSchema);

            return(new APIExchangeRate
            {
                Source = (eCurrencyCode)Enum.Parse(typeof(eCurrencyCode), responseData.ExchangeRate.SourceCurrencyCode, true),
                Target = (eCurrencyCode)Enum.Parse(typeof(eCurrencyCode), responseData.ExchangeRate.TargetCurrencyCode, true),
                Rate = responseData.ExchangeRate.Rate,
                AsOfDate = responseData.ExchangeRate.AsOfDate
            });
        }
예제 #3
0
        /// <summary>
        /// Constructs a currency object with a NumberFormatInfo.
        /// </summary>
        /// <param name="currencyCode"></param>
        public Currency(eCurrencyCode currencyCode)
        {
            CurrencyCode = currencyCode;
            Code         = Enum.GetName(typeof(eCurrencyCode), CurrencyCode);
            var cultureInfo = CultureInfoFromCurrencyISO(Code);

            NumberFormat = cultureInfo.NumberFormat;
            var region = new RegionInfo(cultureInfo.LCID);

            Symbol      = region?.CurrencySymbol;
            EnglishName = region?.CurrencyEnglishName;
            NativeName  = region?.CurrencyNativeName;
        }
예제 #4
0
 public static bool Exists(eCurrencyCode currencyCodeCode)
 {
     return(CurrencyDictionary.ContainsKey(currencyCodeCode));
 }
예제 #5
0
 public MoneyAmount(eCurrencyCode currencyCode, decimal amount)
 {
     this.CurrencyCode = currencyCode;
     this.Amount       = amount;
 }