/// <summary> /// Requests a new device key from Humm using the (initialisation) device token created in the Humm Seller (merchant) portal. /// </summary> /// <param name="request">A <see cref="CreateKeyRequest" /> instance containing details of the request to make.</param> /// <returns> /// <para>A <see cref="CreateKeyResponse" /> instance containing the Humm response.</para> /// <para>See the Humm documentation at https://docs.shophumm.com.au/pos/api/create_key/ </para> /// </returns> /// <remarks> /// If the <see cref="CreateKeyRequest.AutoUpdateClientToken" /> argument is true and the request is successsful, the client will automatically call <see cref="SetDeviceKey(string)" /> with the value of <see cref="CreateKeyResponse.Key" /> for you, ensuring all future calls made with this client instance use the new token. /// </remarks> /// <seealso cref="CreateKeyRequest" /> /// <seealso cref="CreateKeyResponse" /> /// <seealso cref="SetDeviceKey(string)" /> /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="request"/>, <see cref="CreateKeyRequest.DeviceToken"/> or <see cref="CreateKeyRequest.PosVendor"/> is null.</exception> /// <exception cref="System.ArgumentException">Thrown if <see cref="CreateKeyRequest.DeviceToken"/> or <see cref="CreateKeyRequest.PosVendor"/> is an empty string or contain only whitespace characters.</exception> /// <exception cref="System.ObjectDisposedException">Thrown if this instance has been disposed.</exception> /// <exception cref="HummResponseSignatureException">Thrown if the response signature cannot be validated.</exception> /// <exception cref="System.Net.Http.HttpRequestException">Thrown if an HTTP protocol level or <see cref="System.Net.Http.HttpClient"/> pipeline error occurs.</exception> public async Task <CreateKeyResponse> CreateKeyAsync(CreateKeyRequest request) { if (_IsDisposed) { throw new ObjectDisposedException(nameof(HummClient)); } request.GuardNull(nameof(request)); request.FillFromConfig(_Config); if (_Config.AutoValidateRequests) { request.Validate(); } #pragma warning disable CS8604 // Possible null reference argument. using (var sigGen = new Hmac256SignatureGenerator(request.DeviceToken)) #pragma warning restore CS8604 // Possible null reference argument. using (var writer = new SignedRequestWriter(sigGen)) { var response = await SendRequest <CreateKeyRequest, CreateKeyResponse>(RelativePath_CreateKey, request, writer, sigGen).ConfigureAwait(false); if (request.AutoUpdateClientToken && !String.IsNullOrEmpty(response.Key) && response.Status == RequestStates.Success) { SetDeviceKey(response.Key); } return(response); } }
public void Creates_Expected_Signature_For_Sample_Invite_Request() { //The original signature for this request as shown in the API documentation is 9acbc32115e19c3135738bbef891c864ef734e2f66c3c3d3aeb5e0b1982db5f4 //however that is not the signature generated by the algorithm and key provided. Even using the sample C# code from the Humm API documentation //doesn't generate that signature, but does generate the same signature as the one actually tested here. I suspect the samples were generated //with a different key than the sample docs generate. I wasn't able to get Humm to understand/answer or change the docs. For now, testing using the //key that I expect is the right one, since it was confirmed with the Humm sample code and actual calls to the API seem to work. var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); var values = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_merchant_id", "30299999"), new KeyValuePair <string, object>("x_device_id", "d555"), new KeyValuePair <string, object>("x_operator_id", "test_operator"), new KeyValuePair <string, object>("x_firmware_version", "123"), new KeyValuePair <string, object>("x_mobile", "0400000000"), new KeyValuePair <string, object>("x_purchase_amount", 100M), new KeyValuePair <string, object>("signature", "e8045e8fdd521d9da2b4cd0c00f816680e9ec4d85bddab95c839d91f170f9deb") }; var signature = generator.GenerateSignature(values); Assert.AreEqual("e8045e8fdd521d9da2b4cd0c00f816680e9ec4d85bddab95c839d91f170f9deb", signature); }
public void Writes_Expected_ProcessSalesAdjustment_Request_With_Signature() { var sigGen = new Hmac256SignatureGenerator("dy33vQhksVsv"); var writer = new SignedRequestWriter(sigGen); var request = new ProcessSalesAdjustmentRequest() { MerchantId = "30299999", DeviceId = "d555", OperatorId = "test_operator", PosVersion = "123", ClientTransactionReference = "tnx-ref1", PurchaseReference = "123456789", Amount = 10 }; var result = writer.WriteRequest(request); //Note: The signature expected here is different to the one shown in the Humm sample page (https://docs.shophumm.com.au/pos/api_information/http_examples/). //The sample C# code provided by Humm at (https://docs.shophumm.com.au/pos/security/signature_generation/) generates the same code used here //and this signature gen works with the API endpoints, so it would appear the sample was updated using a different key or something, and the //sample signature is now incorrect. Assert.AreEqual("{\"x_pos_transaction_ref\":\"tnx-ref1\",\"x_purchase_ref\":\"123456789\",\"x_amount\":1000,\"x_merchant_id\":\"30299999\",\"x_device_id\":\"d555\",\"x_firmware_version\":\"123\",\"x_operator_id\":\"test_operator\",\"signature\":\"77d67d8dbae3aa2b403adc65c4e957af6dd918e62276a1cae0fadac743433f3b\"}", result); Assert.IsTrue(result.Contains("ce20e2f1a9fe0d92b3d021ba7f1b372b006778cfab5fc4c09efa60a6d910c471")); }
public void Creates_Expected_Signature_For_Sample_ProcessSalesAdjustmentReversal_Request() { //The original signature for this request as shown in the API documentation is 1949a14cfdd8e6062a54f28ab3a607637f081afb7b8f4cffa3fb413fadab963b //however that is not the signature generated by the algorithm and key provided. Even using the sample C# code from the Humm API documentation //doesn't generate that signature, but does generate the same signature as the one actually tested here. I suspect the samples were generated //with a different key than the sample docs generate. I wasn't able to get Humm to understand/answer or change the docs. For now, testing using the //key that I expect is the right one, since it was confirmed with the Humm sample code and actual calls to the API seem to work. var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); var values = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_pos_transaction_ref", "tnx-rev1"), new KeyValuePair <string, object>("x_adjustment_signature", "ce20e2f1a9fe0d92b3d021ba7f1b372b006778cfab5fc4c09efa60a6d910c471"), new KeyValuePair <string, object>("x_merchant_id", "30299999"), new KeyValuePair <string, object>("x_device_id", "d555"), new KeyValuePair <string, object>("x_operator_id", "test_operator"), new KeyValuePair <string, object>("x_firmware_version", "123"), new KeyValuePair <string, object>("signature", "83a8f5b53cbd205474cd8c993f911b465d25a381d3fc09c781fefb9bef18859d") }; var signature = generator.GenerateSignature(values); Assert.AreEqual("83a8f5b53cbd205474cd8c993f911b465d25a381d3fc09c781fefb9bef18859d", signature); }
public void Throws_On_Null_Request() { var sigGen = new Hmac256SignatureGenerator("dy33vQhksVsv"); var writer = new SignedRequestWriter(sigGen); _ = writer.WriteRequest <CreateKeyRequest>(null); }
public void Creates_Expected_Signature_For_Sample_ProcessSalesAdjustment_Request() { //The original signature for this request as shown in the API documentation is ce20e2f1a9fe0d92b3d021ba7f1b372b006778cfab5fc4c09efa60a6d910c471 //however that is not the signature generated by the algorithm and key provided. Even using the sample C# code from the Humm API documentation //doesn't generate that signature, but does generate the same signature as the one actually tested here. I suspect the samples were generated //with a different key than the sample docs generate. I wasn't able to get Humm to understand/answer or change the docs. For now, testing using the //key that I expect is the right one, since it was confirmed with the Humm sample code and actual calls to the API seem to work. var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); var signature = generator.GenerateSignature ( new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_pos_transaction_ref", "tnx-ref1"), new KeyValuePair <string, object>("x_purchase_ref", "123456789"), new KeyValuePair <string, object>("x_merchant_id", "30299999"), new KeyValuePair <string, object>("x_amount", 10M), new KeyValuePair <string, object>("x_device_id", "d555"), new KeyValuePair <string, object>("x_operator_id", "test_operator"), new KeyValuePair <string, object>("x_firmware_version", "123"), new KeyValuePair <string, object>("signature", "77d67d8dbae3aa2b403adc65c4e957af6dd918e62276a1cae0fadac743433f3b") } ); Assert.AreEqual("77d67d8dbae3aa2b403adc65c4e957af6dd918e62276a1cae0fadac743433f3b", signature); }
public void Writes_Expected_ProcessAuthorisation_Request_With_Signature() { var sigGen = new Hmac256SignatureGenerator("dy33vQhksVsv"); var writer = new SignedRequestWriter(sigGen); var request = new ProcessAuthorisationRequest() { MerchantId = "30299999", DeviceId = "d555", OperatorId = "test_operator", PosVersion = "123", ClientTransactionReference = "tnx-ref1", PreapprovalCode = "6111NHQMAM4Z", FinanceAmount = 100, PurchaseAmount = 500, PurchaseItems = new PurchaseItemsCollection ( new string[] { "Item1", "Item2" } ) }; var result = writer.WriteRequest(request); Assert.AreEqual("{\"x_pos_transaction_ref\":\"tnx-ref1\",\"x_pre_approval_code\":\"6111NHQMAM4Z\",\"x_finance_amount\":10000,\"x_purchase_amount\":50000,\"purchase_items\":\"{\\\"PurchaseItems\\\":[\\\"Item1\\\",\\\"Item2\\\"]}\",\"buyer_confirms\":false,\"x_merchant_id\":\"30299999\",\"x_device_id\":\"d555\",\"x_firmware_version\":\"123\",\"x_operator_id\":\"test_operator\",\"signature\":\"d6967970b99e585fc7d1a11702690f25b4be0c5fbfd10b39fbea3953ba48bad2\"}", result); Assert.IsTrue(result.Contains("d6967970b99e585fc7d1a11702690f25b4be0c5fbfd10b39fbea3953ba48bad2")); }
public void Disposes_Multiple_Times_Without_Error() { var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); generator.Dispose(); generator.Dispose(); }
public void GenerateSignature_Returns_Empty_If_No_Properties() { var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); var sig = generator.GenerateSignature(new Dictionary <string, object>(0)); Assert.AreEqual(string.Empty, sig); }
public void Can_Dispose_Mutiple_Times_Without_Exception() { var sigGen = new Hmac256SignatureGenerator("dy33vQhksVsv"); var writer = new SignedRequestWriter(sigGen); writer.Dispose(); writer.Dispose(); writer.Dispose(); writer.Dispose(); }
public void GenerateSignature_Throws_If_Properties_Null() { var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); try { generator.GenerateSignature(null); } finally { generator.Dispose(); } }
public void Throws_On_Null_OutputStream() { var sigGen = new Hmac256SignatureGenerator("dy33vQhksVsv"); var writer = new SignedRequestWriter(sigGen); var request = new ProcessSalesAdjustmentReversalRequest() { MerchantId = "30299999", DeviceId = "d555", OperatorId = "test_operator", PosVersion = "123", ClientTransactionReference = "tnx-rev1", AdjustmentSignature = "ce20e2f1a9fe0d92b3d021ba7f1b372b006778cfab5fc4c09efa60a6d910c471" }; writer.WriteRequest(request, null); }
public void Creates_Expected_Signature_For_Sample_ProcessAuthorisation_Response() { var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); var signature = generator.GenerateSignature ( new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_status", "Success"), new KeyValuePair <string, object>("x_code", "SPRA01"), new KeyValuePair <string, object>("x_message", "Approved"), new KeyValuePair <string, object>("signature", "07fa5c9b43520bb9417d7eadb8390a87bf7a42767a67bd5af95627b51c2d8bae"), new KeyValuePair <string, object>("tracking_data", null) } ); Assert.AreEqual("07fa5c9b43520bb9417d7eadb8390a87bf7a42767a67bd5af95627b51c2d8bae", signature); }
public void Creates_Expected_Signature_For_Sample_SendReceipt_Response() { var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); var signature = generator.GenerateSignature ( new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_status", "Success"), new KeyValuePair <string, object>("x_code", "SSER01"), new KeyValuePair <string, object>("x_message", "Success"), new KeyValuePair <string, object>("signature", "b55c8cbe59305d3d8abc6ea8f0cdcf4702059d6d2fa935c83595e56e7001157b"), new KeyValuePair <string, object>("tracking_data", null) } ); Assert.AreEqual("b55c8cbe59305d3d8abc6ea8f0cdcf4702059d6d2fa935c83595e56e7001157b", signature); }
public void Creates_Expected_Signature_For_Sample_CreateKey_Request() { var generator = new Hmac256SignatureGenerator("nb4i6ldxuVQC"); var signature = generator.GenerateSignature ( new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_merchant_id", "30299999"), new KeyValuePair <string, object>("x_device_id", "d555"), new KeyValuePair <string, object>("x_operator_id", "test_operator"), new KeyValuePair <string, object>("x_firmware_version", "123"), new KeyValuePair <string, object>("x_device_token", "nb4i6ldxuVQC"), new KeyValuePair <string, object>("x_pos_vendor", "Pos Provider"), } ); Assert.AreEqual("cf4f4a19662c7617ea83a47456934123f530c82cdfdd66f5b706dd2263806848", signature); }
public void Throws_If_Called_When_Disposed() { var generator = new Hmac256SignatureGenerator("nb4i6ldxuVQC"); generator.Dispose(); _ = generator.GenerateSignature ( new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_merchant_id", "30299999"), new KeyValuePair <string, object>("x_device_id", "d555"), new KeyValuePair <string, object>("x_operator_id", "test_operator"), new KeyValuePair <string, object>("x_firmware_version", "123"), new KeyValuePair <string, object>("x_device_token", "nb4i6ldxuVQC"), new KeyValuePair <string, object>("x_pos_vendor", "Pos Provider"), } ); }
public void Creates_Expected_Signature_For_Sample_CreateKey_Response() { var generator = new Hmac256SignatureGenerator("nb4i6ldxuVQC"); var signature = generator.GenerateSignature ( new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_key", "dy33vQhksVsv"), new KeyValuePair <string, object>("x_status", "Success"), new KeyValuePair <string, object>("x_code", "SCRK01"), new KeyValuePair <string, object>("x_message", "Success"), new KeyValuePair <string, object>("signature", "c8340d19b24f8ec2fb915202ea7fb08d81fc711681fbfea297106d219a5c30a6"), new KeyValuePair <string, object>("tracking_data", null) } ); Assert.AreEqual("c8340d19b24f8ec2fb915202ea7fb08d81fc711681fbfea297106d219a5c30a6", signature); }
public void Writes_Expected_CreateKey_Request_With_Signature() { var sigGen = new Hmac256SignatureGenerator("nb4i6ldxuVQC"); var writer = new SignedRequestWriter(sigGen); var request = new CreateKeyRequest() { MerchantId = "30299999", DeviceId = "d555", DeviceToken = "nb4i6ldxuVQC", OperatorId = "test_operator", PosVersion = "123", PosVendor = "Pos Provider" }; var result = writer.WriteRequest(request); Assert.AreEqual("{\"x_device_token\":\"nb4i6ldxuVQC\",\"x_pos_vendor\":\"Pos Provider\",\"x_merchant_id\":\"30299999\",\"x_device_id\":\"d555\",\"x_firmware_version\":\"123\",\"x_operator_id\":\"test_operator\",\"signature\":\"cf4f4a19662c7617ea83a47456934123f530c82cdfdd66f5b706dd2263806848\"}", result); Assert.IsTrue(result.Contains("cf4f4a19662c7617ea83a47456934123f530c82cdfdd66f5b706dd2263806848")); }
public void Writes_Full_Request_When_Passed_Base_Type() { var sigGen = new Hmac256SignatureGenerator("dy33vQhksVsv"); var writer = new SignedRequestWriter(sigGen); RequestBase request = new InviteRequest() { MerchantId = "30299999", DeviceId = "d555", OperatorId = "test_operator", PosVersion = "123", MobileNumber = "0400000000", PurchaseAmount = 100M }; var result = writer.WriteRequest(request); Assert.AreEqual("{\"x_mobile\":\"0400000000\",\"x_purchase_amount\":10000,\"x_merchant_id\":\"30299999\",\"x_device_id\":\"d555\",\"x_firmware_version\":\"123\",\"x_operator_id\":\"test_operator\",\"signature\":\"e8045e8fdd521d9da2b4cd0c00f816680e9ec4d85bddab95c839d91f170f9deb\"}", result); Assert.IsTrue(result.Contains("e8045e8fdd521d9da2b4cd0c00f816680e9ec4d85bddab95c839d91f170f9deb")); }
public void Creates_Expected_Signature_For_Sample_SendReceipt_Request() { var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); var signature = generator.GenerateSignature ( new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_merchant_id", "30299999"), new KeyValuePair <string, object>("x_device_id", "d555"), new KeyValuePair <string, object>("x_operator_id", "test_operator"), new KeyValuePair <string, object>("x_firmware_version", "123"), new KeyValuePair <string, object>("x_pos_transaction_ref", "tnx-ref1"), new KeyValuePair <string, object>("x_receipt_number", "NewReceipt"), new KeyValuePair <string, object>("signature", "ac164e40585474838641bde1ad9bab08b6e6e0ab0c2dae814298e4fcef9c52fa") } ); Assert.AreEqual("ac164e40585474838641bde1ad9bab08b6e6e0ab0c2dae814298e4fcef9c52fa", signature); }
public void Can_Write_Multiple_Requests_With_Signature() { var sigGen = new Hmac256SignatureGenerator("dy33vQhksVsv"); var writer = new SignedRequestWriter(sigGen); var request = new InviteRequest() { MerchantId = "30299999", DeviceId = "d555", OperatorId = "test_operator", PosVersion = "123", MobileNumber = "0400000000", PurchaseAmount = 100M }; var result = writer.WriteRequest(request); //Note: The signature expected here is different to the one shown in the Humm sample page (https://docs.shophumm.com.au/pos/api_information/http_examples/). //The sample C# code provided by Humm at (https://docs.shophumm.com.au/pos/security/signature_generation/) generates the same code used here //and this signature gen works with the API endpoints, so it would appear the sample was updated using a different key or something, and the //sample signature is now incorrect. Assert.AreEqual("{\"x_mobile\":\"0400000000\",\"x_purchase_amount\":10000,\"x_merchant_id\":\"30299999\",\"x_device_id\":\"d555\",\"x_firmware_version\":\"123\",\"x_operator_id\":\"test_operator\",\"signature\":\"e8045e8fdd521d9da2b4cd0c00f816680e9ec4d85bddab95c839d91f170f9deb\"}", result); Assert.IsTrue(result.Contains("e8045e8fdd521d9da2b4cd0c00f816680e9ec4d85bddab95c839d91f170f9deb")); request = new InviteRequest() { MerchantId = "30299999", DeviceId = "d555", OperatorId = "test_operator", PosVersion = "123", MobileNumber = "0410000000", PurchaseAmount = 10M }; result = writer.WriteRequest(request); Assert.AreEqual("{\"x_mobile\":\"0410000000\",\"x_purchase_amount\":1000,\"x_merchant_id\":\"30299999\",\"x_device_id\":\"d555\",\"x_firmware_version\":\"123\",\"x_operator_id\":\"test_operator\",\"signature\":\"4e4927bee1ab8e3e5ea354766ba81982ad5da8e65653cb696e140a2e784d6238\"}", result); Assert.IsTrue(result.Contains("4e4927bee1ab8e3e5ea354766ba81982ad5da8e65653cb696e140a2e784d6238")); }
public void Creates_Expected_Signature_For_Sample_ProcessAuthorisation_Request() { var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); var signature = generator.GenerateSignature ( new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_merchant_id", "30299999"), new KeyValuePair <string, object>("x_device_id", "d555"), new KeyValuePair <string, object>("x_operator_id", "test_operator"), new KeyValuePair <string, object>("x_firmware_version", "123"), new KeyValuePair <string, object>("x_pos_transaction_ref", "tnx-ref1"), new KeyValuePair <string, object>("x_pre_approval_code", "6111NHQMAM4Z"), new KeyValuePair <string, object>("x_finance_amount", 100M), new KeyValuePair <string, object>("x_purchase_amount", 500M), new KeyValuePair <string, object>("purchase_items", "{ \"PurchaseItems\": [ \"Item1\", \"Item2\" ] }"), new KeyValuePair <string, object>("signature", "d6967970b99e585fc7d1a11702690f25b4be0c5fbfd10b39fbea3953ba48bad2") } ); Assert.AreEqual("d6967970b99e585fc7d1a11702690f25b4be0c5fbfd10b39fbea3953ba48bad2", signature); }
public void Writes_Expected_SendReceipt_Request_With_Signature() { var sigGen = new Hmac256SignatureGenerator("dy33vQhksVsv"); var writer = new SignedRequestWriter(sigGen); var request = new SendReceiptRequest() { MerchantId = "30299999", DeviceId = "d555", OperatorId = "test_operator", PosVersion = "123", ClientTransactionReference = "tnx-ref1", ReceiptNumber = "NewReceipt" }; var result = writer.WriteRequest(request); //Note: The signature expected here is different to the one shown in the Humm sample page (https://docs.shophumm.com.au/pos/api_information/http_examples/). //The sample C# code provided by Humm at (https://docs.shophumm.com.au/pos/security/signature_generation/) generates the same code used here //and this signature gen works with the API endpoints, so it would appear the sample was updated using a different key or something, and the //sample signature is now incorrect. Assert.AreEqual("{\"x_pos_transaction_ref\":\"tnx-ref1\",\"x_receipt_number\":\"NewReceipt\",\"x_merchant_id\":\"30299999\",\"x_device_id\":\"d555\",\"x_firmware_version\":\"123\",\"x_operator_id\":\"test_operator\",\"signature\":\"ac164e40585474838641bde1ad9bab08b6e6e0ab0c2dae814298e4fcef9c52fa\"}", result); Assert.IsTrue(result.Contains("ac164e40585474838641bde1ad9bab08b6e6e0ab0c2dae814298e4fcef9c52fa")); }
public void Creates_Expected_Signature_For_Sample_ProcessSalesAdjustment_Response() { //The original signature for this request as shown in the API documentation is b490b0565a93b31bdf93037ede44b3619f08a1e0e5f68332db52f02176a86bb2 //however that is not the signature generated by the algorithm and key provided. Even using the sample C# code from the Humm API documentation //doesn't generate that signature, but does generate the same signature as the one actually tested here. I suspect the samples were generated //with a different key than the sample docs generate. I wasn't able to get Humm to understand/answer or change the docs. For now, testing using the //key that I expect is the right one, since it was confirmed with the Humm sample code and actual calls to the API seem to work. var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); var signature = generator.GenerateSignature ( new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_status", "Failed"), new KeyValuePair <string, object>("x_code", "FPSA05"), new KeyValuePair <string, object>("x_message", "Unable to process a sales adjustment for this contract. Please contact Merchant Services on [CollectionsPhone] during business hours for further information"), new KeyValuePair <string, object>("signature", "0c796d7e5f6720f5b56ed021e1bba8681d095fd764735f3c62c2d84b9b843af4"), new KeyValuePair <string, object>("tracking_data", null) } ); Assert.AreEqual("0c796d7e5f6720f5b56ed021e1bba8681d095fd764735f3c62c2d84b9b843af4", signature); }
public void Creates_Expected_Signature_For_Sample_ProcessSalesAdjustmentReversal_Response() { //The original signature for this request as shown in the API documentation is 1949a14cfdd8e6062a54f28ab3a607637f081afb7b8f4cffa3fb413fadab963b //however that is not the signature generated by the algorithm and key provided. Even using the sample C# code from the Humm API documentation //doesn't generate that signature, but does generate the same signature as the one actually tested here. I suspect the samples were generated //with a different key than the sample docs generate. I wasn't able to get Humm to understand/answer or change the docs. For now, testing using the //key that I expect is the right one, since it was confirmed with the Humm sample code and actual calls to the API seem to work. var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); var signature = generator.GenerateSignature ( new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_status", "Failed"), new KeyValuePair <string, object>("x_code", "FPSA05"), new KeyValuePair <string, object>("x_message", "Unable to process a sales adjustment reversal for this contract. Please contact Merchant Services on [CollectionsPhone] during business hours for further information"), new KeyValuePair <string, object>("signature", "5397070a731b81064e69ebbff7814cb9458a885af5e5087f87cc554b20c36b24"), new KeyValuePair <string, object>("tracking_data", null) } ); Assert.AreEqual("5397070a731b81064e69ebbff7814cb9458a885af5e5087f87cc554b20c36b24", signature); }
public void Writes_Expected_ProcessSalesAdjustmentReversal_Request_With_Signature() { var sigGen = new Hmac256SignatureGenerator("dy33vQhksVsv"); var writer = new SignedRequestWriter(sigGen); var request = new ProcessSalesAdjustmentReversalRequest() { MerchantId = "30299999", DeviceId = "d555", OperatorId = "test_operator", PosVersion = "123", ClientTransactionReference = "tnx-rev1", AdjustmentSignature = "ce20e2f1a9fe0d92b3d021ba7f1b372b006778cfab5fc4c09efa60a6d910c471" }; var result = writer.WriteRequest(request); //Note: The signature expected here is different to the one shown in the Humm sample page (https://docs.shophumm.com.au/pos/api_information/http_examples/). //The sample C# code provided by Humm at (https://docs.shophumm.com.au/pos/security/signature_generation/) generates the same code used here //and this signature gen works with the API endpoints, so it would appear the sample was updated using a different key or something, and the //sample signature is now incorrect. Assert.AreEqual("{\"x_pos_transaction_ref\":\"tnx-rev1\",\"x_adjustment_signature\":\"ce20e2f1a9fe0d92b3d021ba7f1b372b006778cfab5fc4c09efa60a6d910c471\",\"x_merchant_id\":\"30299999\",\"x_device_id\":\"d555\",\"x_firmware_version\":\"123\",\"x_operator_id\":\"test_operator\",\"signature\":\"83a8f5b53cbd205474cd8c993f911b465d25a381d3fc09c781fefb9bef18859d\"}", result); Assert.IsTrue(result.Contains("1949a14cfdd8e6062a54f28ab3a607637f081afb7b8f4cffa3fb413fadab963b")); }
public void Creates_Expected_Signature_For_Sample_Invite_Response() { //The original signature for this request as shown in the API documentation is 2e7ddc54f5457b22fcdd7382ce4e9651abd527051dbc069a3171b4201d8e359c //however that is not the signature generated by the algorithm and key provided. Even using the sample C# code from the Humm API documentation //doesn't generate that signature, but does generate the same signature as the one actually tested here. I suspect the samples were generated //with a different key than the sample docs generate. I wasn't able to get Humm to understand/answer or change the docs. For now, testing using the //key that I expect is the right one, since it was confirmed with the Humm sample code and actual calls to the API seem to work. var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); var signature = generator.GenerateSignature ( new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("x_status", "Success"), new KeyValuePair <string, object>("x_code", "SINV01"), new KeyValuePair <string, object>("x_message", "Success"), new KeyValuePair <string, object>("signature", "07a431469cb23ebcf024f7933e75dfb10fe76c44e0295de72e6912b12af91157"), new KeyValuePair <string, object>("tracking_data", null) } ); Assert.AreEqual("07a431469cb23ebcf024f7933e75dfb10fe76c44e0295de72e6912b12af91157", signature); }
public void Constructor_Throws_If_ApiKey_Null() { var generator = new Hmac256SignatureGenerator(null); generator.Dispose(); }
public void Constructor_Throws_If_ApiKey_Empty() { var generator = new Hmac256SignatureGenerator(string.Empty); generator.Dispose(); }
public void Disposes_Properly() { var generator = new Hmac256SignatureGenerator("dy33vQhksVsv"); generator.Dispose(); }