public async Task <Customer> GetCustomerByWebhook(WebHookEvent ev) { Customer customer = null; if (ev == null) { return(null); } var apiEndPoint = this.ApiWebHookEndPoint + ev.Resource; log.LogInformation("GetCustomerByWebhook HTTP " + apiEndPoint); using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", this.AuthInfo); var responseMessage = await httpClient.GetAsync(apiEndPoint); if (responseMessage.IsSuccessStatusCode) { var json = await responseMessage.Content.ReadAsStringAsync(); customer = JsonConvert.DeserializeObject <Customer>(json); } else { log.LogError("GetCustomerByWebhook HTTP error: " + responseMessage.StatusCode.ToString()); } } return(customer); }
public async Task <SalesOrder> GetOrderByWebhook(WebHookEvent ev) { SalesOrder orders = null; if (ev == null || ev.Value == null || ev.Value.Count == 0) { return(null); } if (!ev.Value[0].Resource.Contains("salesOrders")) { return(null); } var apiEndPoint = this.ApiWebHookEndPoint + ev.Value[0].Resource; using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", this.AuthInfo); var responseMessage = await httpClient.GetAsync(apiEndPoint); if (responseMessage.IsSuccessStatusCode) { orders = JsonConvert.DeserializeObject <SalesOrder>(await responseMessage.Content.ReadAsStringAsync()); } } return(orders); }
public async Task <SalesOrder> GetPayPalOrderByWebhook(WebHookEvent ev) { SalesOrder order = null; var apiEndPoint = this.ApiWebHookEndPoint + ev.Resource; log.LogInformation("GetPayPalOrderByWebhook with endpoint " + apiEndPoint); using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", this.AuthInfo); var responseMessage = await httpClient.GetAsync(apiEndPoint); if (responseMessage.IsSuccessStatusCode) { order = JsonConvert.DeserializeObject <SalesOrder>(await responseMessage.Content.ReadAsStringAsync()); //Only allow PAYPAL payments not yet paid and not being processed to be processed if (order != null) { order = (order.PaymentTermsId.ToString().Equals(config.paymentTermsIdPayPal) && order.ExternalDocumentNumber.Equals(String.Empty)) ? order : null; } } } return(order); }