private static DtoChargeRequestMessage NovoRequestCriarBoletos(DtoChargeRequestMessage dtoChargeRequestMessage) { dtoChargeRequestMessage = new DtoChargeRequestMessage { token = dtoChargeRequestMessage.token, method = Constants.PaymentMethods.BANK_SLIP, customer_id = dtoChargeRequestMessage.customer_id, discount_cents = dtoChargeRequestMessage.discount_cents, items = dtoChargeRequestMessage.items, payer = new DtoPayerModel() { cpf_cnpj = dtoChargeRequestMessage.payer.cpf_cnpj, name = dtoChargeRequestMessage.payer.name, email = dtoChargeRequestMessage.payer.email, phone = dtoChargeRequestMessage.payer.phone, phone_prefix = dtoChargeRequestMessage.payer.phone_prefix, address = new DtoAddressModel() { zip_code = dtoChargeRequestMessage.payer.address.zip_code, district = dtoChargeRequestMessage.payer.address.district, state = dtoChargeRequestMessage.payer.address.state, street = dtoChargeRequestMessage.payer.address.street, number = dtoChargeRequestMessage.payer.address.number, city = dtoChargeRequestMessage.payer.address.city, country = dtoChargeRequestMessage.payer.address.country } } }; return(dtoChargeRequestMessage); }
/// <summary> /// Cria uma nova cobrança possibilitando envio do token customizado, geralmente de uma subconta, em maketplaces /// </summary> /// <param name="request">Parametros para criar uma cobrança</param> /// <param name="customApiToken">Token customizado/param> /// <returns>Uma cobrança do tipo boleto</returns> public async Task <DtoChargeResponseMessage> CreateAsync(DtoChargeRequestMessage request, string customApiToken) { var retorno = await PostAsync <DtoChargeResponseMessage>(request, null, customApiToken).ConfigureAwait(false); return(retorno); }
/// <summary> /// Cria uma nova cobrança /// </summary> /// <param name="request">Parametros para criar uma cobrança</param> /// <returns>Uma cobrança do tipo boleto</returns> public async Task <DtoChargeResponseMessage> CreateAsync(DtoChargeRequestMessage request) { return(await CreateAsync(request, null).ConfigureAwait(false)); }
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)); } }