Example #1
0
        private async Task <bool> ProcessarPagamento(Domain.Pedidos.Pedido pedido, AdicionarPedidoCommand message)
        {
            var pedidoIniciado = new PedidoIniciadoIntegrationEvent
            {
                PedidoId         = pedido.Id,
                ClienteId        = pedido.ClienteId,
                Valor            = pedido.ValorTotal,
                TipoPagamento    = 1, //fixo - cartão de crédito
                NomeCartao       = message.NomeCartao,
                NumeroCartao     = message.NumeroCartao,
                MesAnoVencimento = message.ExpiracaoCartao,
                CVV = message.CvvCartao
            };

            var result = await _bus.RequestAsync <PedidoIniciadoIntegrationEvent, ResponseMessage>(pedidoIniciado);

            if (result.ValidationResult.IsValid)
            {
                return(true);
            }

            foreach (var erro in result.ValidationResult.Errors)
            {
                AdicionarErro(erro.ErrorMessage);
            }

            return(false);
        }
        private async Task <ResponseMessage> AutorizarPagamento(PedidoIniciadoIntegrationEvent message)
        {
            using var scope = _serviceProvider.CreateScope();
            var pagamentoService = scope.ServiceProvider.GetRequiredService <IPagamentoService>();
            var pagamento        = new Pagamento
            {
                PedidoId      = message.PedidoId,
                TipoPagamento = (TipoPagamento)message.TipoPagamento,
                Valor         = message.Valor,
                CartaoCredito = new CartaoCredito(
                    message.NomeCartao, message.NumeroCartao, message.MesAnoVencimento, message.CVV)
            };

            var response = await pagamentoService.AutorizarPagamento(pagamento);

            return(response);
        }