示例#1
0
        public DepositPaymentTransaction MakeDepositTransaction(decimal depositAmount)
        {
            CheckIfWalletIsBlocked();
            bool isLimitExceeded = LimitPaymentTransactionCalculator.IsDepositLimitExceed(this, depositAmount);

            if (isLimitExceeded)
            {
                throw new LimitExceededException();
            }
            var depositPaymentTransaction = new DepositPaymentTransaction(this, depositAmount);

            PaymentTransactions.Add(depositPaymentTransaction);
            CurrentAmount += depositAmount;
            return(depositPaymentTransaction);
        }
示例#2
0
        public WithdrawalPaymentTransaction MakeWithdrawalTransaction(decimal withdrawalAmount)
        {
            CheckIfWalletIsBlocked();
            bool isLimitExceeded = LimitPaymentTransactionCalculator.IsWithdrawalLimitExceed(this, withdrawalAmount);

            if (isLimitExceeded)
            {
                throw new LimitExceededException();
            }
            if (CurrentAmount < withdrawalAmount)
            {
                throw new NotEnoughAmountException();
            }
            CurrentAmount -= withdrawalAmount;
            var withdrawalPaymentTransaction = new WithdrawalPaymentTransaction(this, withdrawalAmount);

            PaymentTransactions.Add(withdrawalPaymentTransaction);
            return(withdrawalPaymentTransaction);
        }
示例#3
0
        public InternalTransferPaymentTransactions MakeInternalTransfer(Wallet toWallet, decimal amount)
        {
            CheckIfWalletIsBlocked();
            toWallet.CheckIfWalletIsBlocked();
            decimal feeAmount = FeeCalculator.CalculateFee(this, amount);
            bool    isWithdrawalLimitExceeded = LimitPaymentTransactionCalculator.IsWithdrawalLimitExceed(this, amount);

            if (isWithdrawalLimitExceeded)
            {
                throw new LimitExceededException();
            }
            bool isDepositLimitExceeded = LimitPaymentTransactionCalculator.IsDepositLimitExceed(toWallet, amount);

            if (isDepositLimitExceeded)
            {
                throw new LimitExceededException();
            }
            if (CurrentAmount < amount + feeAmount)
            {
                throw new NotEnoughAmountException();
            }
            string internalTransferId = Guid.NewGuid().ToString();
            var    deposit            = new DepositInternalTransferPaymentTransaction(toWallet, this, amount, internalTransferId);
            var    withdrawal         = new WithdrawalInternalTransferPaymentTransaction(this, toWallet, amount, internalTransferId);
            FeeInternalTransferPaymentTransaction feePaymentTransaction = new FeeInternalTransferPaymentTransaction(this, toWallet, feeAmount, internalTransferId);

            this.CurrentAmount     -= amount;
            toWallet.CurrentAmount += amount;
            PaymentTransactions.Add(withdrawal);
            toWallet.PaymentTransactions.Add(deposit);
            var internalTransferPaymentTransactions = new InternalTransferPaymentTransactions(deposit, withdrawal, feePaymentTransaction);

            if (internalTransferPaymentTransactions.HasFee())
            {
                this.CurrentAmount -= feeAmount;
                PaymentTransactions.Add(feePaymentTransaction);
            }
            return(internalTransferPaymentTransactions);
        }