Ejemplo n.º 1
0
        /// <summary>
        /// Calculates Transaction fee - applies Previous (base) fee and Merchant discount if applicable
        /// </summary>
        /// <param name="transaction">Transaction that requires fee calculation</param>
        /// <returns>Calculated transaction fee</returns>
        public double GetTransactionFee(Transaction transaction)
        {
            if (_baseTransactionFeeCalculator == null)
            {
                throw new ArgumentNullException("Please provide valid baseTransactionFeeCalculator");
            }

            var baseFee = _baseTransactionFeeCalculator.GetTransactionFee(transaction);

            // Check if Merchant has discount - if so, then apply it, otherwise just return base fee
            return(_merchantDiscounts != null && _merchantDiscounts.ContainsKey(transaction.MerchantName) ?
                   baseFee * (100 - _merchantDiscounts[transaction.MerchantName]) / 100
                : baseFee);
        }
        /// <summary>
        /// Calculates Transaction fee - applies Previous (base) fee and Monthly fixed fee
        /// </summary>
        /// <param name="transaction">Transaction that requires fee calculation</param>
        /// <returns>Calculated transaction fee</returns>
        public double GetTransactionFee(Transaction transaction)
        {
            if (_baseTransactionFeeCalculator == null)
            {
                throw new ArgumentNullException("Please provide valid baseTransactionFeeCalculator");
            }

            var baseFee             = _baseTransactionFeeCalculator.GetTransactionFee(transaction);
            var merchantNewMonthKey = $"{transaction.MerchantName}_{transaction.TransactionDate.Month}";

            // Check if Merchant already paid this month or fee = 0, if so, then only apply base fee
            if (_firstTransactionInMonth.ContainsKey(merchantNewMonthKey) || baseFee == 0)
            {
                return(baseFee);
            }

            // Mark monthly fee for this merchant and add fixed fee.
            _firstTransactionInMonth.Add(merchantNewMonthKey, true);
            return(baseFee + _fixedFee);
        }