From efae7c2c81e76cfcdc798367b8d529519970c697 Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 8 Oct 2019 08:23:05 -0300 Subject: [PATCH 01/29] Add Logic to obtain IOT credentials and sign websocket url --- .../Onepay/Exceptions/Sigv4UtilException.cs | 22 +++ .../Onepay/Model/WebsocketCredentials.cs | 20 +++ Transbank/Onepay/Utils/HttpHelper.cs | 39 +++++ Transbank/Onepay/Utils/Sigv4util.cs | 147 ++++++++++++++++++ Transbank/Onepay/Utils/WebSocketMessage.cs | 14 ++ Transbank/Onepay/Websocket.cs | 10 ++ 6 files changed, 252 insertions(+) create mode 100644 Transbank/Onepay/Exceptions/Sigv4UtilException.cs create mode 100644 Transbank/Onepay/Model/WebsocketCredentials.cs create mode 100644 Transbank/Onepay/Utils/HttpHelper.cs create mode 100644 Transbank/Onepay/Utils/Sigv4util.cs create mode 100644 Transbank/Onepay/Utils/WebSocketMessage.cs create mode 100644 Transbank/Onepay/Websocket.cs diff --git a/Transbank/Onepay/Exceptions/Sigv4UtilException.cs b/Transbank/Onepay/Exceptions/Sigv4UtilException.cs new file mode 100644 index 0000000..ffe1c56 --- /dev/null +++ b/Transbank/Onepay/Exceptions/Sigv4UtilException.cs @@ -0,0 +1,22 @@ +using System; + + +namespace Transbank.Onepay.Exceptions +{ + public class AmountException : TransbankException + { + public AmountException() : base() + { + } + + public AmountException(string message) + : base(-1, message) + { + } + + public AmountException(string message, Exception innerException) + : base(-1, message, innerException) + { + } + } +} diff --git a/Transbank/Onepay/Model/WebsocketCredentials.cs b/Transbank/Onepay/Model/WebsocketCredentials.cs new file mode 100644 index 0000000..96a16ea --- /dev/null +++ b/Transbank/Onepay/Model/WebsocketCredentials.cs @@ -0,0 +1,20 @@ +namespace Transbank.Onepay.Model +{ + public class WebsocketCredentials + { + public string iotEndpoint; + public string region; + public string accessKey; + public string secretKey; + public string sessionToken; + + public override string ToString() + { + return "Endpoint: " + iotEndpoint + "\n" + + "Region: " + region + "\n" + + "Acces Key: " + accessKey + "\n" + + "SecretKey: " + secretKey + "\n" + + "SessionToken: " + sessionToken; + } + } +} \ No newline at end of file diff --git a/Transbank/Onepay/Utils/HttpHelper.cs b/Transbank/Onepay/Utils/HttpHelper.cs new file mode 100644 index 0000000..e9e2b06 --- /dev/null +++ b/Transbank/Onepay/Utils/HttpHelper.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OnepayWebSocket.Utils +{ + public static class HttpHelper + { + // The Set of accepted and valid Url characters per RFC3986. Characters outside of this set will be encoded. + const string ValidUrlCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~"; + + public static string UrlEncode(string data, bool isPath = false) + { + + var encoded = new StringBuilder(data.Length * 2); + + try + { + string unreservedChars = String.Concat(ValidUrlCharacters, (isPath ? "/:" : "")); + + foreach (char symbol in System.Text.Encoding.UTF8.GetBytes(data)) + { + if (unreservedChars.IndexOf(symbol) != -1) + encoded.Append(symbol); + else + encoded.Append("%").Append(String.Format("{0:X2}", (int)symbol)); + } + } + catch (Exception ex) + { + Logger.LogError(ex.Message); + + } + return encoded.ToString(); + } + } +} diff --git a/Transbank/Onepay/Utils/Sigv4util.cs b/Transbank/Onepay/Utils/Sigv4util.cs new file mode 100644 index 0000000..f8ec775 --- /dev/null +++ b/Transbank/Onepay/Utils/Sigv4util.cs @@ -0,0 +1,147 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Security; +using System.Security.Cryptography; +using System.Text; +using System.Text.RegularExpressions; +using System.Globalization; + +namespace OnepayWebSocket.Utils +{ + public static class Sigv4util + { + public const string ISO8601BasicFormat = "yyyyMMddTHHmmssZ"; + public const string DateStringFormat = "yyyyMMdd"; + public const string EmptyBodySha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; + public static HashAlgorithm CanonicalRequestHashAlgorithm = HashAlgorithm.Create("SHA-256"); + // the name of the keyed hash algorithm used in signing + public const string HmacSha256 = "HMACSHA256"; + public const string XAmzSignature = "X-Amz-Signature"; + + + + + private static byte[] HmacSHA256(String data, byte[] key) + { + String algorithm = "HmacSHA256"; + KeyedHashAlgorithm keyHashAlgorithm = KeyedHashAlgorithm.Create(algorithm); + keyHashAlgorithm.Key = key; + + return keyHashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(data)); + } + + private static byte[] ComputeKeyedHash(string algorithm, byte[] key, byte[] data) + { + var kha = KeyedHashAlgorithm.Create(algorithm); + kha.Key = key; + return kha.ComputeHash(data); + } + + public static string ToHexString(byte[] data, bool lowerCase) + { + StringBuilder stringBuilder = new StringBuilder(); + + try + { + for (var i = 0; i < data.Length; i++) + { + stringBuilder.Append(data[i].ToString(lowerCase ? "x2" : "X2")); + } + + } + catch (Exception ex) + { + Logger.LogDebug(ex.Message); + } + + return stringBuilder.ToString(); + } + + private static byte[] getSignatureKey(String key, String dateStamp, String regionName, String serviceName) + { + byte[] kSecret = Encoding.UTF8.GetBytes(("AWS4" + key).ToCharArray()); + byte[] kDate = HmacSHA256(dateStamp, kSecret); + byte[] kRegion = HmacSHA256(regionName, kDate); + byte[] kService = HmacSHA256(serviceName, kRegion); + byte[] kSigning = HmacSHA256("aws4_request", kService); + + return kSigning; + } + + public static string getSignedurl(WebSocketResponse credentials) + { + string requestUrl = ""; + try + { + + DateTime requestDateTime = DateTime.UtcNow; + string datetime = requestDateTime.ToString(ISO8601BasicFormat, CultureInfo.InvariantCulture); + var date = requestDateTime.ToString(DateStringFormat, CultureInfo.InvariantCulture); + + string method = "GET";//ConfigHelper.ReadSetting("method"); + + string protocol = "wss"; // ConfigHelper.ReadSetting("protocol"); + + string uri = "/mqtt"; //ConfigHelper.ReadSetting("uri"); + + string service = "iotdevicegateway"; //ConfigHelper.ReadSetting("service"); + + string algorithm = "AWS4-HMAC-SHA256"; //ConfigHelper.ReadSetting("algorithm"); + + string credentialScope = date + "/" + credentials.region + "/" + service + "/" + "aws4_request"; + string canonicalQuerystring = "X-Amz-Algorithm=" + algorithm; + canonicalQuerystring += "&X-Amz-Credential=" + HttpHelper.UrlEncode(credentials.accessKey + '/' + credentialScope); + + canonicalQuerystring += "&X-Amz-Date=" + datetime; + canonicalQuerystring += "&X-Amz-Expires=86400"; + canonicalQuerystring += "&X-Amz-SignedHeaders=host"; + + string canonicalHeaders = "host:" + credentials.iotEndpoint + "\n"; + + var canonicalRequest = method + "\n" + uri + "\n" + canonicalQuerystring + "\n" + canonicalHeaders + "\n" + "host" + "\n" + EmptyBodySha256; + + byte[] hashValueCanonicalRequest = CanonicalRequestHashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(canonicalRequest)); + + + + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < hashValueCanonicalRequest.Length; i++) + { + builder.Append(hashValueCanonicalRequest[i].ToString("x2")); + } + + string byteString = builder.ToString(); + + var stringToSign = algorithm + "\n" + datetime + "\n" + credentialScope + "\n" + byteString; + // compute the signing key + KeyedHashAlgorithm keyedHashAlgorithm = KeyedHashAlgorithm.Create(HmacSha256); + + keyedHashAlgorithm.Key = getSignatureKey(credentials.secretKey, date, credentials.region, service); + + var signingKey = keyedHashAlgorithm.Key; + + var signature = ComputeKeyedHash(HmacSha256, signingKey, Encoding.UTF8.GetBytes(stringToSign)); + var signatureString = ToHexString(signature, true); + + canonicalQuerystring += "&X-Amz-Signature=" + signatureString; + canonicalQuerystring += "&X-Amz-Security-Token=" + HttpHelper.UrlEncode(credentials.sessionToken); + + requestUrl = protocol + "://" + credentials.iotEndpoint + uri + "?" + canonicalQuerystring; + + + } + + catch (Exception ex) + { + Logger.LogError(ex.Message); + + } + + + return requestUrl; + } + } +} diff --git a/Transbank/Onepay/Utils/WebSocketMessage.cs b/Transbank/Onepay/Utils/WebSocketMessage.cs new file mode 100644 index 0000000..6363931 --- /dev/null +++ b/Transbank/Onepay/Utils/WebSocketMessage.cs @@ -0,0 +1,14 @@ +namespace OnepayWebSocket.Utils +{ + public class WebsocketMessage + { + public string status; + public string description; + + public override string ToString() + { + return "Status: " + status + "\n" + + "Description: " + description; + } + } +} \ No newline at end of file diff --git a/Transbank/Onepay/Websocket.cs b/Transbank/Onepay/Websocket.cs new file mode 100644 index 0000000..c7f1359 --- /dev/null +++ b/Transbank/Onepay/Websocket.cs @@ -0,0 +1,10 @@ +using System; +namespace Transbank.Onepay +{ + public class Websocket + { + public Websocket() + { + } + } +} From c4e11f504566cfd4b81286d34501114c0aa633ad Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 8 Oct 2019 08:40:04 -0300 Subject: [PATCH 02/29] Refactor amazon example --- .../Onepay/Exceptions/Sigv4UtilException.cs | 8 +-- .../Onepay/Model/WebsocketCredentials.cs | 8 +-- Transbank/Onepay/Utils/HttpHelper.cs | 13 ++--- Transbank/Onepay/Utils/Sigv4util.cs | 58 +++++++------------ Transbank/Transbank.csproj | 1 + 5 files changed, 35 insertions(+), 53 deletions(-) diff --git a/Transbank/Onepay/Exceptions/Sigv4UtilException.cs b/Transbank/Onepay/Exceptions/Sigv4UtilException.cs index ffe1c56..545b42f 100644 --- a/Transbank/Onepay/Exceptions/Sigv4UtilException.cs +++ b/Transbank/Onepay/Exceptions/Sigv4UtilException.cs @@ -3,18 +3,18 @@ namespace Transbank.Onepay.Exceptions { - public class AmountException : TransbankException + public class Sigv4UtilException : TransbankException { - public AmountException() : base() + public Sigv4UtilException() : base() { } - public AmountException(string message) + public Sigv4UtilException(string message) : base(-1, message) { } - public AmountException(string message, Exception innerException) + public Sigv4UtilException(string message, Exception innerException) : base(-1, message, innerException) { } diff --git a/Transbank/Onepay/Model/WebsocketCredentials.cs b/Transbank/Onepay/Model/WebsocketCredentials.cs index 96a16ea..d1c366f 100644 --- a/Transbank/Onepay/Model/WebsocketCredentials.cs +++ b/Transbank/Onepay/Model/WebsocketCredentials.cs @@ -11,10 +11,10 @@ public class WebsocketCredentials public override string ToString() { return "Endpoint: " + iotEndpoint + "\n" + - "Region: " + region + "\n" + - "Acces Key: " + accessKey + "\n" + - "SecretKey: " + secretKey + "\n" + - "SessionToken: " + sessionToken; + "Region: " + region + "\n" + + "Acces Key: " + accessKey + "\n" + + "SecretKey: " + secretKey + "\n" + + "SessionToken: " + sessionToken; } } } \ No newline at end of file diff --git a/Transbank/Onepay/Utils/HttpHelper.cs b/Transbank/Onepay/Utils/HttpHelper.cs index e9e2b06..40b4c0b 100644 --- a/Transbank/Onepay/Utils/HttpHelper.cs +++ b/Transbank/Onepay/Utils/HttpHelper.cs @@ -1,10 +1,8 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Text; -using System.Threading.Tasks; +using Transbank.Onepay.Exceptions; -namespace OnepayWebSocket.Utils +namespace Transbank.Onepay.Utils { public static class HttpHelper { @@ -20,7 +18,7 @@ public static string UrlEncode(string data, bool isPath = false) { string unreservedChars = String.Concat(ValidUrlCharacters, (isPath ? "/:" : "")); - foreach (char symbol in System.Text.Encoding.UTF8.GetBytes(data)) + foreach (char symbol in Encoding.UTF8.GetBytes(data)) { if (unreservedChars.IndexOf(symbol) != -1) encoded.Append(symbol); @@ -28,10 +26,9 @@ public static string UrlEncode(string data, bool isPath = false) encoded.Append("%").Append(String.Format("{0:X2}", (int)symbol)); } } - catch (Exception ex) + catch (Exception e) { - Logger.LogError(ex.Message); - + throw new HttpHelperException("Unable to encode URL", e); } return encoded.ToString(); } diff --git a/Transbank/Onepay/Utils/Sigv4util.cs b/Transbank/Onepay/Utils/Sigv4util.cs index f8ec775..87223bb 100644 --- a/Transbank/Onepay/Utils/Sigv4util.cs +++ b/Transbank/Onepay/Utils/Sigv4util.cs @@ -1,14 +1,11 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Security; using System.Security.Cryptography; using System.Text; -using System.Text.RegularExpressions; using System.Globalization; +using Transbank.Onepay.Exceptions; +using Transbank.Onepay.Model; -namespace OnepayWebSocket.Utils +namespace Transbank.Onepay.Utils { public static class Sigv4util { @@ -16,17 +13,13 @@ public static class Sigv4util public const string DateStringFormat = "yyyyMMdd"; public const string EmptyBodySha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; public static HashAlgorithm CanonicalRequestHashAlgorithm = HashAlgorithm.Create("SHA-256"); - // the name of the keyed hash algorithm used in signing public const string HmacSha256 = "HMACSHA256"; public const string XAmzSignature = "X-Amz-Signature"; - - - private static byte[] HmacSHA256(String data, byte[] key) { - String algorithm = "HmacSHA256"; - KeyedHashAlgorithm keyHashAlgorithm = KeyedHashAlgorithm.Create(algorithm); + var algorithm = "HmacSHA256"; + var keyHashAlgorithm = KeyedHashAlgorithm.Create(algorithm); keyHashAlgorithm.Key = key; return keyHashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(data)); @@ -41,7 +34,7 @@ private static byte[] ComputeKeyedHash(string algorithm, byte[] key, byte[] data public static string ToHexString(byte[] data, bool lowerCase) { - StringBuilder stringBuilder = new StringBuilder(); + var stringBuilder = new StringBuilder(); try { @@ -51,11 +44,10 @@ public static string ToHexString(byte[] data, bool lowerCase) } } - catch (Exception ex) + catch (Exception e) { - Logger.LogDebug(ex.Message); + throw new Sigv4UtilException("Unable to convert data to hex string", e); } - return stringBuilder.ToString(); } @@ -70,25 +62,21 @@ private static byte[] getSignatureKey(String key, String dateStamp, String regio return kSigning; } - public static string getSignedurl(WebSocketResponse credentials) + public static string getSignedurl(WebsocketCredentials credentials) { - string requestUrl = ""; + string requestUrl; try { - DateTime requestDateTime = DateTime.UtcNow; + var requestDateTime = DateTime.UtcNow; string datetime = requestDateTime.ToString(ISO8601BasicFormat, CultureInfo.InvariantCulture); var date = requestDateTime.ToString(DateStringFormat, CultureInfo.InvariantCulture); - string method = "GET";//ConfigHelper.ReadSetting("method"); - - string protocol = "wss"; // ConfigHelper.ReadSetting("protocol"); - - string uri = "/mqtt"; //ConfigHelper.ReadSetting("uri"); - - string service = "iotdevicegateway"; //ConfigHelper.ReadSetting("service"); - - string algorithm = "AWS4-HMAC-SHA256"; //ConfigHelper.ReadSetting("algorithm"); + string method = "GET"; + string protocol = "wss"; + string uri = "/mqtt"; + string service = "iotdevicegateway"; + string algorithm = "AWS4-HMAC-SHA256"; string credentialScope = date + "/" + credentials.region + "/" + service + "/" + "aws4_request"; string canonicalQuerystring = "X-Amz-Algorithm=" + algorithm; @@ -104,9 +92,7 @@ public static string getSignedurl(WebSocketResponse credentials) byte[] hashValueCanonicalRequest = CanonicalRequestHashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(canonicalRequest)); - - - StringBuilder builder = new StringBuilder(); + var builder = new StringBuilder(); for (int i = 0; i < hashValueCanonicalRequest.Length; i++) { @@ -116,8 +102,9 @@ public static string getSignedurl(WebSocketResponse credentials) string byteString = builder.ToString(); var stringToSign = algorithm + "\n" + datetime + "\n" + credentialScope + "\n" + byteString; + // compute the signing key - KeyedHashAlgorithm keyedHashAlgorithm = KeyedHashAlgorithm.Create(HmacSha256); + var keyedHashAlgorithm = KeyedHashAlgorithm.Create(HmacSha256); keyedHashAlgorithm.Key = getSignatureKey(credentials.secretKey, date, credentials.region, service); @@ -130,14 +117,11 @@ public static string getSignedurl(WebSocketResponse credentials) canonicalQuerystring += "&X-Amz-Security-Token=" + HttpHelper.UrlEncode(credentials.sessionToken); requestUrl = protocol + "://" + credentials.iotEndpoint + uri + "?" + canonicalQuerystring; - - } - catch (Exception ex) + catch (Exception e) { - Logger.LogError(ex.Message); - + throw new Sigv4UtilException("Unable to get signed url", e); } diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index b826bf3..94a606a 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -110,6 +110,7 @@ + From 79e67bedec208707a5c0235a85fc4b2aad77a4fd Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 8 Oct 2019 08:40:45 -0300 Subject: [PATCH 03/29] Add Websocket Class in Onepay namespace --- Transbank/Onepay/Websocket.cs | 42 +++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/Transbank/Onepay/Websocket.cs b/Transbank/Onepay/Websocket.cs index c7f1359..1283c64 100644 --- a/Transbank/Onepay/Websocket.cs +++ b/Transbank/Onepay/Websocket.cs @@ -1,10 +1,48 @@ -using System; +using System; +using System.IO; +using System.Net; +using MQTTnet; +using MQTTnet.Client; +using Newtonsoft.Json; +using Transbank.Onepay.Model; +using Transbank.Onepay.Utils; + namespace Transbank.Onepay { public class Websocket { - public Websocket() + private static readonly string OnepayIotEndpoint = "https://qml1wjqokl.execute-api.us-east-1.amazonaws.com/prod/onepayjs/auth/keys"; + internal WebsocketCredentials Credentials; + + public IMqttClient mqttClient; + public IMqttClientOptions mqttClientOptions; + + public Websocket(string Ott) { + Credentials = FetchCredentials(); + + string requestUrl = Sigv4util.getSignedurl(Credentials); + + string clientId = Guid.NewGuid().ToString(); + + var factory = new MqttFactory(); + mqttClient = factory.CreateMqttClient(); + + mqttClientOptions = new MqttClientOptionsBuilder(). + WithWebSocketServer(requestUrl).Build(); + + mqttClient.ConnectAsync(mqttClientOptions); + mqttClient.SubscribeAsync(Ott); + } + + private WebsocketCredentials FetchCredentials() + { + var request = (HttpWebRequest)WebRequest.Create(OnepayIotEndpoint); + + using var responseStream = request.GetResponse().GetResponseStream(); + using var streamReader = new StreamReader(responseStream); + var credentialsAsJson = streamReader.ReadToEnd(); + return JsonConvert.DeserializeObject(credentialsAsJson); } } } From 87d6b615d9470623977a7bb7cd08c420242a4969 Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 8 Oct 2019 08:41:25 -0300 Subject: [PATCH 04/29] Add missing httpHelper exception --- .../Onepay/Exceptions/HttpHelperException.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Transbank/Onepay/Exceptions/HttpHelperException.cs diff --git a/Transbank/Onepay/Exceptions/HttpHelperException.cs b/Transbank/Onepay/Exceptions/HttpHelperException.cs new file mode 100644 index 0000000..6fb19cf --- /dev/null +++ b/Transbank/Onepay/Exceptions/HttpHelperException.cs @@ -0,0 +1,22 @@ +using System; + + +namespace Transbank.Onepay.Exceptions +{ + public class HttpHelperException : TransbankException + { + public HttpHelperException() : base() + { + } + + public HttpHelperException(string message) + : base(-1, message) + { + } + + public HttpHelperException(string message, Exception innerException) + : base(-1, message, innerException) + { + } + } +} From 3569047728dc461ced93529a77bfec65f0cdcc50 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 9 Oct 2019 11:33:12 -0300 Subject: [PATCH 05/29] Move WebsocketMessage from utils to Model --- Transbank/Onepay/{Utils => Model}/WebSocketMessage.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Transbank/Onepay/{Utils => Model}/WebSocketMessage.cs (100%) diff --git a/Transbank/Onepay/Utils/WebSocketMessage.cs b/Transbank/Onepay/Model/WebSocketMessage.cs similarity index 100% rename from Transbank/Onepay/Utils/WebSocketMessage.cs rename to Transbank/Onepay/Model/WebSocketMessage.cs From 26c5c613270a0ab8be007ac145c7030554e8772c Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 9 Oct 2019 11:34:16 -0300 Subject: [PATCH 06/29] Update WebsocketMessage namespace --- Transbank/Onepay/Model/WebSocketMessage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Transbank/Onepay/Model/WebSocketMessage.cs b/Transbank/Onepay/Model/WebSocketMessage.cs index 6363931..b3e0e9f 100644 --- a/Transbank/Onepay/Model/WebSocketMessage.cs +++ b/Transbank/Onepay/Model/WebSocketMessage.cs @@ -1,4 +1,4 @@ -namespace OnepayWebSocket.Utils +namespace Transbank.Onepay.Model { public class WebsocketMessage { From 29979fc2236f4d1b42829226d2064acdf0585229 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 9 Oct 2019 11:35:53 -0300 Subject: [PATCH 07/29] Add handler for new Messages --- Transbank/Onepay/Websocket.cs | 48 ++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/Transbank/Onepay/Websocket.cs b/Transbank/Onepay/Websocket.cs index 1283c64..7dbe55c 100644 --- a/Transbank/Onepay/Websocket.cs +++ b/Transbank/Onepay/Websocket.cs @@ -17,7 +17,7 @@ public class Websocket public IMqttClient mqttClient; public IMqttClientOptions mqttClientOptions; - public Websocket(string Ott) + public Websocket(long Ott) { Credentials = FetchCredentials(); @@ -31,18 +31,58 @@ public Websocket(string Ott) mqttClientOptions = new MqttClientOptionsBuilder(). WithWebSocketServer(requestUrl).Build(); + mqttClient.Connected += + (sender, e) => Console.WriteLine("Connected :D"); + + mqttClient.ApplicationMessageReceived += + (sender, e) => MqttClient_ApplicationMessageReceived(sender, e, new TransactionCreateResponse()); + + mqttClient.Disconnected += + (sender, e) => Console.WriteLine("Conection Lost :("); + mqttClient.ConnectAsync(mqttClientOptions); - mqttClient.SubscribeAsync(Ott); + mqttClient.SubscribeAsync(Ott.ToString()); } private WebsocketCredentials FetchCredentials() { var request = (HttpWebRequest)WebRequest.Create(OnepayIotEndpoint); - using var responseStream = request.GetResponse().GetResponseStream(); - using var streamReader = new StreamReader(responseStream); + var responseStream = request.GetResponse().GetResponseStream(); + var streamReader = new StreamReader(responseStream); var credentialsAsJson = streamReader.ReadToEnd(); return JsonConvert.DeserializeObject(credentialsAsJson); } + + private void MqttClient_ApplicationMessageReceived + (object sender, MqttApplicationMessageReceivedEventArgs e, TransactionCreateResponse response) + { + string payload = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload, 0, e.ApplicationMessage.Payload.Length); + + + WebsocketMessage message = JsonConvert.DeserializeObject(payload); + Console.WriteLine(message); + + switch (message.status) + { + case "OTT_ASSIGNED": + break; + + case "AUTHORIZED": + //Commit(response); + mqttClient.DisconnectAsync(); + break; + + case "REJECTED_BY_USER": + break; + + case "AUTHORIZATION_ERROR": + break; + + default: + Console.WriteLine("No action found"); + break; + } + } } } From 3a408936c0fb6476516cb27ae493f3d1e61f9957 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 9 Oct 2019 11:37:01 -0300 Subject: [PATCH 08/29] Remove commented lines --- Transbank/Onepay/Websocket.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Transbank/Onepay/Websocket.cs b/Transbank/Onepay/Websocket.cs index 7dbe55c..a5dcf21 100644 --- a/Transbank/Onepay/Websocket.cs +++ b/Transbank/Onepay/Websocket.cs @@ -23,8 +23,6 @@ public Websocket(long Ott) string requestUrl = Sigv4util.getSignedurl(Credentials); - string clientId = Guid.NewGuid().ToString(); - var factory = new MqttFactory(); mqttClient = factory.CreateMqttClient(); @@ -69,7 +67,6 @@ private void MqttClient_ApplicationMessageReceived break; case "AUTHORIZED": - //Commit(response); mqttClient.DisconnectAsync(); break; From c6cf1bd4e78981fb61d02846db94a2c4aa6e4771 Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 17 Oct 2019 10:10:14 -0300 Subject: [PATCH 09/29] Ignore line ending unifier config file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fd984e8..cf887b5 100644 --- a/.gitignore +++ b/.gitignore @@ -337,3 +337,4 @@ coverage/ opencover.xml .[Dd][Ss]_[Ss][Tt][Oo][Rr][Ee] +.leu From 552b53e68f08a9f1e40d6d0c11580fd1db2aa701 Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 17 Oct 2019 10:18:01 -0300 Subject: [PATCH 10/29] Refactor WebSocket class --- Transbank/Onepay/Websocket.cs | 143 +++++++++++++++------------------- 1 file changed, 61 insertions(+), 82 deletions(-) diff --git a/Transbank/Onepay/Websocket.cs b/Transbank/Onepay/Websocket.cs index a5dcf21..9497431 100644 --- a/Transbank/Onepay/Websocket.cs +++ b/Transbank/Onepay/Websocket.cs @@ -1,85 +1,64 @@ using System; -using System.IO; -using System.Net; -using MQTTnet; -using MQTTnet.Client; -using Newtonsoft.Json; -using Transbank.Onepay.Model; -using Transbank.Onepay.Utils; - -namespace Transbank.Onepay -{ - public class Websocket - { - private static readonly string OnepayIotEndpoint = "https://qml1wjqokl.execute-api.us-east-1.amazonaws.com/prod/onepayjs/auth/keys"; - internal WebsocketCredentials Credentials; - - public IMqttClient mqttClient; - public IMqttClientOptions mqttClientOptions; - - public Websocket(long Ott) - { - Credentials = FetchCredentials(); - - string requestUrl = Sigv4util.getSignedurl(Credentials); - - var factory = new MqttFactory(); - mqttClient = factory.CreateMqttClient(); - - mqttClientOptions = new MqttClientOptionsBuilder(). - WithWebSocketServer(requestUrl).Build(); - - mqttClient.Connected += - (sender, e) => Console.WriteLine("Connected :D"); - - mqttClient.ApplicationMessageReceived += - (sender, e) => MqttClient_ApplicationMessageReceived(sender, e, new TransactionCreateResponse()); - - mqttClient.Disconnected += - (sender, e) => Console.WriteLine("Conection Lost :("); - - mqttClient.ConnectAsync(mqttClientOptions); - mqttClient.SubscribeAsync(Ott.ToString()); - } - - private WebsocketCredentials FetchCredentials() - { +using System.IO; +using System.Net; +using System.Threading.Tasks; +using MQTTnet; +using MQTTnet.Client; +using Newtonsoft.Json; +using Transbank.Onepay.Model; +using Transbank.Onepay.Utils; + +namespace Transbank.Onepay +{ + public class Websocket + { + private static readonly string OnepayIotEndpoint = "https://qml1wjqokl.execute-api.us-east-1.amazonaws.com/prod/onepayjs/auth/keys"; + internal WebsocketCredentials Credentials; + + public IMqttClient mqttClient; + public IMqttClientOptions mqttClientOptions; + + public Websocket() + { + Credentials = FetchCredentials(); + + string requestUrl = Sigv4util.getSignedurl(Credentials); + + var factory = new MqttFactory(); + mqttClient = factory.CreateMqttClient(); + + mqttClientOptions = new MqttClientOptionsBuilder(). + WithWebSocketServer(requestUrl).Build(); + + } + + public async Task Connect(long ott, IOnepayPayment obj) + { + mqttClient.Connected += + (sender, e) => obj.Connected(); + + mqttClient.ApplicationMessageReceived += + (sender, e) => obj.NewMessage( + System.Text.Encoding.UTF8.GetString( + e.ApplicationMessage.Payload, 0, + e.ApplicationMessage.Payload.Length)); + + mqttClient.Disconnected += + (sender, e) => obj.Disconnected(); + + await mqttClient.ConnectAsync(mqttClientOptions); + await mqttClient.SubscribeAsync(ott.ToString()); + } + + private WebsocketCredentials FetchCredentials() + { var request = (HttpWebRequest)WebRequest.Create(OnepayIotEndpoint); - var responseStream = request.GetResponse().GetResponseStream(); - var streamReader = new StreamReader(responseStream); - var credentialsAsJson = streamReader.ReadToEnd(); - return JsonConvert.DeserializeObject(credentialsAsJson); - } - - private void MqttClient_ApplicationMessageReceived - (object sender, MqttApplicationMessageReceivedEventArgs e, TransactionCreateResponse response) - { - string payload = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload, 0, e.ApplicationMessage.Payload.Length); - - - WebsocketMessage message = JsonConvert.DeserializeObject(payload); - Console.WriteLine(message); - - switch (message.status) - { - case "OTT_ASSIGNED": - break; - - case "AUTHORIZED": - mqttClient.DisconnectAsync(); - break; - - case "REJECTED_BY_USER": - break; - - case "AUTHORIZATION_ERROR": - break; - - default: - Console.WriteLine("No action found"); - break; - } - } - } -} + var responseStream = request.GetResponse().GetResponseStream(); + var streamReader = new StreamReader(responseStream); + var credentialsAsJson = streamReader.ReadToEnd(); + return JsonConvert.DeserializeObject(credentialsAsJson); + } + + } +} From e8e3137ae54d5ae5fbfd54e5852a6c9127463129 Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 17 Oct 2019 10:18:49 -0300 Subject: [PATCH 11/29] Add Interface for users of weboscket class to implement --- Transbank/Onepay/IOnepayPayment.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Transbank/Onepay/IOnepayPayment.cs diff --git a/Transbank/Onepay/IOnepayPayment.cs b/Transbank/Onepay/IOnepayPayment.cs new file mode 100644 index 0000000..aab94af --- /dev/null +++ b/Transbank/Onepay/IOnepayPayment.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MQTTnet; +using MQTTnet.Client; + + +namespace Transbank.Onepay +{ + public interface IOnepayPayment + { + void Connected(); + void NewMessage(string payload); + void Disconnected(); + } + +} From d91a15dcc7776220da373c8ddaf04d199fdd2866 Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 17 Oct 2019 10:21:07 -0300 Subject: [PATCH 12/29] Update pre-release version --- Transbank/Transbank.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 94a606a..39411aa 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -16,7 +16,7 @@ en-US payments, cl, chile, transbank http://www.transbankdevelopers.cl/library/img/favicon/mstile-310x310.png - 2.2.2 + 2.3.0 $(VersionSuffix) TransbankSDK 2018 - Transbank From 9d854546fab954b7842fbb09d043835adf754454 Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 17 Oct 2019 11:53:00 -0300 Subject: [PATCH 13/29] Use ott as string to subscrive topic --- Transbank/Onepay/Websocket.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Transbank/Onepay/Websocket.cs b/Transbank/Onepay/Websocket.cs index 9497431..0206be5 100644 --- a/Transbank/Onepay/Websocket.cs +++ b/Transbank/Onepay/Websocket.cs @@ -32,7 +32,7 @@ public Websocket() } - public async Task Connect(long ott, IOnepayPayment obj) + public async Task Connect(string ott, IOnepayPayment obj) { mqttClient.Connected += (sender, e) => obj.Connected(); @@ -47,7 +47,7 @@ public async Task Connect(long ott, IOnepayPayment obj) (sender, e) => obj.Disconnected(); await mqttClient.ConnectAsync(mqttClientOptions); - await mqttClient.SubscribeAsync(ott.ToString()); + await mqttClient.SubscribeAsync(ott); } private WebsocketCredentials FetchCredentials() From 112fb1a8eea8b88181e46e468616b5d4ed182617 Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 22 Oct 2019 17:20:29 -0300 Subject: [PATCH 14/29] Add Ott, Occ, Ticket, total and eun to the IOnepayPayment object Interface --- Transbank/Onepay/IOnepayPayment.cs | 6 ++++++ Transbank/Onepay/Websocket.cs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Transbank/Onepay/IOnepayPayment.cs b/Transbank/Onepay/IOnepayPayment.cs index aab94af..826e38b 100644 --- a/Transbank/Onepay/IOnepayPayment.cs +++ b/Transbank/Onepay/IOnepayPayment.cs @@ -11,6 +11,12 @@ namespace Transbank.Onepay { public interface IOnepayPayment { + int Ticket { get; } + int Total { get; } + string ExternalUniqueNumber { get; } + string Occ { get; } + string Ott { get; } + void Connected(); void NewMessage(string payload); void Disconnected(); diff --git a/Transbank/Onepay/Websocket.cs b/Transbank/Onepay/Websocket.cs index 0206be5..18e5a33 100644 --- a/Transbank/Onepay/Websocket.cs +++ b/Transbank/Onepay/Websocket.cs @@ -32,7 +32,7 @@ public Websocket() } - public async Task Connect(string ott, IOnepayPayment obj) + public async Task Connect(IOnepayPayment obj) { mqttClient.Connected += (sender, e) => obj.Connected(); @@ -47,7 +47,7 @@ public async Task Connect(string ott, IOnepayPayment obj) (sender, e) => obj.Disconnected(); await mqttClient.ConnectAsync(mqttClientOptions); - await mqttClient.SubscribeAsync(ott); + await mqttClient.SubscribeAsync(obj.Ott); } private WebsocketCredentials FetchCredentials() From bbe1894bbd479bf28ba7fe412ebc298ca4f73a8c Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 5 Nov 2019 11:59:32 -0300 Subject: [PATCH 15/29] Remove Console Output on Commit signature check --- Transbank/Onepay/Model/TransactionCommitResponse.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Transbank/Onepay/Model/TransactionCommitResponse.cs b/Transbank/Onepay/Model/TransactionCommitResponse.cs index 89699fb..e5d0b5c 100644 --- a/Transbank/Onepay/Model/TransactionCommitResponse.cs +++ b/Transbank/Onepay/Model/TransactionCommitResponse.cs @@ -23,7 +23,6 @@ public string GetDataToSign() + InstallmentsAmount.ToString().Length + InstallmentsAmount.ToString() + InstallmentsNumber.ToString().Length + InstallmentsNumber.ToString() + BuyOrder.Length + BuyOrder; - Console.WriteLine(ret); return ret; } From fcad6e68b796cdeb20a872bccd19f350e92fd074 Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 5 Nov 2019 12:00:39 -0300 Subject: [PATCH 16/29] Update MqttNet to the latest version Also, use apropiate event handlers --- Transbank/Onepay/Websocket.cs | 30 +++++++++++++++++------------- Transbank/Transbank.csproj | 4 ++-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Transbank/Onepay/Websocket.cs b/Transbank/Onepay/Websocket.cs index 18e5a33..9dc580d 100644 --- a/Transbank/Onepay/Websocket.cs +++ b/Transbank/Onepay/Websocket.cs @@ -1,9 +1,12 @@ using System; using System.IO; using System.Net; +using System.Text; +using System.Threading; using System.Threading.Tasks; using MQTTnet; using MQTTnet.Client; +using MQTTnet.Client.Options; using Newtonsoft.Json; using Transbank.Onepay.Model; using Transbank.Onepay.Utils; @@ -28,26 +31,27 @@ public Websocket() mqttClient = factory.CreateMqttClient(); mqttClientOptions = new MqttClientOptionsBuilder(). - WithWebSocketServer(requestUrl).Build(); + WithWebSocketServer(requestUrl). + WithKeepAlivePeriod(TimeSpan.FromMinutes(10)).Build(); } - public async Task Connect(IOnepayPayment obj) + public async Task ConnectAsync(IOnepayPayment obj) { - mqttClient.Connected += - (sender, e) => obj.Connected(); + mqttClient.UseConnectedHandler(e => { + obj.Connected(); + }); - mqttClient.ApplicationMessageReceived += - (sender, e) => obj.NewMessage( - System.Text.Encoding.UTF8.GetString( - e.ApplicationMessage.Payload, 0, - e.ApplicationMessage.Payload.Length)); + mqttClient.UseApplicationMessageReceivedHandler(e => { + obj.NewMessage(Encoding.UTF8.GetString(e.ApplicationMessage.Payload)); + }); - mqttClient.Disconnected += - (sender, e) => obj.Disconnected(); + mqttClient.UseDisconnectedHandler(e => { + obj.Disconnected(); + }); - await mqttClient.ConnectAsync(mqttClientOptions); - await mqttClient.SubscribeAsync(obj.Ott); + _ = await mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None); + _ = await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(obj.Ott).Build()); } private WebsocketCredentials FetchCredentials() diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 39411aa..14b4ab8 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -109,8 +109,8 @@ - - + + From 162cae5fcab0ced49240aa0315d880b59e392144 Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 12 Nov 2019 17:16:10 -0300 Subject: [PATCH 17/29] Update Changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f633a8..cfd8589 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ Todos los cambios notables a este proyecto serán documentados en este archivo. El formato está basado en [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) y este proyecto adhiere a [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [2.3.0] - 2019-11-12 + +### Added + +- Se agregan las clases necesarias para conectarse al Websocket de Onepay. Estas clases pueden ser utilizadas independientes, pero estan especialmente diseñadas para ser utilizadas por el SDK de POSIntegrado + +- Se agregan templates para crear Issues en Github. + ## [2.2.1] - 2019-05-20 ### Fixed From 44eacd8487751ff12b3645250af9e147b28cd164 Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 12 Nov 2019 17:16:24 -0300 Subject: [PATCH 18/29] Update Version --- Transbank/Transbank.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 14b4ab8..a8f592c 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -16,7 +16,7 @@ en-US payments, cl, chile, transbank http://www.transbankdevelopers.cl/library/img/favicon/mstile-310x310.png - 2.3.0 + 2.3.1 $(VersionSuffix) TransbankSDK 2018 - Transbank From ec0d7d8f50f0dadffc56df3912e9523ebf470b60 Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 21 Nov 2019 15:21:29 -0300 Subject: [PATCH 19/29] Update Nuget Package Icon --- Transbank/Transbank.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index a8f592c..04f156d 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -10,7 +10,7 @@ TransbankSDK This is the .Net SDK for Transbank Integration. https://raw.githubusercontent.com/TransbankDevelopers/transbank-sdk-dotnet/master/LICENSE - http://www.transbankdevelopers.cl/ + https://www.transbankdevelopers.cl//favicon.ico https://github.com/TransbankDevelopers/transbank-sdk-dotnet git en-US From 598b810de88d0deba0e2532a3d6cbb9d46df1d6b Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 21 Nov 2019 15:35:57 -0300 Subject: [PATCH 20/29] Restore PackageProjectUrl and update PackageIcon --- Transbank/Transbank.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 04f156d..bbd7090 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -10,12 +10,12 @@ TransbankSDK This is the .Net SDK for Transbank Integration. https://raw.githubusercontent.com/TransbankDevelopers/transbank-sdk-dotnet/master/LICENSE - https://www.transbankdevelopers.cl//favicon.ico + http://www.transbankdevelopers.cl/ https://github.com/TransbankDevelopers/transbank-sdk-dotnet git en-US payments, cl, chile, transbank - http://www.transbankdevelopers.cl/library/img/favicon/mstile-310x310.png + https://www.transbankdevelopers.cl/favicon.ico 2.3.1 $(VersionSuffix) TransbankSDK From 239380170a26a908051cc4421420e004a57ebd64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20C=C3=A1rdenas?= Date: Thu, 19 Dec 2019 22:56:46 -0300 Subject: [PATCH 21/29] Remove unused test --- .../WebpayRest/WebpayPlus/OptionsTest.cs | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs diff --git a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs deleted file mode 100644 index 2cbdaa3..0000000 --- a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Transbank.Common; -using Transbank.Webpay.Common; - -namespace TransbankTest.WebpayRest.WebpayPlus -{ - [TestClass] - public class OptionsTest - { - [TestMethod] - public void TestDefaultConfiguration() - { - var options = Transbank.Webpay.WebpayPlus.Transaction.DefaultOptions(); - Assert.AreEqual("597055555532", options.CommerceCode); - Assert.AreEqual("579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C", options.ApiKey); - Assert.AreEqual(options.IntegrationType, WebpayIntegrationType.Test); - - - } - - private static string _commerceCodeHeaderName = "Tbk-Api-Key-Id"; - private static string _apiKeyHeaderName = "Tbk-Api-Key-Secret"; - - private static RequestServiceHeaders _headers = new RequestServiceHeaders(_apiKeyHeaderName, _commerceCodeHeaderName); - - public static RequestServiceHeaders Headers - { - get => _headers; - set => _headers = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null." - ); - } - - [TestMethod] - public void TestCommerceCodeNotNull() => Assert.ThrowsException(() => new Options(null, "someapikey", WebpayIntegrationType.Test, Headers)); - - [TestMethod] - public void TestApiKeyNotNull() => Assert.ThrowsException(() => new Options("somecommercecode", null, WebpayIntegrationType.Test, Headers)); - - [TestMethod] - public void TestIntegrationTypeNotNull() => Assert.ThrowsException(() => new Options("someapikey", "somecommercecode", null, Headers)); - } -} From 8eee1c95d6a117f2194d6d40466c3cd8ce0c2d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20C=C3=A1rdenas?= Date: Thu, 19 Dec 2019 22:57:59 -0300 Subject: [PATCH 22/29] Fix finish response params --- .../Oneclick/Responses/FinishResponse.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs index 87d2305..43b07df 100644 --- a/Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs @@ -11,19 +11,19 @@ public class FinishResponse public string TbkUser { get; private set; } [JsonProperty("authorization_code")] public string AuthorizationCode { get; private set; } - [JsonProperty("credit_card_type")] - public string CreditCardType { get; private set; } - [JsonProperty("last_four_card_digits")] - public string LastFourCardDigits { get; private set; } + [JsonProperty("card_type")] + public string CardType { get; private set; } + [JsonProperty("card_number")] + public string CardNumber { get; private set; } public FinishResponse(int responseCode, string transbankUser, - string authorizationCode, string creditCardType, string lastFourCardDigits) + string authorizationCode, string cardType, string cardNumber) { ResponseCode = responseCode; TbkUser = transbankUser; AuthorizationCode = authorizationCode; - CreditCardType = creditCardType; - LastFourCardDigits = lastFourCardDigits; + CardType = cardType; + CardNumber = cardNumber; } public override string ToString() From ae37f9a57a5a6673f81ad6c871a0257c77f2d1cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20C=C3=A1rdenas?= Date: Thu, 19 Dec 2019 22:59:19 -0300 Subject: [PATCH 23/29] Add details param to Mall status response --- .../WebpayRest/Oneclick/Responses/MallStatusResponse.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs index fe189eb..7f0e58c 100644 --- a/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using Newtonsoft.Json; using Transbank.Webpay.Common; @@ -17,6 +18,9 @@ public class MallStatusResponse [JsonProperty("transaction_date")] public string TransactionDate { get; set; } + [JsonProperty("details")] + public List Details { get; private set; } + public MallStatusResponse(string buyOrder, CardDetail cardDetail, string accountingDate, string transactionDate) { BuyOrder = buyOrder; @@ -51,7 +55,8 @@ public class Detail [JsonProperty("buy_order")] public string BuyOrder { get; set; } - public Detail(decimal amount, string status, string authorizationCode, string paymentTypeCode, int responseCode, int installmentsNumber, string commerceCode, string buyOrder) + public Detail(decimal amount, string status, string authorizationCode, string paymentTypeCode, + int responseCode, int installmentsNumber, string commerceCode, string buyOrder) { Amount = amount; Status = status; From 52afc32be75a3d436db3ad62f08074999e431982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20C=C3=A1rdenas?= Date: Thu, 19 Dec 2019 22:59:53 -0300 Subject: [PATCH 24/29] Remove unused test folder --- TransbankTest/TransbankTest.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/TransbankTest/TransbankTest.csproj b/TransbankTest/TransbankTest.csproj index 46a982f..f60b4c9 100644 --- a/TransbankTest/TransbankTest.csproj +++ b/TransbankTest/TransbankTest.csproj @@ -20,6 +20,5 @@ - From 1afa1381f43a5d063921bdd4183df178ea7c0183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20C=C3=A1rdenas?= Date: Thu, 19 Dec 2019 23:00:33 -0300 Subject: [PATCH 25/29] Fix responses toString --- .../Oneclick/Responses/FinishResponse.cs | 10 ++++---- .../Responses/MallAuthorizeResponse.cs | 14 +++++------ .../Oneclick/Responses/MallRefundResponse.cs | 12 +++++----- .../Oneclick/Responses/MallStatusResponse.cs | 8 +++++++ .../Responses/CommitResponse.cs | 24 +++++++++---------- .../Responses/CreateResponse.cs | 2 +- .../Responses/InstallmentsResponse.cs | 6 ++--- .../Responses/RefundResponse.cs | 12 +++++----- .../Responses/StatusResponse.cs | 24 +++++++++---------- 9 files changed, 60 insertions(+), 52 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs index 43b07df..2013cb6 100644 --- a/Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs @@ -28,11 +28,11 @@ public FinishResponse(int responseCode, string transbankUser, public override string ToString() { - return $"\"Response Code\": \"{ResponseCode}\"\n" + - $"\"Transbank User\": \"{TbkUser}\"\n" + - $"\"Authorization Code\": \"{AuthorizationCode}\"\n" + - $"\"Credit Card Type\": \"{CreditCardType}\"\n" + - $"\"Last Four Card Digits\": \"{LastFourCardDigits}\""; + return $"\"ResponseCode\": \"{ResponseCode}\"\n" + + $"\"TransbankUser\": \"{TbkUser}\"\n" + + $"\"AuthorizationCode\": \"{AuthorizationCode}\"\n" + + $"\"CardType\": \"{CardType}\"\n" + + $"\"CardNumber\": \"{CardNumber}\""; } } } diff --git a/Transbank/WebpayRest/Oneclick/Responses/MallAuthorizeResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/MallAuthorizeResponse.cs index f778acd..1b9ec34 100644 --- a/Transbank/WebpayRest/Oneclick/Responses/MallAuthorizeResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Responses/MallAuthorizeResponse.cs @@ -43,13 +43,13 @@ public MallAuthorizeResponse(string buyOrder, string sessionId, string cardNumbe public override string ToString() { - return $"\"BuyOrder\": {BuyOrder}\"\n" + - $"\"SessionId\": {SessionId}\"\n" + - $"\"CardNumber\": {CardNumber}\"\n" + - $"\"ExpirationDate\": {ExpirationDate}\"\n" + - $"\"AccountingDate\": {AccountingDate}\"\n" + - $"\"TransactionDate\": {TransactionDate}\"\n" + - $"\"Details\": {Details.ToString()}\""; + return $"\"BuyOrder\": \"{BuyOrder}\"\n" + + $"\"SessionId\": \"{SessionId}\"\n" + + $"\"CardNumber\": \"{CardNumber}\"\n" + + $"\"ExpirationDate\": \"{ExpirationDate}\"\n" + + $"\"AccountingDate\": \"{AccountingDate}\"\n" + + $"\"TransactionDate\": \"{TransactionDate}\"\n" + + $"\"Details\": \"{Details.ToString()}\""; } } } diff --git a/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs index 29b8e30..97331f8 100644 --- a/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs @@ -33,12 +33,12 @@ public MallRefundResponse(string type, decimal balance, string authorizationCode } public override string ToString() { - return $"\"Type\": {Type}\"\n" + - $"\"Balance\": {Balance}\"\n" + - $"\"AuthorizationCode\": {AuthorizationCode}\"\n" + - $"\"ResponseCode\": {ResponseCode}\"\n" + - $"\"AuthorizationDate\": {AuthorizationDate}\"\n" + - $"\"NullifiedAmount\": {NullifiedAmount}\"\n" ; + return $"\"Type\": \"{Type}\"\n" + + $"\"Balance\": \"{Balance}\"\n" + + $"\"AuthorizationCode\": \"{AuthorizationCode}\"\n" + + $"\"ResponseCode\": \"{ResponseCode}\"\n" + + $"\"AuthorizationDate\": \"{AuthorizationDate}\"\n" + + $"\"NullifiedAmount\": \"{NullifiedAmount}\"\n" ; } } } diff --git a/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs index 7f0e58c..5fb43b8 100644 --- a/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs @@ -29,6 +29,14 @@ public MallStatusResponse(string buyOrder, CardDetail cardDetail, string account TransactionDate = transactionDate; } + public override string ToString() + { + return $"\"BuyOrder\": \"{BuyOrder}\"\n" + + $"\"AccountingDate\": \"{AccountingDate}\"\n" + + $"\"TransactionDate\": \"{TransactionDate}\"\n" + + $"\"Details\": \"{Details.ToString()}\""; + } + public class Detail { [JsonProperty("amount")] diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs index 66caee6..241ca7c 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs @@ -58,18 +58,18 @@ public CommitResponse(int amount, string status, string buyOrder, string session public override string ToString() { - return $"Amount={Amount}\n" + - $"Status={Status}\n" + - $"Buy Order={BuyOrder}\n" + - $"Session Id={SessionId}\n" + - $"Card Detail={CardDetail.ToString()}\n" + - $"Accounting Date={AccountingDate}\n" + - $"Transaction Date={TransactionDate}\n" + - $"Authorization Code={AuthorizationCode}\n" + - $"Payment Type Code={PaymentTypeCode}\n" + - $"Response Code={ResponseCode}\n" + - $"Installments Amount={InstallmentsAmount}\n" + - $"Installments Number={InstallmentsNumber}\n"; + return $"\"Amount\":\"{Amount}\"\n" + + $"\"Status\":\"{Status}\"\n" + + $"\"BuyOrder\":\"{BuyOrder}\"\n" + + $"\"SessionId\":\"{SessionId}\"\n" + + $"\"CardDetail\":\"{CardDetail.ToString()}\"\n" + + $"\"AccountingDate\":\"{AccountingDate}\"\n" + + $"\"TransactionDate\":\"{TransactionDate}\"\n" + + $"\"AuthorizationCode\":\"{AuthorizationCode}\"\n" + + $"\"PaymentTypeCode:\"{PaymentTypeCode}\"\n" + + $"\"ResponseCode\":\"{ResponseCode}\"\n" + + $"\"InstallmentsAmount\":\"{InstallmentsAmount}\"\n" + + $"\"InstallmentsNumber\":\"{InstallmentsNumber}\"\n"; } } diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs index 5814598..c07dd8a 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs @@ -14,7 +14,7 @@ public CreateResponse(string token) public override string ToString() { - return $"Token={Token}"; + return $"\"Token\":\"{Token}\""; } } } diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs index fd347f8..b804a1a 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs @@ -24,9 +24,9 @@ public InstallmentsResponse(int installmentsAmount, int idQueryInstallments, Lis public override string ToString() { - return $"InstallmentsAmount={InstallmentsAmount}\n" + - $"IdQueryInstallments={IdQueryInstallments}\n" + - $"DeferredPeriods={DeferredPeriods.ToString()}"; + return $"\"InstallmentsAmount\":\"{InstallmentsAmount}\"\n" + + $"\"IdQueryInstallments\":\"{IdQueryInstallments}\"\n" + + $"\"DeferredPeriods\":\"{DeferredPeriods.ToString()}\""; } } } diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/RefundResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/RefundResponse.cs index d36d2df..66c382c 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/RefundResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/RefundResponse.cs @@ -35,12 +35,12 @@ public RefundResponse(string type, string authorizationCode, string authorizatio public override string ToString() { - return $"Type={Type}\n" + - $"AuthorizationCode={AuthorizationCode}\n" + - $"AuthorizationDate={AuthorizationDate}\n" + - $"NullifiedAmount={NullifiedAmount}\n" + - $"Balance={Balance}\n" + - $"ResponseCode={ResponseCode}\n"; + return $"\"Type\":\"{Type}\"\n" + + $"\"AuthorizationCode\":\"{AuthorizationCode}\"\n" + + $"\"AuthorizationDate\":\"{AuthorizationDate}\"\n" + + $"\"NullifiedAmount\":\"{NullifiedAmount}\"\n" + + $"\"Balance\":\"{Balance}\"\n" + + $"\"ResponseCode\":\"{ResponseCode}\"\n"; } } } diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs index 658a019..7a3f07f 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs @@ -59,18 +59,18 @@ public StatusResponse(int amount, string status, string buyOrder, string session public override string ToString() { - return $"Amount={Amount}\n" + - $"Status={Status}\n" + - $"BuyOrder={BuyOrder}\n" + - $"SessionId={SessionId}\n" + - $"CardDetail={CardDetail}\n" + - $"AccountingDate={AccountingDate}\n" + - $"TransactionDate={TransactionDate}\n" + - $"AuthorizationCode={AuthorizationCode}\n" + - $"PaymentTypeCode={PaymentTypeCode}\n" + - $"ResponseCode={ResponseCode}\n" + - $"InstallmentsAmount={InstallmentsAmount}\n" + - $"InstallmentsAmount={InstallmentsAmount}\n"; + return $"\"Amount\":\"{Amount}\"\n" + + $"\"Status\":\"{Status}\"\n" + + $"\"BuyOrder\":\"{BuyOrder}\"\n" + + $"\"SessionId\":\"{SessionId}\"\n" + + $"\"CardDetail\":\"{CardDetail}\"\n" + + $"\"AccountingDate\":\"{AccountingDate}\"\n" + + $"\"TransactionDate\":\"{TransactionDate}\"\n" + + $"\"AuthorizationCode\":\"{AuthorizationCode}\"\n" + + $"\"PaymentTypeCode\":\"{PaymentTypeCode}\"\n" + + $"\"ResponseCode\":\"{ResponseCode}\"\n" + + $"\"InstallmentsAmount\":\"{InstallmentsAmount}\"\n" + + $"\"InstallmentsAmount\":\"{InstallmentsAmount}\"\n"; } } } From 6d71fedec28a375bb188e84327bc878a9e1eaf73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20C=C3=A1rdenas?= Date: Thu, 26 Dec 2019 11:16:04 -0300 Subject: [PATCH 26/29] Prepare release 2.4.0 --- CHANGELOG.md | 7 +++++++ Transbank/Transbank.csproj | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfd8589..30bc384 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ Todos los cambios notables a este proyecto serán documentados en este archivo. El formato está basado en [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) y este proyecto adhiere a [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [2.4.0] - 2019-12-26 + +### Added + +- Se agrega soporte para Oneclick Mall y Transacción Completa en sus versiones REST. + + ## [2.3.0] - 2019-11-12 ### Added diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 2281837..a2b226c 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -16,7 +16,7 @@ en-US payments, cl, chile, transbank https://www.transbankdevelopers.cl/favicon.ico - 2.3.1 + 2.4.1 $(VersionSuffix) TransbankSDK 2018 - Transbank From 5ddf72d6cac84db51e292c99b3949544a3603d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20C=C3=A1rdenas?= Date: Tue, 28 Jan 2020 12:38:42 -0300 Subject: [PATCH 27/29] Add missing files and comments --- Transbank/Onepay/Utils/HttpHelper.cs | 5 +- Transbank/Onepay/Utils/IRequestBuilder.cs | 5 +- Transbank/Onepay/Utils/ISignUtil.cs | 5 +- Transbank/Onepay/Utils/LICENSE | 177 ++++++++++++++++++ Transbank/Onepay/Utils/NOTICE | 2 + .../Onepay/Utils/OnepayRequestBuilder.cs | 5 +- Transbank/Onepay/Utils/OnepaySignUtil.cs | 5 +- Transbank/Onepay/Utils/Sigv4util.cs | 5 +- 8 files changed, 203 insertions(+), 6 deletions(-) create mode 100644 Transbank/Onepay/Utils/LICENSE create mode 100644 Transbank/Onepay/Utils/NOTICE diff --git a/Transbank/Onepay/Utils/HttpHelper.cs b/Transbank/Onepay/Utils/HttpHelper.cs index 40b4c0b..3ea588c 100644 --- a/Transbank/Onepay/Utils/HttpHelper.cs +++ b/Transbank/Onepay/Utils/HttpHelper.cs @@ -1,4 +1,7 @@ -using System; +// Class based in https://github.com/aws-samples/aws-iot-core-dotnet-app-mqtt-over-websockets-sigv4 +// subsequently modified. + +using System; using System.Text; using Transbank.Onepay.Exceptions; diff --git a/Transbank/Onepay/Utils/IRequestBuilder.cs b/Transbank/Onepay/Utils/IRequestBuilder.cs index c17be68..aadcf86 100644 --- a/Transbank/Onepay/Utils/IRequestBuilder.cs +++ b/Transbank/Onepay/Utils/IRequestBuilder.cs @@ -1,4 +1,7 @@ -using System; +// Class based in https://github.com/aws-samples/aws-iot-core-dotnet-app-mqtt-over-websockets-sigv4 +// subsequently modified. + +using System; using System.Collections.Generic; using System.Text; using Transbank.Onepay.Enums; diff --git a/Transbank/Onepay/Utils/ISignUtil.cs b/Transbank/Onepay/Utils/ISignUtil.cs index 9b0c5c9..8931eeb 100644 --- a/Transbank/Onepay/Utils/ISignUtil.cs +++ b/Transbank/Onepay/Utils/ISignUtil.cs @@ -1,4 +1,7 @@ -using Transbank.Onepay.Model; +// Class based in https://github.com/aws-samples/aws-iot-core-dotnet-app-mqtt-over-websockets-sigv4 +// subsequently modified. + +using Transbank.Onepay.Model; namespace Transbank.Onepay.Utils { diff --git a/Transbank/Onepay/Utils/LICENSE b/Transbank/Onepay/Utils/LICENSE new file mode 100644 index 0000000..dadb359 --- /dev/null +++ b/Transbank/Onepay/Utils/LICENSE @@ -0,0 +1,177 @@ + +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5.Submission of Contributions.Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6.Trademarks.This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7.Disclaimer of Warranty.Unless required by applicable law or + agreed to in writing, Licensor provides the Work(and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON - INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE.You are solely responsible for determining the + + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8.Limitation of Liability. In no event and under no legal theory, + whether in tort(including negligence), contract, or otherwise, + unless required by applicable law(such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work(including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9.Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and / or rights consistent with this + License.However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. \ No newline at end of file diff --git a/Transbank/Onepay/Utils/NOTICE b/Transbank/Onepay/Utils/NOTICE new file mode 100644 index 0000000..b2d443a --- /dev/null +++ b/Transbank/Onepay/Utils/NOTICE @@ -0,0 +1,2 @@ +AWS Iot Core Dotnet App Mqtt Over Websockets Sigv4 +Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. \ No newline at end of file diff --git a/Transbank/Onepay/Utils/OnepayRequestBuilder.cs b/Transbank/Onepay/Utils/OnepayRequestBuilder.cs index 203174d..57adb17 100644 --- a/Transbank/Onepay/Utils/OnepayRequestBuilder.cs +++ b/Transbank/Onepay/Utils/OnepayRequestBuilder.cs @@ -1,4 +1,7 @@ -using System; +// Class based in https://github.com/aws-samples/aws-iot-core-dotnet-app-mqtt-over-websockets-sigv4 +// subsequently modified. + +using System; using System.Collections.Generic; using System.Text; using Transbank.Onepay.Enums; diff --git a/Transbank/Onepay/Utils/OnepaySignUtil.cs b/Transbank/Onepay/Utils/OnepaySignUtil.cs index 70bfe90..d27222c 100644 --- a/Transbank/Onepay/Utils/OnepaySignUtil.cs +++ b/Transbank/Onepay/Utils/OnepaySignUtil.cs @@ -1,4 +1,7 @@ -using System; +// Class based in https://github.com/aws-samples/aws-iot-core-dotnet-app-mqtt-over-websockets-sigv4 +// subsequently modified. + +using System; using System.Security.Cryptography; using System.Text; using Transbank.Onepay.Model; diff --git a/Transbank/Onepay/Utils/Sigv4util.cs b/Transbank/Onepay/Utils/Sigv4util.cs index 87223bb..ca5335b 100644 --- a/Transbank/Onepay/Utils/Sigv4util.cs +++ b/Transbank/Onepay/Utils/Sigv4util.cs @@ -1,4 +1,7 @@ -using System; +// Class based in https://github.com/aws-samples/aws-iot-core-dotnet-app-mqtt-over-websockets-sigv4 +// subsequently modified. + +using System; using System.Security.Cryptography; using System.Text; using System.Globalization; From 4bc2777c58bf47809d8631e60829b22b690afd30 Mon Sep 17 00:00:00 2001 From: Maria Paz Date: Tue, 3 Mar 2020 16:09:00 -0300 Subject: [PATCH 28/29] add quotes to name files --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 98178e2..dafcca2 100644 --- a/README.md +++ b/README.md @@ -112,8 +112,8 @@ Para generar una nueva versión, se debe crear un PR (con un título "Prepare re En ese PR deben incluirse los siguientes cambios: -1. Modificar el archivo CHANGELOG.md para incluir una nueva entrada (al comienzo) para `X.Y.Z` que explique en español los cambios **de cara al usuario del SDK**. -2. Modificar el archivo `Transbank/Transbank.csproj` para que <`VersionPrefix`> sea `X.Y.{Z+1}` (de manera que los pre-releases que se generen después del release sean de la siguiente versión). +1. Modificar el archivo `CHANGELOG.md` para incluir una nueva entrada (al comienzo) para `X.Y.Z` que explique en español los cambios **de cara al usuario del SDK**. +2. Modificar [Transbank.csproj](./Transbank/Transbank.csproj) para que <`VersionPrefix`> sea `X.Y.{Z+1}` (de manera que los pre-releases que se generen después del release sean de la siguiente versión). Luego de obtener aprobación del pull request, debe mezclarse a master e inmediatamente generar un release en GitHub con el tag `vX.Y.Z`. En la descripción del release debes poner lo mismo que agregaste al changelog. From 5666cd90d106ef1eea8b0bd801fa88af5b2c9f2a Mon Sep 17 00:00:00 2001 From: Ricardo Cisterna Date: Tue, 24 Mar 2020 16:32:56 -0300 Subject: [PATCH 29/29] Create troubleshoorint section in README --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index dafcca2..2b0ed0d 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,25 @@ La documentación relevante para usar este SDK es: - Primeros pasos con [Webpay](https://www.transbankdevelopers.cl/documentacion/webpay) y [Onepay](https://www.transbankdevelopers.cl/documentacion/onepay). - Referencia detallada sobre [Webpay](https://www.transbankdevelopers.cl/referencia/webpay) y [Onepay](https://www.transbankdevelopers.cl/referencia/onepay). +## Solución de problemas + +### CryptographicException: Invalid algorithm specified + +Si al intentar ejecutar el código en el que integras, se lanza una excepción similar a la siguiente: +``` +System.Security.Cryptography.CryptographicException + HResult=0x80090008 + Message=Invalid algorithm specified. + Source= + StackTrace: +``` +puedes solucionarlo agregando a tu código, antes de llamar a initTransaction, las siguientes líneas: + +```csharp +AppContext.SetSwitch("Switch.System.Security.Cryptography.Xml.UseInsecureHashAlgorithms", true); +AppContext.SetSwitch("Switch.System.Security.Cryptography.Pkcs.UseInsecureHashAlgorithms", true); +``` + ## Información para contribuir y desarrollar este SDK ### Windows