public static async Task <string> InsertInvoiceToIEAsync(HttpClient client, InvoiceProcessResource resource) { // Create the HTTP client to perform the request var jsonInvoices = new StringContent( JsonSerializer.Serialize(resource), Encoding.UTF8, "application/json"); string url = string.Format( MiddlewareRoutes.InvoicesPostRoute, Constants.MiddlewareUrlBase, Identity.Account, Identity.Subscription, MiddlewareRoutes.InvoicesUrlBase); var response = await client.PostAsync(url, jsonInvoices).ConfigureAwait(false); if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsStringAsync()); } else { throw new Exception(await response.Content.ReadAsStringAsync()); } }
public static async Task <List <MiddlewareResponse> > CreateBulkInvoiceMiddlewareAsync(AuthenticationProvider authenticationProvider, List <OrderResource> orders) { try { List <MiddlewareResponse> result = new List <MiddlewareResponse>(); // Create the HTTP client to perform the request using (HttpClient client = new HttpClient()) { await authenticationProvider.SetAccessTokenAsync(client); foreach (var order in orders) { InvoiceProcessResource resource = Mappers.ToInvoiceProcess(order); string res = await MiddlewareController.InsertInvoiceToIEAsync(client, resource); MiddlewareResponse r = JsonSerializer.Deserialize <MiddlewareResponse>(res); result.Add(r); } } return(result); } catch (Exception exception) { throw new Exception(exception.Message); } }
public static async Task <string> CreateInvoiceMiddlewareAsync(AuthenticationProvider authenticationProvider, OrderResource order) { try { // Converter objeto order para invoice InvoiceProcessResource resource = Mappers.ToInvoiceProcess(order); // Inserir invoice do IE return(await MiddlewareController.InsertInvoiceToIEAsync(authenticationProvider, resource).ConfigureAwait(false)); } catch (Exception exception) { throw new Exception(exception.Message); } }
public static InvoiceProcessResource ToInvoiceProcess(OrderResource order) { string clientKey = order.shipping.key; InvoiceProcessResource resource = new InvoiceProcessResource() { company = Constants.Identity.Company, note = order.key, customer = new Customer() { key = clientKey, name = order.shipping.name, address = new Address() { city = order.shipping.city, street = order.shipping.addressLine1, zipCode = order.shipping.postalzone, country = "PT" } }, items = new List <Resources.Middleware.Item>() }; foreach (var l in order.items) { resource.items.Add(new Resources.Middleware.Item() { quantity = l.quantity, item = l.key, description = l.title, unitPrice = l.price }); } return(resource); }