예제 #1
0
        public static string Serialize <T>(this T source)
        {
            if (source == null)
            {
                return(string.Empty);
            }

            try
            {
                return(Json.Encode(source));
            }
            catch (Exception e)
            {
                SaeIuguApiStatus.Log("Falha ao Serializar texto. Ver mais detalhes no log de erros.");
                SaeIuguApiStatus.SetNovoException(e);
                return(string.Empty);
            }
        }
예제 #2
0
        public void Execute(int codigoEscola, int unidadeFisica, int idUsuario)
        {
            // notification=ca1cab92-66df-4b38-a7de-30b981d1df41

            string requestResult = this.Request.Content.ReadAsStringAsync().Result;

            SaeIuguApiStatus.Log(requestResult);

            try
            {
                var dtoRequestNotification = new DtoRequestNotification()
                {
                    codigo_escola = codigoEscola
                };

                //TODO AQUI PROVAVELMENTE TEM QUE FICAR CONSULTANDO A API DO IUGU (VER GATILHOS)
                //QUANDO ATUALIZAR BOLETO, EXECUTA BaixarOuCancelarBoleto

                //var clientToken = mhundAsApi.GetClientToken(dtoRequestNotification);

                if (Utils.StatusTransacaoRelevante(/*response.data.LastOrDefault().status.current)*/ ""))
                {
                    var dtoRequestNotificacao = new DtoRequestNotification()
                    {
                        codigo_escola  = codigoEscola,
                        unidade_fisica = unidadeFisica,
                        id_usuario     = idUsuario,
                        //data = response.data.LastOrDefault()
                    };

                    new MhundAsApi().BaixarOuCancelarBoleto(dtoRequestNotificacao);
                }
            }
            catch (GnException e)
            {
                SaeIuguApiStatus.SetNovoException(e);
            }
            catch (Exception e)
            {
                SaeIuguApiStatus.SetNovoException(e);
            }
        }
예제 #3
0
        public async Task <JsonResult <DtoChargeResponseMessage> > ExecuteAsync(DtoChargeRequestMessage dtoChargeRequestMessage)
        {
            try
            {
                DtoCustomerModel dtoCustomerModel;

                if (string.IsNullOrEmpty(dtoChargeRequestMessage.customer_id))
                {
                    //var customVariables = new List<CustomVariables>
                    //{
                    //    new CustomVariables {name = "Tipo", value = "Pizzaria"},
                    //    new CustomVariables {name = "Gerente", value = "Fernando Chilvarguer"}
                    //};

                    var customer = new DtoCustomerRequestMessage
                    {
                        email    = dtoChargeRequestMessage.payer.email,
                        name     = dtoChargeRequestMessage.payer.name,
                        cpf_cnpj = dtoChargeRequestMessage.payer.cpf_cnpj,
                        //notes = dtoChargeRequestMessage.notes,
                        //custom_variables = customVariables,
                    };

                    using (var apiCustomer = new Customer())
                    {
                        /*"ccf9fdba30425bd85516114e976b53b0"*/
                        dtoCustomerModel = await apiCustomer.CreateAsync(customer, dtoChargeRequestMessage.token).ConfigureAwait(false);
                    };

                    dtoChargeRequestMessage.customer_id = dtoCustomerModel.id;
                }
                //else
                //{
                //    using (var apiClient = new Customer())
                //    {
                //        dtoCustomerModel = await apiClient.GetAsync(Guid.NewGuid().ToString()).ConfigureAwait(false);
                //    };
                //}

                dtoChargeRequestMessage = NovoRequestCriarBoletos(dtoChargeRequestMessage);

                DtoChargeResponseMessage chargeTokenResponse;

                using (var apiCharge = new Charge())
                {
                    chargeTokenResponse = await apiCharge.CreateAsync(dtoChargeRequestMessage).ConfigureAwait(false);
                }

                return(Json(chargeTokenResponse));
            }
            catch (GnException e)
            {
                SaeIuguApiStatus.SetNovoException(e);
                var dtoResponseBoletos = new DtoChargeResponseMessage()
                {
                    success = false,
                    message = ApiResponseHelper.GetApiResponseMessage(e.Code, e.Message, false),
                    errors  = new Dictionary <string, object>()
                    {
                        { "exception", new DtoExceptionMessage()
                          {
                              property = e.Code.ToString(),
                              message  = e.ErrorType
                          } }
                    }
                };

                return(Json(dtoResponseBoletos));
            }
            catch (Exception e)
            {
                SaeIuguApiStatus.SetNovoException(e);
                var dtoChargeResponseMessage = new DtoChargeResponseMessage()
                {
                    success = false,
                    message = e.Message,
                    errors  = new Dictionary <string, object>()
                    {
                        { "exception", new DtoExceptionMessage()
                          {
                              property = "exception",
                              message  = e.Message
                          } }
                    }
                };

                return(Json(dtoChargeResponseMessage));
            }
        }