public static async Task <ExchangeRateHelper> ExchangeRatesAsHelper() { var exchangeRates = await CoinpaymentsApi.ExchangeRates(accepted : true); if (!exchangeRates.IsSuccess) { throw new Exception("Coinpayments error: " + exchangeRates.Error); } var helper = new ExchangeRateHelper(exchangeRates.Result); return(helper); }
public ActionResult Index(CurrencyConverterModel model) { if (ModelState.IsValid) { var resultModel = new CurrencyConverterModel() { Amount = model.Amount, CurrencyOptions = DropdownHelper.GetCurrencies(), FromCurrency = model.FromCurrency, ToCurrency = model.ToCurrency, ShowResult = true, Result = ExchangeRateHelper.GetExchangedValue(model.Amount, model.FromCurrency, model.ToCurrency).ToString() }; return(View(resultModel)); } return(RedirectToAction("Index")); }
public override async Task <ProviderAuthorisationResult> AuthoriseAsync(AuthorisationDetails authorisationDetails) { try { //Convert before sending to paystack. float amount = (await ExchangeRateHelper.GetNairaTodayAgainstDollar()); int nonStringAmount = int.Parse(authorisationDetails.Amount); authorisationDetails.Amount = (amount * nonStringAmount).ToString(); authorisationDetails.Reference = Guid.NewGuid().ToString(); HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(authorisationDetails), Encoding.UTF8, "application/json"); var getAuthEndpoint = await httpClient.PostAsync(AuthorizationEndpoint, httpContent); Console.WriteLine(getAuthEndpoint.Content.ReadAsStringAsync().Result); if (getAuthEndpoint.IsSuccessStatusCode) { var json = await getAuthEndpoint.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(json)) { var payStackAuthModel = JsonConvert.DeserializeObject <PaystackAuthModel>(json); if (null != payStackAuthModel) { return(new ProviderAuthorisationResult { AccessCode = payStackAuthModel.data.access_code, AuthEndpoint = payStackAuthModel.data.authorization_url, Status = getAuthEndpoint.StatusCode.ToString(), Reference = payStackAuthModel.data.reference }); } } } } catch { return(null); } return(null); }