Esempio n. 1
0
        public IHttpActionResult UpdatePagamento(string operation, string notification_type, string hash_codes)
        {
            /*
             * The payment status. The following statuses are available:
             *  OP: the customer has not yet filled the payment details on the EBANX Checkout. It can change either to CA (time out) or PE.
             *  PE: the payment is pending confirmation. It can change either to CA or CO.
             *  CO: the payment is confirmed (paid).
             *  CA: the payment is cancelled.
             */

            var hash_list = hash_codes.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);

            foreach (var hash in hash_list)
            {
                var pedido = _pedidoServico.PrimeiroPor(p => p.ListaHistorico.Any(lh => lh.StatusPedido == StatusPedido.AguardandoPagamento && lh.CodigoRetornoTransacao == hash));

                var consultaResponse = _apiTransacaoCartaoEbanx.Consulta(hash: hash);
                if (consultaResponse.payment.status.Equals("PE"))
                {
                    _pedidoServico.AtribuiStatus(pedido.Id, (int)StatusPedido.AguardandoConfirmacao, pedido.Usuario, consultaResponse.Message, consultaResponse.Code);
                }
                else if (consultaResponse.payment.status.Equals("CO"))
                {
                    _pedidoServico.AtribuiStatus(pedido.Id, (int)StatusPedido.PagamentoAprovado, pedido.Usuario, "Pagamento aprovado", consultaResponse.Code + "-" + consultaResponse.Message);
                    _pedidoServico.AtribuiStatus(pedido.Id, (int)StatusPedido.AguardandoAvaliacao, pedido.Usuario, "Sua avaliação é muito importante para nós");
                }
                else if (consultaResponse.payment.status.Equals("CA"))
                {
                    _pedidoServico.AtribuiStatus(pedido.Id, (int)StatusPedido.PagamentoNaoAprovado, pedido.Usuario, "Pagamento não aprovado", consultaResponse.Code + "-" + consultaResponse.Message);
                }
            }

            return(Ok());
        }
        public IHttpActionResult Consultar(string hash)
        {
            var pedido = pedidoServico.PrimeiroPor(p => p.ListaHistorico.Any(lh => lh.StatusPedido == StatusPedido.AguardandoPagamento && lh.CodigoRetornoTransacao == hash));

            if (pedido == null)
            {
                throw new BusinessRuleException("Pedido não encontrado.");
            }

            var response = _apiTransacaoEbanx.Consulta(hash);

            return(Ok(response));
        }