public static void Main(string[] args) { string result = null; string payload = ""; var authProvider = new HmacAuthProvider(); var headers = authProvider.GenerateAuthHeaders(apiKey, secret, payload, url); var task = Task.Factory.StartNew(() => { using (var client = new HttpClient()) { System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //We can remove this line under the assumption that the Developer is running the latest framework foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } Console.WriteLine("Request: " + payload); HttpResponseMessage response = client.PostAsync(url, new StringContent(payload, Encoding.UTF8, "application/json")).Result; result = response.Content.ReadAsStringAsync().Result; } }); task.Wait(); Console.WriteLine("Response: " + result); }
public void WhenCtorWithAppSettings_ThenSecretReadFromAppSettings() { var appSettings = new Mock <IAppSettings>(); appSettings.Setup(settings => settings.GetString(It.IsAny <string>())) .Returns("asecret"); provider = new HmacAuthProvider(appSettings.Object); Assert.That(provider.Secret, Is.EqualTo("asecret")); }
public async void PostWithHmac(string resourcePath, string payload) { var authProvider = new HmacAuthProvider(); var headers = authProvider.GenerateAuthHeaders(_config[ConfigurationKeys.CLIENT_KEY], _config[ConfigurationKeys.CLIENT_SECRET], payload, _config[ConfigurationKeys.BASE_URL] + resourcePath); var client = new HttpClient(); foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } HttpResponseMessage response = await client.PostAsync(_config[ConfigurationKeys.BASE_URL] + resourcePath, new StringContent(payload, Encoding.UTF8, "application/json")); var result = response.Content.ReadAsStringAsync().Result; Assert.True(result.ToLower().Contains("success")); //Console.WriteLine("Response: " + result); }
private static string InvokeResource(string url) { string result = null; var authProvider = new HmacAuthProvider(); var headers = authProvider.GenerateAuthHeaders(apiKey, secret, string.Empty, url, "GET"); var task = Task.Factory.StartNew(() => { using (var client = new HttpClient()) { foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } result = client.GetStringAsync(url).Result; } }); task.Wait(); return(result); }
public static void Main(string[] args) { string result = null; string payload = "{\"payee_id\": \"OSKzWacFQ5mef07R\",\"payer_pymt_ref_id\": \"INVOICE1231\",\"payment_value\": \"892.91\",\"currency_code\": \"USD\",\"payment_due_date\": \"20160923\",\"payment_method\": \"CH\",\"check_payment\": { \"payer_account_id\": \"AB1v6pb1eagWUkt2\", \"check_no\": \"16556511\", \"check_date\": \"20160923\", \"check_memo\": \"Payment\", \"payee_name\": \"WALMART\", \"mail_deadline\": \"S\", \"check_delivery_details\": {\"delivery_indicator\": \"1000\", \"mail_vendor_method_code\": \"USPS FULL\", \"mail_vendor_account_no\": \"AT7676\" }, \"address\": [{\"id\": \"908908098\", \"type\": \"Check_Destination\", \"address_line_1\": \"3232 bell rd\", \"address_line_2\": \"SUITE 45334\", \"address_line_3\": null, \"address_line_4\": null, \"address_line_5\": null, \"city\": \"Phoenix\", \"region_code\": \"AZ\", \"region_name\": \"Arizona\", \"country_code\": \"US\", \"country_name\": \"USA\", \"zip_code\": \"85302\"}], \"company_affiliate\": {\"id\": \"CA357656\", \"type\": \"Contact\", \"title\": \"Executive\", \"salutation\": \"Mr\", \"first_name\": \"Michael\", \"middle_name\": null, \"last_name\": \"Johnson\", \"email_id\": \"[email protected]\", \"phones\": [{\"number\": \"5553490200\", \"extension\": \"40411\", \"type\": \"business\"}], \"fax_no\": \"5554344565\" }},\"attachments\": [ {\"id\": \"Invoice1.pdf\", \"file\": \"B9DQogICAgfQ0KfQ==\" }],\"invoices\": [ {\"id\": \"Payment1122\", \"date\": \"20160903\", \"due_date\": \"20160923\", \"payee_ref\": \"INVX00222\", \"payer_ref\": \"WORKORDER912\", \"paid_amount\": \"892.91\", \"gross_amount\": \"892.91\", \"net_value\": \"892.91\", \"tax_code\": \"3\", \"tax_value\": \"0.01\", \"freight_value\": \"0.01\", \"discount_value\": \"0.15\", \"adjustment_value\": \"0.11\", \"payer_field_1\": \"Michael\", \"payer_field_2\": null, \"payer_field_3\": null, \"payer_field_4\": null, \"short_pay_code\": \"T3\", \"short_pay_text\": \"forSOAP\", \"short_pay_value\": \"892.91\", \"additional_text\": \"for retail of SOAP\", \"line_items\": [{\"line_number\": \"121\", \"line_description\": \"for soap\", \"line_paid_value\": \"892.91\", \"purchase_order_item\": \"18\", \"part_number\": \"B200\", \"unit_price\": \"300\", \"quantity\": \"5\", \"unit_of_measure\": \"EA\", \"line_value\": \"1500\", \"purchase_order\": \"P6405\", \"tax_code\": \"3\", \"tax_jurisdiction\": \"State\", \"line_freight_value\": \"0.91\", \"line_discount_value\": \"0.18\", \"line_adjustment_value\": \"0.10\", \"payer_field_1\": \"Michael\", \"payer_field_2\": null, \"payer_field_3\": null, \"payer_field_4\": null, \"short_pay_code\": \"FE\", \"short_pay_text\": \"FreightExceedsPOMaximum\", \"short_pay_value\": \"140\"}] }],\"risk_management_details\": { \"user_id\": \"WAL232\", \"title\": \"Executive\", \"salutation\": \"Mr\", \"first_name\": \"James\", \"middle_name\": null, \"last_name\": \"Philip\", \"email_id\": \"[email protected]\", \"phones\": [{\"number\": \"5553490200\", \"extension\": \"404\", \"type\": \"business\"}], \"fax_no\": \"5554344565\", \"user_count\": 0, \"transaction_count\": 50, \"login_volume\": 10, \"user_tenure\": \"01/02/2015\", \"ip_address\": \"10.235.11.11\", \"device_id\": \"D23232323\", \"session_id\": \"NE625256\", \"submit_date\": \"01/02/2015 12:15:12\", \"user_agent\": {\"web_action_path\": \"Mozilla/5.0 (Windows NT 6.1; / 20100101 Firefox/ 12.0 \", \"browser_type\": \"Firefox\", \"browser_version\": \"12.0\" }, \"payer_agent_email_ids\": [{\"payer_agent_email_id\": \"[email protected]\"}]}}"; var authProvider = new HmacAuthProvider(); var headers = authProvider.GenerateAuthHeaders(apiKey, secret, payload, url); var task = Task.Factory.StartNew(() => { using (var client = new HttpClient()) { foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } HttpResponseMessage response = client.PostAsync(url, new StringContent(payload, Encoding.UTF8, "application/vnd.amex.ace.organization.v2.hal+json")).Result; result = response.Content.ReadAsStringAsync().Result; } }); task.Wait(); Console.WriteLine("Response: " + result); }
public static void Main(string[] args) { string result = null; string payload = "{\"merchant_client_id\":\"Test Merchant\",\"timestamp\":\"2015-10-16T00:40:00.715-07:00\",\"card\":{\"number\":\"375987654321001\"}}"; var authProvider = new HmacAuthProvider(); var headers = authProvider.GenerateAuthHeaders(apiKey, secret, payload, url); var task = Task.Factory.StartNew(() => { using (var client = new HttpClient()) { foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } HttpResponseMessage response = client.PostAsync(url, new StringContent(payload, Encoding.UTF8, "application/json")).Result; result = response.Content.ReadAsStringAsync().Result; } }); task.Wait(); Console.WriteLine("Response: " + result); }
public static void Main(string[] args) { string result = null; string payload = "{\"acknowledge_offer\": {\"offer_request_id\":\"1467840166684U75512110048uMjPR8z\", \"request_timestamp\": \"2012010516024\"}}"; var authProvider = new HmacAuthProvider(); var headers = authProvider.GenerateAuthHeaders(apiKey, secret, payload, url); var task = Task.Factory.StartNew(() => { using (var client = new HttpClient()) { foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } Console.WriteLine("Request: " + payload); HttpResponseMessage response = client.PostAsync(url, new StringContent(payload, Encoding.UTF8, "application/json")).Result; result = response.Content.ReadAsStringAsync().Result; } }); task.Wait(); Console.WriteLine("Response: " + result); }
public static void Main(string[] args) { string result = null; string payload = "{\"timestamp\":\"2013-12-13T11:10:00.715-05:00\",\"transaction_data\":{\"card_number\":\"375987654321001\",\"amount\":\"175.25\",\"timestamp\":\"2013-12-13T11:10:00.715-05:00\",\"currency_code\":\"840\",\"card_acceptor_id\":\"1030026553\",\"is_coupon_used\":\"false\",\"electronic_delivery_email\":\"[email protected]\",\"top5_items_in_cart\":\"00010002000300040005\",\"merchant_product_sku\":\"TKDC315U\",\"shipping_method\":\"02\",\"number_of_gift_cards_in_cart\":\"2\"},\"purchaser_information\":{\"customer_email\":\"[email protected]\",\"billing_address\":\"1234 Main Street\",\"billing_postal_code\":\"12345\",\"billing_first_name\":\"Test\",\"billing_last_name\":\"User\",\"billing_phone_number\":\"6028888888\",\"shipto_address\":\"1234 Main Street\",\"shipto_postal_code\":\"12345\",\"shipto_first_name\":\"Test\",\"shipto_last_name\":\"User\",\"shipto_phone_number\":\"6028888888\",\"shipto_country_code\":\"840\",\"latitude_of_customers_device\":\"38.897683\",\"longitude_of_customers_device\":\"-77.036497\",\"device_id\":\"123456789012345678901234567890123456\",\"device_type\":\"01\",\"device_timezone\":\"UTC-07:00\",\"device_ip\":\"10.0.0.0\",\"host_name\":\"PHX.QW.AOL.COM\",\"user_agent\":\"Mozilla\",\"customer_ani\":\"\",\"customer_II_digits\":\"11\"},\"registration_details\":{\"is_registered\":\"true\",\"registered_name\":\"John Smith\",\"registered_email\":\"[email protected]\",\"registered_postal_code\":\"123456\",\"registered_address\":\"4712 Good Road\",\"registered_phone\":\"6027777777\",\"count_of_shipto_addresses_on_file\":\"03\",\"registered_account_tenure\":\"720\"},\"registration_details_change_history\":{\"is_registration_updated\":\"1\",\"registered_name\":\"36500\",\"registered_email\":\"1\",\"registered_password\":\"0000036500\",\"registered_postal_code\":\"36500\",\"registered_address\":\"0000036500\",\"registered_phone\":\"0000036500\",\"shipto_address\":\"0000036500\",\"shipto_name\":\"0000036500\"},\"seller_information\":{\"latitude\":\"38.897683\",\"longitude\":\"-77.036497\",\"owner_name\":\"Iam Owner\",\"seller_id\":\"1234567890\",\"business_name\":\"TestITD\",\"tenure\":\"36\",\"transaction_type_indicator\":\"\",\"address\":\"123 Main Street\",\"phone\":\"6021111111\",\"email\":\"[email protected]\",\"postal_code\":\"45678\",\"region\":\"USA\",\"country_code\":\"840\"}}"; var authProvider = new HmacAuthProvider(); var headers = authProvider.GenerateAuthHeaders(apiKey, secret, payload, url); var task = Task.Factory.StartNew(() => { using (var client = new HttpClient()) { foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } Console.WriteLine("Request: " + payload); HttpResponseMessage response = client.PostAsync(url, new StringContent(payload, Encoding.UTF8, "application/json")).Result; result = response.Content.ReadAsStringAsync().Result; } }); task.Wait(); Console.WriteLine("Response: " + result); }
private static string InvokeResource(string url, string payload, HttpMethod method) { string result = null; string contentType = "application/vnd.amex.ace.organization.v2.hal+json"; var authProvider = new HmacAuthProvider(); var headers = authProvider.GenerateAuthHeaders(apiKey, secret, payload, url, method.ToString()); var task = Task.Factory.StartNew(() => { using (var client = new HttpClient()) { foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } HttpResponseMessage response; switch (method) { case HttpMethod.PUT: response = client.PutAsync(url, new StringContent(payload, Encoding.UTF8, contentType)).Result; break; case HttpMethod.DELETE: response = client.DeleteAsync(url).Result; break; default: response = client.PostAsync(url, new StringContent(payload, Encoding.UTF8, contentType)).Result; break; } result = string.Format("success = {0}, response = {1}", response.IsSuccessStatusCode, response.Content.ReadAsStringAsync().Result); } }); task.Wait(); return(result); }
public void Initialize() { provider = new HmacAuthProvider(); }