public async Task <EstimationDto> GetEstimationAsync(string estimationId) { var estimation = await _estimationRepository.GetEstimationAsync(estimationId); if (string.IsNullOrEmpty(estimation)) { throw new ArgumentException("Invalid estimationId", "estimationId"); } return(EstimationDto.FromString(estimation)); }
public async Task <EstimationDto> CreateEstimationAsync(string from, string to, decimal transferAmount, CancellationToken cxlToken) { if (!await _countryService.IsSupportedCountryAsync(from, to, cxlToken)) { throw new ArgumentException("Country not supported"); } TransactionAmount allowedAmount = await _paymentService.TransactionRangeAsync(from); if (transferAmount < allowedAmount.MinAmount || transferAmount > allowedAmount.MaxAmount) { throw new ArgumentException($"Transfer amount must be between {allowedAmount.MinAmount} and {allowedAmount.MaxAmount}"); } var fees = await _taxAndFeeService.GetFeeAsync(from, to, transferAmount, cxlToken); var applicableRate = await _exchangeService.GetExchangeRateAsync(from, to, cxlToken); var recieveAmount = Math.Round(applicableRate * transferAmount, Accuracy, MidpointRounding.AwayFromZero); var applicablePaymentModes = await _paymentService.GetPaymentModesAsync(from); var applicableTaxes = await _taxAndFeeService.GetTaxAsync(from, transferAmount, cxlToken); var estimation = new EstimationDto { EstimationId = Guid.NewGuid().ToString(), ExchangeRate = applicableRate, AmountToSend = transferAmount, AmountToRecieve = recieveAmount, Fees = fees, PaymentModes = applicablePaymentModes, Taxes = applicableTaxes }; await _estimationRepository.SaveEstimationAsync(estimation.EstimationId, EstimationDto.ToString(estimation)); return(estimation); }
public static string ToString(EstimationDto estimation) { return(JsonConvert.SerializeObject(estimation)); }