public Withdraw ValidateFundsForWithdrawal(AccountId accountId, Currency currency, decimal amount, TransactionId transactionId, BitcoinAddress bitcoinAddress) { Tuple <bool, string> isTierVerified = IsTierVerified(accountId.Value, currency.IsCryptoCurrency); if (isTierVerified.Item1) { //if (currency.IsCryptoCurrency) //{ WithdrawFees withdrawFees = _withdrawFeesRepository.GetWithdrawFeesByCurrencyName(currency.Name); if (withdrawFees != null) { // Check if the current withdrawal amount is greater than the amount required mentioned with the Fees if (amount >= withdrawFees.MinimumAmount) { Balance balance = GetBalanceForAccountId(accountId, currency); if (balance != null) { // Get all the Withdraw Ledgers IList <Withdraw> withdrawals = GetWithdrawalLedgers(currency, accountId); // Evaluate if the current withdrawal is within the limits of the maximum withdrawal allowed and // the balance available if (_limitsConfigurationService.EvaluateWithdrawLimits(currency.Name, isTierVerified.Item2, amount, withdrawals, balance.AvailableBalance, balance.CurrentBalance)) { Withdraw withdraw = new Withdraw(currency, _withdrawIdGeneratorService.GenerateNewId(), DateTime.Now, GetWithdrawType(currency.Name), amount - withdrawFees.Fee, withdrawFees.Fee, TransactionStatus.Pending, accountId, bitcoinAddress); // Set amount In US Dollars, which will be used in later calculations regarding withdrawals withdraw.SetAmountInUsd(_limitsConfigurationService.ConvertCurrencyToFiat(currency.Name, amount)); _fundsPersistenceRepository.SaveOrUpdate(withdraw); balance.AddPendingTransaction(withdraw.WithdrawId, PendingTransactionType.Withdraw, -(withdraw.Amount + withdrawFees.Fee)); _fundsPersistenceRepository.SaveOrUpdate(balance); return(withdraw); } else { throw new InvalidOperationException("Not enough balance or withdraw limit reached"); } } else { throw new InvalidOperationException(string.Format("No balance available AccountID = {0} | Currency = {1}", accountId.Value, currency.Name)); } } else { throw new InvalidOperationException(string.Format("Withdraw amount less than Minimum Amount: " + "AccountID = {0} | Currency = {1}", accountId.Value, currency.Name)); } } else { throw new InstanceNotFoundException(string.Format("No Withdraw Fees Found: " + "AccountID = {0} | Currency = {1}", accountId.Value, currency.Name)); } } else { throw new InvalidOperationException(string.Format("Required Tier not verified for Withdraw: Account ID = {0}", accountId.Value)); } }