Exemplo n.º 1
0
        public IActionResult Post([FromBody] RechargeCommand rechargeCommands)
        {
            RechargeViewModel rechargeViewModel = _tefService.RealizaTransacao(rechargeCommands);

            return(Ok(rechargeViewModel));
        }
Exemplo n.º 2
0
        public RechargeViewModel RealizaTransacao(RechargeCommand rechargeCommand)
        {
            bool endOfPayment = false;

            /* ******************* Continua Sitef Interativo Variaveis ******************* */
            int           Comando   = 0;
            int           TamBuffer = 0;
            int           Continua  = 0;
            int           TamMinimo = 0;
            int           TamMaximo = 0;
            int           TipoCampo = 0;
            StringBuilder Buffer    = new StringBuilder(20000); //buffer de 20k bytes
            /* *************************************************************************** */

            IniciafSitefInterativoModel sitefInterativo = new IniciafSitefInterativoModel(rechargeCommand.Valor, rechargeCommand.Operator, "123456", rechargeCommand.PaymentMode);

            try
            {
                CheckPinPad();

                value = CliSiTefMethods.IniciaFuncaoSiTefInterativo((int)sitefInterativo.PaymentMode, sitefInterativo.Valor, sitefInterativo.CupomFiscal, sitefInterativo.DataFiscal, sitefInterativo.HoraFiscal, sitefInterativo.Operador, null);

                if (value != CONTINUA)
                {
                    TefMessages.ValueErrors(value);
                }

                while (!endOfPayment)
                {
                    value = CliSiTefMethods.ContinuaFuncaoSiTefInterativo(ref Comando, ref TipoCampo, ref TamMinimo, ref TamMaximo, Buffer, TamBuffer, Continua);

                    if (value == CONTINUA)
                    {
                        ComandoTipoCampo(Comando, TipoCampo, ref Buffer, rechargeCommand.Id);

                        if (Comando == 0 && TipoCampo == 132 && string.IsNullOrEmpty(codBandeira))
                        {
                            Continua = -1;
                        }
                    }
                    else if (value == FINALIZA_TRANSACAO)
                    {
                        endOfPayment = true;
                    }
                    else
                    {
                        TefMessages.ValueErrors(value, Continua);
                    }
                }
            } catch (Exception e)
            {
                // Se foi lançada nenhuma exceção é porque ocorreu erro na transação
                CliSiTefMethods.FinalizaFuncaoSiTefInterativo(0, sitefInterativo.CupomFiscal, sitefInterativo.DataFiscal, sitefInterativo.HoraFiscal, null);

                throw e;
            }

            return(new RechargeViewModel()
            {
                CupomFiscal = sitefInterativo.CupomFiscal.ToString(),
                HoraFiscal = sitefInterativo.HoraFiscal.ToString(),
                DataFiscal = sitefInterativo.DataFiscal.ToString(),
                Bandeira = codBandeira
            });
        }