public async Task Handle(IThrowsException gatewayExceptionSimulator, Guid gatewayPaymentId)
        {
            var knownPayment = await _paymentsRepository.GetById(gatewayPaymentId);

            knownPayment.BankConnectionFails();

            await _paymentsRepository.Save(knownPayment, knownPayment.Version);
        }
        public async Task <ActionResult <PaymentDto> > GetPaymentInfo([FromRoute] Guid gateWayPaymentId)
        {
            // Etag can be added when the `PaymentDto` becomes to large
            // When `PaymentDto` not changed, send NotChanged back to client.
            //var etag = Request.GetTypedHeaders().IfNoneMatch?.FirstOrDefault();
            try
            {
                var payment = await _repository.GetById(gateWayPaymentId);

                return(payment.AsDto());
            }
            catch (AggregateNotFoundException)
            {
                return(NotFound(gateWayPaymentId));
            }
        }
        public async Task Handle(IThrowsException gatewayExceptionSimulator, Guid gatewayPaymentId)
        {
            Payment knownPayment  = null;
            var     bankPaymentId = _bankResponse.BankPaymentId;

            try
            {
                try
                {
                    knownPayment = await _paymentsRepository.GetById(gatewayPaymentId);

                    gatewayExceptionSimulator?.Throws();
                }
                catch (AggregateNotFoundException)
                {
                    return;
                }

                switch (_bankResponse.PaymentStatus)
                {
                case BankPaymentStatus.Accepted:
                    knownPayment.AcceptPayment(bankPaymentId);
                    break;

                case BankPaymentStatus.Rejected:
                    knownPayment.BankRejectPayment(bankPaymentId);
                    break;
                }

                await _paymentsRepository.Save(knownPayment, knownPayment.Version);
            }

            catch (Exception)
            {
                //TODO: log
                knownPayment.FailOnGateway(bankPaymentId);
                await _paymentsRepository.Save(knownPayment, knownPayment.Version);
            }
        }