Exemplo n.º 1
0
        public void EfetuarPedido(Carrinho carrinho, DetalhePagamento detalhePagamento, bool notificarClienteEmail,
                                  bool notificarClienteSms)
        {
            if (VerificaDisponibilidade(carrinho))
            {
                CalculaImposto(carrinho);

                if (EfetuaPagamento(carrinho, detalhePagamento))
                {
                    TrataEstoque(carrinho);
                }
                else
                {
                    throw new ExternalException("O pagamento não foi efetuado.");
                }

                NotificadorEmail(carrinho, notificarClienteEmail);

                NotificadorSMS(carrinho, notificarClienteSms);
            }
            else
            {
                var produtosIndisponiveis = ProdutosIndisponiveis.Select(t => t.Descricao).ToList();

                var text = new StringBuilder();
                text.AppendLine("Esses produtos estão indisponíveis no momento: ");
                foreach (var desc in produtosIndisponiveis)
                {
                    text.Append(desc + "; ");
                }

                throw new ExternalException(text.ToString());
            }
        }
        public bool EfetuarPagamentoPedido(DetalhePagamento detalhePagamento, decimal valorTotalPedido)
        {
            try
            {
                switch (detalhePagamento.FormaPagamento)
                {
                case FormaPagamento.CartaoDebito:
                case FormaPagamento.CartaoCredito:

                    _gatewayPagamentoService.AtribuiInformacoesPagamento("login", "senha",
                                                                         detalhePagamento.NomeImpressoCartao, valorTotalPedido, detalhePagamento.MesExpiracao,
                                                                         detalhePagamento.AnoExpiracao, ObtemFormaPagamentoCartao(detalhePagamento.FormaPagamento));

                    _gatewayPagamentoService.EfetuarPagamento();

                    return(true);

                case FormaPagamento.Dinheiro: return(true);

                default: return(false);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 3
0
 public void Pagar(Carrinho carrinho, DetalhePagamento detalhePagamento)
 {
     try
     {
         //Efetuar pagamento com operadora do cartão
     }
     catch (AvsMismatchException ex)
     {
         throw new Exception("O Cartao foi rejeitado.", ex);
     }
 }
 public void Pagar(Carrinho carrinho, DetalhePagamento detalhePagamento)
 {
     try
     {
         GerarBoleto(carrinho, detalhePagamento);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
 public void GerarBoleto(Carrinho carrinho, DetalhePagamento detalhePagamento)
 {
     try
     {
         //Gerar Boleto para o o cliente
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Exemplo n.º 6
0
 public void Pagar(Carrinho carrinho, DetalhePagamento detalhePagamento)
 {
     try
     {
         if (ValidaCartao(detalhePagamento))
         {
             //Finaliza compra com operador contratada
         }
     }
     catch (AvsMismatchException ex)
     {
         throw new Exception("O Cartao foi rejeitado.", ex);
     };
 }
        public void EfetuarPedido(Carrinho carrinho, DetalhePagamento detalhePagamento, bool notificarClienteEmail,
                                  bool notificarClienteSms)
        {
            try
            {
                // Parte 1# - Calculo de imposto de produtos e valor total do carrinho.

                // Calcula imposto dos produtos do carrinho
                carrinho.Produtos = _carrinhoService.CalculaImpostoProdutosCarrinho(carrinho.Produtos);

                // Calcula o valor total do carrinho
                carrinho.ValorTotalPedido = _carrinhoService.CalculaValorTotalCarrinho(carrinho.Produtos);

                // Parte 2# - Pagamento do Pedido

                // Realiza o pagamento
                carrinho.FoiPago = _pagamentoService.EfetuarPagamentoPedido(detalhePagamento, carrinho.ValorTotalPedido);

                // Parte 3# - Solicitação e Entrega de Produto(s)
                if (!_carrinhoService.CarrinhoFoiPago(carrinho))
                {
                    throw new ExternalException("O pagamento não foi efetuado.");
                }

                _carrinhoService.SolicitarProdutosCarrinho(carrinho);

                carrinho.FoiEntregue = _carrinhoService.EntregarProdutosCarrinho(carrinho);

                // Parte 4# - Baixa no estoque
                if (!_estoqueService.ProdutosCarrinhoEntregue(carrinho))
                {
                    throw new ExternalException("Os produtos não foram entregues.");
                }

                _carrinhoService.BaixarEstoqueCarrinho(carrinho);

                // Parte 5# - Notificação de Cliente por e-mail
                _mailService.notificarClienteEmail(carrinho.Cliente, notificarClienteEmail);


                // Parte 5# - Notificação de Cliente por SMS
                _smsService.NotificarClienteSms(carrinho.Cliente, notificarClienteSms);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 8
0
        public ActionResult Get()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"http://{Ip}");
            request.Method = "GET";
            request.KeepAlive = true;
            request.ContentType = "application/x-www-form-urlencoded";

            HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();

            StreamReader reader = new StreamReader(webResponse.GetResponseStream());
            string responseBody = reader.ReadToEnd();
            reader.Close();

            DetalhePagamento serverInfo = JsonConvert.DeserializeObject<DetalhePagamento>(responseBody);
            return Ok(serverInfo);
        }
        public void TestaEfetuarPagamentoPedidoCartaoDinheiro()
        {
            decimal valorTotalPedido = 1000.00M;

            IGatewayPagamento gatewayPagamentoService = new GatewayPagamentoService();

            PagamentoService pagamentoService = new PagamentoService(gatewayPagamentoService);

            DetalhePagamento detalhePagamento = new DetalhePagamento
            {
                FormaPagamento     = FormaPagamento.Dinheiro,
                NumeroCartao       = "12453",
                MesExpiracao       = 4,
                AnoExpiracao       = 2022,
                NomeImpressoCartao = "ADRIAN"
            };

            Assert.IsTrue(pagamentoService.EfetuarPagamentoPedido(detalhePagamento, valorTotalPedido));
        }
Exemplo n.º 10
0
        private DetalhePagamento Cobrar(TicketModel ticketModel, UserDevice device)
        {
            if (ticketModel == null)
            {
                return(new DetalhePagamento
                {
                    Id = Guid.NewGuid(),
                    PagoComSucesso = true,
                    CartaoDeCreditoSalvo = new Entity.Pagamento.SavedCreditCard
                    {
                        CreditCardBrand = CreditCardBrand.Visa,
                        MaskedCreditCardNumber = "12345567890",
                        CreatedAt = DateTimeOffset.Now,
                        UserDevice = device,
                    }
                });
            }

            var dadosPagamento = ticketModel.DadosDeCobranca;

            var pagamentoService = new ParkAndGoBackend.MundipaggService.MundpaggPaymentService();
            var result           = pagamentoService.PayWithCreditCard(dadosPagamento);

            var result2 = new DetalhePagamento
            {
                Id                   = Guid.NewGuid(),
                PagoComSucesso       = result.PaymentBilledSuccessful,
                CartaoDeCreditoSalvo = new Entity.Pagamento.SavedCreditCard
                {
                    CreditCardBrand        = result.SavedCreditCard.CreditCardBrand,
                    MaskedCreditCardNumber = result.SavedCreditCard.MaskedCreditCardNumber,
                    CreatedAt  = DateTimeOffset.Now,
                    UserDevice = device,
                }
            };

            return(result2);
        }
Exemplo n.º 11
0
        private bool EfetuaPagamento(Carrinho carrinho, DetalhePagamento detalhePagamento)
        {
            if (detalhePagamento.FormaPagamento.Equals(FormaPagamento.Dinheiro))
            {
                carrinho.FoiPago = true;
                return(true);
            }

            using (var gatewayPatamento = new GatewayPagamentoService())
            {
                gatewayPatamento.Login = "******";
                gatewayPatamento.Senha = "senha";
                gatewayPatamento.FormaPagamentoCartao = (FormaPagamentoCartao)detalhePagamento.FormaPagamento;
                gatewayPatamento.NomeImpresso         = detalhePagamento.NomeImpressoCartao;
                gatewayPatamento.AnoExpiracao         = detalhePagamento.AnoExpiracao;
                gatewayPatamento.MesExpiracao         = detalhePagamento.MesExpiracao;
                gatewayPatamento.Valor = carrinho.ValorTotalPedido;

                gatewayPatamento.EfetuarPagamento();

                carrinho.FoiPago = true;
                return(true);
            }
        }
 public void GerarBoleto(Carrinho carrinho, DetalhePagamento detalhePagamento)
 {
     throw new NotImplementedException();
 }
 public void Pagar(Carrinho carrinho, DetalhePagamento detalhePagamento)
 {
     //BoletoService não implementa este método
     throw new NotImplementedException();
 }
 public bool ValidaCartao(DetalhePagamento detalhePagamento)
 {
     //BoletoService não implementa este método
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
        public void EfetuarPedido(Carrinho carrinho, DetalhePagamento detalhePagamento, bool notificarClienteEmail,
                                  bool notificarClienteSms)
        {
            foreach (var produto in carrinho.Produtos)
            {
                if (produto.TipoProduto == TipoProduto.Alimentos)
                {
                    produto.ValorImposto       = produto.Valor * 0.05M;
                    carrinho.ValorTotalPedido += (produto.Valor + produto.ValorImposto) * produto.Quantidade;
                }
                else
                {
                    if (produto.TipoProduto == TipoProduto.Eletronico)
                    {
                        produto.ValorImposto       = produto.Valor * 0.15M;
                        carrinho.ValorTotalPedido += (produto.Valor + produto.ValorImposto) * produto.Quantidade;
                    }
                    else
                    {
                        if (produto.TipoProduto == TipoProduto.Superfulos)
                        {
                            produto.ValorImposto       = produto.Valor * 0.20M;
                            carrinho.ValorTotalPedido += (produto.Valor + produto.ValorImposto) * produto.Quantidade;
                        }
                        else
                        {
                            throw new ArgumentException("O tipo de produto informado não está disponível.");
                        }
                    }
                }
            }

            if (detalhePagamento.FormaPagamento.Equals(FormaPagamento.CartaoCredito) ||
                detalhePagamento.FormaPagamento.Equals(FormaPagamento.CartaoDebito))
            {
                using (var gatewayPatamento = new GatewayPagamentoService())
                {
                    gatewayPatamento.Login = "******";
                    gatewayPatamento.Senha = "senha";
                    gatewayPatamento.FormaPagamentoCartao = (FormaPagamentoCartao)detalhePagamento.FormaPagamento;
                    gatewayPatamento.NomeImpresso         = detalhePagamento.NomeImpressoCartao;
                    gatewayPatamento.AnoExpiracao         = detalhePagamento.AnoExpiracao;
                    gatewayPatamento.MesExpiracao         = detalhePagamento.MesExpiracao;
                    gatewayPatamento.Valor = carrinho.ValorTotalPedido;

                    gatewayPatamento.EfetuarPagamento();
                }

                InformarPagamento(carrinho);
            }

            if (detalhePagamento.FormaPagamento.Equals(FormaPagamento.Dinheiro))
            {
                InformarPagamento(carrinho);
            }

            var estoque = new EstoqueService();

            if (carrinho.FoiPago)
            {
                foreach (var produto in carrinho.Produtos)
                {
                    estoque.SolicitarProduto(produto);
                }

                EntregarProdutos(carrinho);
            }
            else
            {
                throw new ExternalException("O pagamento não foi efetuado.");
            }

            if (carrinho.FoiEntregue)
            {
                foreach (var produto in carrinho.Produtos)
                {
                    estoque.BaixarEstoque(produto);
                }
            }
            else
            {
                throw new ExternalException("Os produtos não foram entregues.");
            }

            if (notificarClienteEmail)
            {
                if (!string.IsNullOrWhiteSpace(carrinho.Cliente.Email))
                {
                    using (var msg = new MailMessage("*****@*****.**", carrinho.Cliente.Email))
                        using (var smtp = new SmtpClient("servidor.smtp"))
                        {
                            msg.Subject = "Dados da sua compra";
                            msg.Body    = $"Obrigado por efetuar sua compra conosco.";

                            smtp.Send(msg);
                        }
                }
            }

            if (notificarClienteSms)
            {
                if (!string.IsNullOrWhiteSpace(carrinho.Cliente.Celular))
                {
                    var smsService = new SmsService();
                    smsService.Mensagem = "Obrigado por sua compra";
                    smsService.Celular  = carrinho.Cliente.Celular;
                    smsService.EnviarSms();
                }
            }
        }
Exemplo n.º 16
0
 public bool ValidaCartao(DetalhePagamento detalhePagamento)
 {
     return(Convert.ToInt32(detalhePagamento.AnoValidade) > Convert.ToInt32(DateTime.Now.Year));
 }
Exemplo n.º 17
0
        public void TestaEfetuarPedido()
        {
            try
            {
                bool notificarClienteEmail = false;
                bool notificarClienteSms   = true;

                IProdutoImposto produtoImpostoService = new ProdutoImpostoService();
                IEstoque        estoqueService        = new EstoqueService();

                ICarrinho carrinhoService = new CarrinhoService(produtoImpostoService, estoqueService);

                IGatewayPagamento gatewayPagamentoService = new GatewayPagamentoService();

                IPagamento pagamentoService = new PagamentoService(gatewayPagamentoService);

                IMail mailService = new MailService();

                ISms smsService = new SmsService();

                IPedido pedidoService = new PedidoService(carrinhoService, pagamentoService, estoqueService,
                                                          mailService, smsService);

                Cliente cliente = new Cliente
                {
                    Cpf     = "443",
                    Nome    = "ADRIAN",
                    Email   = "*****@*****.**",
                    Celular = "900000000"
                };

                Carrinho carrinho = new Carrinho
                {
                    Produtos         = new List <Produto>(),
                    Cliente          = cliente,
                    FoiEntregue      = false,
                    FoiPago          = false,
                    ValorTotalPedido = 0M
                };

                carrinho.Produtos.Add(new Produto
                {
                    Descricao    = "",
                    Valor        = 100M,
                    Quantidade   = 3,
                    ValorImposto = 0M,
                    TipoProduto  = TipoProduto.Alimentos
                });

                carrinho.Produtos.Add(new Produto
                {
                    Descricao    = "",
                    Valor        = 100M,
                    Quantidade   = 3,
                    ValorImposto = 0M,
                    TipoProduto  = TipoProduto.Eletronico
                });

                carrinho.Produtos.Add(new Produto
                {
                    Descricao    = "",
                    Valor        = 100M,
                    Quantidade   = 3,
                    ValorImposto = 0M,
                    TipoProduto  = TipoProduto.Superfulos
                });

                DetalhePagamento detalhePagamento = new DetalhePagamento
                {
                    FormaPagamento     = FormaPagamento.CartaoDebito,
                    NumeroCartao       = "12453",
                    MesExpiracao       = 4,
                    AnoExpiracao       = 2022,
                    NomeImpressoCartao = "ADRIAN"
                };

                pedidoService.EfetuarPedido(carrinho, detalhePagamento, notificarClienteEmail, notificarClienteSms);
            }
            catch (Exception ex)
            {
                Assert.Fail("Exceção não esperada: " + ex.Message);
            }
        }