public List <RixtyProduct> GetProducts() { try { using (var client = new HttpClient()) { var signature = RixtySignature.GenerateProductSignature(); var url = $"{ConfigurationManager.AppSettings["RixtyProductUrl"]}"; var request = new HttpRequestMessage(HttpMethod.Post, url); var keyValues = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("applicationCode", applicationCode), new KeyValuePair <string, string>("version", version), new KeyValuePair <string, string>("signature", signature) }; request.Content = new FormUrlEncodedContent(keyValues); var resp = client.SendAsync(request).Result; resp.EnsureSuccessStatusCode(); var resultJson = resp.Content.ReadAsStringAsync().Result; var result = JsonConvert.DeserializeObject <RixtyProductResponse>(resultJson); return(result.Products); } } catch (Exception ex) { throw new Exception($"ERRO AO CHAMAR API RIXTY PRODUCTS", ex); } }
public PurchaseInitiation GetPurchaseInitiation(string referenceId, string productCode, int quantity) { try { using (var client = new HttpClient()) { var signature = RixtySignature.GeneratePurchaseInitiationSignature(productCode, referenceId, quantity); var url = $"{ConfigurationManager.AppSettings["RixtyPurchaseInitiationUrl"]}"; var request = new HttpRequestMessage(HttpMethod.Post, url); var keyValues = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("applicationCode", applicationCode), new KeyValuePair <string, string>("version", version), new KeyValuePair <string, string>("referenceId", referenceId), new KeyValuePair <string, string>("productCode", productCode), new KeyValuePair <string, string>("quantity", quantity.ToString()), new KeyValuePair <string, string>("signature", signature) }; request.Content = new FormUrlEncodedContent(keyValues); var resp = client.SendAsync(request).Result; resp.EnsureSuccessStatusCode(); var resultJson = resp.Content.ReadAsStringAsync().Result; var result = JsonConvert.DeserializeObject <PurchaseInitiation>(resultJson); return(result); } } catch (Exception ex) { throw new Exception($"ERRO AO CHAMAR API RIXTY PURCHASE INITIATION", ex); } }