public static Currency GetTodaysCrossRates(CurrencyCode ToCurrencyCode, CurrencyCode FromCurrencyCode) { try { Dictionary <string, Currency> CurrencyRates = GetCurrencyRates("http://www.tcmb.gov.tr/kurlar/today.xml"); if (!CurrencyRates.Keys.Contains(FromCurrencyCode.ToString())) { throw new Exception("The specified currency(" + FromCurrencyCode.ToString() + ") was not found!"); } else if (!CurrencyRates.Keys.Contains(ToCurrencyCode.ToString())) { throw new Exception("The specified currency(" + ToCurrencyCode.ToString() + ") was not found!"); } else { Currency MainCurrency = CurrencyRates[FromCurrencyCode.ToString()]; Currency OtherCurrency = CurrencyRates[ToCurrencyCode.ToString()]; return(new Currency( OtherCurrency.Name, OtherCurrency.Code, OtherCurrency.Code + "/" + MainCurrency.Code, (OtherCurrency.ForexBuying == 0 || MainCurrency.ForexBuying == 0)? 0: Math.Round((OtherCurrency.ForexBuying / MainCurrency.ForexBuying), 4), (OtherCurrency.ForexSelling == 0 || MainCurrency.ForexSelling == 0)? 0: Math.Round((OtherCurrency.ForexSelling / MainCurrency.ForexSelling), 4), (OtherCurrency.BanknoteBuying == 0 || MainCurrency.BanknoteBuying == 0)? 0: Math.Round((OtherCurrency.BanknoteBuying / MainCurrency.BanknoteBuying), 4), (OtherCurrency.BanknoteSelling == 0 || MainCurrency.BanknoteSelling == 0)? 0: Math.Round((OtherCurrency.BanknoteSelling / MainCurrency.BanknoteSelling), 4) )); } } catch (Exception ex) { throw new Exception("The date specified may be a weekend or a public holiday!"); } }
public static double CalculateHistoricalExchange(double Amount, CurrencyCode FromCurrencyCode, CurrencyCode ToCurrencyCode, int Year, int Month, int Day) { try { string SYear = String.Format("{0:0000}", Year); string SMonth = String.Format("{0:00}", Month); string SDay = String.Format("{0:00}", Day); Dictionary <string, Currency> CurrencyRates = GetCurrencyRates("http://www.tcmb.gov.tr/kurlar/" + SYear + SMonth + "/" + SDay + SMonth + SYear + ".xml"); if (!CurrencyRates.Keys.Contains(FromCurrencyCode.ToString())) { throw new Exception("The specified currency(" + FromCurrencyCode.ToString() + ") was not found!"); } else if (!CurrencyRates.Keys.Contains(ToCurrencyCode.ToString())) { throw new Exception("The specified currency(" + ToCurrencyCode.ToString() + ") was not found!"); } else { Currency MainCurrency = CurrencyRates[FromCurrencyCode.ToString()]; Currency OtherCurrency = CurrencyRates[ToCurrencyCode.ToString()]; return((OtherCurrency.ForexBuying == 0 || MainCurrency.ForexBuying == 0) ? 0 : Math.Round(Amount * (MainCurrency.ForexBuying / OtherCurrency.ForexBuying), 4)); } } catch (Exception ex) { throw new Exception("The date specified may be a weekend or a public holiday!"); } }
public static double CalculateTodaysExchange(double Amount, CurrencyCode FromCurrencyCode, CurrencyCode ToCurrencyCode) { try { Dictionary <string, Currency> CurrencyRates = GetCurrencyRates("http://www.tcmb.gov.tr/kurlar/today.xml"); if (!CurrencyRates.Keys.Contains(FromCurrencyCode.ToString())) { throw new Exception("The specified currency(" + FromCurrencyCode.ToString() + ") was not found!"); } else if (!CurrencyRates.Keys.Contains(ToCurrencyCode.ToString())) { throw new Exception("The specified currency(" + ToCurrencyCode.ToString() + ") was not found!"); } else { Currency MainCurrency = CurrencyRates[FromCurrencyCode.ToString()]; Currency OtherCurrency = CurrencyRates[ToCurrencyCode.ToString()]; return((OtherCurrency.ForexBuying == 0 || MainCurrency.ForexBuying == 0) ? 0 : Math.Round(Amount * (MainCurrency.ForexBuying / OtherCurrency.ForexBuying), 4)); } } catch (Exception ex) { throw new Exception("The date specified may be a weekend or a public holiday!"); } }
public WorldPay(HtmlHelper html, string installationId, string cartId, string amount, CurrencyCode currency) { fWorldPayPaymentModel.instId = installationId; fWorldPayPaymentModel.cartId = cartId; fWorldPayPaymentModel.amount = amount; fWorldPayPaymentModel.currency = currency.ToString(); }
public void TestDefault() { var code = new CurrencyCode(); Assert.False(code.IsStandard); Assert.Equal("XRP", code.ToString()); }
public void TestXrpStandardCode() { var code = new CurrencyCode("XRP"); Assert.Equal(CurrencyCode.XRP, code); Assert.Equal("XRP", code.ToString()); }
/// <summary> /// Checks whether the <paramref name="money"/> has the same currency as the instance, throwing an exception if that is not the case. /// </summary> /// <param name="money"><see cref="Money"/> instance to check against.</param> /// <exception cref="DifferentCurrencyException"><paramref name="money"/> has a different currency from the instance's.</exception> public void AssertSameCurrency(Money money) { if (!HasSameCurrencyAs(money)) { throw new DifferentCurrencyException(CurrencyCode.ToString(), money.CurrencyCode.ToString()); } }
public static ECurrencyCode Convert(this CurrencyCode currencyCode) { var value = currencyCode.ToString(); if (Enum.TryParse <ECurrencyCode>(value, out var result)) { return(result); } throw new ArgumentOutOfRangeException(nameof(currencyCode), currencyCode, null); }
/// <summary> /// Checks whether each of the <paramref name="moneys"/> has the same currency as the instance, throwing an exception if that is not the case. /// </summary> /// <param name="moneys">Collection of <see cref="Money"/> instance to check against.</param> /// <exception cref="DifferentCurrencyException">At least one of the <paramref name="moneys"/> has a different currency from the instance's.</exception> public void AssertSameCurrency(IEnumerable <Money> moneys) { Guard.AgainstNullArgument(nameof(moneys), moneys); foreach (var money in moneys) { if (!HasSameCurrencyAs(money)) { throw new DifferentCurrencyException(CurrencyCode.ToString(), money.CurrencyCode.ToString()); } } }
public static Currency GetTodaysExchangeRates(CurrencyCode Currency) { try { Dictionary <string, Currency> CurrencyRates = GetCurrencyRates("http://www.tcmb.gov.tr/kurlar/today.xml"); if (CurrencyRates.Keys.Contains(Currency.ToString())) { return(CurrencyRates[Currency.ToString()]); } else { throw new Exception("The specified currency(" + Currency.ToString() + ") was not found!"); } } catch (Exception ex) { throw new Exception("The date specified may be a weekend or a public holiday!"); } }
private static double GetExchangeRate(CurrencyCode currencyCode) { if (currencyCode == CurrencyCode.USD) { return 1; } else { ClientDataContext db = new ClientDataContext(); var currency = from c in db.Currencies where c.CurrencyCode.Equals(currencyCode.ToString()) select c; return currency.FirstOrDefault().Rate.Value; } }
public static Promise AddCurrency(CurrencyCode currencyCode, int amount) { var promise = new Promise(); var request = new AddUserVirtualCurrencyRequest { VirtualCurrency = currencyCode.ToString(), Amount = amount }; PlayFabClientAPI.AddUserVirtualCurrency(request, (result) => { SuccessCallback(result); promise.Resolve(); }, ErrorCallback); return(promise); }
public static Currency GetHistoricalCrossRates(CurrencyCode ToCurrencyCode, CurrencyCode FromCurrencyCode, DateTime date) { try { string SYear = String.Format("{0:0000}", date.Year); string SMonth = String.Format("{0:00}", date.Month); string SDay = String.Format("{0:00}", date.Day); Dictionary <string, Currency> CurrencyRates = GetCurrencyRates("http://www.tcmb.gov.tr/kurlar/" + SYear + SMonth + "/" + SDay + SMonth + SYear + ".xml"); if (!CurrencyRates.Keys.Contains(FromCurrencyCode.ToString())) { throw new Exception("The specified currency(" + FromCurrencyCode.ToString() + ") was not found!"); } else if (!CurrencyRates.Keys.Contains(ToCurrencyCode.ToString())) { throw new Exception("The specified currency(" + ToCurrencyCode.ToString() + ") was not found!"); } else { Currency MainCurrency = CurrencyRates[FromCurrencyCode.ToString()]; Currency OtherCurrency = CurrencyRates[ToCurrencyCode.ToString()]; return(new Currency( OtherCurrency.Name, OtherCurrency.Code, OtherCurrency.Code + "/" + MainCurrency.Code, (OtherCurrency.ForexBuying == 0 || MainCurrency.ForexBuying == 0) ? 0 : Math.Round((OtherCurrency.ForexBuying / MainCurrency.ForexBuying), 4), (OtherCurrency.ForexBuying == 0 || MainCurrency.ForexBuying == 0) ? 0 : Math.Round((OtherCurrency.ForexBuying / MainCurrency.ForexBuying), 4), (OtherCurrency.ForexBuying == 0 || MainCurrency.ForexBuying == 0) ? 0 : Math.Round((OtherCurrency.ForexBuying / MainCurrency.ForexBuying), 4), (OtherCurrency.ForexBuying == 0 || MainCurrency.ForexBuying == 0) ? 0 : Math.Round((OtherCurrency.ForexBuying / MainCurrency.ForexBuying), 4) )); } } catch (Exception ex) { throw new Exception("The date specified may be a weekend or a public holiday!"); } }
public static Currency GetHistoricalExchangeRates(CurrencyCode Currency, DateTime date) { try { string SYear = String.Format("{0:0000}", date.Year); string SMonth = String.Format("{0:00}", date.Month); string SDay = String.Format("{0:00}", date.Day); Dictionary <string, Currency> CurrencyRates = GetCurrencyRates("http://www.tcmb.gov.tr/kurlar/" + SYear + SMonth + "/" + SDay + SMonth + SYear + ".xml"); if (CurrencyRates.Keys.Contains(Currency.ToString())) { return(CurrencyRates[Currency.ToString()]); } else { throw new Exception("The specified currency(" + Currency.ToString() + ") was not found!"); } } catch (Exception ex) { throw new Exception("The date specified may be a weekend or a public holiday!"); } }
decimal GetExchangeRate(CurrencyCode fromCurrency, CurrencyCode toCurrency) { decimal d = 0; try { CurrencyServiceClient csc = new CurrencyServiceClient(); var result = csc.GetConversionRate(fromCurrency, toCurrency); if (result != null) { d = (decimal)result.Rate; } } catch (Exception ex) { Debug.WriteLine("BeginGetExchangeRate for " + fromCurrency.ToString() + " threw exception: " + ex.Message); } return d; }
public string ToJson() { NumberFormatInfo moneyFormatInfo = new NumberFormatInfo(); moneyFormatInfo.NumberDecimalSeparator = "."; if (CreditCard == null) { CreditCard = new CreditCard(); } string json = new JavaScriptSerializer().Serialize(new { TransactionType = TransactionType.ToString(), ClientMerchantCode = ClientMerchantCode, SubMerchantCode = SubMerchantCode, BankId = (int)Enum.Parse(typeof(Bank), Bank.ToString()), TranscationId = TranscationId, CurrencyAmount = CurrencyAmount.Value.ToString(moneyFormatInfo), CurrencyCode = (int)Enum.Parse(typeof(Currency), CurrencyCode.ToString()), InstallmentCount = CreditCard.InstallmentCount.HasValue ? CreditCard.InstallmentCount.Value.ToString() : "", Pan = CreditCard.Pan, Expiry = CreditCard.Expiry, Cvv = CreditCard.CVV, ReferenceTransactionId = ReferenceTransactionId, CardHoldersClientIp = CreditCard.CardHolderIp, CardHoldersEmail = CreditCard.CardHolderName, OrderId = OrderId, OrderDescription = OrderDescription, Cavv = Cavv, Eci = Eci, Xid = Xid, Md = Md, TryMultiBanks = TryMultiBanks.HasValue ? (TryMultiBanks.Value ? "1" : "") : "", Token = Token }); return(json); }
private void DownloadExchangeRates(CurrencyCode currencyCode, DateTime date) { List <Currency> currencyList = new List <Currency>(); XmlSerializer xs = new XmlSerializer(typeof(ValCurs)); XmlReader xr = new XmlTextReader(String.Format("http://www.cbr.ru/scripts/XML_daily.asp?date_req={0}", date)); foreach (ValCursValute valute in ((ValCurs)xs.Deserialize(xr)).ValuteList) { currencyList.Add(new Currency() { Name = valute.ValuteName, CharCode = valute.ValuteCharCode, Id = valute.ValuteNumCode, Nominal = valute.Nominal, Value = Convert.ToDecimal(valute.ExchangeRate), Date = date }); } var currency = currencyList.FindLast(c => c.CharCode.ToString() == currencyCode.ToString()); _context.Currencies.Add(currency); _context.SaveChanges(); }
private decimal GetExchangeRatesFromDb(CurrencyCode currencyCode, DateTime date) { Currency currency = _context.Currencies.FirstOrDefault(c => c.CharCode == currencyCode.ToString() && c.Date == date); if (currency != null) { return(currency.Value); } else { return(-1); } }
public string ToXML() { NumberFormatInfo moneyFormatInfo = new NumberFormatInfo(); moneyFormatInfo.NumberDecimalSeparator = "."; if (CreditCard == null) { CreditCard = new CreditCard(); } StringBuilder strXML = new StringBuilder(); strXML.AppendFormat("<{0}>", "VposRequest"); if (!string.IsNullOrWhiteSpace(MerchantId)) { strXML.AppendFormat("<{0}>{1}</{0}>", "MerchantId", MerchantId); } if (!string.IsNullOrWhiteSpace(Password)) { strXML.AppendFormat("<{0}>{1}</{0}>", "Password", Password); } if (!string.IsNullOrWhiteSpace(TransactionId)) { strXML.AppendFormat("<{0}>{1}</{0}>", "TransactionId", TransactionId); } if (!string.IsNullOrWhiteSpace(TerminalNo)) { strXML.AppendFormat("<{0}>{1}</{0}>", "TerminalNo", TerminalNo); } if (TransactionType.HasValue) { strXML.AppendFormat("<{0}>{1}</{0}>", "TransactionType", TransactionType.ToString()); } if (CurrencyAmount.HasValue) { strXML.AppendFormat("<{0}>{1}</{0}>", "CurrencyAmount", CurrencyAmount.Value.ToString(moneyFormatInfo)); } if (SurchargeAmount.HasValue) { strXML.AppendFormat("<{0}>{1}</{0}>", "SurchargeAmount", SurchargeAmount.Value.ToString(moneyFormatInfo)); } if (CurrencyCode.HasValue) { strXML.AppendFormat("<{0}>{1}</{0}>", "CurrencyCode", (int)Enum.Parse(typeof(Currency), CurrencyCode.ToString())); } if (!string.IsNullOrWhiteSpace(CreditCard.PointAmount)) { strXML.AppendFormat("<{0}>{1}</{0}>", "PointAmount", CreditCard.PointAmount); } if (!string.IsNullOrWhiteSpace(CreditCard.PointCode)) { strXML.AppendFormat("<{0}>{1}</{0}>", "PointCode", CreditCard.PointCode); } if (CreditCard.NumberOfInstallments.HasValue) { strXML.AppendFormat("<{0}>{1}</{0}>", "NumberOfInstallments", CreditCard.NumberOfInstallments); } if (CreditCard.BrandName.HasValue) { strXML.AppendFormat("{0}={1}&", "BrandName", (int)Enum.Parse(typeof(BrandName), CreditCard.BrandName.ToString())); } if (!string.IsNullOrWhiteSpace(CreditCard.Pan)) { strXML.AppendFormat("<{0}>{1}</{0}>", "Pan", CreditCard.Pan); } if (!string.IsNullOrWhiteSpace(CreditCard.Expiry)) { strXML.AppendFormat("<{0}>{1}</{0}>", "Expiry", CreditCard.Expiry); } if (!string.IsNullOrWhiteSpace(CreditCard.CVV)) { strXML.AppendFormat("<{0}>{1}</{0}>", "Cvv", CreditCard.CVV); } if (!string.IsNullOrWhiteSpace(CreditCard.SecurityCode)) { strXML.AppendFormat("<{0}>{1}</{0}>", "SecurityCode", CreditCard.SecurityCode); } if (!string.IsNullOrWhiteSpace(ReferenceTransactionId)) { strXML.AppendFormat("<{0}>{1}</{0}>", "ReferenceTransactionId", ReferenceTransactionId); } if (!string.IsNullOrWhiteSpace(CreditCard.CardHolderName)) { strXML.AppendFormat("<{0}>{1}</{0}>", "CardHoldersName", CreditCard.CardHolderName); } if (!string.IsNullOrWhiteSpace(CreditCard.CardHolderIp)) { strXML.AppendFormat("<{0}>{1}</{0}>", "ClientIp", CreditCard.CardHolderIp); } if (!string.IsNullOrWhiteSpace(OrderId)) { strXML.AppendFormat("<{0}>{1}</{0}>", "OrderId", OrderId); } if (!string.IsNullOrWhiteSpace(OrderDescription)) { strXML.AppendFormat("<{0}>{1}</{0}>", "OrderDescription", OrderDescription); } if (!string.IsNullOrWhiteSpace(RecurringFrequencyType)) { strXML.AppendFormat("<{0}>{1}</{0}>", "RecurringFrequencyType", RecurringFrequencyType); } if (RecurringFrequency.HasValue) { strXML.AppendFormat("<{0}>{1}</{0}>", "RecurringFrequency", RecurringFrequency); } if (IsRecurring.HasValue) { strXML.AppendFormat("<{0}>{1}</{0}>", "IsRecurring", IsRecurring.Value); } if (!string.IsNullOrWhiteSpace(TriggerDate)) { strXML.AppendFormat("<{0}>{1}</{0}>", "TriggerDate", TriggerDate); } if (RecurringInstallmentCount.HasValue) { strXML.AppendFormat("<{0}>{1}</{0}>", "RecurringInstallmentCount", RecurringInstallmentCount); } if (!string.IsNullOrWhiteSpace(CAVV)) { strXML.AppendFormat("<{0}>{1}</{0}>", "CAVV", CAVV); } if (!string.IsNullOrWhiteSpace(ECI)) { strXML.AppendFormat("<{0}>{1}</{0}>", "ECI", ECI); } if (CustomItems != null) { strXML.AppendFormat("<{0}>", "CustomItems"); for (int i = 0; i < CustomItems.Count; i++) { strXML.AppendFormat($"<Item name=\"{CustomItems.ElementAt(0).Key}\" value=\"{CustomItems.ElementAt(0).Value}\"/>"); } strXML.AppendFormat("</{0}>", "CustomItems"); } if (DeviceType.HasValue) { strXML.AppendFormat("<{0}>{1}</{0}>", "DeviceType", (int)Enum.Parse(typeof(DeviceType), DeviceType.ToString())); } if (TransactionDeviceSource.HasValue) { strXML.AppendFormat("<{0}>{1}</{0}>", "TransactionDeviceSource", (int)Enum.Parse(typeof(TransactionDeviceSource), TransactionDeviceSource.ToString())); } if (!string.IsNullOrWhiteSpace(Extract)) { strXML.AppendFormat("<{0}>{1}</{0}>", "Extract", Extract); } if (!string.IsNullOrWhiteSpace(ExpSign)) { strXML.AppendFormat("<{0}>{1}</{0}>", "ExpSign", ExpSign); } if (!string.IsNullOrWhiteSpace(MpiTransactionId)) { strXML.AppendFormat("<{0}>{1}</{0}>", "MpiTransactionId", MpiTransactionId); } if (!string.IsNullOrWhiteSpace(Location)) { strXML.AppendFormat("<{0}>{1}</{0}>", "Location", Location); } if (MerchantType.HasValue) { strXML.AppendFormat("<{0}>{1}</{0}>", "MerchantType", (int)Enum.Parse(typeof(MerchantType), MerchantType.ToString())); } if (!string.IsNullOrWhiteSpace(SubMerchantId)) { strXML.AppendFormat("<{0}>{1}</{0}>", "SubMerchantId", SubMerchantId); } if (!string.IsNullOrWhiteSpace(ClientIp)) { strXML.AppendFormat("<{0}>{1}</{0}>", "ClientIp", ClientIp); } strXML.AppendFormat("</{0}>", "VposRequest"); return(strXML.ToString()); }
public Task<ConvertResponseContext> ConvertAsync(decimal amount, CurrencyCode fromCurrency, CurrencyCode toCurrency) { if (!Enum.IsDefined(typeof(CurrencyCode), fromCurrency)) throw new ArgumentNullException("fromCurrency"); if (!Enum.IsDefined(typeof(CurrencyCode), toCurrency)) throw new ArgumentNullException("toCurrency"); if (fromCurrency == toCurrency) throw new ArgumentException("fromCurrency and toCurrency paramaters cannot be the same"); string fromCurrencyStr = fromCurrency.ToString(); string toCurrencyStr = toCurrency.ToString(); //NOTE: HttpContext.Current nulls itself after async call //get a reference of it and work on that one. _currentHttpContext = HttpContext.Current; return getRatesStatusAsync().Then(ratesStatus => { //NOTE: we are here sure that these two paramates have not the same value set if (fromCurrency == CurrencyCode.TRY || toCurrency == CurrencyCode.TRY) { //NOTE: request has been made for some sort of TRY convert //deal with it accordingly //NOTE: if request is to convert from TRY if (fromCurrency == CurrencyCode.TRY) { var ___currency = ratesStatus.Currencies.FirstOrDefault(cur => cur.CurrencyCode == toCurrencyStr && !string.IsNullOrEmpty(cur.ForexSelling) ); if (___currency == null) { return new ConvertResponseContext { IsConvertSuccessful = false, BaseAmount = amount, ErrorMessage = string.Format( "There is no currency rate available for {0} currency", toCurrencyStr ) }; } decimal ___currenyRate; if (!decimal.TryParse(___currency.ForexSelling, out ___currenyRate)) { return new ConvertResponseContext { IsConvertSuccessful = false, BaseAmount = amount, ErrorMessage = string.Format( "{0} amount for {1} currency is not in a correct format.", "ForexSelling", toCurrencyStr ) }; } var ___convertedAmount = (amount / ___currenyRate); return new ConvertResponseContext { IsConvertSuccessful = true, BaseAmount = amount, BaseCurrencyRate = ___currenyRate, ConvertedFrom = fromCurrency, ConvertedTo = toCurrency, ConvertedAmount = decimal.Round(___convertedAmount, 2) }; } //NOTE: if request is to convert to TRY else { var ___currency = ratesStatus.Currencies.FirstOrDefault(cur => cur.CurrencyCode == fromCurrencyStr && !string.IsNullOrEmpty(cur.ForexSelling) ); if (___currency == null) { return new ConvertResponseContext { IsConvertSuccessful = false, BaseAmount = amount, ErrorMessage = string.Format( "There is no currency rate available for {0} currency", fromCurrencyStr ) }; } decimal ___currenyRate; if (!decimal.TryParse(___currency.ForexSelling, out ___currenyRate)) { return new ConvertResponseContext { IsConvertSuccessful = false, BaseAmount = amount, ErrorMessage = string.Format( "{0} amount for {1} currency is not in a correct format.", "ForexSelling", fromCurrencyStr ) }; } var ___convertedAmount = (amount * ___currenyRate); return new ConvertResponseContext { IsConvertSuccessful = true, BaseAmount = amount, BaseCurrencyRate = ___currenyRate, ConvertedFrom = fromCurrency, ConvertedTo = toCurrency, ConvertedAmount = decimal.Round(___convertedAmount, 2) }; } } else { //NOTE: request has been made for some sort of cross rate calculation //deal with it accordingly return new ConvertResponseContext { IsConvertSuccessful = false, BaseAmount = amount, ErrorMessage = string.Format( "Cross-rate calculation is not supported." ) }; } }, runSynchronously: true); }
public override string ToString() { NumberFormatInfo moneyFormatInfo = new NumberFormatInfo(); moneyFormatInfo.NumberDecimalSeparator = "."; if (CreditCard == null) { CreditCard = new CreditCard(); } StringBuilder str = new StringBuilder(); if (!string.IsNullOrWhiteSpace(TransactionType.ToString())) { str.AppendFormat("{0}={1}&", "TransactionType", TransactionType.ToString()); } if (!string.IsNullOrWhiteSpace(ClientMerchantCode)) { str.AppendFormat("{0}={1}&", "ClientMerchantCode", ClientMerchantCode); } if (!string.IsNullOrWhiteSpace(Password)) { str.AppendFormat("{0}={1}&", "Password", Password); } if (!string.IsNullOrWhiteSpace(SubMerchantCode)) { str.AppendFormat("{0}={1}&", "SubMerchantCode", SubMerchantCode); } if (Bank.HasValue) { str.AppendFormat("{0}={1}&", "BankId", (int)Enum.Parse(typeof(Bank), Bank.ToString())); } if (!string.IsNullOrWhiteSpace(TranscationId)) { str.AppendFormat("{0}={1}&", "TranscationId", TranscationId); } if (CurrencyAmount.HasValue) { str.AppendFormat("{0}={1}&", "CurrencyAmount", CurrencyAmount.Value.ToString(moneyFormatInfo)); } if (CurrencyCode.HasValue) { str.AppendFormat("{0}={1}&", "CurrencyCode", (int)Enum.Parse(typeof(Currency), CurrencyCode.ToString())); } if (CreditCard.InstallmentCount.HasValue) { str.AppendFormat("{0}={1}&", "InstallmentCount", CreditCard.InstallmentCount.Value.ToString()); } if (!string.IsNullOrWhiteSpace(CreditCard.Pan)) { str.AppendFormat("{0}={1}&", "Pan", CreditCard.Pan); } if (!string.IsNullOrWhiteSpace(CreditCard.Expiry)) { str.AppendFormat("{0}={1}&", "Expiry", CreditCard.Expiry); } if (!string.IsNullOrWhiteSpace(CreditCard.CVV)) { str.AppendFormat("{0}={1}&", "Cvv", CreditCard.CVV); } if (!string.IsNullOrWhiteSpace(ReferenceTransactionId)) { str.AppendFormat("{0}={1}&", "ReferenceTransactionId", ReferenceTransactionId); } if (!string.IsNullOrWhiteSpace(CreditCard.CardHolderIp)) { str.AppendFormat("{0}={1}&", "CardHoldersClientIp", CreditCard.CardHolderIp); } if (!string.IsNullOrWhiteSpace(CreditCard.CardHolderEmail)) { str.AppendFormat("{0}={1}&", "CardHoldersEmail", CreditCard.CardHolderEmail); } if (!string.IsNullOrWhiteSpace(OrderId)) { str.AppendFormat("{0}={1}&", "OrderId", OrderId); } if (!string.IsNullOrWhiteSpace(OrderDescription)) { str.AppendFormat("{0}={1}&", "OrderDescription", OrderDescription); } if (!string.IsNullOrWhiteSpace(Cavv)) { str.AppendFormat("{0}={1}&", "Cavv", Cavv); } if (!string.IsNullOrWhiteSpace(Eci)) { str.AppendFormat("{0}={1}&", "Eci", Eci); } if (!string.IsNullOrWhiteSpace(Xid)) { str.AppendFormat("{0}={1}&", "Xid", Xid); } if (!string.IsNullOrWhiteSpace(Md)) { str.AppendFormat("{0}={1}&", "Md", Md); } if (TryMultiBanks.HasValue) { str.AppendFormat("{0}={1}&", "TryMultiBanks", TryMultiBanks.Value ? "1" : ""); } if (!string.IsNullOrWhiteSpace(Token)) { str.AppendFormat("{0}={1}&", "Token", Token); } if (!string.IsNullOrWhiteSpace(CustomerId)) { str.AppendFormat("{0}={1}&", "CustomerId", CustomerId); } if (!string.IsNullOrWhiteSpace(CreditCard.CardHolderName)) { str.AppendFormat("{0}={1}", "CardHolderName", CreditCard.CardHolderName); } return(str.ToString()); }
public override string ToString() { var sb = new StringBuilder("PaidCallCurrencyExchangeRate("); bool __first = true; if (CurrencyCode != null && __isset.currencyCode) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("CurrencyCode: "); CurrencyCode.ToString(sb); } if (CurrencyName != null && __isset.currencyName) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("CurrencyName: "); CurrencyName.ToString(sb); } if (CurrencySign != null && __isset.currencySign) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("CurrencySign: "); CurrencySign.ToString(sb); } if (__isset.preferred) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Preferred: "); Preferred.ToString(sb); } if (CoinRate != null && __isset.coinRate) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("CoinRate: "); CoinRate.ToString(sb); } if (CreditRate != null && __isset.creditRate) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("CreditRate: "); CreditRate.ToString(sb); } sb.Append(")"); return(sb.ToString()); }
public decimal this[CurrencyCode code] { get { switch (code) { case CurrencyCode.AED: return AED; case CurrencyCode.AFN: return AFN; case CurrencyCode.ALL: return ALL; case CurrencyCode.AMD: return AMD; case CurrencyCode.ANG: return ANG; case CurrencyCode.AOA: return AOA; case CurrencyCode.ARS: return ARS; case CurrencyCode.AUD: return AUD; case CurrencyCode.AWG: return AWG; case CurrencyCode.AZN: return AZN; case CurrencyCode.BAM: return BAM; case CurrencyCode.BBD: return BBD; case CurrencyCode.BDT: return BDT; case CurrencyCode.BGN: return BGN; case CurrencyCode.BHD: return BHD; case CurrencyCode.BIF: return BIF; case CurrencyCode.BMD: return BMD; case CurrencyCode.BND: return BND; case CurrencyCode.BOB: return BOB; case CurrencyCode.BOV: throw new NotSupportedException("Provider does not support BOV"); case CurrencyCode.BRL: return BRL; case CurrencyCode.BSD: return BSD; case CurrencyCode.BTN: return BTN; case CurrencyCode.BWP: return BWP; case CurrencyCode.BYR: return BYR; case CurrencyCode.BZD: return BZD; case CurrencyCode.CAD: return CAD; case CurrencyCode.CDF: return CDF; case CurrencyCode.CHE: throw new NotSupportedException("Provider does not support CHE"); case CurrencyCode.CHF: return CHF; case CurrencyCode.CHW: throw new NotSupportedException("Provider does not support CHW"); case CurrencyCode.CLF: return CLF; case CurrencyCode.CLP: return CLP; case CurrencyCode.CNY: return CNY; case CurrencyCode.COP: return COP; case CurrencyCode.COU: throw new NotSupportedException("Provider does not support COU"); case CurrencyCode.CRC: return CRC; case CurrencyCode.CUC: return CUC; case CurrencyCode.CUP: return CUP; case CurrencyCode.CVE: return CVE; case CurrencyCode.CZK: return CZK; case CurrencyCode.DJF: return DJF; case CurrencyCode.DKK: return DKK; case CurrencyCode.DOP: return DOP; case CurrencyCode.DZD: return DZD; case CurrencyCode.EGP: return EGP; case CurrencyCode.ERN: return ERN; case CurrencyCode.ETB: return ETB; case CurrencyCode.EUR: return EUR; case CurrencyCode.FJD: return FJD; case CurrencyCode.FKP: return FKP; case CurrencyCode.GBP: return GBP; case CurrencyCode.GEL: return GEL; case CurrencyCode.GHS: return GHS; case CurrencyCode.GIP: return GIP; case CurrencyCode.GMD: return GMD; case CurrencyCode.GNF: return GNF; case CurrencyCode.GTQ: return GTQ; case CurrencyCode.GYD: return GYD; case CurrencyCode.HKD: return HKD; case CurrencyCode.HNL: return HNL; case CurrencyCode.HRK: return HRK; case CurrencyCode.HTG: return HTG; case CurrencyCode.HUF: return HUF; case CurrencyCode.IDR: return IDR; case CurrencyCode.ILS: return ILS; case CurrencyCode.INR: return INR; case CurrencyCode.IQD: return IQD; case CurrencyCode.IRR: return IRR; case CurrencyCode.ISK: return ISK; case CurrencyCode.JMD: return JMD; case CurrencyCode.JOD: return JOD; case CurrencyCode.JPY: return JPY; case CurrencyCode.KES: return KES; case CurrencyCode.KGS: return KGS; case CurrencyCode.KHR: return KHR; case CurrencyCode.KMF: return KMF; case CurrencyCode.KPW: return KPW; case CurrencyCode.KRW: return KRW; case CurrencyCode.KWD: return KWD; case CurrencyCode.KYD: return KYD; case CurrencyCode.KZT: return KZT; case CurrencyCode.LAK: return LAK; case CurrencyCode.LBP: return LBP; case CurrencyCode.LKR: return LKR; case CurrencyCode.LRD: return LRD; case CurrencyCode.LSL: return LSL; case CurrencyCode.LYD: return LYD; case CurrencyCode.MAD: return MAD; case CurrencyCode.MDL: return MDL; case CurrencyCode.MGA: return MGA; case CurrencyCode.MKD: return MKD; case CurrencyCode.MMK: return MMK; case CurrencyCode.MNT: return MNT; case CurrencyCode.MOP: return MOP; case CurrencyCode.MRO: return MRO; case CurrencyCode.MUR: return MUR; case CurrencyCode.MVR: return MVR; case CurrencyCode.MWK: return MWK; case CurrencyCode.MXN: return MXN; case CurrencyCode.MXV: throw new NotSupportedException("Provider does not support MXV"); case CurrencyCode.MYR: return MYR; case CurrencyCode.MZN: return MZN; case CurrencyCode.NAD: return NAD; case CurrencyCode.NGN: return NGN; case CurrencyCode.NIO: return NIO; case CurrencyCode.NOK: return NOK; case CurrencyCode.NPR: return NPR; case CurrencyCode.NZD: return NZD; case CurrencyCode.OMR: return OMR; case CurrencyCode.PAB: return PAB; case CurrencyCode.PEN: return PEN; case CurrencyCode.PGK: return PGK; case CurrencyCode.PHP: return PHP; case CurrencyCode.PKR: return PKR; case CurrencyCode.PLN: return PLN; case CurrencyCode.PYG: return PYG; case CurrencyCode.QAR: return QAR; case CurrencyCode.RON: return RON; case CurrencyCode.RSD: return RSD; case CurrencyCode.RUB: return RUB; case CurrencyCode.RWF: return RWF; case CurrencyCode.SAR: return SAR; case CurrencyCode.SBD: return SBD; case CurrencyCode.SCR: return SCR; case CurrencyCode.SDG: return SDG; case CurrencyCode.SEK: return SEK; case CurrencyCode.SGD: return SGD; case CurrencyCode.SHP: return SHP; case CurrencyCode.SLL: return SLL; case CurrencyCode.SOS: return SOS; case CurrencyCode.SRD: return SRD; case CurrencyCode.SSP: throw new NotSupportedException("Provider does not support SSP"); case CurrencyCode.STD: return STD; case CurrencyCode.SYP: return SYP; case CurrencyCode.SZL: return SZL; case CurrencyCode.THB: return THB; case CurrencyCode.TJS: return TJS; case CurrencyCode.TMT: return TMT; case CurrencyCode.TND: return TND; case CurrencyCode.TOP: return TOP; case CurrencyCode.TRY: return TRY; case CurrencyCode.TTD: return TTD; case CurrencyCode.TWD: return TWD; case CurrencyCode.TZS: return TZS; case CurrencyCode.UAH: return UAH; case CurrencyCode.UGX: return UGX; case CurrencyCode.USD: return USD; case CurrencyCode.USN: throw new NotSupportedException("Provider does not support USN"); case CurrencyCode.USS: throw new NotSupportedException("Provider does not support USS"); case CurrencyCode.UYI: throw new NotSupportedException("Provider does not support UYI"); case CurrencyCode.UYU: return UYU; case CurrencyCode.UZS: return UZS; case CurrencyCode.VEF: return VEF; case CurrencyCode.VND: return VND; case CurrencyCode.VUV: return VUV; case CurrencyCode.WST: return WST; case CurrencyCode.XAF: return XAF; case CurrencyCode.XAG: return XAG; case CurrencyCode.XAU: return XAU; case CurrencyCode.XBA: throw new NotSupportedException("Provider does not support XBA"); case CurrencyCode.XBB: throw new NotSupportedException("Provider does not support XBB"); case CurrencyCode.XBC: throw new NotSupportedException("Provider does not support XBC"); case CurrencyCode.XBD: throw new NotSupportedException("Provider does not support XBD"); case CurrencyCode.XCD: return XCD; case CurrencyCode.XDR: return XDR; case CurrencyCode.XFU: throw new NotSupportedException("Provider does not support XFU"); case CurrencyCode.XOF: return XOF; case CurrencyCode.XPD: return XPD; case CurrencyCode.XPF: return XPF; case CurrencyCode.XPT: return XPT; case CurrencyCode.XSU: throw new NotSupportedException("Provider does not support XSU"); case CurrencyCode.XTS: throw new NotSupportedException("Provider does not support XTS"); case CurrencyCode.XUA: throw new NotSupportedException("Provider does not support XUA"); case CurrencyCode.XXX: throw new NotSupportedException("Provider does not support XXX"); case CurrencyCode.YER: return YER; case CurrencyCode.ZAR: return ZAR; case CurrencyCode.ZMW: return ZMW; default: throw new NotSupportedException("Provider does not support " + code.ToString()); } } }
public override String ToString() { return(CurrencyCode.ToString()); }
public void TestRoundTrip(string input) { var code = new CurrencyCode(input); Assert.Equal(input, code.ToString()); }
public Task <ConvertResponseContext> ConvertAsync(decimal amount, CurrencyCode fromCurrency, CurrencyCode toCurrency) { if (!Enum.IsDefined(typeof(CurrencyCode), fromCurrency)) { throw new ArgumentNullException("fromCurrency"); } if (!Enum.IsDefined(typeof(CurrencyCode), toCurrency)) { throw new ArgumentNullException("toCurrency"); } if (fromCurrency == toCurrency) { throw new ArgumentException("fromCurrency and toCurrency paramaters cannot be the same"); } string fromCurrencyStr = fromCurrency.ToString(); string toCurrencyStr = toCurrency.ToString(); //NOTE: HttpContext.Current nulls itself after async call //get a reference of it and work on that one. _currentHttpContext = HttpContext.Current; return(getRatesStatusAsync().Then(ratesStatus => { //NOTE: we are here sure that these two paramates have not the same value set if (fromCurrency == CurrencyCode.TRY || toCurrency == CurrencyCode.TRY) { //NOTE: request has been made for some sort of TRY convert //deal with it accordingly //NOTE: if request is to convert from TRY if (fromCurrency == CurrencyCode.TRY) { var ___currency = ratesStatus.Currencies.FirstOrDefault(cur => cur.CurrencyCode == toCurrencyStr && !string.IsNullOrEmpty(cur.ForexSelling) ); if (___currency == null) { return new ConvertResponseContext { IsConvertSuccessful = false, BaseAmount = amount, ErrorMessage = string.Format( "There is no currency rate available for {0} currency", toCurrencyStr ) }; } decimal ___currenyRate; if (!decimal.TryParse(___currency.ForexSelling, out ___currenyRate)) { return new ConvertResponseContext { IsConvertSuccessful = false, BaseAmount = amount, ErrorMessage = string.Format( "{0} amount for {1} currency is not in a correct format.", "ForexSelling", toCurrencyStr ) }; } var ___convertedAmount = (amount / ___currenyRate); return new ConvertResponseContext { IsConvertSuccessful = true, BaseAmount = amount, BaseCurrencyRate = ___currenyRate, ConvertedFrom = fromCurrency, ConvertedTo = toCurrency, ConvertedAmount = decimal.Round(___convertedAmount, 2) }; } //NOTE: if request is to convert to TRY else { var ___currency = ratesStatus.Currencies.FirstOrDefault(cur => cur.CurrencyCode == fromCurrencyStr && !string.IsNullOrEmpty(cur.ForexSelling) ); if (___currency == null) { return new ConvertResponseContext { IsConvertSuccessful = false, BaseAmount = amount, ErrorMessage = string.Format( "There is no currency rate available for {0} currency", fromCurrencyStr ) }; } decimal ___currenyRate; if (!decimal.TryParse(___currency.ForexSelling, out ___currenyRate)) { return new ConvertResponseContext { IsConvertSuccessful = false, BaseAmount = amount, ErrorMessage = string.Format( "{0} amount for {1} currency is not in a correct format.", "ForexSelling", fromCurrencyStr ) }; } var ___convertedAmount = (amount * ___currenyRate); return new ConvertResponseContext { IsConvertSuccessful = true, BaseAmount = amount, BaseCurrencyRate = ___currenyRate, ConvertedFrom = fromCurrency, ConvertedTo = toCurrency, ConvertedAmount = decimal.Round(___convertedAmount, 2) }; } } else { //NOTE: request has been made for some sort of cross rate calculation //deal with it accordingly return new ConvertResponseContext { IsConvertSuccessful = false, BaseAmount = amount, ErrorMessage = string.Format( "Cross-rate calculation is not supported." ) }; } }, runSynchronously: true)); }
public static Promise <Currency> GetCurrency(CurrencyCode currencyCode) { var promise = new Promise <Currency>(); var request = new GetUserInventoryRequest(); PlayFabClientAPI.GetUserInventory(request, (result) => { try { Currency currency = new Currency(currencyCode, result.VirtualCurrency[currencyCode.ToString()]); promise.Resolve(currency); GetCurrencySuccessCallback(result); } catch (Exception ex) { promise.Reject(ex); } }, ErrorCallback); return(promise); }
public static CultureInfo?GetCultureInfo(this CurrencyCode eCurrencyCode) { return(CultureInfo.GetCultures(CultureTypes.SpecificCultures) .FirstOrDefault(culture => new RegionInfo(culture.LCID).ISOCurrencySymbol == eCurrencyCode.ToString())); }
public string GetPriceCurrencyCode() { return(_currencyCode.ToString("G")); }
/// <summary> /// Sets the specific merchant to use when communicating with the Bank. /// If you use multiple mechants you should explicitly call this method to set a specific active merchant, that will be used by other methods, /// otherwise the system will try to find a matching merchant automatically and might not select the one you might actually need. /// </summary> /// <param name="currency">Currency to search for</param> /// <exception cref="TbcBankEcommerceClientConfigurationException">Thrown when merchant configuration not found or more than one merchant configuration found with the specified currency</exception> public void SelectMerchant(CurrencyCode currency) { var merchantOptionsList = _optionsList .Where(o => o.Currencies.Contains(currency)) .ToList(); if (merchantOptionsList.Count == 0) { throw new TbcBankEcommerceClientConfigurationException($"Merchant configuration not found using the speficied currency '{currency.ToString()}'"); } if (merchantOptionsList.Count > 1) { throw new TbcBankEcommerceClientConfigurationException($"More than one merchant configuration not found using the speficied currency '{currency.ToString()}'"); } _manuallySetActiveOptions = merchantOptionsList .First(); }