public async Task Create_a_valid_charge_of_type_bank_slip() { // Arrange var chargeRequest = new ChargeRequestMessage { Method = Constants.PaymentMethod.BANK_SLIP, CustomerId = "31F26DC9D613403B837B678335B2CCB0", Email = "*****@*****.**", InvoiceItems = new InvoiceItem[] { new InvoiceItem { Description = "Mensalidade", PriceCents = 100000, Quantity = 1 } }, PayerCustomer = PayerModelDataBuilder.CreateValid() }; ChargeResponseMessage chargeTokenResponse; // Act using (var apiClient = new Charge()) { chargeTokenResponse = await apiClient.CreateAsync(chargeRequest).ConfigureAwait(false); } // Assert Assert.That(chargeTokenResponse.Success, Is.True); Assert.That(chargeTokenResponse.Url, Is.Not.Empty); }
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)); } }