public void AddPayment_CorrectAttributes_Success(int _clientId, string _paymentId)
        {
            var testSessionToken = SessionRepository.StartNewSession(_clientId);

            DatabaseQueryProcessor.Erase();
            Shared.FillTheDatabase();

            var addPaymentCommand = new AddPaymentCommand
            {
                sessionToken = testSessionToken,
                paymentId    = _paymentId
            };

            var lastOrder = DatabaseQueryProcessor.GetTheMostRecentOrder(_clientId);
            var total     = DatabaseQueryProcessor.GetTotal(lastOrder.orderId);

            var isSuccessfulPayment = PaymentMethod.Check(_paymentId, total);
            var handler             = new AddPaymentCommandHandler();
            var result = (SuccessInfoDto)handler.Handle(addPaymentCommand);

            DatabaseQueryProcessor.Erase();

            SessionRepository.RemoveSession(testSessionToken);
            Assert.IsTrue(result.isSuccess);
            Assert.IsTrue(isSuccessfulPayment);
        }
        public async Task <AddPaymentCommandResult> Post([FromBody] AddPaymentCommand command)
        {
            if (ModelState.IsValid)
            {
                return(await _addPaymentCommandHandler.ExecuteAsync(command));
            }

            return(null);
        }
Exemplo n.º 3
0
        public async Task <Unit> Handle(AddPaymentCommand request, CancellationToken cancellationToken)
        {
            await PerformAsync(request, async creditCard =>
            {
                var subscription = await _subscriptionRepo.GetByIdAsync(creditCard.SubscriptionId);
                subscription.AddTransactionTo(creditCard, request.Payment, request.Occured);
            });

            return(Unit.Value);
        }
        public static AddPaymentCommand CreateValidCommand()
        {
            var command = new AddPaymentCommand()
            {
                Amount     = 20.22m,
                CreditCard = CreditCardValidatorTests.CreateValidCard(),
                Currency   = "USD"
            };

            return(command);
        }
Exemplo n.º 5
0
        public ActionResult CashierPaymentApprove(AddPaymentCommand command)
        {
            if (command == null)
            {
                return(RedirectToAction("CashierGetCreditAccounts"));
            }
            command.EmployeeId =
                _employeeService.GetEmployee(EmployeeQuery.WithUserId(int.Parse(User.Identity.GetUserId()))).Value.Id;
            _employeeService.AddPayment(command);
            var account = _creditAccountService.GetActualAccountStateDto(new ActualCreditAccountStateQuery()
            {
                Id = command.CreditAccountId
            });

            return(RedirectToAction("CashierGetCreditAccounts", "Employee",
                                    new { agreementNumber = account.Value.CreditAccount.CreditAgreementNumber }));
        }
        public void AddPayment_IncorrectClientId_Exception(int _clientId)
        {
            var testSessionToken = SessionRepository.StartNewSession(_clientId);

            var addPaymentCommand = new AddPaymentCommand
            {
                sessionToken = testSessionToken,
                paymentId    = "PAY-2RR93057JR3600055LQ5FWMA"
            };

            var          handler = new AddPaymentCommandHandler();
            TestDelegate result  = () => handler.Handle(addPaymentCommand);

            SessionRepository.RemoveSession(testSessionToken);

            Assert.Throws <Exception>(result);
        }
        public void AddPayment_ClientHasNoOrders_Success(int _clientId, string _paymentId)
        {
            var testSessionToken = SessionRepository.StartNewSession(_clientId);

            DatabaseQueryProcessor.Erase();
            Shared.FillTheDatabase();

            var addPaymentCommand = new AddPaymentCommand
            {
                sessionToken = testSessionToken,
                paymentId    = _paymentId
            };

            var          handler = new AddPaymentCommandHandler();
            TestDelegate result  = () => handler.Handle(addPaymentCommand);

            SessionRepository.RemoveSession(testSessionToken);

            Assert.Throws <Exception>(result);
        }
Exemplo n.º 8
0
        public async Task <CommandResult> AddPaymentAsync(AddPaymentCommand command)
        {
            var rightsRes = await CheckEmployeeRightsAsync(command.EmployeeId, EmployeeRights.Cashier);

            var employeeRes = await GetEmployeeAsync(command.EmployeeId);

            var accountRes = await GetCreditAccountAsync(command.CreditAccountId);

            var res = CheckPayment(rightsRes, employeeRes, accountRes, command.PaymentSum);

            if (res.IsFailed)
            {
                return(new CommandResult(command, false).From(res));
            }
            var payment = new CreditPaymentDto
            {
                Timestamp     = DateTime.Now,
                PaymentSum    = command.PaymentSum,
                CreditAccount = accountRes.Value,
                Employee      = employeeRes.Value
            };
            var paymentRes = await _creditPaymentService.CreateModelAsync(payment);

            if (paymentRes.IsFailed)
            {
                return(new CommandResult(command, false).From(paymentRes));
            }
            var action = new PaymentActionDto
            {
                Timestamp     = DateTime.Now,
                Employee      = employeeRes.Value,
                CreditPayment = payment,
                ActionType    = GetActionType(command.GetType().Name)
            };

            action.Signature = GetPaymentSignature(action);
            await _paymentActionService.CreateModelAsync(action);

            return(new CommandResult(command, true));
        }
        public Task <int> StartPaymentAsync(int merchantId, AddPaymentCommand command)
        {
            // threadsafe id increment because the repository is singleton scope
            var paymentId = Interlocked.Increment(ref _currentId);

            var payment = new PaymentDetails()
            {
                PaymentId = paymentId,
                Amount    = command.Amount,
                Currency  = command.Currency,
                MaskedCreditCardNumber = CreditCardNumberFormatter.Mask(command.CreditCard.CardNumber),
                MerchantId             = merchantId,
                RequestedDate          = DateTime.UtcNow,
                Status = PaymentStatus.Started
            };

            _payments.Add(paymentId, payment);

            _logger.LogDebug("Started payment successfully for merchant {MerchantId}. PaymentId: {PaymentId}", merchantId, paymentId);

            return(Task.FromResult(paymentId));
        }