public string RefillBalance(int customerId, decimal moneyAmount)
        {
            Result <MoneyToCharge>      moneyToCharge = MoneyToCharge.Create(moneyAmount);
            Result <CustomerManagement> customer      = _database.GetById(customerId).ToResult("Customer is not found");

            return(Result.Combine(moneyToCharge, customer)
                   .OnSuccess(() => customer.value.AddBalance(moneyToCharge.value))
                   .OnSuccess(() => _paymentGateway.ChargePayment(customer.value.BillingInfo, moneyToCharge.value))
                   .OnSuccess(
                       () => _database.Save(customer.value)
                       .OnFailure(() => _paymentGateway.RollbackLastTransaction()))
                   .OnBoth(result => Log(result))
                   .OnBoth(result => result.isSuccues ? "OK" : result.Error));
        }
Ejemplo n.º 2
0
        public Atm Handle(WithdrawCommand request)
        {
            var atm = _atmRepository.GetById(request.AtmId);

            if (atm.Withdraw(request.Amount))
            {
                var charge = request.Amount + atm.CalculateCommision(request.Amount);

                _paymentGateway.ChargePayment(charge);

                _atmRepository.Save(atm);
            }

            return(atm);
        }
Ejemplo n.º 3
0
        private void TakeMoney(decimal amount)
        {
            var error = _atm.CanTake(amount);

            if (error != string.Empty)
            {
                MessageBox.Show(error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var amountWithComission = _atm.CalculateWithComission(amount);

            _paymentGateway.ChargePayment(amountWithComission);
            _atm.TakeMoney(amount);
            _atmRepository.Save(_atm);
            NotifyClient($"You have taken {amount.ToString("C2")}");
        }