Exemplo n.º 1
0
        /// <summary>
        /// Cria um cliente em uma conta especifica
        /// </summary>
        /// <param name="request"></param>
        /// <param name="customApiToken"></param>
        /// <returns></returns>
        public async Task <DtoCustomerModel> CreateAsync(DtoCustomerRequestMessage request, string customApiToken)
        {
            var retorno = await PostAsync <DtoCustomerModel>(request, null, customApiToken).ConfigureAwait(false);

            return(retorno);
        }
Exemplo n.º 2
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));
            }
        }