Exemplo n.º 1
0
        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);
        }