From 13c4c93ea8f50021e3d2020044a0faca1d43d87d Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Wed, 19 Jun 2019 16:28:18 -0400 Subject: [PATCH 001/120] Add Options class --- Transbank/Transbank.csproj | 5 ++- Transbank/WebpayRest/Common/Options.cs | 41 +++++++++++++++++++ .../Common/WebpayIntegrationType.cs | 20 +++++++++ Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs | 40 ++++++++++++++++++ TransbankTest/TransbankTest.csproj | 4 ++ .../WebpayRest/WebpayPlus/OptionsTest.cs | 28 +++++++++++++ 6 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 Transbank/WebpayRest/Common/Options.cs create mode 100644 Transbank/WebpayRest/Common/WebpayIntegrationType.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs create mode 100644 TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index b826bf3..26c90c9 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -1,4 +1,4 @@ - + net452 @@ -114,6 +114,9 @@ + + + diff --git a/Transbank/WebpayRest/Common/Options.cs b/Transbank/WebpayRest/Common/Options.cs new file mode 100644 index 0000000..02560a8 --- /dev/null +++ b/Transbank/WebpayRest/Common/Options.cs @@ -0,0 +1,41 @@ +using System; +namespace Transbank.Webpay.Common +{ + public class Options + { + private string _commerceCode; + private string _apiKey; + private WebpayIntegrationType _integrationType; + + public string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "IntegrationType can't be null." + ); + } + + public Options(string commerceCode, string apiKey, WebpayIntegrationType webpayIntegrationType) + { + CommerceCode = commerceCode; + ApiKey = apiKey; + IntegrationType = webpayIntegrationType; + } + } +} diff --git a/Transbank/WebpayRest/Common/WebpayIntegrationType.cs b/Transbank/WebpayRest/Common/WebpayIntegrationType.cs new file mode 100644 index 0000000..f4c6c95 --- /dev/null +++ b/Transbank/WebpayRest/Common/WebpayIntegrationType.cs @@ -0,0 +1,20 @@ +using System; +namespace Transbank.Webpay.Common +{ + public class WebpayIntegrationType + { + public string Key { get; private set; } + public string ApiBase { get; private set; } + + private WebpayIntegrationType(string key, string apiBase) + { + Key = key; + ApiBase = apiBase; + } + + public static readonly WebpayIntegrationType Live = + new WebpayIntegrationType("LIVE", "https://webpay3g.transbank.cl/"); + public static readonly WebpayIntegrationType Test = + new WebpayIntegrationType("TEST", "https://webpay3gint.transbank.cl/"); + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs b/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs new file mode 100644 index 0000000..5ea9edb --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs @@ -0,0 +1,40 @@ +using System; +using Transbank.Webpay.Common; +namespace Transbank.Webpay.WebpayPlus +{ + public static class WebpayPlus + { + private static string _commerceCode = "597055555532"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Live; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + } +} diff --git a/TransbankTest/TransbankTest.csproj b/TransbankTest/TransbankTest.csproj index 71047dd..46a982f 100644 --- a/TransbankTest/TransbankTest.csproj +++ b/TransbankTest/TransbankTest.csproj @@ -18,4 +18,8 @@ + + + + diff --git a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs new file mode 100644 index 0000000..91c034a --- /dev/null +++ b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs @@ -0,0 +1,28 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Transbank.Webpay.Common; + +namespace TransbankTest.WebpayRest.WebpayPlus +{ + [TestClass] + public class OptionsTest + { + [TestMethod] + public void TestDefaultConfiguration() + { + var options = Transbank.Webpay.WebpayPlus.WebpayPlus.DefaultOptions(); + Assert.AreEqual("597055555532", options.CommerceCode); + Assert.AreEqual("579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C", options.ApiKey); + Assert.AreEqual(options.IntegrationType, WebpayIntegrationType.Live); + } + + [TestMethod] + public void TestApiKeyNotNull() => Assert.ThrowsException(() => new Options(null, "somecommercecode", WebpayIntegrationType.Live)); + + [TestMethod] + public void TestCommerceCodeNotNull() => Assert.ThrowsException(() => new Options("someapikey", null, WebpayIntegrationType.Live)); + + [TestMethod] + public void TestIntegrationTypeNotNull() => Assert.ThrowsException(() => new Options("someapikey", "somecommercecode", null)); + } +} From 84cd9b044652021568d018d272088f2d4f7d482c Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Wed, 19 Jun 2019 16:37:08 -0400 Subject: [PATCH 002/120] Change options arguments order in tests --- TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs index 91c034a..8b3696d 100644 --- a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs +++ b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs @@ -17,10 +17,10 @@ public void TestDefaultConfiguration() } [TestMethod] - public void TestApiKeyNotNull() => Assert.ThrowsException(() => new Options(null, "somecommercecode", WebpayIntegrationType.Live)); + public void TestCommerceCodeNotNull() => Assert.ThrowsException(() => new Options(null, "someapikey", WebpayIntegrationType.Live)); [TestMethod] - public void TestCommerceCodeNotNull() => Assert.ThrowsException(() => new Options("someapikey", null, WebpayIntegrationType.Live)); + public void TestApiKeyNotNull() => Assert.ThrowsException(() => new Options("somecommercecode", null, WebpayIntegrationType.Live)); [TestMethod] public void TestIntegrationTypeNotNull() => Assert.ThrowsException(() => new Options("someapikey", "somecommercecode", null)); From 56fa166163f11ca6e243bf113619d48ad8a2e1f1 Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Tue, 25 Jun 2019 12:09:36 -0400 Subject: [PATCH 003/120] Add transaction create --- Transbank/Transbank.csproj | 4 +- Transbank/WebpayRest/Common/BaseRequest.cs | 21 ++++++++++ Transbank/WebpayRest/Common/RequestService.cs | 42 +++++++++++++++++++ .../Common/WebpayIntegrationType.cs | 4 +- .../WebpayPlus/Requests/CreateRequest.cs | 35 ++++++++++++++++ .../WebpayPlus/Responses/CreateResponse.cs | 20 +++++++++ .../WebpayRest/WebpayPlus/Transaction.cs | 26 ++++++++++++ Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs | 2 +- 8 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 Transbank/WebpayRest/Common/BaseRequest.cs create mode 100644 Transbank/WebpayRest/Common/RequestService.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Transaction.cs diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 26c90c9..625d30d 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -1,4 +1,4 @@ - + net452 @@ -117,6 +117,8 @@ + + diff --git a/Transbank/WebpayRest/Common/BaseRequest.cs b/Transbank/WebpayRest/Common/BaseRequest.cs new file mode 100644 index 0000000..3a3d4a7 --- /dev/null +++ b/Transbank/WebpayRest/Common/BaseRequest.cs @@ -0,0 +1,21 @@ +using System; +using Newtonsoft.Json; +namespace Transbank.Webpay.Common +{ + public abstract class BaseRequest + { + [JsonIgnore] + private readonly string _endpoint; + [JsonIgnore] + public string Endpoint { get { return _endpoint; } } + + protected BaseRequest(string endpoint) + { + if (String.IsNullOrEmpty(endpoint)) + throw new ArgumentNullException( + nameof(endpoint), "Endpoint can't be null."); + + _endpoint = endpoint; + } + } +} diff --git a/Transbank/WebpayRest/Common/RequestService.cs b/Transbank/WebpayRest/Common/RequestService.cs new file mode 100644 index 0000000..35b2c31 --- /dev/null +++ b/Transbank/WebpayRest/Common/RequestService.cs @@ -0,0 +1,42 @@ +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using Newtonsoft.Json; + +namespace Transbank.Webpay.Common +{ + public static class RequestService + { + private static readonly string CONTENT_TYPE = "application/json"; + + private static void AddRequiredHeaders(HttpClient client, string commerceCode, string apiKey) + { + var header = new MediaTypeWithQualityHeaderValue(CONTENT_TYPE); + client.DefaultRequestHeaders.Accept.Add(header); + client.DefaultRequestHeaders.Add("Tbk-Api-Key-Id", commerceCode); + client.DefaultRequestHeaders.Add("Tbk-Api-Key-Secret", apiKey); + } + + public static string Post(BaseRequest request, Options options) + { + var message = new HttpRequestMessage(HttpMethod.Post, new Uri(options.IntegrationType.ApiBase + request.Endpoint)) + { + Content = new StringContent(JsonConvert.SerializeObject(request), + Encoding.UTF8, CONTENT_TYPE) + }; + + using (var client = new HttpClient()) + { + AddRequiredHeaders(client, options.CommerceCode, options.ApiKey); + + var response = client.SendAsync(message).ConfigureAwait(false) + .GetAwaiter().GetResult(); + response.EnsureSuccessStatusCode(); + var jsonResponse = response.Content.ReadAsStringAsync() + .ConfigureAwait(false).GetAwaiter().GetResult(); + return jsonResponse; + } + } + } +} diff --git a/Transbank/WebpayRest/Common/WebpayIntegrationType.cs b/Transbank/WebpayRest/Common/WebpayIntegrationType.cs index f4c6c95..b6742cb 100644 --- a/Transbank/WebpayRest/Common/WebpayIntegrationType.cs +++ b/Transbank/WebpayRest/Common/WebpayIntegrationType.cs @@ -13,8 +13,8 @@ private WebpayIntegrationType(string key, string apiBase) } public static readonly WebpayIntegrationType Live = - new WebpayIntegrationType("LIVE", "https://webpay3g.transbank.cl/"); + new WebpayIntegrationType("LIVE", "https://webpay3g.transbank.cl"); public static readonly WebpayIntegrationType Test = - new WebpayIntegrationType("TEST", "https://webpay3gint.transbank.cl/"); + new WebpayIntegrationType("TEST", "https://webpay3gint.transbank.cl"); } } diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs new file mode 100644 index 0000000..6b79ea6 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs @@ -0,0 +1,35 @@ +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.WebpayPlus.Requests +{ + internal class CreateRequest : BaseRequest + { + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + [JsonProperty("session_id")] + public string SessionId { get; set; } + + [JsonProperty("amount")] + public decimal Amount { get; set; } + + [JsonProperty("return_url")] + public string ReturnUrl { get; set; } + + public override string ToString() + { + return $"BuyOrder={BuyOrder}, SessionId={SessionId}, " + + $"Amount={Amount}, ReturnUrl={ReturnUrl}"; + } + + internal CreateRequest(string buyOrder, string sessionId, decimal amount, string returnUrl) + : base("/rswebpaytransaction/api/webpay/v1.0/transactions") + { + BuyOrder = buyOrder; + SessionId = sessionId; + Amount = amount; + ReturnUrl = returnUrl; + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs new file mode 100644 index 0000000..c9fbab2 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs @@ -0,0 +1,20 @@ +using System; +namespace Transbank.Webpay.WebpayPlus.Responses +{ + public class CreateResponse + { + public string Token { get; private set; } + public string Url { get; private set; } + + public CreateResponse(string token, string url) + { + Token = token; + Url = url; + } + + public override string ToString() + { + return $"Token={Token}, Url={Url}"; + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs new file mode 100644 index 0000000..839d757 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -0,0 +1,26 @@ +using System; +using Transbank.Webpay.WebpayPlus.Requests; +using Transbank.Webpay.Common; +using Transbank.Webpay.WebpayPlus.Responses; +using Newtonsoft.Json; + +namespace Transbank.Webpay.WebpayPlus +{ + public static class Transaction + { + public static CreateResponse Create(string buyOrder, string sessionId, + decimal amount, string returnUrl) + { + return Create(buyOrder, sessionId, amount, returnUrl, WebpayPlus.DefaultOptions()); + } + + public static CreateResponse Create(string buyOrder, string sessionId, + decimal amount, string returnUrl, Options options) + { + var createRequest = new CreateRequest(buyOrder, sessionId, amount, returnUrl); + var response = RequestService.Post(createRequest, options); + + return JsonConvert.DeserializeObject(response); + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs b/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs index 5ea9edb..5e6bdb7 100644 --- a/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs +++ b/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs @@ -6,7 +6,7 @@ public static class WebpayPlus { private static string _commerceCode = "597055555532"; private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Live; + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; public static string CommerceCode { From a2464ca5cc41946842a524fed2fdb9e4ac89f49f Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Wed, 26 Jun 2019 12:11:02 -0400 Subject: [PATCH 004/120] Add method to requests --- Transbank/WebpayRest/Common/BaseRequest.cs | 10 +++++++++- Transbank/WebpayRest/Common/RequestService.cs | 4 ++-- .../WebpayRest/WebpayPlus/Requests/CreateRequest.cs | 3 ++- Transbank/WebpayRest/WebpayPlus/Transaction.cs | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Transbank/WebpayRest/Common/BaseRequest.cs b/Transbank/WebpayRest/Common/BaseRequest.cs index 3a3d4a7..1111889 100644 --- a/Transbank/WebpayRest/Common/BaseRequest.cs +++ b/Transbank/WebpayRest/Common/BaseRequest.cs @@ -1,4 +1,5 @@ using System; +using System.Net.Http; using Newtonsoft.Json; namespace Transbank.Webpay.Common { @@ -8,14 +9,21 @@ public abstract class BaseRequest private readonly string _endpoint; [JsonIgnore] public string Endpoint { get { return _endpoint; } } + [JsonIgnore] + private readonly HttpMethod _method; + [JsonIgnore] + public HttpMethod Method { get { return _method; } } - protected BaseRequest(string endpoint) + protected BaseRequest(string endpoint, HttpMethod method) { if (String.IsNullOrEmpty(endpoint)) throw new ArgumentNullException( nameof(endpoint), "Endpoint can't be null."); _endpoint = endpoint; + + _method = method ?? throw new ArgumentNullException( + nameof(method), "Method can't be null."); } } } diff --git a/Transbank/WebpayRest/Common/RequestService.cs b/Transbank/WebpayRest/Common/RequestService.cs index 35b2c31..cb967a5 100644 --- a/Transbank/WebpayRest/Common/RequestService.cs +++ b/Transbank/WebpayRest/Common/RequestService.cs @@ -18,9 +18,9 @@ private static void AddRequiredHeaders(HttpClient client, string commerceCode, s client.DefaultRequestHeaders.Add("Tbk-Api-Key-Secret", apiKey); } - public static string Post(BaseRequest request, Options options) + public static string Perform(BaseRequest request, Options options) { - var message = new HttpRequestMessage(HttpMethod.Post, new Uri(options.IntegrationType.ApiBase + request.Endpoint)) + var message = new HttpRequestMessage(request.Method, new Uri(options.IntegrationType.ApiBase + request.Endpoint)) { Content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, CONTENT_TYPE) diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs index 6b79ea6..858ff7d 100644 --- a/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs +++ b/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using Transbank.Webpay.Common; +using System.Net.Http; namespace Transbank.Webpay.WebpayPlus.Requests { @@ -24,7 +25,7 @@ public override string ToString() } internal CreateRequest(string buyOrder, string sessionId, decimal amount, string returnUrl) - : base("/rswebpaytransaction/api/webpay/v1.0/transactions") + : base("/rswebpaytransaction/api/webpay/v1.0/transactions", HttpMethod.Post) { BuyOrder = buyOrder; SessionId = sessionId; diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs index 839d757..ce7a80b 100644 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -1,4 +1,4 @@ -using System; +using System; using Transbank.Webpay.WebpayPlus.Requests; using Transbank.Webpay.Common; using Transbank.Webpay.WebpayPlus.Responses; @@ -18,7 +18,7 @@ public static CreateResponse Create(string buyOrder, string sessionId, decimal amount, string returnUrl, Options options) { var createRequest = new CreateRequest(buyOrder, sessionId, amount, returnUrl); - var response = RequestService.Post(createRequest, options); + var response = RequestService.Perform(createRequest, options); return JsonConvert.DeserializeObject(response); } From 1fd3f7d61106ad5a58dcac43bc1f3b887210b68a Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Wed, 26 Jun 2019 12:27:29 -0400 Subject: [PATCH 005/120] Fix options test --- TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs index 8b3696d..e66b1bb 100644 --- a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs +++ b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs @@ -13,14 +13,14 @@ public void TestDefaultConfiguration() var options = Transbank.Webpay.WebpayPlus.WebpayPlus.DefaultOptions(); Assert.AreEqual("597055555532", options.CommerceCode); Assert.AreEqual("579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C", options.ApiKey); - Assert.AreEqual(options.IntegrationType, WebpayIntegrationType.Live); + Assert.AreEqual(options.IntegrationType, WebpayIntegrationType.Test); } [TestMethod] - public void TestCommerceCodeNotNull() => Assert.ThrowsException(() => new Options(null, "someapikey", WebpayIntegrationType.Live)); + public void TestCommerceCodeNotNull() => Assert.ThrowsException(() => new Options(null, "someapikey", WebpayIntegrationType.Test)); [TestMethod] - public void TestApiKeyNotNull() => Assert.ThrowsException(() => new Options("somecommercecode", null, WebpayIntegrationType.Live)); + public void TestApiKeyNotNull() => Assert.ThrowsException(() => new Options("somecommercecode", null, WebpayIntegrationType.Test)); [TestMethod] public void TestIntegrationTypeNotNull() => Assert.ThrowsException(() => new Options("someapikey", "somecommercecode", null)); From dacc523a18d925c3276697513568daa9dfd5a8d7 Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Wed, 26 Jun 2019 16:27:31 -0400 Subject: [PATCH 006/120] Add Plus Transaction Commit --- .../WebpayPlus/Requests/CommitRequest.cs | 11 ++++ .../WebpayPlus/Responses/CommitResponse.cs | 52 +++++++++++++++++++ .../WebpayRest/WebpayPlus/Transaction.cs | 13 +++++ 3 files changed, 76 insertions(+) create mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/CommitResponse.cs diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs new file mode 100644 index 0000000..b8cc472 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs @@ -0,0 +1,11 @@ +using System; +using System.Net.Http; +using Transbank.Webpay.Common; +namespace Transbank.Webpay.WebpayPlus.Requests +{ + internal class CommitRequest : BaseRequest + { + internal CommitRequest(string token) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) {} + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/CommitResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/CommitResponse.cs new file mode 100644 index 0000000..ef7bbe9 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Responses/CommitResponse.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.WebpayPlus.Responses +{ + public class CommitResponse + { + [JsonProperty("vci")] + public string Vci { get; set; } + [JsonProperty("amount")] + public decimal Amount { get; set; } + [JsonProperty("status")] + public string Status { get; set; } + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + [JsonProperty("session_id")] + public string SessionId { get; set; } + [JsonProperty("card_detail")] + public CardDetail CardDetail { get; set; } + [JsonProperty("accounting_date")] + public string AccountingDate { get; set; } + [JsonProperty("transaction_date")] + public DateTime TransactionDate { get; set; } + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + [JsonProperty("payment_type_code")] + public string PaymentTypeCode { get; set; } + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + [JsonProperty("installments_amount")] + public int InstallmentsAmount { get; set; } + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; set; } + [JsonProperty("balance")] + public decimal Balance { get; set; } + + public override string ToString() + { + var properties = new List(); + foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) + { + string name = descriptor.Name; + object value = descriptor.GetValue(this); + properties.Add($"{name}={value}"); + } + return String.Join(", ", properties); + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs index ce7a80b..07ea330 100644 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -22,5 +22,18 @@ public static CreateResponse Create(string buyOrder, string sessionId, return JsonConvert.DeserializeObject(response); } + + public static CommitResponse Commit(string token) + { + return Commit(token, WebpayPlus.DefaultOptions()); + } + + public static CommitResponse Commit(string token, Options options) + { + var commitRequest = new CommitRequest(token); + var response = RequestService.Perform(commitRequest, options); + + return JsonConvert.DeserializeObject(response); + } } } From 5551b586534a9789dbdcd683abe940b70aacc06f Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Wed, 26 Jun 2019 16:33:10 -0400 Subject: [PATCH 007/120] Add CardDetail class --- Transbank/WebpayRest/Common/CardDetail.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Transbank/WebpayRest/Common/CardDetail.cs diff --git a/Transbank/WebpayRest/Common/CardDetail.cs b/Transbank/WebpayRest/Common/CardDetail.cs new file mode 100644 index 0000000..4c9537d --- /dev/null +++ b/Transbank/WebpayRest/Common/CardDetail.cs @@ -0,0 +1,16 @@ +using System; +using Newtonsoft.Json; + +namespace Transbank.Webpay.Common +{ + public class CardDetail + { + [JsonProperty("card_number")] + public string CardNumber { get; set; } + + public override string ToString() + { + return $"CardNumber={CardNumber}"; + } + } +} From d5e372615e2068d6c812a98f6098163699664e81 Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Wed, 26 Jun 2019 16:36:22 -0400 Subject: [PATCH 008/120] Add Plus Transaction Refund --- .../WebpayPlus/Requests/RefundRequest.cs | 24 +++++++++++++ .../WebpayPlus/Responses/RefundResponse.cs | 35 +++++++++++++++++++ .../WebpayRest/WebpayPlus/Transaction.cs | 13 +++++++ 3 files changed, 72 insertions(+) create mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/RefundResponse.cs diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs new file mode 100644 index 0000000..1304ae5 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs @@ -0,0 +1,24 @@ +using System; +using Transbank.Webpay.Common; +using Newtonsoft.Json; +using System.Net.Http; + +namespace Transbank.Webpay.WebpayPlus.Requests +{ + internal class RefundRequest : BaseRequest + { + [JsonProperty("amount")] + public decimal Amount { get; set; } + + public override string ToString() + { + return $"Amount={Amount}"; + } + + internal RefundRequest(string token, decimal amount) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/refunds", HttpMethod.Post) + { + Amount = amount; + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/RefundResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/RefundResponse.cs new file mode 100644 index 0000000..b6a1245 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Responses/RefundResponse.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Newtonsoft.Json; + +namespace Transbank.Webpay.WebpayPlus.Responses +{ + public class RefundResponse + { + [JsonProperty("type")] + public string Type { get; set; } + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + [JsonProperty("authorization_date")] + public DateTime AuthorizationDate { get; set; } + [JsonProperty("nullified_amount")] + public decimal NullifiedAmount { get; set; } + [JsonProperty("balance")] + public decimal Balance { get; set; } + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + + public override string ToString() + { + var properties = new List(); + foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) + { + string name = descriptor.Name; + object value = descriptor.GetValue(this); + properties.Add($"{name}={value}"); + } + return String.Join(", ", properties); + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs index 07ea330..8d188b8 100644 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -35,5 +35,18 @@ public static CommitResponse Commit(string token, Options options) return JsonConvert.DeserializeObject(response); } + + public static RefundResponse Refund(string token, decimal amount) + { + return Refund(token, amount, WebpayPlus.DefaultOptions()); + } + + public static RefundResponse Refund(string token, decimal amount, Options options) + { + var refundRequest = new RefundRequest(token, amount); + var response = RequestService.Perform(refundRequest, options); + + return JsonConvert.DeserializeObject(response); + } } } From 5fe9cffc3a28f4722741d92d64f64660d3eab2cb Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Wed, 26 Jun 2019 16:41:19 -0400 Subject: [PATCH 009/120] Add Plus Transaction Status --- Transbank/WebpayRest/Common/RequestService.cs | 9 ++++----- .../WebpayRest/WebpayPlus/Requests/StatusRequest.cs | 12 ++++++++++++ .../WebpayPlus/Responses/StatusResponse.cs | 5 +++++ Transbank/WebpayRest/WebpayPlus/Transaction.cs | 13 +++++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/StatusResponse.cs diff --git a/Transbank/WebpayRest/Common/RequestService.cs b/Transbank/WebpayRest/Common/RequestService.cs index cb967a5..a6d8ba2 100644 --- a/Transbank/WebpayRest/Common/RequestService.cs +++ b/Transbank/WebpayRest/Common/RequestService.cs @@ -20,11 +20,10 @@ private static void AddRequiredHeaders(HttpClient client, string commerceCode, s public static string Perform(BaseRequest request, Options options) { - var message = new HttpRequestMessage(request.Method, new Uri(options.IntegrationType.ApiBase + request.Endpoint)) - { - Content = new StringContent(JsonConvert.SerializeObject(request), - Encoding.UTF8, CONTENT_TYPE) - }; + var message = new HttpRequestMessage(request.Method, new Uri(options.IntegrationType.ApiBase + request.Endpoint)); + if (request.Method != HttpMethod.Get) + message.Content = new StringContent(JsonConvert.SerializeObject(request), + Encoding.UTF8, CONTENT_TYPE); using (var client = new HttpClient()) { diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs new file mode 100644 index 0000000..2ed3151 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs @@ -0,0 +1,12 @@ +using System; +using Transbank.Webpay.Common; +using System.Net.Http; + +namespace Transbank.Webpay.WebpayPlus.Requests +{ + public class StatusRequest : BaseRequest + { + internal StatusRequest(string token) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Get) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/StatusResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/StatusResponse.cs new file mode 100644 index 0000000..59b8958 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Responses/StatusResponse.cs @@ -0,0 +1,5 @@ +using System; +namespace Transbank.Webpay.WebpayPlus.Responses +{ + public class StatusResponse : CommitResponse { } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs index 8d188b8..736bc25 100644 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -48,5 +48,18 @@ public static RefundResponse Refund(string token, decimal amount, Options option return JsonConvert.DeserializeObject(response); } + + public static StatusResponse Status(string token) + { + return Status(token, WebpayPlus.DefaultOptions()); + } + + public static StatusResponse Status(string token, Options options) + { + var statusRequest = new StatusRequest(token); + var response = RequestService.Perform(statusRequest, options); + + return JsonConvert.DeserializeObject(response); + } } } From a1579a4ac76922ee323da54431f959be726ef74b Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Tue, 2 Jul 2019 19:04:56 -0400 Subject: [PATCH 010/120] Return rest api error as exception --- Transbank/WebpayRest/Common/RequestService.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Transbank/WebpayRest/Common/RequestService.cs b/Transbank/WebpayRest/Common/RequestService.cs index a6d8ba2..d691dfe 100644 --- a/Transbank/WebpayRest/Common/RequestService.cs +++ b/Transbank/WebpayRest/Common/RequestService.cs @@ -1,8 +1,11 @@ using System; +using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Transbank.Onepay.Exceptions; namespace Transbank.Webpay.Common { @@ -28,12 +31,16 @@ public static string Perform(BaseRequest request, Options options) using (var client = new HttpClient()) { AddRequiredHeaders(client, options.CommerceCode, options.ApiKey); - var response = client.SendAsync(message).ConfigureAwait(false) .GetAwaiter().GetResult(); - response.EnsureSuccessStatusCode(); var jsonResponse = response.Content.ReadAsStringAsync() .ConfigureAwait(false).GetAwaiter().GetResult(); + if (!response.IsSuccessStatusCode) + { + var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonResponse); + throw new TransbankException(-1, $"Error message: {jsonObject.Value("error_message")}"); + } + return jsonResponse; } } From abaeb909db01abc5cf360f794e9704a5c2ee15f5 Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Tue, 2 Jul 2019 19:05:04 -0400 Subject: [PATCH 011/120] add plus transaction capture --- .../WebpayPlus/Requests/CaptureRequest.cs | 34 +++++++++++++++++++ .../WebpayPlus/Responses/CaptureResponse.cs | 34 +++++++++++++++++++ .../WebpayRest/WebpayPlus/Transaction.cs | 21 ++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs new file mode 100644 index 0000000..e288d82 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs @@ -0,0 +1,34 @@ +using System; +using System.Net.Http; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.WebpayPlus.Requests +{ + internal class CaptureRequest : BaseRequest + { + [JsonProperty("buy_order")] + internal string BuyOrder { get; set; } + + [JsonProperty("authorization_code")] + internal string AuthorizationCode { get; set; } + + [JsonProperty("capture_amount")] + internal decimal CaptureAmount { get; set; } + + [JsonProperty("commerce_code", NullValueHandling = NullValueHandling.Ignore)] + internal string CommerceCode { get; set; } + + internal CaptureRequest(string token, string buyOrder, string authorizationCode, + decimal captureAmount, string commerceCode = null) : + base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/capture", HttpMethod.Put) + { + BuyOrder = buyOrder; + AuthorizationCode = authorizationCode; + CaptureAmount = captureAmount; + CommerceCode = commerceCode; + } + } +} + + diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs new file mode 100644 index 0000000..f8109e1 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.WebpayPlus.Responses +{ + public class CaptureResponse + { + [JsonProperty("Token")] + public string Token { get; set; } + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + [JsonProperty("authorization_date")] + public DateTime AuthorizationDate { get; set; } + [JsonProperty("captured_amount")] + public decimal CapturedAmount { get; set; } + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + + public override string ToString() + { + var properties = new List(); + foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) + { + string name = descriptor.Name; + object value = descriptor.GetValue(this); + properties.Add($"{name}={value}"); + } + return String.Join(", ", properties); + } + } +} \ No newline at end of file diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs index 736bc25..3456f23 100644 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -61,5 +61,26 @@ public static StatusResponse Status(string token, Options options) return JsonConvert.DeserializeObject(response); } + + public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, + decimal captureAmount, string commerceCode = null) + { + return Capture(token, buyOrder, authorizationCode, captureAmount, commerceCode, WebpayPlus.DefaultOptions()); + } + + public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, + decimal captureAmount, Options options) + { + return Capture(token, buyOrder, authorizationCode, captureAmount, null, options); + } + + public static CaptureResponse Capture(string token, string buyOrder,string authorizationCode, + decimal captureAmount, string commerceCode, Options options) + { + var captureRequest = new CaptureRequest(token, buyOrder, authorizationCode, captureAmount, commerceCode); + var response = RequestService.Perform(captureRequest, options); + + return JsonConvert.DeserializeObject(response); + } } } From 2423d1e0059aeaafb4407feaf28b747e2da201b1 Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Tue, 2 Jul 2019 19:06:58 -0400 Subject: [PATCH 012/120] Fix capture response token json property --- Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs index f8109e1..fe5ca95 100644 --- a/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs +++ b/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs @@ -8,7 +8,7 @@ namespace Transbank.Webpay.WebpayPlus.Responses { public class CaptureResponse { - [JsonProperty("Token")] + [JsonProperty("token")] public string Token { get; set; } [JsonProperty("authorization_code")] public string AuthorizationCode { get; set; } @@ -31,4 +31,4 @@ public override string ToString() return String.Join(", ", properties); } } -} \ No newline at end of file +} From 79f745e3df6edf126a9cbc9b73605ef1ecb86583 Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Tue, 9 Jul 2019 15:30:12 -0400 Subject: [PATCH 013/120] Add Webpay Plus Mall Create --- .../WebpayRest/Common/TransactionDetail.cs | 24 ++++++++++++++ .../WebpayRest/WebpayPlus/MallTransaction.cs | 25 +++++++++++++++ .../WebpayPlus/Requests/MallCreateRequest.cs | 31 +++++++++++++++++++ .../WebpayPlus/Responses/CreateResponse.cs | 12 +++---- .../Responses/MallCreateResponse.cs | 5 +++ Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs | 12 +++++++ 6 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 Transbank/WebpayRest/Common/TransactionDetail.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/MallTransaction.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/MallCreateResponse.cs diff --git a/Transbank/WebpayRest/Common/TransactionDetail.cs b/Transbank/WebpayRest/Common/TransactionDetail.cs new file mode 100644 index 0000000..3f1f1d0 --- /dev/null +++ b/Transbank/WebpayRest/Common/TransactionDetail.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Newtonsoft.Json; + +namespace Transbank.Webpay.Common +{ + public class TransactionDetail + { + [JsonProperty("amount")] + public decimal Amount { get; set; } + [JsonProperty("commerce_code")] + public string CommerceCode { get; set; } + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + public TransactionDetail(decimal amount, string commerceCode, string buyOrder) + { + Amount = amount; + CommerceCode = commerceCode; + BuyOrder = buyOrder; + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs new file mode 100644 index 0000000..d0696e6 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; +using Transbank.Webpay.Common; +using Transbank.Webpay.WebpayPlus.Requests; +using Transbank.Webpay.WebpayPlus.Responses; + +namespace Transbank.Webpay.WebpayPlus +{ + public class MallTransaction + { + public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, List transactions) + { + return Create(buyOrder, sessionId, returnUrl, transactions, WebpayPlus.DefaultOptions()); + } + + public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, List transactions, Options options) + { + var mallCreateRequest = new MallCreateRequest(buyOrder, sessionId, returnUrl, transactions); + var response = RequestService.Perform(mallCreateRequest, options); + + return JsonConvert.DeserializeObject(response); + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs new file mode 100644 index 0000000..eb75f70 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Net.Http; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.WebpayPlus.Requests +{ + internal class MallCreateRequest : BaseRequest + { + [JsonProperty("buy_order")] + internal string BuyOrder { get; set; } + [JsonProperty("session_id")] + internal string SessionId { get; set; } + [JsonProperty("return_url")] + internal string ReturnUrl { get; set; } + [JsonProperty("details", ItemReferenceLoopHandling = ReferenceLoopHandling.Serialize)] + internal List Transactions { get; set; } + + internal MallCreateRequest(string buyOrder, string sessionId, string returnUrl, + List transactions) : base( + "/rswebpaytransaction/api/webpay/v1.0/transactions", HttpMethod.Post) + { + BuyOrder = buyOrder; + SessionId = sessionId; + ReturnUrl = returnUrl; + Transactions = transactions; + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs index c9fbab2..a3e1e38 100644 --- a/Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs +++ b/Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs @@ -1,16 +1,14 @@ using System; +using Newtonsoft.Json; + namespace Transbank.Webpay.WebpayPlus.Responses { public class CreateResponse { + [JsonProperty("token")] public string Token { get; private set; } - public string Url { get; private set; } - - public CreateResponse(string token, string url) - { - Token = token; - Url = url; - } + [JsonProperty("url")] + public string Url { get; private set; } public override string ToString() { diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/MallCreateResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/MallCreateResponse.cs new file mode 100644 index 0000000..9e51d70 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Responses/MallCreateResponse.cs @@ -0,0 +1,5 @@ +using System; +namespace Transbank.Webpay.WebpayPlus.Responses +{ + public class MallCreateResponse : CreateResponse {} +} diff --git a/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs b/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs index 5e6bdb7..240f142 100644 --- a/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs +++ b/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs @@ -36,5 +36,17 @@ public static Options DefaultOptions() { return new Options(CommerceCode, ApiKey, IntegrationType); } + + public static void ConfigureForTesting() + { + CommerceCode = "597055555532"; + ApiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + } + + public static void ConfigureMallForTesting() + { + CommerceCode = "597055555535"; + ApiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + } } } From a4bd2b26c5ceba403c687b8413de4e95564c2f46 Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 9 Jul 2019 15:39:15 -0400 Subject: [PATCH 014/120] Add Oneclick Mall Inscription Start --- Transbank/Transbank.csproj | 2 + Transbank/WebpayRest/Oneclick/Inscription.cs | 25 +++++++++++ Transbank/WebpayRest/Oneclick/Oneclick.cs | 42 +++++++++++++++++++ .../Oneclick/Request/StartRequest.cs | 32 ++++++++++++++ .../Oneclick/Response/StartResponse.cs | 24 +++++++++++ 5 files changed, 125 insertions(+) create mode 100644 Transbank/WebpayRest/Oneclick/Inscription.cs create mode 100644 Transbank/WebpayRest/Oneclick/Oneclick.cs create mode 100644 Transbank/WebpayRest/Oneclick/Request/StartRequest.cs create mode 100644 Transbank/WebpayRest/Oneclick/Response/StartResponse.cs diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 625d30d..1d2dcc7 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -119,6 +119,8 @@ + + diff --git a/Transbank/WebpayRest/Oneclick/Inscription.cs b/Transbank/WebpayRest/Oneclick/Inscription.cs new file mode 100644 index 0000000..aec972d --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Inscription.cs @@ -0,0 +1,25 @@ +using Transbank.Webpay.Oneclick.Requests; +using Transbank.Webpay.Common; +using Transbank.Webpay.Oneclick.Responses; +using Newtonsoft.Json; + +namespace Transbank.Webpay.Oneclick +{ + public static class Inscription + { + public static StartResponse Start(string userName, string email, + string responseUrl) + { + return Start(userName, email, responseUrl, Oneclick.DefaultOptions()); + } + + public static StartResponse Start(string userName, string email, + string responseUrl, Options options) + { + var startRequest = new StartRequest(userName, email, responseUrl); + var response = RequestService.Perform(startRequest, options); + + return JsonConvert.DeserializeObject(response); + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Oneclick.cs b/Transbank/WebpayRest/Oneclick/Oneclick.cs new file mode 100644 index 0000000..1194a62 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Oneclick.cs @@ -0,0 +1,42 @@ +using System; +using Transbank.Webpay.Common; +namespace Transbank.Webpay.Oneclick +{ + public static class Oneclick + { + private static string _commerceCode = "597055555541"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + private static string[] _storeCodes = { "597055555542", "597055555543" }; + + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs b/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs new file mode 100644 index 0000000..db3f4ac --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs @@ -0,0 +1,32 @@ +using Newtonsoft.Json; +using Transbank.Webpay.Common; +using System.Net.Http; + +namespace Transbank.Webpay.Oneclick.Requests +{ + internal class StartRequest : BaseRequest + { + [JsonProperty("username")] + public string UserName { get; set; } + + [JsonProperty("email")] + public string Email { get; set; } + + [JsonProperty("response_url")] + public string ResponseUrl { get; set; } + + public override string ToString() + { + return $"UserName={UserName}, Email={Email}, " + + $"RsponseUrl={ResponseUrl}"; + } + + internal StartRequest(string userName, string email, string responseUrl) + : base("/rswebpaytransaction/api/oneclick/v1.0/inscriptions", HttpMethod.Post) + { + UserName = userName; + Email = email; + ResponseUrl = responseUrl; + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs b/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs new file mode 100644 index 0000000..09f3346 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs @@ -0,0 +1,24 @@ +using Transbank.Webpay.Common; +using Newtonsoft.Json; + +namespace Transbank.Webpay.Oneclick.Responses +{ + public class StartResponse + { + [JsonProperty("token")] + public string Token { get; private set; } + [JsonProperty("url_webpay")] + public string Url { get; private set; } + + public StartResponse(string token, string url) + { + Token = token; + Url = url; + } + + public override string ToString() + { + return $"Token={Token}, Url={Url}"; + } + } +} From d451ede93c742d5a956ca22ea832db7f7e014137 Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Tue, 9 Jul 2019 15:44:00 -0400 Subject: [PATCH 015/120] Add Integration Type to configuration methods --- Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs b/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs index 240f142..d6e0fdb 100644 --- a/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs +++ b/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs @@ -1,4 +1,4 @@ -using System; +using System; using Transbank.Webpay.Common; namespace Transbank.Webpay.WebpayPlus { @@ -41,12 +41,14 @@ public static void ConfigureForTesting() { CommerceCode = "597055555532"; ApiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + IntegrationType = WebpayIntegrationType.Test; } public static void ConfigureMallForTesting() { CommerceCode = "597055555535"; ApiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + IntegrationType = WebpayIntegrationType.Test; } } } From 18f368df68c519398d09e0080687804453431f1a Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Tue, 9 Jul 2019 15:59:58 -0400 Subject: [PATCH 016/120] Add deferred configuration for testing --- Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs b/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs index d6e0fdb..4cd2e96 100644 --- a/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs +++ b/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs @@ -1,4 +1,4 @@ -using System; +using System; using Transbank.Webpay.Common; namespace Transbank.Webpay.WebpayPlus { @@ -44,6 +44,13 @@ public static void ConfigureForTesting() IntegrationType = WebpayIntegrationType.Test; } + public static void ConfigureDeferredForTesting() + { + CommerceCode = "597055555540"; + ApiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + IntegrationType = WebpayIntegrationType.Test; + } + public static void ConfigureMallForTesting() { CommerceCode = "597055555535"; From fca01df8f097669a81a1a1fbf8808ac41d84a2b2 Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Tue, 2 Jul 2019 19:04:56 -0400 Subject: [PATCH 017/120] Return rest api error as exception --- Transbank/WebpayRest/Common/RequestService.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Transbank/WebpayRest/Common/RequestService.cs b/Transbank/WebpayRest/Common/RequestService.cs index a6d8ba2..d691dfe 100644 --- a/Transbank/WebpayRest/Common/RequestService.cs +++ b/Transbank/WebpayRest/Common/RequestService.cs @@ -1,8 +1,11 @@ using System; +using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Transbank.Onepay.Exceptions; namespace Transbank.Webpay.Common { @@ -28,12 +31,16 @@ public static string Perform(BaseRequest request, Options options) using (var client = new HttpClient()) { AddRequiredHeaders(client, options.CommerceCode, options.ApiKey); - var response = client.SendAsync(message).ConfigureAwait(false) .GetAwaiter().GetResult(); - response.EnsureSuccessStatusCode(); var jsonResponse = response.Content.ReadAsStringAsync() .ConfigureAwait(false).GetAwaiter().GetResult(); + if (!response.IsSuccessStatusCode) + { + var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonResponse); + throw new TransbankException(-1, $"Error message: {jsonObject.Value("error_message")}"); + } + return jsonResponse; } } From f56b68cd1aba4ff7084503a2c3a5d6d9f5d26b4f Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Tue, 2 Jul 2019 19:05:04 -0400 Subject: [PATCH 018/120] add plus transaction capture --- .../WebpayPlus/Requests/CaptureRequest.cs | 34 +++++++++++++++++++ .../WebpayPlus/Responses/CaptureResponse.cs | 34 +++++++++++++++++++ .../WebpayRest/WebpayPlus/Transaction.cs | 21 ++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs new file mode 100644 index 0000000..e288d82 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs @@ -0,0 +1,34 @@ +using System; +using System.Net.Http; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.WebpayPlus.Requests +{ + internal class CaptureRequest : BaseRequest + { + [JsonProperty("buy_order")] + internal string BuyOrder { get; set; } + + [JsonProperty("authorization_code")] + internal string AuthorizationCode { get; set; } + + [JsonProperty("capture_amount")] + internal decimal CaptureAmount { get; set; } + + [JsonProperty("commerce_code", NullValueHandling = NullValueHandling.Ignore)] + internal string CommerceCode { get; set; } + + internal CaptureRequest(string token, string buyOrder, string authorizationCode, + decimal captureAmount, string commerceCode = null) : + base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/capture", HttpMethod.Put) + { + BuyOrder = buyOrder; + AuthorizationCode = authorizationCode; + CaptureAmount = captureAmount; + CommerceCode = commerceCode; + } + } +} + + diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs new file mode 100644 index 0000000..f8109e1 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.WebpayPlus.Responses +{ + public class CaptureResponse + { + [JsonProperty("Token")] + public string Token { get; set; } + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + [JsonProperty("authorization_date")] + public DateTime AuthorizationDate { get; set; } + [JsonProperty("captured_amount")] + public decimal CapturedAmount { get; set; } + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + + public override string ToString() + { + var properties = new List(); + foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) + { + string name = descriptor.Name; + object value = descriptor.GetValue(this); + properties.Add($"{name}={value}"); + } + return String.Join(", ", properties); + } + } +} \ No newline at end of file diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs index 736bc25..3456f23 100644 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -61,5 +61,26 @@ public static StatusResponse Status(string token, Options options) return JsonConvert.DeserializeObject(response); } + + public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, + decimal captureAmount, string commerceCode = null) + { + return Capture(token, buyOrder, authorizationCode, captureAmount, commerceCode, WebpayPlus.DefaultOptions()); + } + + public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, + decimal captureAmount, Options options) + { + return Capture(token, buyOrder, authorizationCode, captureAmount, null, options); + } + + public static CaptureResponse Capture(string token, string buyOrder,string authorizationCode, + decimal captureAmount, string commerceCode, Options options) + { + var captureRequest = new CaptureRequest(token, buyOrder, authorizationCode, captureAmount, commerceCode); + var response = RequestService.Perform(captureRequest, options); + + return JsonConvert.DeserializeObject(response); + } } } From af122399c68992e39f9677e9fec7dc456bb31f4b Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Tue, 2 Jul 2019 19:06:58 -0400 Subject: [PATCH 019/120] Fix capture response token json property --- Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs index f8109e1..fe5ca95 100644 --- a/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs +++ b/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs @@ -8,7 +8,7 @@ namespace Transbank.Webpay.WebpayPlus.Responses { public class CaptureResponse { - [JsonProperty("Token")] + [JsonProperty("token")] public string Token { get; set; } [JsonProperty("authorization_code")] public string AuthorizationCode { get; set; } @@ -31,4 +31,4 @@ public override string ToString() return String.Join(", ", properties); } } -} \ No newline at end of file +} From 4207578168ac1462de0e55a5ca11171012fdde17 Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 11 Jul 2019 09:15:07 -0400 Subject: [PATCH 020/120] Improve toString function --- Transbank/WebpayRest/Oneclick/Inscription.cs | 8 ++++---- Transbank/WebpayRest/Oneclick/Request/StartRequest.cs | 2 +- Transbank/WebpayRest/Oneclick/Response/StartResponse.cs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Inscription.cs b/Transbank/WebpayRest/Oneclick/Inscription.cs index aec972d..7dd4385 100644 --- a/Transbank/WebpayRest/Oneclick/Inscription.cs +++ b/Transbank/WebpayRest/Oneclick/Inscription.cs @@ -1,14 +1,14 @@ -using Transbank.Webpay.Oneclick.Requests; +using System; +using Newtonsoft.Json; using Transbank.Webpay.Common; +using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.Oneclick.Responses; -using Newtonsoft.Json; namespace Transbank.Webpay.Oneclick { public static class Inscription { - public static StartResponse Start(string userName, string email, - string responseUrl) + public static StartResponse Start(string userName, string email, string responseUrl) { return Start(userName, email, responseUrl, Oneclick.DefaultOptions()); } diff --git a/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs b/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs index db3f4ac..d87501a 100644 --- a/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs @@ -17,7 +17,7 @@ internal class StartRequest : BaseRequest public override string ToString() { - return $"UserName={UserName}, Email={Email}, " + + return $"UserName={UserName},\nEmail={Email},\n" + $"RsponseUrl={ResponseUrl}"; } diff --git a/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs b/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs index 09f3346..9dd5cf2 100644 --- a/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs @@ -18,7 +18,7 @@ public StartResponse(string token, string url) public override string ToString() { - return $"Token={Token}, Url={Url}"; + return $"Token={Token},\nUrl={Url}"; } } } From c7fe7dd192f4f07a446766602632dbc8a3182b5d Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 11 Jul 2019 09:16:42 -0400 Subject: [PATCH 021/120] Add Finish Inscription --- Transbank/WebpayRest/Oneclick/Inscription.cs | 13 +++++++ .../Oneclick/Request/FinishRequest.cs | 11 ++++++ .../Oneclick/Response/FinishResponse.cs | 38 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 Transbank/WebpayRest/Oneclick/Request/FinishRequest.cs create mode 100644 Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs diff --git a/Transbank/WebpayRest/Oneclick/Inscription.cs b/Transbank/WebpayRest/Oneclick/Inscription.cs index 7dd4385..67ba2a4 100644 --- a/Transbank/WebpayRest/Oneclick/Inscription.cs +++ b/Transbank/WebpayRest/Oneclick/Inscription.cs @@ -21,5 +21,18 @@ public static StartResponse Start(string userName, string email, return JsonConvert.DeserializeObject(response); } + + public static FinishResponse Finish(string token) + { + return Finish(token, Oneclick.DefaultOptions()); + } + + public static FinishResponse Finish(string token, Options options) + { + var finishRequest = new FinishRequest(token); + var response = RequestService.Perform(finishRequest, options); + + return JsonConvert.DeserializeObject(response); + } } } diff --git a/Transbank/WebpayRest/Oneclick/Request/FinishRequest.cs b/Transbank/WebpayRest/Oneclick/Request/FinishRequest.cs new file mode 100644 index 0000000..1d4d6d6 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Request/FinishRequest.cs @@ -0,0 +1,11 @@ +using System.Net.Http; +using Transbank.Webpay.Common; +namespace Transbank.Webpay.Oneclick.Requests +{ + internal class FinishRequest : BaseRequest + { + internal FinishRequest(string token) + : base($"/rswebpaytransaction/api/oneclick/v1.0/inscriptions/{token}", + HttpMethod.Put){} + } +} diff --git a/Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs b/Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs new file mode 100644 index 0000000..3136847 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs @@ -0,0 +1,38 @@ +using Transbank.Webpay.Common; +using Newtonsoft.Json; + +namespace Transbank.Webpay.Oneclick.Responses +{ + public class FinishResponse + { + [JsonProperty("response_code")] + public int ResponseCode { get; private set; } + [JsonProperty("tbk_user")] + public string TransbankUser { 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; } + + public FinishResponse(int responseCode, string transbankUser, + string authorizationCode, string creditCardType, string lastFourCardDigits) + { + ResponseCode = responseCode; + TransbankUser = transbankUser; + AuthorizationCode = authorizationCode; + CreditCardType = creditCardType; + LastFourCardDigits = lastFourCardDigits; + } + + public override string ToString() + { + return $"Response Code = {ResponseCode}\n" + + $"Transbank User = {TransbankUser}\n" + + $"Authorization Code = {AuthorizationCode}\n" + + $"Credit Card Type = {CreditCardType}\n" + + $"Last Four Card Digits = {LastFourCardDigits}"; + } + } +} From 3754ce2b00e6897ab39b7d537ca12985a21ab2bc Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Mon, 22 Jul 2019 15:07:22 -0400 Subject: [PATCH 022/120] Add Plus Mall Transaction commit --- .../WebpayRest/WebpayPlus/MallTransaction.cs | 15 +++- .../WebpayPlus/Requests/MallCommitRequest.cs | 12 +++ .../Responses/MallCommitResponse.cs | 80 +++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/MallCommitResponse.cs diff --git a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs index d0696e6..646394b 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs @@ -7,7 +7,7 @@ namespace Transbank.Webpay.WebpayPlus { - public class MallTransaction + public static class MallTransaction { public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, List transactions) { @@ -21,5 +21,18 @@ public static MallCreateResponse Create(string buyOrder, string sessionId, strin return JsonConvert.DeserializeObject(response); } + + public static MallCommitResponse Commit(string token) + { + return Commit(token, WebpayPlus.DefaultOptions()); + } + + public static MallCommitResponse Commit(string token, Options options) + { + var mallCommitRequest = new MallCommitRequest(token); + var response = RequestService.Perform(mallCommitRequest, options); + + return JsonConvert.DeserializeObject(response); + } } } diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs new file mode 100644 index 0000000..e94ace3 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Net.Http; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.WebpayPlus.Requests +{ + public class MallCommitRequest : BaseRequest + { + public MallCommitRequest(string token) : + base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/MallCommitResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/MallCommitResponse.cs new file mode 100644 index 0000000..fe1156e --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Responses/MallCommitResponse.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.WebpayPlus.Responses +{ + public class MallCommitResponse + { + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + [JsonProperty("session_id")] + public string SessionId { get; set; } + [JsonProperty("vci")] + public string Vci { get; set; } + [JsonProperty("card_detail")] + public CardDetail CardDetail { get; set; } + [JsonProperty("accounting_date")] + public string AccountingDate { get; set; } + [JsonProperty("transaction_date")] + public DateTime TransactionDate { get; set; } + [JsonProperty("details")] + public List Details { get; set; } + + public override string ToString() + { + var properties = new List(); + foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) + { + string name = descriptor.Name; + object value = null; + System.Diagnostics.Debug.WriteLine($"{name}={value}"); + if (name == "Details") + { + value = string.Join(", ", (List)descriptor.GetValue(this)); + value = $" {{{value}}} "; + } else + { + value = descriptor.GetValue(this); + } + properties.Add($"{name}={value}"); + } + return String.Join(", ", properties); + } + + public class Detail + { + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + [JsonProperty("commerce_code")] + public string CommerceCode { get; set; } + [JsonProperty("amount")] + public decimal Amount { get; set; } + [JsonProperty("status")] + public string Status { get; set; } + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + [JsonProperty("payment_type_code")] + public string PaymentTypeCode { get; set; } + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; set; } + + public override string ToString() + { + var properties = new List(); + foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) + { + string name = descriptor.Name; + object value = descriptor.GetValue(this); + properties.Add($"{name}={value}"); + } + return String.Join(", ", properties); + } + } + } + +} From 69071e49c39688de983d07dd3a7da8e4b15a6403 Mon Sep 17 00:00:00 2001 From: afiebig Date: Mon, 22 Jul 2019 17:04:53 -0400 Subject: [PATCH 023/120] Add Payment Request and Response --- .../WebpayRest/Common/DateFormatConverter.cs | 12 +++++ Transbank/WebpayRest/Common/PaymentRequest.cs | 34 ++++++++++++ .../WebpayRest/Common/PaymentResponse.cs | 37 +++++++++++++ .../Oneclick/Request/AuthorizeRequest.cs | 37 +++++++++++++ .../Oneclick/Response/AuthorizeResponse.cs | 54 +++++++++++++++++++ 5 files changed, 174 insertions(+) create mode 100644 Transbank/WebpayRest/Common/DateFormatConverter.cs create mode 100644 Transbank/WebpayRest/Common/PaymentRequest.cs create mode 100644 Transbank/WebpayRest/Common/PaymentResponse.cs create mode 100644 Transbank/WebpayRest/Oneclick/Request/AuthorizeRequest.cs create mode 100644 Transbank/WebpayRest/Oneclick/Response/AuthorizeResponse.cs diff --git a/Transbank/WebpayRest/Common/DateFormatConverter.cs b/Transbank/WebpayRest/Common/DateFormatConverter.cs new file mode 100644 index 0000000..7289d75 --- /dev/null +++ b/Transbank/WebpayRest/Common/DateFormatConverter.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json.Converters; + +namespace Transbank.Webpay.Common +{ + public class DateFormatConverter : IsoDateTimeConverter + { + public DateFormatConverter(string format) + { + DateTimeFormat = format; + } + } +} diff --git a/Transbank/WebpayRest/Common/PaymentRequest.cs b/Transbank/WebpayRest/Common/PaymentRequest.cs new file mode 100644 index 0000000..6f79a0c --- /dev/null +++ b/Transbank/WebpayRest/Common/PaymentRequest.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.Common +{ + public class PaymentRequest + { + [JsonProperty("commerce_code")] + public string ComerceCode { get; private set; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; private set; } + + [JsonProperty("amount")] + public int Amount { get; private set; } + + [JsonProperty("installments_number")] + public int Installments { get; private set; } + + public PaymentRequest (string comerceCode, string buyOrder, int amount) + { + ComerceCode = comerceCode; + BuyOrder = buyOrder; + Amount = amount; + } + + public override string ToString() + { + return $"Comerce Code= {ComerceCode}\n" + + $"Buy Order= {BuyOrder}\n" + + $"Amount= {Amount}\n" + + $"Installments= {Installments}"; + } + } +} \ No newline at end of file diff --git a/Transbank/WebpayRest/Common/PaymentResponse.cs b/Transbank/WebpayRest/Common/PaymentResponse.cs new file mode 100644 index 0000000..b51ae62 --- /dev/null +++ b/Transbank/WebpayRest/Common/PaymentResponse.cs @@ -0,0 +1,37 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.Common +{ + public class PaymentResponse : PaymentRequest + { + [JsonProperty("authorization_code")] + public int AuthorizationCode { get; private set; } + + [JsonProperty("payment_type_code")] + public string PaymentTypeCode { get; private set; } + + [JsonProperty("response_code")] + public int ResponseCode { get; private set; } + + [JsonProperty("installments_amount")] + public int InstallmentsAmount { get; private set; } + + public PaymentResponse (string comerceCode, string buyOrder, int ammount, int autorizationCode, + string paymentTypeCode, int responseCode, int installmentsAmmount) : base(comerceCode, buyOrder, ammount) + { + AuthorizationCode = autorizationCode; + PaymentTypeCode = paymentTypeCode; + ResponseCode = responseCode; + InstallmentsAmount = installmentsAmmount; + } + + public override string ToString() + { + return base.ToString() + "\n" + + $"InstallmentsAmount= {InstallmentsAmount}\n" + + $"AuthorizationCode= {AuthorizationCode}\n" + + $"PaymentTypeCode= {PaymentTypeCode}\n" + + $"ResponseCode= {ResponseCode}\n"; + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Request/AuthorizeRequest.cs b/Transbank/WebpayRest/Oneclick/Request/AuthorizeRequest.cs new file mode 100644 index 0000000..77e89cc --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Request/AuthorizeRequest.cs @@ -0,0 +1,37 @@ +using System.Net.Http; +using System.Collections.Generic; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.Oneclick.Requests +{ + internal class AuthorizeRequest : BaseRequest + { + + [JsonProperty("username")] + public string UserName { get; set; } + + [JsonProperty("tbk_user")] + public string TBKUser { get; set; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + [JsonProperty("details")] + public List Details { get; set; } + + public override string ToString() + { + return $"UserName={UserName}"; + } + + internal AuthorizeRequest(string userName, string tbkUser, string buyOrder, List details) + : base("/rswebpaytransaction/api/oneclick/v1.0/transactions", HttpMethod.Post) + { + UserName = userName; + TBKUser = tbkUser; + BuyOrder = buyOrder; + Details = details; + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Response/AuthorizeResponse.cs b/Transbank/WebpayRest/Oneclick/Response/AuthorizeResponse.cs new file mode 100644 index 0000000..c8611e9 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Response/AuthorizeResponse.cs @@ -0,0 +1,54 @@ +using System; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.Oneclick.Responses +{ + public class AuthorizeResponse + { + [JsonProperty("buy_order")] + public string BuyOrder { get; private set; } + + [JsonProperty("session_id")] + public string SessionId { get; private set; } + + [JsonProperty("card_number")] + public string CardNumber { get; private set; } + + [JsonProperty("expiration_date")] + [JsonConverter(typeof(DateFormatConverter), "yyyy-mm-ddd")] + public DateTime ExpirationDate { get; private set; } + + [JsonProperty("accounting_date")] + public DateTime AccountingDate { get; private set; } + + [JsonProperty("transaction_date")] + public DateTime TransactionDate { get; private set; } + + [JsonProperty("details")] + public PaymentResponse Details{get; private set; } + + public AuthorizeResponse(string buyOrder, string sessionId, string cardNumber, DateTime expirationDate, + DateTime accountingDate, DateTime transactionDate, PaymentResponse details) + { + BuyOrder = buyOrder; + SessionId = sessionId; + CardNumber = cardNumber; + ExpirationDate = expirationDate; + AccountingDate = accountingDate; + TransactionDate = transactionDate; + Details = details; + } + + 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()}"; + } + } +} From ca7d8edd125c0073f970229f4a4ed4b0430b8baf Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Mon, 22 Jul 2019 17:45:43 -0400 Subject: [PATCH 024/120] Put options into Transaction classes --- .../WebpayPlus/DeferredTransaction.cs | 107 ++++++++++++++++++ .../WebpayRest/WebpayPlus/MallTransaction.cs | 37 +++++- .../WebpayRest/WebpayPlus/Transaction.cs | 62 ++++++---- Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs | 61 ---------- .../WebpayRest/WebpayPlus/OptionsTest.cs | 2 +- 5 files changed, 180 insertions(+), 89 deletions(-) create mode 100644 Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs diff --git a/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs new file mode 100644 index 0000000..f52d271 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs @@ -0,0 +1,107 @@ +using System; +using Newtonsoft.Json; +using Transbank.Webpay.Common; +using Transbank.Webpay.WebpayPlus.Requests; +using Transbank.Webpay.WebpayPlus.Responses; + +namespace Transbank.Webpay.WebpayPlus +{ + public static class DeferredTransaction + { + private static string _commerceCode = "597055555540"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + + public static CreateResponse Create(string buyOrder, string sessionId, + decimal amount, string returnUrl) + { + return Create(buyOrder, sessionId, amount, returnUrl, DefaultOptions()); + } + + public static CreateResponse Create(string buyOrder, string sessionId, + decimal amount, string returnUrl, Options options) + { + return Transaction.Create(buyOrder, sessionId, amount, returnUrl, options); + } + + public static CommitResponse Commit(string token) + { + return Commit(token, DefaultOptions()); + } + + public static CommitResponse Commit(string token, Options options) + { + return Transaction.Commit(token, options); + } + + public static RefundResponse Refund(string token, decimal amount) + { + return Refund(token, amount, DefaultOptions()); + } + + public static RefundResponse Refund(string token, decimal amount, Options options) + { + return Transaction.Refund(token, amount, options); + } + + public static StatusResponse Status(string token) + { + return Status(token, DefaultOptions()); + } + + public static StatusResponse Status(string token, Options options) + { + return Transaction.Status(token, options); + } + + public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, + decimal captureAmount, string commerceCode = null) + { + return Capture(token, buyOrder, authorizationCode, captureAmount, commerceCode, DefaultOptions()); + } + + public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, + decimal captureAmount, Options options) + { + return Capture(token, buyOrder, authorizationCode, captureAmount, null, options); + } + + public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, + decimal captureAmount, string commerceCode, Options options) + { + var captureRequest = new CaptureRequest(token, buyOrder, authorizationCode, captureAmount, commerceCode); + var response = RequestService.Perform(captureRequest, options); + + return JsonConvert.DeserializeObject(response); + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs index 646394b..6ff9374 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs @@ -9,9 +9,42 @@ namespace Transbank.Webpay.WebpayPlus { public static class MallTransaction { + private static string _commerceCode = "597055555535"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, List transactions) { - return Create(buyOrder, sessionId, returnUrl, transactions, WebpayPlus.DefaultOptions()); + return Create(buyOrder, sessionId, returnUrl, transactions, DefaultOptions()); } public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, List transactions, Options options) @@ -24,7 +57,7 @@ public static MallCreateResponse Create(string buyOrder, string sessionId, strin public static MallCommitResponse Commit(string token) { - return Commit(token, WebpayPlus.DefaultOptions()); + return Commit(token, DefaultOptions()); } public static MallCommitResponse Commit(string token, Options options) diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs index 3456f23..aebcf7a 100644 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -8,10 +8,43 @@ namespace Transbank.Webpay.WebpayPlus { public static class Transaction { + private static string _commerceCode = "597055555532"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + public static CreateResponse Create(string buyOrder, string sessionId, decimal amount, string returnUrl) { - return Create(buyOrder, sessionId, amount, returnUrl, WebpayPlus.DefaultOptions()); + return Create(buyOrder, sessionId, amount, returnUrl, DefaultOptions()); } public static CreateResponse Create(string buyOrder, string sessionId, @@ -25,7 +58,7 @@ public static CreateResponse Create(string buyOrder, string sessionId, public static CommitResponse Commit(string token) { - return Commit(token, WebpayPlus.DefaultOptions()); + return Commit(token, DefaultOptions()); } public static CommitResponse Commit(string token, Options options) @@ -38,7 +71,7 @@ public static CommitResponse Commit(string token, Options options) public static RefundResponse Refund(string token, decimal amount) { - return Refund(token, amount, WebpayPlus.DefaultOptions()); + return Refund(token, amount, DefaultOptions()); } public static RefundResponse Refund(string token, decimal amount, Options options) @@ -51,7 +84,7 @@ public static RefundResponse Refund(string token, decimal amount, Options option public static StatusResponse Status(string token) { - return Status(token, WebpayPlus.DefaultOptions()); + return Status(token, DefaultOptions()); } public static StatusResponse Status(string token, Options options) @@ -61,26 +94,5 @@ public static StatusResponse Status(string token, Options options) return JsonConvert.DeserializeObject(response); } - - public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, - decimal captureAmount, string commerceCode = null) - { - return Capture(token, buyOrder, authorizationCode, captureAmount, commerceCode, WebpayPlus.DefaultOptions()); - } - - public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, - decimal captureAmount, Options options) - { - return Capture(token, buyOrder, authorizationCode, captureAmount, null, options); - } - - public static CaptureResponse Capture(string token, string buyOrder,string authorizationCode, - decimal captureAmount, string commerceCode, Options options) - { - var captureRequest = new CaptureRequest(token, buyOrder, authorizationCode, captureAmount, commerceCode); - var response = RequestService.Perform(captureRequest, options); - - return JsonConvert.DeserializeObject(response); - } } } diff --git a/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs b/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs deleted file mode 100644 index 4cd2e96..0000000 --- a/Transbank/WebpayRest/WebpayPlus/WebpayPlus.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using Transbank.Webpay.Common; -namespace Transbank.Webpay.WebpayPlus -{ - public static class WebpayPlus - { - private static string _commerceCode = "597055555532"; - private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; - - public static string CommerceCode - { - get => _commerceCode; - set => _commerceCode = value ?? throw new ArgumentNullException( - nameof(value), "Commerce code can't be null." - ); - } - - public static string ApiKey - { - get => _apiKey; - set => _apiKey = value ?? throw new ArgumentNullException( - nameof(value), "Api Key can't be null." - ); - } - - public static WebpayIntegrationType IntegrationType - { - get => _integrationType; - set => _integrationType = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null." - ); - } - - public static Options DefaultOptions() - { - return new Options(CommerceCode, ApiKey, IntegrationType); - } - - public static void ConfigureForTesting() - { - CommerceCode = "597055555532"; - ApiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - IntegrationType = WebpayIntegrationType.Test; - } - - public static void ConfigureDeferredForTesting() - { - CommerceCode = "597055555540"; - ApiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - IntegrationType = WebpayIntegrationType.Test; - } - - public static void ConfigureMallForTesting() - { - CommerceCode = "597055555535"; - ApiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - IntegrationType = WebpayIntegrationType.Test; - } - } -} diff --git a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs index e66b1bb..1b17d73 100644 --- a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs +++ b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs @@ -10,7 +10,7 @@ public class OptionsTest [TestMethod] public void TestDefaultConfiguration() { - var options = Transbank.Webpay.WebpayPlus.WebpayPlus.DefaultOptions(); + var options = Transbank.Webpay.WebpayPlus.Transaction.DefaultOptions(); Assert.AreEqual("597055555532", options.CommerceCode); Assert.AreEqual("579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C", options.ApiKey); Assert.AreEqual(options.IntegrationType, WebpayIntegrationType.Test); From 3526bd55caed04c97b598f1a5d5dcff44530359e Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 23 Jul 2019 14:44:36 -0400 Subject: [PATCH 025/120] Add Transaction Class --- Transbank/WebpayRest/Oneclick/Transaction.cs | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Transbank/WebpayRest/Oneclick/Transaction.cs diff --git a/Transbank/WebpayRest/Oneclick/Transaction.cs b/Transbank/WebpayRest/Oneclick/Transaction.cs new file mode 100644 index 0000000..7fbb03a --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Transaction.cs @@ -0,0 +1,38 @@ +using System; +using Newtonsoft.Json; +using Transbank.Webpay.Common; +using Transbank.Webpay.Oneclick.Requests; +using Transbank.Webpay.Oneclick.Responses; + +namespace Transbank.Webpay.Oneclick +{ + public static class Transaction + { + public static AuthorizeResponse Authorize(string userName, string email, string responseUrl) + { + return Authorize(userName, email, responseUrl, Oneclick.DefaultOptions()); + } + + public static AuthorizeResponse Authorize(string userName, string email, + string responseUrl, Options options) + { + var startRequest = new StartRequest(userName, email, responseUrl); + var response = RequestService.Perform(startRequest, options); + + return JsonConvert.DeserializeObject(response); + } + + public static FinishResponse Finish(string token) + { + return Finish(token, Oneclick.DefaultOptions()); + } + + public static FinishResponse Finish(string token, Options options) + { + var finishRequest = new FinishRequest(token); + var response = RequestService.Perform(finishRequest, options); + + return JsonConvert.DeserializeObject(response); + } + } +} From 0b76f830b61b5250fedb1cf544eba2098c8b8216 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 24 Jul 2019 08:46:09 -0400 Subject: [PATCH 026/120] Add Delete Inscription classes --- Transbank/WebpayRest/Oneclick/Inscription.cs | 13 ++++++++ .../Oneclick/Request/DeleteRequest.cs | 30 +++++++++++++++++++ .../Oneclick/Response/DeleteResponse.cs | 5 ++++ 3 files changed, 48 insertions(+) create mode 100644 Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs create mode 100644 Transbank/WebpayRest/Oneclick/Response/DeleteResponse.cs diff --git a/Transbank/WebpayRest/Oneclick/Inscription.cs b/Transbank/WebpayRest/Oneclick/Inscription.cs index 67ba2a4..22806f8 100644 --- a/Transbank/WebpayRest/Oneclick/Inscription.cs +++ b/Transbank/WebpayRest/Oneclick/Inscription.cs @@ -34,5 +34,18 @@ public static FinishResponse Finish(string token, Options options) return JsonConvert.DeserializeObject(response); } + + public static DeleteResponse Delete(string userName, string tbkUser) + { + return Delete(userName, tbkUser, Oneclick.DefaultOptions()); + } + + public static DeleteResponse Delete(string userName, string tbkUser, Options options) + { + var deleteRequest = new DeleteRequest(userName, tbkUser); + var response = RequestService.Perform(deleteRequest, options); + + return JsonConvert.DeserializeObject(response); + } } } diff --git a/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs b/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs new file mode 100644 index 0000000..cc307d1 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs @@ -0,0 +1,30 @@ +using System.Net.Http; +using System.Collections.Generic; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.Oneclick.Requests +{ + internal class DeleteRequest : BaseRequest + { + + [JsonProperty("username")] + public string UserName { get; set; } + + [JsonProperty("tbk_user")] + public string TBKUser { get; set; } + + public override string ToString() + { + return $"UserName= {UserName}\n" + + $"TbkUser={TBKUser}"; + } + + internal DeleteRequest(string userName, string tbkUser) + : base("/rswebpaytransaction/api/oneclick/v1.0/transactions", HttpMethod.Delete) + { + UserName = userName; + TBKUser = tbkUser; + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Response/DeleteResponse.cs b/Transbank/WebpayRest/Oneclick/Response/DeleteResponse.cs new file mode 100644 index 0000000..5d2aa64 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Response/DeleteResponse.cs @@ -0,0 +1,5 @@ + +namespace Transbank.Webpay.Oneclick.Responses +{ + public class DeleteResponse{} +} From 6992ddfa1ab9f31f2a6d7770547b739b53579837 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 24 Jul 2019 08:46:31 -0400 Subject: [PATCH 027/120] Fix ToString methods --- Transbank/WebpayRest/Oneclick/Request/AuthorizeRequest.cs | 5 ++++- Transbank/WebpayRest/Oneclick/Request/StartRequest.cs | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Request/AuthorizeRequest.cs b/Transbank/WebpayRest/Oneclick/Request/AuthorizeRequest.cs index 77e89cc..d63eaab 100644 --- a/Transbank/WebpayRest/Oneclick/Request/AuthorizeRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Request/AuthorizeRequest.cs @@ -22,7 +22,10 @@ internal class AuthorizeRequest : BaseRequest public override string ToString() { - return $"UserName={UserName}"; + return $"UserName= {UserName}\n" + + $"TbkUser= {TBKUser}\n" + + $"BuyOrder= {BuyOrder}\n" + + $"Details= {Details.ToString()}\n"; } internal AuthorizeRequest(string userName, string tbkUser, string buyOrder, List details) diff --git a/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs b/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs index d87501a..a52c23f 100644 --- a/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs @@ -17,8 +17,9 @@ internal class StartRequest : BaseRequest public override string ToString() { - return $"UserName={UserName},\nEmail={Email},\n" + - $"RsponseUrl={ResponseUrl}"; + return $"UserName= {UserName}\n" + + $"Email= {Email}\n" + + $"RsponseUrl= {ResponseUrl}"; } internal StartRequest(string userName, string email, string responseUrl) From e45230374e1c1cd7d83c853109461288d66998eb Mon Sep 17 00:00:00 2001 From: afiebig Date: Mon, 29 Jul 2019 15:02:19 -0400 Subject: [PATCH 028/120] Add TransbankException on top level Also, Onepay exceptions extend this class. Had to keep Onepay.TransbankException in order to maintain backwards compatibility --- Transbank/Exceptions/TransbankException.cs | 25 +++++++++++++++++++ .../Onepay/Exceptions/AmountException.cs | 3 +-- .../Exceptions/RefundCreateException.cs | 2 +- .../Onepay/Exceptions/SignatureException.cs | 2 +- .../Exceptions/TransactionCommitException.cs | 2 +- .../Exceptions/TransactionCreateException.cs | 2 +- Transbank/Transbank.csproj | 2 ++ Transbank/WebpayRest/Common/RequestService.cs | 2 +- .../Exception/InscriptionStartException.cs | 10 ++++++++ .../Exceptions/InscriptionStartException.cs | 12 +++++++++ Transbank/WebpayRest/Oneclick/Inscription.cs | 1 + 11 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 Transbank/Exceptions/TransbankException.cs create mode 100644 Transbank/WebpayRest/Oneclick/Exception/InscriptionStartException.cs create mode 100644 Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs diff --git a/Transbank/Exceptions/TransbankException.cs b/Transbank/Exceptions/TransbankException.cs new file mode 100644 index 0000000..764d5c6 --- /dev/null +++ b/Transbank/Exceptions/TransbankException.cs @@ -0,0 +1,25 @@ +using System; + +namespace Transbank.Exceptions +{ + public class TransbankException : Exception + { + public int Code { get; set; } + + public TransbankException() + : base() + { + } + public TransbankException(int code, string message) + : base(message) + { + Code = code; + } + + public TransbankException(int code, string message, Exception inner) + : base(message, inner) + { + Code = code; + } + } +} diff --git a/Transbank/Onepay/Exceptions/AmountException.cs b/Transbank/Onepay/Exceptions/AmountException.cs index ffe1c56..c035bd8 100644 --- a/Transbank/Onepay/Exceptions/AmountException.cs +++ b/Transbank/Onepay/Exceptions/AmountException.cs @@ -1,9 +1,8 @@ using System; - namespace Transbank.Onepay.Exceptions { - public class AmountException : TransbankException + public class AmountException : Transbank.Exceptions.TransbankException { public AmountException() : base() { diff --git a/Transbank/Onepay/Exceptions/RefundCreateException.cs b/Transbank/Onepay/Exceptions/RefundCreateException.cs index f1d903d..8f399b0 100644 --- a/Transbank/Onepay/Exceptions/RefundCreateException.cs +++ b/Transbank/Onepay/Exceptions/RefundCreateException.cs @@ -3,7 +3,7 @@ namespace Transbank.Onepay.Exceptions { - public class RefundCreateException : TransbankException + public class RefundCreateException : Transbank.Exceptions.TransbankException { public RefundCreateException() : base() { diff --git a/Transbank/Onepay/Exceptions/SignatureException.cs b/Transbank/Onepay/Exceptions/SignatureException.cs index 70917c7..f9a83dd 100644 --- a/Transbank/Onepay/Exceptions/SignatureException.cs +++ b/Transbank/Onepay/Exceptions/SignatureException.cs @@ -3,7 +3,7 @@ namespace Transbank.Onepay.Exceptions { - public class SignatureException : TransbankException + public class SignatureException : Transbank.Exceptions.TransbankException { public SignatureException() : base() { diff --git a/Transbank/Onepay/Exceptions/TransactionCommitException.cs b/Transbank/Onepay/Exceptions/TransactionCommitException.cs index 00b8935..a4ea281 100644 --- a/Transbank/Onepay/Exceptions/TransactionCommitException.cs +++ b/Transbank/Onepay/Exceptions/TransactionCommitException.cs @@ -3,7 +3,7 @@ namespace Transbank.Onepay.Exceptions { - public class TransactionCommitException : TransbankException + public class TransactionCommitException : Transbank.Exceptions.TransbankException { public TransactionCommitException() : base() { diff --git a/Transbank/Onepay/Exceptions/TransactionCreateException.cs b/Transbank/Onepay/Exceptions/TransactionCreateException.cs index dc08415..c1819d6 100644 --- a/Transbank/Onepay/Exceptions/TransactionCreateException.cs +++ b/Transbank/Onepay/Exceptions/TransactionCreateException.cs @@ -3,7 +3,7 @@ namespace Transbank.Onepay.Exceptions { - public class TransactionCreateException : TransbankException + public class TransactionCreateException : Transbank.Exceptions.TransbankException { public TransactionCreateException() : base() { diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 1d2dcc7..9d0b836 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -121,6 +121,8 @@ + + diff --git a/Transbank/WebpayRest/Common/RequestService.cs b/Transbank/WebpayRest/Common/RequestService.cs index d691dfe..21f0970 100644 --- a/Transbank/WebpayRest/Common/RequestService.cs +++ b/Transbank/WebpayRest/Common/RequestService.cs @@ -5,7 +5,7 @@ using System.Text; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Transbank.Onepay.Exceptions; +using Transbank.Exceptions; namespace Transbank.Webpay.Common { diff --git a/Transbank/WebpayRest/Oneclick/Exception/InscriptionStartException.cs b/Transbank/WebpayRest/Oneclick/Exception/InscriptionStartException.cs new file mode 100644 index 0000000..b5400a5 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Exception/InscriptionStartException.cs @@ -0,0 +1,10 @@ +using System; +namespace Transbank.WebpayRest.Oneclick.Exception +{ + public class InscriptionStartException + { + public InscriptionStartException() + { + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs b/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs new file mode 100644 index 0000000..86b02bf --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs @@ -0,0 +1,12 @@ +using System; + +namespace Transbank.Webpay.Oneclick.Exception +{ + public class InscriptionStartException : SystemException + { + public InscriptionStartException() + { + + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Inscription.cs b/Transbank/WebpayRest/Oneclick/Inscription.cs index 22806f8..66c9877 100644 --- a/Transbank/WebpayRest/Oneclick/Inscription.cs +++ b/Transbank/WebpayRest/Oneclick/Inscription.cs @@ -1,6 +1,7 @@ using System; using Newtonsoft.Json; using Transbank.Webpay.Common; +using Transbank.Exceptions; using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.Oneclick.Responses; From b35172c9a25c66f45dfa2856e6cb9bae6e641483 Mon Sep 17 00:00:00 2001 From: afiebig Date: Mon, 29 Jul 2019 15:16:16 -0400 Subject: [PATCH 029/120] Return Http Status Code, inside TransbankException --- Transbank/WebpayRest/Common/RequestService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Transbank/WebpayRest/Common/RequestService.cs b/Transbank/WebpayRest/Common/RequestService.cs index 21f0970..b70bdb6 100644 --- a/Transbank/WebpayRest/Common/RequestService.cs +++ b/Transbank/WebpayRest/Common/RequestService.cs @@ -38,7 +38,7 @@ public static string Perform(BaseRequest request, Options options) if (!response.IsSuccessStatusCode) { var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonResponse); - throw new TransbankException(-1, $"Error message: {jsonObject.Value("error_message")}"); + throw new TransbankException((int)response.StatusCode , $"Error message: {jsonObject.Value("error_message")}"); } return jsonResponse; From 815a87ccddf85cc79e2db3652d47249d6087c54f Mon Sep 17 00:00:00 2001 From: afiebig Date: Mon, 29 Jul 2019 15:34:41 -0400 Subject: [PATCH 030/120] Add Inscription Exceptions --- .../Exception/InscriptionStartException.cs | 10 ------- .../Exceptions/InscriptionDeleteException.cs | 27 +++++++++++++++++++ .../Exceptions/InscriptionFinishException.cs | 27 +++++++++++++++++++ .../Exceptions/InscriptionStartException.cs | 21 ++++++++++++--- 4 files changed, 72 insertions(+), 13 deletions(-) delete mode 100644 Transbank/WebpayRest/Oneclick/Exception/InscriptionStartException.cs create mode 100644 Transbank/WebpayRest/Oneclick/Exceptions/InscriptionDeleteException.cs create mode 100644 Transbank/WebpayRest/Oneclick/Exceptions/InscriptionFinishException.cs diff --git a/Transbank/WebpayRest/Oneclick/Exception/InscriptionStartException.cs b/Transbank/WebpayRest/Oneclick/Exception/InscriptionStartException.cs deleted file mode 100644 index b5400a5..0000000 --- a/Transbank/WebpayRest/Oneclick/Exception/InscriptionStartException.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -namespace Transbank.WebpayRest.Oneclick.Exception -{ - public class InscriptionStartException - { - public InscriptionStartException() - { - } - } -} diff --git a/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionDeleteException.cs b/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionDeleteException.cs new file mode 100644 index 0000000..f97ffb2 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionDeleteException.cs @@ -0,0 +1,27 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.Oneclick.Exceptions +{ + public class InscriptionDeleteException : TransbankException + { + public InscriptionDeleteException() : base() + { + } + + public InscriptionDeleteException(string message) + : base(-1, message) + { + } + + public InscriptionDeleteException(int code, string message) + : base(code, message) + { + } + + public InscriptionDeleteException(int code, string message, + Exception innerException) : base(code, message, innerException) + { + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionFinishException.cs b/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionFinishException.cs new file mode 100644 index 0000000..77b3ee6 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionFinishException.cs @@ -0,0 +1,27 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.Oneclick.Exceptions +{ + public class InscriptionFinishException : TransbankException + { + public InscriptionFinishException() : base() + { + } + + public InscriptionFinishException(string message) + : base(-1, message) + { + } + + public InscriptionFinishException(int code, string message) + : base(code, message) + { + } + + public InscriptionFinishException(int code, string message, + Exception innerException) : base(code, message, innerException) + { + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs b/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs index 86b02bf..ab0a716 100644 --- a/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs +++ b/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs @@ -1,12 +1,27 @@ using System; +using Transbank.Exceptions; -namespace Transbank.Webpay.Oneclick.Exception +namespace Transbank.Webpay.Oneclick.Exceptions { - public class InscriptionStartException : SystemException + public class InscriptionStartException : TransbankException { - public InscriptionStartException() + public InscriptionStartException() : base() { + } + + public InscriptionStartException(string message) + : base(-1, message) + { + } + public InscriptionStartException(int code, string message) + : base(code, message) + { + } + + public InscriptionStartException(int code, string message, + Exception innerException) : base(code, message, innerException) + { } } } From 6b98809cdf6556b764779c90621690ac88c8d2af Mon Sep 17 00:00:00 2001 From: afiebig Date: Mon, 29 Jul 2019 15:37:47 -0400 Subject: [PATCH 031/120] Update toString methods to print in new lines --- .../WebpayRest/Oneclick/Request/DeleteRequest.cs | 4 ++-- .../WebpayRest/Oneclick/Request/StartRequest.cs | 6 +++--- .../Oneclick/Response/AuthorizeResponse.cs | 14 +++++++------- .../WebpayRest/Oneclick/Response/FinishResponse.cs | 10 +++++----- .../WebpayRest/Oneclick/Response/StartResponse.cs | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs b/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs index cc307d1..0aba386 100644 --- a/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs @@ -16,8 +16,8 @@ internal class DeleteRequest : BaseRequest public override string ToString() { - return $"UserName= {UserName}\n" + - $"TbkUser={TBKUser}"; + return $"\"UserName\": \"{UserName}\"\n" + + $"\"TbkUser\": \"{TBKUser}\""; } internal DeleteRequest(string userName, string tbkUser) diff --git a/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs b/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs index a52c23f..46ce720 100644 --- a/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs @@ -17,9 +17,9 @@ internal class StartRequest : BaseRequest public override string ToString() { - return $"UserName= {UserName}\n" + - $"Email= {Email}\n" + - $"RsponseUrl= {ResponseUrl}"; + return $"\"UserName\": \"{UserName}\"\n" + + $"\"Email\": \"{Email}\"\n" + + $"\"RsponseUrl\": \"{ResponseUrl}\""; } internal StartRequest(string userName, string email, string responseUrl) diff --git a/Transbank/WebpayRest/Oneclick/Response/AuthorizeResponse.cs b/Transbank/WebpayRest/Oneclick/Response/AuthorizeResponse.cs index c8611e9..37114fa 100644 --- a/Transbank/WebpayRest/Oneclick/Response/AuthorizeResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Response/AuthorizeResponse.cs @@ -42,13 +42,13 @@ public AuthorizeResponse(string buyOrder, string sessionId, string cardNumber, D 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/Response/FinishResponse.cs b/Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs index 3136847..512be95 100644 --- a/Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs @@ -28,11 +28,11 @@ public FinishResponse(int responseCode, string transbankUser, public override string ToString() { - return $"Response Code = {ResponseCode}\n" + - $"Transbank User = {TransbankUser}\n" + - $"Authorization Code = {AuthorizationCode}\n" + - $"Credit Card Type = {CreditCardType}\n" + - $"Last Four Card Digits = {LastFourCardDigits}"; + return $"\"Response Code\": \"{ResponseCode}\"\n" + + $"\"Transbank User\": \"{TbkUser}\"\n" + + $"\"Authorization Code\": \"{AuthorizationCode}\"\n" + + $"\"Credit Card Type\": \"{CreditCardType}\"\n" + + $"\"Last Four Card Digits\": \"{LastFourCardDigits}\""; } } } diff --git a/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs b/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs index 9dd5cf2..68c6710 100644 --- a/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs @@ -18,7 +18,7 @@ public StartResponse(string token, string url) public override string ToString() { - return $"Token={Token},\nUrl={Url}"; + return $"\"Token\": \"{Token}\"\n\"Url\": \"{Url}\""; } } } From 8ac8f8a2cfec59cb1a7bfd1927abd47a92b8ac01 Mon Sep 17 00:00:00 2001 From: afiebig Date: Mon, 29 Jul 2019 15:41:05 -0400 Subject: [PATCH 032/120] Update Oneclick Delete endpoint Also, rename TransbankUser to TbkUser --- Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs | 2 +- Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs b/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs index 0aba386..8f8a8f5 100644 --- a/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs @@ -21,7 +21,7 @@ public override string ToString() } internal DeleteRequest(string userName, string tbkUser) - : base("/rswebpaytransaction/api/oneclick/v1.0/transactions", HttpMethod.Delete) + : base("/rswebpaytransaction/api/oneclick/v1.0/inscriptions", HttpMethod.Delete) { UserName = userName; TBKUser = tbkUser; diff --git a/Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs b/Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs index 512be95..87d2305 100644 --- a/Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs @@ -8,7 +8,7 @@ public class FinishResponse [JsonProperty("response_code")] public int ResponseCode { get; private set; } [JsonProperty("tbk_user")] - public string TransbankUser { get; private set; } + public string TbkUser { get; private set; } [JsonProperty("authorization_code")] public string AuthorizationCode { get; private set; } [JsonProperty("credit_card_type")] @@ -20,7 +20,7 @@ public FinishResponse(int responseCode, string transbankUser, string authorizationCode, string creditCardType, string lastFourCardDigits) { ResponseCode = responseCode; - TransbankUser = transbankUser; + TbkUser = transbankUser; AuthorizationCode = authorizationCode; CreditCardType = creditCardType; LastFourCardDigits = lastFourCardDigits; From bb74df2aa95a360eb91d134f1411f8ac8cba9951 Mon Sep 17 00:00:00 2001 From: afiebig Date: Mon, 29 Jul 2019 15:44:21 -0400 Subject: [PATCH 033/120] Trow exceptions when request fails --- Transbank/WebpayRest/Oneclick/Inscription.cs | 52 +++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Inscription.cs b/Transbank/WebpayRest/Oneclick/Inscription.cs index 66c9877..e3328e5 100644 --- a/Transbank/WebpayRest/Oneclick/Inscription.cs +++ b/Transbank/WebpayRest/Oneclick/Inscription.cs @@ -4,6 +4,7 @@ using Transbank.Exceptions; using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.Oneclick.Responses; +using Transbank.Webpay.Oneclick.Exceptions; namespace Transbank.Webpay.Oneclick { @@ -17,10 +18,19 @@ public static StartResponse Start(string userName, string email, string response public static StartResponse Start(string userName, string email, string responseUrl, Options options) { - var startRequest = new StartRequest(userName, email, responseUrl); - var response = RequestService.Perform(startRequest, options); + try + { + var startRequest = new StartRequest(userName, email, responseUrl); + var response = RequestService.Perform(startRequest, options); - return JsonConvert.DeserializeObject(response); + return JsonConvert.DeserializeObject(response); + } + catch (Exception e) + { + int code = e.GetType().Equals(typeof(TransbankException)) ? + ((TransbankException)e).Code : -1; + throw new InscriptionStartException(code, e.Message, e); + } } public static FinishResponse Finish(string token) @@ -30,23 +40,39 @@ public static FinishResponse Finish(string token) public static FinishResponse Finish(string token, Options options) { - var finishRequest = new FinishRequest(token); - var response = RequestService.Perform(finishRequest, options); + try + { + var finishRequest = new FinishRequest(token); + var response = RequestService.Perform(finishRequest, options); - return JsonConvert.DeserializeObject(response); + return JsonConvert.DeserializeObject(response); + } + catch (Exception e) + { + int code = e.GetType().Equals(typeof(TransbankException)) ? + ((TransbankException)e).Code : -1; + throw new InscriptionFinishException(code, e.Message, e); + } } - public static DeleteResponse Delete(string userName, string tbkUser) + public static void Delete(string userName, string tbkUser) { - return Delete(userName, tbkUser, Oneclick.DefaultOptions()); + Delete(userName, tbkUser, Oneclick.DefaultOptions()); } - public static DeleteResponse Delete(string userName, string tbkUser, Options options) + public static void Delete(string userName, string tbkUser, Options options) { - var deleteRequest = new DeleteRequest(userName, tbkUser); - var response = RequestService.Perform(deleteRequest, options); - - return JsonConvert.DeserializeObject(response); + try + { + var deleteRequest = new DeleteRequest(userName, tbkUser); + RequestService.Perform(deleteRequest, options); + } + catch (Exception e) + { + int code = e.GetType().Equals(typeof(TransbankException)) ? + ((TransbankException)e).Code : -1; + throw new InscriptionDeleteException(code, e.Message, e); + } } } } From 54a4c21b3f4652bd023071fb787537c159fe94ca Mon Sep 17 00:00:00 2001 From: afiebig Date: Mon, 29 Jul 2019 16:28:25 -0400 Subject: [PATCH 034/120] Remove duplicated code --- Transbank/WebpayRest/Oneclick/Transaction.cs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Transaction.cs b/Transbank/WebpayRest/Oneclick/Transaction.cs index 7fbb03a..b4f7cdd 100644 --- a/Transbank/WebpayRest/Oneclick/Transaction.cs +++ b/Transbank/WebpayRest/Oneclick/Transaction.cs @@ -21,18 +21,5 @@ public static AuthorizeResponse Authorize(string userName, string email, return JsonConvert.DeserializeObject(response); } - - public static FinishResponse Finish(string token) - { - return Finish(token, Oneclick.DefaultOptions()); - } - - public static FinishResponse Finish(string token, Options options) - { - var finishRequest = new FinishRequest(token); - var response = RequestService.Perform(finishRequest, options); - - return JsonConvert.DeserializeObject(response); - } } } From b7b7f5a32bbeac776111e81028d69a3500b0efc9 Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 30 Jul 2019 12:09:33 -0400 Subject: [PATCH 035/120] Move Request and Resources to corresponding plural named folders --- Transbank/Transbank.csproj | 4 ++-- .../Oneclick/{Request => Requests}/AuthorizeRequest.cs | 0 .../Oneclick/{Request => Requests}/DeleteRequest.cs | 0 .../Oneclick/{Request => Requests}/FinishRequest.cs | 0 .../WebpayRest/Oneclick/{Request => Requests}/StartRequest.cs | 0 .../Oneclick/{Response => Responses}/AuthorizeResponse.cs | 0 .../Oneclick/{Response => Responses}/DeleteResponse.cs | 0 .../Oneclick/{Response => Responses}/FinishResponse.cs | 0 .../Oneclick/{Response => Responses}/StartResponse.cs | 0 TransbankSDK.sln | 4 ++-- 10 files changed, 4 insertions(+), 4 deletions(-) rename Transbank/WebpayRest/Oneclick/{Request => Requests}/AuthorizeRequest.cs (100%) rename Transbank/WebpayRest/Oneclick/{Request => Requests}/DeleteRequest.cs (100%) rename Transbank/WebpayRest/Oneclick/{Request => Requests}/FinishRequest.cs (100%) rename Transbank/WebpayRest/Oneclick/{Request => Requests}/StartRequest.cs (100%) rename Transbank/WebpayRest/Oneclick/{Response => Responses}/AuthorizeResponse.cs (100%) rename Transbank/WebpayRest/Oneclick/{Response => Responses}/DeleteResponse.cs (100%) rename Transbank/WebpayRest/Oneclick/{Response => Responses}/FinishResponse.cs (100%) rename Transbank/WebpayRest/Oneclick/{Response => Responses}/StartResponse.cs (100%) diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 9d0b836..4da1aa3 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -119,8 +119,8 @@ - - + + diff --git a/Transbank/WebpayRest/Oneclick/Request/AuthorizeRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs similarity index 100% rename from Transbank/WebpayRest/Oneclick/Request/AuthorizeRequest.cs rename to Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs diff --git a/Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs similarity index 100% rename from Transbank/WebpayRest/Oneclick/Request/DeleteRequest.cs rename to Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs diff --git a/Transbank/WebpayRest/Oneclick/Request/FinishRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/FinishRequest.cs similarity index 100% rename from Transbank/WebpayRest/Oneclick/Request/FinishRequest.cs rename to Transbank/WebpayRest/Oneclick/Requests/FinishRequest.cs diff --git a/Transbank/WebpayRest/Oneclick/Request/StartRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs similarity index 100% rename from Transbank/WebpayRest/Oneclick/Request/StartRequest.cs rename to Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs diff --git a/Transbank/WebpayRest/Oneclick/Response/AuthorizeResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/AuthorizeResponse.cs similarity index 100% rename from Transbank/WebpayRest/Oneclick/Response/AuthorizeResponse.cs rename to Transbank/WebpayRest/Oneclick/Responses/AuthorizeResponse.cs diff --git a/Transbank/WebpayRest/Oneclick/Response/DeleteResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/DeleteResponse.cs similarity index 100% rename from Transbank/WebpayRest/Oneclick/Response/DeleteResponse.cs rename to Transbank/WebpayRest/Oneclick/Responses/DeleteResponse.cs diff --git a/Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs similarity index 100% rename from Transbank/WebpayRest/Oneclick/Response/FinishResponse.cs rename to Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs diff --git a/Transbank/WebpayRest/Oneclick/Response/StartResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/StartResponse.cs similarity index 100% rename from Transbank/WebpayRest/Oneclick/Response/StartResponse.cs rename to Transbank/WebpayRest/Oneclick/Responses/StartResponse.cs diff --git a/TransbankSDK.sln b/TransbankSDK.sln index ee7050e..31f962e 100644 --- a/TransbankSDK.sln +++ b/TransbankSDK.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27703.2035 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Transbank", "Transbank\Transbank.csproj", "{0381863D-61D0-4541-B0C5-BE41D02C351C}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Transbank", "Transbank\Transbank.csproj", "{0381863D-61D0-4541-B0C5-BE41D02C351C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransbankTest", "TransbankTest\TransbankTest.csproj", "{3575F64E-4B5D-423B-890F-C267790CD303}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransbankTest", "TransbankTest\TransbankTest.csproj", "{3575F64E-4B5D-423B-890F-C267790CD303}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4C7A9B11-AFD0-4B1D-B420-F745BE86E8A9}" ProjectSection(SolutionItems) = preProject From 46d9d55b20d64a03d08c3949816b2e754c8edfb9 Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 30 Jul 2019 12:10:18 -0400 Subject: [PATCH 036/120] Change request acces modifier to internal, since they can't be modified outside the SDK --- .../Oneclick/Requests/AuthorizeRequest.cs | 16 ++++------------ .../Oneclick/Requests/DeleteRequest.cs | 12 ++---------- .../WebpayRest/Oneclick/Requests/StartRequest.cs | 13 +++---------- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs index d63eaab..18f4b5c 100644 --- a/Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs @@ -9,24 +9,16 @@ internal class AuthorizeRequest : BaseRequest { [JsonProperty("username")] - public string UserName { get; set; } + internal string UserName { get; set; } [JsonProperty("tbk_user")] - public string TBKUser { get; set; } + internal string TBKUser { get; set; } [JsonProperty("buy_order")] - public string BuyOrder { get; set; } + internal string BuyOrder { get; set; } [JsonProperty("details")] - public List Details { get; set; } - - public override string ToString() - { - return $"UserName= {UserName}\n" + - $"TbkUser= {TBKUser}\n" + - $"BuyOrder= {BuyOrder}\n" + - $"Details= {Details.ToString()}\n"; - } + internal List Details { get; set; } internal AuthorizeRequest(string userName, string tbkUser, string buyOrder, List details) : base("/rswebpaytransaction/api/oneclick/v1.0/transactions", HttpMethod.Post) diff --git a/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs index 8f8a8f5..6fcacf0 100644 --- a/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs @@ -1,5 +1,4 @@ using System.Net.Http; -using System.Collections.Generic; using Newtonsoft.Json; using Transbank.Webpay.Common; @@ -7,18 +6,11 @@ namespace Transbank.Webpay.Oneclick.Requests { internal class DeleteRequest : BaseRequest { - [JsonProperty("username")] - public string UserName { get; set; } + internal string UserName { get; set; } [JsonProperty("tbk_user")] - public string TBKUser { get; set; } - - public override string ToString() - { - return $"\"UserName\": \"{UserName}\"\n" + - $"\"TbkUser\": \"{TBKUser}\""; - } + internal string TBKUser { get; set; } internal DeleteRequest(string userName, string tbkUser) : base("/rswebpaytransaction/api/oneclick/v1.0/inscriptions", HttpMethod.Delete) diff --git a/Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs index 46ce720..75d29cf 100644 --- a/Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs @@ -7,20 +7,13 @@ namespace Transbank.Webpay.Oneclick.Requests internal class StartRequest : BaseRequest { [JsonProperty("username")] - public string UserName { get; set; } + internal string UserName { get; set; } [JsonProperty("email")] - public string Email { get; set; } + internal string Email { get; set; } [JsonProperty("response_url")] - public string ResponseUrl { get; set; } - - public override string ToString() - { - return $"\"UserName\": \"{UserName}\"\n" + - $"\"Email\": \"{Email}\"\n" + - $"\"RsponseUrl\": \"{ResponseUrl}\""; - } + internal string ResponseUrl { get; set; } internal StartRequest(string userName, string email, string responseUrl) : base("/rswebpaytransaction/api/oneclick/v1.0/inscriptions", HttpMethod.Post) From 600ba4aa1b838b679c775275131ebb9a2d2653d0 Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 30 Jul 2019 12:16:57 -0400 Subject: [PATCH 037/120] Rename Transaction to MallTransaction since Oneclick Normal is not supported yet. --- .../WebpayRest/Oneclick/{Transaction.cs => MallTransaction.cs} | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename Transbank/WebpayRest/Oneclick/{Transaction.cs => MallTransaction.cs} (94%) diff --git a/Transbank/WebpayRest/Oneclick/Transaction.cs b/Transbank/WebpayRest/Oneclick/MallTransaction.cs similarity index 94% rename from Transbank/WebpayRest/Oneclick/Transaction.cs rename to Transbank/WebpayRest/Oneclick/MallTransaction.cs index b4f7cdd..eb1f1c3 100644 --- a/Transbank/WebpayRest/Oneclick/Transaction.cs +++ b/Transbank/WebpayRest/Oneclick/MallTransaction.cs @@ -1,4 +1,3 @@ -using System; using Newtonsoft.Json; using Transbank.Webpay.Common; using Transbank.Webpay.Oneclick.Requests; @@ -6,7 +5,7 @@ namespace Transbank.Webpay.Oneclick { - public static class Transaction + public static class MallTransaction { public static AuthorizeResponse Authorize(string userName, string email, string responseUrl) { From 5586cd2f2a81e24b15d55b2002f5f6633d12e0e4 Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Thu, 1 Aug 2019 12:40:30 -0400 Subject: [PATCH 038/120] Add Mall Transaction Refund --- .../WebpayRest/WebpayPlus/MallTransaction.cs | 25 ++++++++++++++--- .../WebpayPlus/Requests/MallRefundRequest.cs | 27 +++++++++++++++++++ .../Responses/MallRefundResponse.cs | 9 +++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/MallRefundRequest.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/MallRefundResponse.cs diff --git a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs index 6ff9374..d26e81c 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs @@ -42,14 +42,17 @@ public static Options DefaultOptions() return new Options(CommerceCode, ApiKey, IntegrationType); } - public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, List transactions) + public static MallCreateResponse Create(string buyOrder, string sessionId, + string returnUrl, List transactions) { return Create(buyOrder, sessionId, returnUrl, transactions, DefaultOptions()); } - public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, List transactions, Options options) + public static MallCreateResponse Create(string buyOrder, string sessionId, + string returnUrl, List transactions, Options options) { - var mallCreateRequest = new MallCreateRequest(buyOrder, sessionId, returnUrl, transactions); + var mallCreateRequest = new MallCreateRequest(buyOrder, sessionId, + returnUrl, transactions); var response = RequestService.Perform(mallCreateRequest, options); return JsonConvert.DeserializeObject(response); @@ -67,5 +70,21 @@ public static MallCommitResponse Commit(string token, Options options) return JsonConvert.DeserializeObject(response); } + + public static MallRefundResponse Refund(string token, string buyOrder, + string commerceCode, decimal amount) + { + return Refund(token, buyOrder, commerceCode, amount, DefaultOptions()); + } + + public static MallRefundResponse Refund(string token, string buyOrder, + string commerceCode, decimal amount, Options options) + { + var mallRefundRequest = new MallRefundRequest(token, buyOrder, + commerceCode, amount); + var response = RequestService.Perform(mallRefundRequest, options); + + return JsonConvert.DeserializeObject(response); + } } } diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallRefundRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallRefundRequest.cs new file mode 100644 index 0000000..7c6f823 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Requests/MallRefundRequest.cs @@ -0,0 +1,27 @@ +using System; +using Newtonsoft.Json; + +namespace Transbank.Webpay.WebpayPlus.Requests +{ + internal class MallRefundRequest : RefundRequest + { + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + [JsonProperty("commerce_code")] + public string CommerceCode { get; set; } + + internal MallRefundRequest( + string token, string buyOrder, string commerceCode, + decimal amount) : base(token, amount) + { + BuyOrder = buyOrder; + CommerceCode = commerceCode; + } + + public override string ToString() + { + return $"BuyOrder={BuyOrder}, CommerceCode={CommerceCode}, Amount={Amount}"; + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/MallRefundResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/MallRefundResponse.cs new file mode 100644 index 0000000..7513620 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Responses/MallRefundResponse.cs @@ -0,0 +1,9 @@ +using System; +using Newtonsoft.Json; + +namespace Transbank.Webpay.WebpayPlus.Responses +{ + public class MallRefundResponse : RefundResponse + { + } +} From 8871850beff9546493bf81620dc6cf91b17199de Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Thu, 1 Aug 2019 18:02:14 -0400 Subject: [PATCH 039/120] Add plus mall status --- Transbank/Transbank.csproj | 1 + .../Exceptions/MallStatusException.cs | 16 +++++++++++++ .../WebpayRest/WebpayPlus/MallTransaction.cs | 24 +++++++++++++++++++ .../WebpayPlus/Requests/MallStatusRequest.cs | 10 ++++++++ .../Responses/MallStatusResponse.cs | 5 ++++ 5 files changed, 56 insertions(+) create mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/MallStatusException.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/MallStatusRequest.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/MallStatusResponse.cs diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 4da1aa3..513989b 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -123,6 +123,7 @@ + diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/MallStatusException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallStatusException.cs new file mode 100644 index 0000000..0f0ae6d --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallStatusException.cs @@ -0,0 +1,16 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.WebpayPlus.Exceptions +{ + public class MallStatusException : TransbankException + { + + public MallStatusException(string message) : base(-1, message) { } + + public MallStatusException(int code, string message) : base(code, message) { } + + public MallStatusException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs index d26e81c..b386b42 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using Newtonsoft.Json; +using Transbank.Exceptions; using Transbank.Webpay.Common; +using Transbank.Webpay.WebpayPlus.Exceptions; using Transbank.Webpay.WebpayPlus.Requests; using Transbank.Webpay.WebpayPlus.Responses; @@ -86,5 +88,27 @@ public static MallRefundResponse Refund(string token, string buyOrder, return JsonConvert.DeserializeObject(response); } + + public static MallStatusResponse Status(string token) + { + return Status(token, DefaultOptions()); + } + + public static MallStatusResponse Status(string token, Options options) + { + try + { + var mallStatusRequest = new MallStatusRequest(token); + var response = RequestService.Perform(mallStatusRequest, options); + + return JsonConvert.DeserializeObject(response); + } + catch (Exception e) + { + int code = e.GetType().Equals(typeof(TransbankException)) ? + ((TransbankException)e).Code : -1; + throw new MallStatusException(code, e.Message, e); + } + } } } diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallStatusRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallStatusRequest.cs new file mode 100644 index 0000000..b88bb46 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Requests/MallStatusRequest.cs @@ -0,0 +1,10 @@ +using System; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.WebpayPlus.Requests +{ + public class MallStatusRequest : StatusRequest + { + internal MallStatusRequest(string token) : base(token) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/MallStatusResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/MallStatusResponse.cs new file mode 100644 index 0000000..48f75e0 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Responses/MallStatusResponse.cs @@ -0,0 +1,5 @@ +using System; +namespace Transbank.Webpay.WebpayPlus.Responses +{ + public class MallStatusResponse : MallCommitResponse { } +} From c7369d65d5972ae1894f75faa0de50681caf5d1e Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Thu, 1 Aug 2019 22:14:40 -0400 Subject: [PATCH 040/120] Add exception handler --- .../WebpayRest/Common/ExceptionHandler.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Transbank/WebpayRest/Common/ExceptionHandler.cs diff --git a/Transbank/WebpayRest/Common/ExceptionHandler.cs b/Transbank/WebpayRest/Common/ExceptionHandler.cs new file mode 100644 index 0000000..e04ae05 --- /dev/null +++ b/Transbank/WebpayRest/Common/ExceptionHandler.cs @@ -0,0 +1,47 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.Common +{ + internal static class ExceptionHandler + { + // These two methods should act the same, the difference is the return type. + // This is needed because at the moment Inscription.delete returns void. + + internal static ReturnType Perform(Func block) + where ExceptionType : TransbankException + { + try + { + return block(); + } + catch (Exception e) + { + throw RiseTransbankException(e); + } + } + + internal static void Perform(Action block) + where ExceptionType : TransbankException + { + try + { + block(); + } + catch (Exception e) + { + throw RiseTransbankException(e); + } + } + + private static ExceptionType RiseTransbankException(Exception e) + where ExceptionType : TransbankException + { + int code = e.GetType().Equals(typeof(TransbankException)) ? + ((TransbankException)e).Code : -1; + + return (ExceptionType)Activator.CreateInstance( + typeof(ExceptionType), new object[] { code, e.Message, e }); + } + } +} From 3dcc2ef8b482d514b45328dbdea4ba724c45421b Mon Sep 17 00:00:00 2001 From: Felipe Fiebig Date: Thu, 1 Aug 2019 22:15:57 -0400 Subject: [PATCH 041/120] Use ExceptionHandler on every method --- Transbank/WebpayRest/Common/RequestService.cs | 7 +-- .../MallTransactionAuthorizeException.cs | 15 ++++++ Transbank/WebpayRest/Oneclick/Inscription.cs | 37 ++++---------- .../WebpayRest/Oneclick/MallTransaction.cs | 11 +++-- .../WebpayPlus/DeferredTransaction.cs | 14 ++++-- .../Exceptions/MallStatusException.cs | 16 ------ .../MallTransactionCommitException.cs | 15 ++++++ .../MallTransactionCreateException.cs | 15 ++++++ .../MallTransactionRefundException.cs | 15 ++++++ .../MallTransactionStatusException.cs | 15 ++++++ .../Exceptions/TransactionCaptureException.cs | 15 ++++++ .../Exceptions/TransactionCommitException.cs | 15 ++++++ .../Exceptions/TransactionCreateException.cs | 15 ++++++ .../Exceptions/TransactionRefundException.cs | 15 ++++++ .../Exceptions/TransactionStatusException.cs | 15 ++++++ .../WebpayRest/WebpayPlus/MallTransaction.cs | 47 ++++++++++-------- .../WebpayRest/WebpayPlus/Transaction.cs | 49 +++++++++++++------ 17 files changed, 242 insertions(+), 89 deletions(-) create mode 100644 Transbank/WebpayRest/Oneclick/Exceptions/MallTransactionAuthorizeException.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/MallStatusException.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCommitException.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCreateException.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionRefundException.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionStatusException.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCaptureException.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCommitException.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCreateException.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionRefundException.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionStatusException.cs diff --git a/Transbank/WebpayRest/Common/RequestService.cs b/Transbank/WebpayRest/Common/RequestService.cs index b70bdb6..274d2bb 100644 --- a/Transbank/WebpayRest/Common/RequestService.cs +++ b/Transbank/WebpayRest/Common/RequestService.cs @@ -21,7 +21,7 @@ private static void AddRequiredHeaders(HttpClient client, string commerceCode, s client.DefaultRequestHeaders.Add("Tbk-Api-Key-Secret", apiKey); } - public static string Perform(BaseRequest request, Options options) + public static string Perform(BaseRequest request, Options options) where T : TransbankException { var message = new HttpRequestMessage(request.Method, new Uri(options.IntegrationType.ApiBase + request.Endpoint)); if (request.Method != HttpMethod.Get) @@ -38,9 +38,10 @@ public static string Perform(BaseRequest request, Options options) if (!response.IsSuccessStatusCode) { var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonResponse); - throw new TransbankException((int)response.StatusCode , $"Error message: {jsonObject.Value("error_message")}"); + throw (T)Activator.CreateInstance(typeof(T), new object[] { + (int)response.StatusCode, $"Error message: {jsonObject.Value("error_message")}" + }); } - return jsonResponse; } } diff --git a/Transbank/WebpayRest/Oneclick/Exceptions/MallTransactionAuthorizeException.cs b/Transbank/WebpayRest/Oneclick/Exceptions/MallTransactionAuthorizeException.cs new file mode 100644 index 0000000..d24916d --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Exceptions/MallTransactionAuthorizeException.cs @@ -0,0 +1,15 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.Oneclick.Exceptions +{ + public class MallTransactionAuthorizeException : TransbankException + { + public MallTransactionAuthorizeException(string message) : base(-1, message) { } + + public MallTransactionAuthorizeException(int code, string message) : base(code, message) { } + + public MallTransactionAuthorizeException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Inscription.cs b/Transbank/WebpayRest/Oneclick/Inscription.cs index e3328e5..e28d09e 100644 --- a/Transbank/WebpayRest/Oneclick/Inscription.cs +++ b/Transbank/WebpayRest/Oneclick/Inscription.cs @@ -18,19 +18,14 @@ public static StartResponse Start(string userName, string email, string response public static StartResponse Start(string userName, string email, string responseUrl, Options options) { - try + return ExceptionHandler.Perform(() => { var startRequest = new StartRequest(userName, email, responseUrl); - var response = RequestService.Perform(startRequest, options); + var response = RequestService.Perform( + startRequest, options); return JsonConvert.DeserializeObject(response); - } - catch (Exception e) - { - int code = e.GetType().Equals(typeof(TransbankException)) ? - ((TransbankException)e).Code : -1; - throw new InscriptionStartException(code, e.Message, e); - } + }); } public static FinishResponse Finish(string token) @@ -40,19 +35,13 @@ public static FinishResponse Finish(string token) public static FinishResponse Finish(string token, Options options) { - try + return ExceptionHandler.Perform(() => { var finishRequest = new FinishRequest(token); - var response = RequestService.Perform(finishRequest, options); + var response = RequestService.Perform(finishRequest, options); return JsonConvert.DeserializeObject(response); - } - catch (Exception e) - { - int code = e.GetType().Equals(typeof(TransbankException)) ? - ((TransbankException)e).Code : -1; - throw new InscriptionFinishException(code, e.Message, e); - } + }); } public static void Delete(string userName, string tbkUser) @@ -62,17 +51,11 @@ public static void Delete(string userName, string tbkUser) public static void Delete(string userName, string tbkUser, Options options) { - try + ExceptionHandler.Perform(() => { var deleteRequest = new DeleteRequest(userName, tbkUser); - RequestService.Perform(deleteRequest, options); - } - catch (Exception e) - { - int code = e.GetType().Equals(typeof(TransbankException)) ? - ((TransbankException)e).Code : -1; - throw new InscriptionDeleteException(code, e.Message, e); - } + RequestService.Perform(deleteRequest, options); + }); } } } diff --git a/Transbank/WebpayRest/Oneclick/MallTransaction.cs b/Transbank/WebpayRest/Oneclick/MallTransaction.cs index eb1f1c3..9f8364f 100644 --- a/Transbank/WebpayRest/Oneclick/MallTransaction.cs +++ b/Transbank/WebpayRest/Oneclick/MallTransaction.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using Transbank.Webpay.Common; +using Transbank.Webpay.Oneclick.Exceptions; using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.Oneclick.Responses; @@ -15,10 +16,14 @@ public static AuthorizeResponse Authorize(string userName, string email, string public static AuthorizeResponse Authorize(string userName, string email, string responseUrl, Options options) { - var startRequest = new StartRequest(userName, email, responseUrl); - var response = RequestService.Perform(startRequest, options); + return ExceptionHandler.Perform(() => + { + var startRequest = new StartRequest(userName, email, responseUrl); + var response = RequestService.Perform( + startRequest, options); - return JsonConvert.DeserializeObject(response); + return JsonConvert.DeserializeObject(response); + }); } } } diff --git a/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs index f52d271..4771786 100644 --- a/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs @@ -1,6 +1,7 @@ using System; using Newtonsoft.Json; using Transbank.Webpay.Common; +using Transbank.Webpay.WebpayPlus.Exceptions; using Transbank.Webpay.WebpayPlus.Requests; using Transbank.Webpay.WebpayPlus.Responses; @@ -98,10 +99,15 @@ public static CaptureResponse Capture(string token, string buyOrder, string auth public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, decimal captureAmount, string commerceCode, Options options) { - var captureRequest = new CaptureRequest(token, buyOrder, authorizationCode, captureAmount, commerceCode); - var response = RequestService.Perform(captureRequest, options); - - return JsonConvert.DeserializeObject(response); + return ExceptionHandler.Perform(() => + { + var captureRequest = new CaptureRequest(token, buyOrder, + authorizationCode, captureAmount, commerceCode); + var response = RequestService.Perform( + captureRequest, options); + + return JsonConvert.DeserializeObject(response); + }); } } } diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/MallStatusException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallStatusException.cs deleted file mode 100644 index 0f0ae6d..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Exceptions/MallStatusException.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using Transbank.Exceptions; - -namespace Transbank.Webpay.WebpayPlus.Exceptions -{ - public class MallStatusException : TransbankException - { - - public MallStatusException(string message) : base(-1, message) { } - - public MallStatusException(int code, string message) : base(code, message) { } - - public MallStatusException(int code, string message, Exception innerException) - : base(code, message, innerException) { } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCommitException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCommitException.cs new file mode 100644 index 0000000..39ae8ee --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCommitException.cs @@ -0,0 +1,15 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.WebpayPlus.Exceptions +{ + public class MallTransactionCommitException : TransbankException + { + public MallTransactionCommitException(string message) : base(-1, message) { } + + public MallTransactionCommitException(int code, string message) : base(code, message) { } + + public MallTransactionCommitException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCreateException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCreateException.cs new file mode 100644 index 0000000..3cf4c1e --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCreateException.cs @@ -0,0 +1,15 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.WebpayPlus.Exceptions +{ + public class MallTransactionCreateException : TransbankException + { + public MallTransactionCreateException(string message) : base(-1, message) { } + + public MallTransactionCreateException(int code, string message) : base(code, message) { } + + public MallTransactionCreateException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionRefundException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionRefundException.cs new file mode 100644 index 0000000..5d21185 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionRefundException.cs @@ -0,0 +1,15 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.WebpayPlus.Exceptions +{ + public class MallTransactionRefundException : TransbankException + { + public MallTransactionRefundException(string message) : base(-1, message) { } + + public MallTransactionRefundException(int code, string message) : base(code, message) { } + + public MallTransactionRefundException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionStatusException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionStatusException.cs new file mode 100644 index 0000000..301fdfb --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionStatusException.cs @@ -0,0 +1,15 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.WebpayPlus.Exceptions +{ + public class MallTransactionStatusException : TransbankException + { + public MallTransactionStatusException(string message) : base(-1, message) { } + + public MallTransactionStatusException(int code, string message) : base(code, message) { } + + public MallTransactionStatusException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCaptureException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCaptureException.cs new file mode 100644 index 0000000..9a83643 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCaptureException.cs @@ -0,0 +1,15 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.WebpayPlus.Exceptions +{ + public class TransactionCaptureException : TransbankException + { + public TransactionCaptureException(string message) : base(-1, message) { } + + public TransactionCaptureException(int code, string message) : base(code, message) { } + + public TransactionCaptureException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCommitException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCommitException.cs new file mode 100644 index 0000000..8b04d89 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCommitException.cs @@ -0,0 +1,15 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.WebpayPlus.Exceptions +{ + public class TransactionCommitException : TransbankException + { + public TransactionCommitException(string message) : base(-1, message) { } + + public TransactionCommitException(int code, string message) : base(code, message) { } + + public TransactionCommitException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCreateException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCreateException.cs new file mode 100644 index 0000000..496032a --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCreateException.cs @@ -0,0 +1,15 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.WebpayPlus.Exceptions +{ + public class TransactionCreateException : TransbankException + { + public TransactionCreateException(string message) : base(-1, message) { } + + public TransactionCreateException(int code, string message) : base(code, message) { } + + public TransactionCreateException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionRefundException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionRefundException.cs new file mode 100644 index 0000000..bc7c214 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionRefundException.cs @@ -0,0 +1,15 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.WebpayPlus.Exceptions +{ + public class TransactionRefundException : TransbankException + { + public TransactionRefundException(string message) : base(-1, message) { } + + public TransactionRefundException(int code, string message) : base(code, message) { } + + public TransactionRefundException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionStatusException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionStatusException.cs new file mode 100644 index 0000000..40eede3 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionStatusException.cs @@ -0,0 +1,15 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.WebpayPlus.Exceptions +{ + public class TransactionStatusException : TransbankException + { + public TransactionStatusException(string message) : base(-1, message) { } + + public TransactionStatusException(int code, string message) : base(code, message) { } + + public TransactionStatusException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs index b386b42..51699ab 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs @@ -53,11 +53,15 @@ public static MallCreateResponse Create(string buyOrder, string sessionId, public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, List transactions, Options options) { - var mallCreateRequest = new MallCreateRequest(buyOrder, sessionId, - returnUrl, transactions); - var response = RequestService.Perform(mallCreateRequest, options); + return ExceptionHandler.Perform(() => + { + var mallCreateRequest = new MallCreateRequest(buyOrder, sessionId, + returnUrl, transactions); + var response = RequestService.Perform( + mallCreateRequest, options); - return JsonConvert.DeserializeObject(response); + return JsonConvert.DeserializeObject(response); + }); } public static MallCommitResponse Commit(string token) @@ -67,10 +71,14 @@ public static MallCommitResponse Commit(string token) public static MallCommitResponse Commit(string token, Options options) { - var mallCommitRequest = new MallCommitRequest(token); - var response = RequestService.Perform(mallCommitRequest, options); + return ExceptionHandler.Perform(() => + { + var mallCommitRequest = new MallCommitRequest(token); + var response = RequestService.Perform( + mallCommitRequest, options); - return JsonConvert.DeserializeObject(response); + return JsonConvert.DeserializeObject(response); + }); } public static MallRefundResponse Refund(string token, string buyOrder, @@ -82,11 +90,15 @@ public static MallRefundResponse Refund(string token, string buyOrder, public static MallRefundResponse Refund(string token, string buyOrder, string commerceCode, decimal amount, Options options) { - var mallRefundRequest = new MallRefundRequest(token, buyOrder, - commerceCode, amount); - var response = RequestService.Perform(mallRefundRequest, options); + return ExceptionHandler.Perform(() => + { + var mallRefundRequest = new MallRefundRequest(token, buyOrder, + commerceCode, amount); + var response = RequestService.Perform( + mallRefundRequest, options); - return JsonConvert.DeserializeObject(response); + return JsonConvert.DeserializeObject(response); + }); } public static MallStatusResponse Status(string token) @@ -96,19 +108,14 @@ public static MallStatusResponse Status(string token) public static MallStatusResponse Status(string token, Options options) { - try + return ExceptionHandler.Perform(() => { var mallStatusRequest = new MallStatusRequest(token); - var response = RequestService.Perform(mallStatusRequest, options); + var response = RequestService.Perform( + mallStatusRequest, options); return JsonConvert.DeserializeObject(response); - } - catch (Exception e) - { - int code = e.GetType().Equals(typeof(TransbankException)) ? - ((TransbankException)e).Code : -1; - throw new MallStatusException(code, e.Message, e); - } + }); } } } diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs index aebcf7a..48467c1 100644 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -3,6 +3,7 @@ using Transbank.Webpay.Common; using Transbank.Webpay.WebpayPlus.Responses; using Newtonsoft.Json; +using Transbank.Webpay.WebpayPlus.Exceptions; namespace Transbank.Webpay.WebpayPlus { @@ -50,10 +51,14 @@ public static CreateResponse Create(string buyOrder, string sessionId, public static CreateResponse Create(string buyOrder, string sessionId, decimal amount, string returnUrl, Options options) { - var createRequest = new CreateRequest(buyOrder, sessionId, amount, returnUrl); - var response = RequestService.Perform(createRequest, options); - - return JsonConvert.DeserializeObject(response); + return ExceptionHandler.Perform(() => + { + var createRequest = new CreateRequest(buyOrder, sessionId, amount, returnUrl); + var response = RequestService.Perform( + createRequest, options); + + return JsonConvert.DeserializeObject(response); + }); } public static CommitResponse Commit(string token) @@ -63,10 +68,14 @@ public static CommitResponse Commit(string token) public static CommitResponse Commit(string token, Options options) { - var commitRequest = new CommitRequest(token); - var response = RequestService.Perform(commitRequest, options); - - return JsonConvert.DeserializeObject(response); + return ExceptionHandler.Perform(() => + { + var commitRequest = new CommitRequest(token); + var response = RequestService.Perform( + commitRequest, options); + + return JsonConvert.DeserializeObject(response); + }); } public static RefundResponse Refund(string token, decimal amount) @@ -76,10 +85,14 @@ public static RefundResponse Refund(string token, decimal amount) public static RefundResponse Refund(string token, decimal amount, Options options) { - var refundRequest = new RefundRequest(token, amount); - var response = RequestService.Perform(refundRequest, options); - - return JsonConvert.DeserializeObject(response); + return ExceptionHandler.Perform(() => + { + var refundRequest = new RefundRequest(token, amount); + var response = RequestService.Perform( + refundRequest, options); + + return JsonConvert.DeserializeObject(response); + }); } public static StatusResponse Status(string token) @@ -89,10 +102,14 @@ public static StatusResponse Status(string token) public static StatusResponse Status(string token, Options options) { - var statusRequest = new StatusRequest(token); - var response = RequestService.Perform(statusRequest, options); - - return JsonConvert.DeserializeObject(response); + return ExceptionHandler.Perform(() => + { + var statusRequest = new StatusRequest(token); + var response = RequestService.Perform( + statusRequest, options); + + return JsonConvert.DeserializeObject(response); + }); } } } From 121a5e1f5035ee4a55738f2296b6bbafde8f6e9f Mon Sep 17 00:00:00 2001 From: afiebig Date: Tue, 6 Aug 2019 11:34:11 -0400 Subject: [PATCH 042/120] Onepay Exceptions can't extend from Transbank.Exceptions.TransbankException This will make all people already capturing Onepay Exceptions to miss it, beacause it belongs to a diferent namespace --- Transbank/Onepay/Exceptions/AmountException.cs | 2 +- Transbank/Onepay/Exceptions/RefundCreateException.cs | 2 +- Transbank/Onepay/Exceptions/SignatureException.cs | 2 +- Transbank/Onepay/Exceptions/TransactionCommitException.cs | 2 +- Transbank/Onepay/Exceptions/TransactionCreateException.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Transbank/Onepay/Exceptions/AmountException.cs b/Transbank/Onepay/Exceptions/AmountException.cs index c035bd8..d07d3c7 100644 --- a/Transbank/Onepay/Exceptions/AmountException.cs +++ b/Transbank/Onepay/Exceptions/AmountException.cs @@ -2,7 +2,7 @@ namespace Transbank.Onepay.Exceptions { - public class AmountException : Transbank.Exceptions.TransbankException + public class AmountException : TransbankException { public AmountException() : base() { diff --git a/Transbank/Onepay/Exceptions/RefundCreateException.cs b/Transbank/Onepay/Exceptions/RefundCreateException.cs index 8f399b0..f1d903d 100644 --- a/Transbank/Onepay/Exceptions/RefundCreateException.cs +++ b/Transbank/Onepay/Exceptions/RefundCreateException.cs @@ -3,7 +3,7 @@ namespace Transbank.Onepay.Exceptions { - public class RefundCreateException : Transbank.Exceptions.TransbankException + public class RefundCreateException : TransbankException { public RefundCreateException() : base() { diff --git a/Transbank/Onepay/Exceptions/SignatureException.cs b/Transbank/Onepay/Exceptions/SignatureException.cs index f9a83dd..70917c7 100644 --- a/Transbank/Onepay/Exceptions/SignatureException.cs +++ b/Transbank/Onepay/Exceptions/SignatureException.cs @@ -3,7 +3,7 @@ namespace Transbank.Onepay.Exceptions { - public class SignatureException : Transbank.Exceptions.TransbankException + public class SignatureException : TransbankException { public SignatureException() : base() { diff --git a/Transbank/Onepay/Exceptions/TransactionCommitException.cs b/Transbank/Onepay/Exceptions/TransactionCommitException.cs index a4ea281..00b8935 100644 --- a/Transbank/Onepay/Exceptions/TransactionCommitException.cs +++ b/Transbank/Onepay/Exceptions/TransactionCommitException.cs @@ -3,7 +3,7 @@ namespace Transbank.Onepay.Exceptions { - public class TransactionCommitException : Transbank.Exceptions.TransbankException + public class TransactionCommitException : TransbankException { public TransactionCommitException() : base() { diff --git a/Transbank/Onepay/Exceptions/TransactionCreateException.cs b/Transbank/Onepay/Exceptions/TransactionCreateException.cs index c1819d6..dc08415 100644 --- a/Transbank/Onepay/Exceptions/TransactionCreateException.cs +++ b/Transbank/Onepay/Exceptions/TransactionCreateException.cs @@ -3,7 +3,7 @@ namespace Transbank.Onepay.Exceptions { - public class TransactionCreateException : Transbank.Exceptions.TransbankException + public class TransactionCreateException : TransbankException { public TransactionCreateException() : base() { From 65c168bc83a2290aaa352da0925825a5e9a7144a Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 12:27:25 -0400 Subject: [PATCH 043/120] Move WebPayRest Common, to a uper lever This way this classes can be used by patpass also --- Transbank/{WebpayRest => }/Common/BaseRequest.cs | 3 ++- Transbank/Common/IIntegrationType.cs | 10 ++++++++++ Transbank/{WebpayRest => }/Common/Options.cs | 11 ++++++----- Transbank/{WebpayRest => }/Common/RequestService.cs | 2 +- Transbank/WebpayRest/Oneclick/Inscription.cs | 2 +- Transbank/WebpayRest/Oneclick/Oneclick.cs | 1 + .../WebpayRest/Oneclick/Requests/AuthorizeRequest.cs | 1 + .../WebpayRest/Oneclick/Requests/DeleteRequest.cs | 2 +- .../WebpayRest/Oneclick/Requests/FinishRequest.cs | 3 ++- .../WebpayRest/Oneclick/Requests/StartRequest.cs | 2 +- .../WebpayRest/WebpayPlus/DeferredTransaction.cs | 1 + Transbank/WebpayRest/WebpayPlus/MallTransaction.cs | 2 +- .../WebpayRest/WebpayPlus/Requests/CaptureRequest.cs | 2 +- .../WebpayRest/WebpayPlus/Requests/CommitRequest.cs | 3 ++- .../WebpayRest/WebpayPlus/Requests/CreateRequest.cs | 2 +- .../WebpayPlus/Requests/MallCommitRequest.cs | 2 +- .../WebpayPlus/Requests/MallCreateRequest.cs | 5 ++--- .../WebpayRest/WebpayPlus/Requests/RefundRequest.cs | 2 +- .../WebpayRest/WebpayPlus/Requests/StatusRequest.cs | 2 +- Transbank/WebpayRest/WebpayPlus/Transaction.cs | 1 + TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs | 1 + 21 files changed, 39 insertions(+), 21 deletions(-) rename Transbank/{WebpayRest => }/Common/BaseRequest.cs (96%) create mode 100644 Transbank/Common/IIntegrationType.cs rename Transbank/{WebpayRest => }/Common/Options.cs (75%) rename Transbank/{WebpayRest => }/Common/RequestService.cs (98%) diff --git a/Transbank/WebpayRest/Common/BaseRequest.cs b/Transbank/Common/BaseRequest.cs similarity index 96% rename from Transbank/WebpayRest/Common/BaseRequest.cs rename to Transbank/Common/BaseRequest.cs index 1111889..71e8d97 100644 --- a/Transbank/WebpayRest/Common/BaseRequest.cs +++ b/Transbank/Common/BaseRequest.cs @@ -1,7 +1,8 @@ using System; using System.Net.Http; using Newtonsoft.Json; -namespace Transbank.Webpay.Common + +namespace Transbank.Common { public abstract class BaseRequest { diff --git a/Transbank/Common/IIntegrationType.cs b/Transbank/Common/IIntegrationType.cs new file mode 100644 index 0000000..f876dfa --- /dev/null +++ b/Transbank/Common/IIntegrationType.cs @@ -0,0 +1,10 @@ +using System; + +namespace Transbank.Common +{ + public interface IIntegrationType + { + string Key { get; } + string ApiBase { get; } + } +} diff --git a/Transbank/WebpayRest/Common/Options.cs b/Transbank/Common/Options.cs similarity index 75% rename from Transbank/WebpayRest/Common/Options.cs rename to Transbank/Common/Options.cs index 02560a8..77d3229 100644 --- a/Transbank/WebpayRest/Common/Options.cs +++ b/Transbank/Common/Options.cs @@ -1,11 +1,12 @@ using System; -namespace Transbank.Webpay.Common + +namespace Transbank.Common { public class Options { private string _commerceCode; private string _apiKey; - private WebpayIntegrationType _integrationType; + private IIntegrationType _integrationType; public string CommerceCode { @@ -23,7 +24,7 @@ public string ApiKey ); } - public WebpayIntegrationType IntegrationType + public IIntegrationType IntegrationType { get => _integrationType; set => _integrationType = value ?? throw new ArgumentNullException( @@ -31,11 +32,11 @@ public WebpayIntegrationType IntegrationType ); } - public Options(string commerceCode, string apiKey, WebpayIntegrationType webpayIntegrationType) + public Options(string commerceCode, string apiKey, IIntegrationType integrationType) { CommerceCode = commerceCode; ApiKey = apiKey; - IntegrationType = webpayIntegrationType; + IntegrationType = integrationType; } } } diff --git a/Transbank/WebpayRest/Common/RequestService.cs b/Transbank/Common/RequestService.cs similarity index 98% rename from Transbank/WebpayRest/Common/RequestService.cs rename to Transbank/Common/RequestService.cs index 274d2bb..787679f 100644 --- a/Transbank/WebpayRest/Common/RequestService.cs +++ b/Transbank/Common/RequestService.cs @@ -7,7 +7,7 @@ using Newtonsoft.Json.Linq; using Transbank.Exceptions; -namespace Transbank.Webpay.Common +namespace Transbank.Common { public static class RequestService { diff --git a/Transbank/WebpayRest/Oneclick/Inscription.cs b/Transbank/WebpayRest/Oneclick/Inscription.cs index e28d09e..21a739c 100644 --- a/Transbank/WebpayRest/Oneclick/Inscription.cs +++ b/Transbank/WebpayRest/Oneclick/Inscription.cs @@ -1,6 +1,6 @@ using System; using Newtonsoft.Json; -using Transbank.Webpay.Common; +using Transbank.Common; using Transbank.Exceptions; using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.Oneclick.Responses; diff --git a/Transbank/WebpayRest/Oneclick/Oneclick.cs b/Transbank/WebpayRest/Oneclick/Oneclick.cs index 1194a62..9f382b3 100644 --- a/Transbank/WebpayRest/Oneclick/Oneclick.cs +++ b/Transbank/WebpayRest/Oneclick/Oneclick.cs @@ -1,4 +1,5 @@ using System; +using Transbank.Common; using Transbank.Webpay.Common; namespace Transbank.Webpay.Oneclick { diff --git a/Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs index 18f4b5c..e86027a 100644 --- a/Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs @@ -1,6 +1,7 @@ using System.Net.Http; using System.Collections.Generic; using Newtonsoft.Json; +using Transbank.Common; using Transbank.Webpay.Common; namespace Transbank.Webpay.Oneclick.Requests diff --git a/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs index 6fcacf0..3d391d8 100644 --- a/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs @@ -1,6 +1,6 @@ using System.Net.Http; using Newtonsoft.Json; -using Transbank.Webpay.Common; +using Transbank.Common; namespace Transbank.Webpay.Oneclick.Requests { diff --git a/Transbank/WebpayRest/Oneclick/Requests/FinishRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/FinishRequest.cs index 1d4d6d6..dc9243b 100644 --- a/Transbank/WebpayRest/Oneclick/Requests/FinishRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Requests/FinishRequest.cs @@ -1,5 +1,6 @@ using System.Net.Http; -using Transbank.Webpay.Common; +using Transbank.Common; + namespace Transbank.Webpay.Oneclick.Requests { internal class FinishRequest : BaseRequest diff --git a/Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs index 75d29cf..42e747e 100644 --- a/Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -using Transbank.Webpay.Common; using System.Net.Http; +using Transbank.Common; namespace Transbank.Webpay.Oneclick.Requests { diff --git a/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs index 4771786..0c8c0d6 100644 --- a/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs @@ -1,5 +1,6 @@ using System; using Newtonsoft.Json; +using Transbank.Common; using Transbank.Webpay.Common; using Transbank.Webpay.WebpayPlus.Exceptions; using Transbank.Webpay.WebpayPlus.Requests; diff --git a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs index 51699ab..04fa1b6 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using Newtonsoft.Json; -using Transbank.Exceptions; +using Transbank.Common; using Transbank.Webpay.Common; using Transbank.Webpay.WebpayPlus.Exceptions; using Transbank.Webpay.WebpayPlus.Requests; diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs index e288d82..6fe8c39 100644 --- a/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs +++ b/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs @@ -1,7 +1,7 @@ using System; using System.Net.Http; using Newtonsoft.Json; -using Transbank.Webpay.Common; +using Transbank.Common; namespace Transbank.Webpay.WebpayPlus.Requests { diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs index b8cc472..bfc8720 100644 --- a/Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs +++ b/Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs @@ -1,6 +1,7 @@ using System; using System.Net.Http; -using Transbank.Webpay.Common; +using Transbank.Common; + namespace Transbank.Webpay.WebpayPlus.Requests { internal class CommitRequest : BaseRequest diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs index 858ff7d..cf36f51 100644 --- a/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs +++ b/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs @@ -1,5 +1,5 @@ using Newtonsoft.Json; -using Transbank.Webpay.Common; +using Transbank.Common; using System.Net.Http; namespace Transbank.Webpay.WebpayPlus.Requests diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs index e94ace3..e59f834 100644 --- a/Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs +++ b/Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs @@ -1,6 +1,6 @@ using System; using System.Net.Http; -using Transbank.Webpay.Common; +using Transbank.Common; namespace Transbank.Webpay.WebpayPlus.Requests { diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs index eb75f70..fff1642 100644 --- a/Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs +++ b/Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs @@ -1,8 +1,7 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; +using System.Collections.Generic; using System.Net.Http; using Newtonsoft.Json; +using Transbank.Common; using Transbank.Webpay.Common; namespace Transbank.Webpay.WebpayPlus.Requests diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs index 1304ae5..c5ee1d5 100644 --- a/Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs +++ b/Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs @@ -1,5 +1,5 @@ using System; -using Transbank.Webpay.Common; +using Transbank.Common; using Newtonsoft.Json; using System.Net.Http; diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs index 2ed3151..501d66f 100644 --- a/Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs +++ b/Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs @@ -1,5 +1,5 @@ using System; -using Transbank.Webpay.Common; +using Transbank.Common; using System.Net.Http; namespace Transbank.Webpay.WebpayPlus.Requests diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs index 48467c1..0cb4e4b 100644 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -1,4 +1,5 @@ using System; +using Transbank.Common; using Transbank.Webpay.WebpayPlus.Requests; using Transbank.Webpay.Common; using Transbank.Webpay.WebpayPlus.Responses; diff --git a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs index 1b17d73..6c55c1d 100644 --- a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs +++ b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs @@ -1,5 +1,6 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; +using Transbank.Common; using Transbank.Webpay.Common; namespace TransbankTest.WebpayRest.WebpayPlus From dffe8f9a426b48ed0dc52eb48ff135a865e30c4b Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 12:28:03 -0400 Subject: [PATCH 044/120] IntegrationType now extend from an IIntegrationType Interface --- Transbank/WebpayRest/Common/WebpayIntegrationType.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Transbank/WebpayRest/Common/WebpayIntegrationType.cs b/Transbank/WebpayRest/Common/WebpayIntegrationType.cs index b6742cb..afb5c1e 100644 --- a/Transbank/WebpayRest/Common/WebpayIntegrationType.cs +++ b/Transbank/WebpayRest/Common/WebpayIntegrationType.cs @@ -1,7 +1,9 @@ using System; +using Transbank.Common; + namespace Transbank.Webpay.Common { - public class WebpayIntegrationType + public class WebpayIntegrationType : IIntegrationType { public string Key { get; private set; } public string ApiBase { get; private set; } From e10c9161b19b8c3131e5c30570adffcacfcae9b0 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 12:29:30 -0400 Subject: [PATCH 045/120] Add Detail Class for PatPass Rest sale details --- Transbank/PatpassRest/Common/Detail.cs | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Transbank/PatpassRest/Common/Detail.cs diff --git a/Transbank/PatpassRest/Common/Detail.cs b/Transbank/PatpassRest/Common/Detail.cs new file mode 100644 index 0000000..d0ec17b --- /dev/null +++ b/Transbank/PatpassRest/Common/Detail.cs @@ -0,0 +1,54 @@ +using System; +using Newtonsoft.Json; + +namespace Transbank.PatpassRest.Common +{ + internal class Detail + { + [JsonProperty("service_id")] + internal string ServiceId { get; } + + [JsonProperty("card_holder_id")] + internal string CardHolderId { get; } + + [JsonProperty("card_holder_name")] + internal string CardHolderName { get; } + + [JsonProperty("card_holder_last_name1")] + internal string CardHolderLastName1 { get; } + + [JsonProperty("card_holder_last_name2")] + internal string CardHolderLastName2 { get; } + + [JsonProperty("card_holder_mail")] + internal string CardHolderMail { get; } + + [JsonProperty("cellphone_number")] + internal string CellphoneNumber { get; } + + [JsonProperty("expiration_date")] + internal string ExpirationDate { get; } + + [JsonProperty("commerce_mail")] + internal string CommerceMail { get; } + + [JsonProperty("uf_flag")] + internal bool UfFlag { get; } + + public Detail(string serviceId, string cardHolderId, string cardHolderName, + string cardHolderLastName1, string cardHolderLastName2, string cardHolderMail, + string cellphoneNumber, string expirationDate, string commerceMail, bool ufFlag) + { + ServiceId = serviceId; + CardHolderId = cardHolderId; + CardHolderName = cardHolderName; + CardHolderLastName1 = cardHolderLastName1; + CardHolderLastName2 = cardHolderLastName2; + CardHolderMail = cardHolderMail; + CellphoneNumber = cellphoneNumber; + ExpirationDate = expirationDate; + CommerceMail = commerceMail; + UfFlag = ufFlag; + } + } +} From 21b8945e3144314486c969ab5f0a713ec389569c Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 12:30:01 -0400 Subject: [PATCH 046/120] Add IntegratioType for PatPass --- .../Common/PatpassByWebpayIntegrationType.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Transbank/PatpassRest/Common/PatpassByWebpayIntegrationType.cs diff --git a/Transbank/PatpassRest/Common/PatpassByWebpayIntegrationType.cs b/Transbank/PatpassRest/Common/PatpassByWebpayIntegrationType.cs new file mode 100644 index 0000000..3dfa6db --- /dev/null +++ b/Transbank/PatpassRest/Common/PatpassByWebpayIntegrationType.cs @@ -0,0 +1,22 @@ +using System; +using Transbank.Common; + +namespace Transbank.Patpass.Common +{ + public class PatpassByWebpayIntegrationType : IIntegrationType + { + public string Key { get; private set; } + public string ApiBase { get; private set; } + + private PatpassByWebpayIntegrationType(string key, string apiBase) + { + Key = key; + ApiBase = apiBase; + } + + public static readonly PatpassByWebpayIntegrationType Live = + new PatpassByWebpayIntegrationType("LIVE", "https://webpay3g.transbank.cl"); + public static readonly PatpassByWebpayIntegrationType Test = + new PatpassByWebpayIntegrationType("TEST", "https://webpay3gint.transbank.cl"); + } +} From 7f2588e4b02940775b511bf422d92a26b3e58a5c Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 12:33:04 -0400 Subject: [PATCH 047/120] Add PatPass Create Request and Response --- .../PatpassByWebpay/Requests/CreateRequest.cs | 40 +++++++++++++++++++ .../Responses/CreateResponse.cs | 18 +++++++++ 2 files changed, 58 insertions(+) create mode 100644 Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs create mode 100644 Transbank/PatpassRest/PatpassByWebpay/Responses/CreateResponse.cs diff --git a/Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs b/Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs new file mode 100644 index 0000000..471e96b --- /dev/null +++ b/Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs @@ -0,0 +1,40 @@ +using Newtonsoft.Json; +using Transbank.Common; +using System.Net.Http; +using Transbank.PatpassRest.Common; + +namespace Transbank.Patpass.PatpassByWebpay.Requests +{ + internal class CreateRequest : BaseRequest + { + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + [JsonProperty("session_id")] + public string SessionId { get; set; } + + [JsonProperty("amount")] + public decimal Amount { get; set; } + + [JsonProperty("return_url")] + public string ReturnUrl { get; set; } + + [JsonProperty("wpm_detail")] + public Detail Details { get; set; } + + internal CreateRequest(string buyOrder, string sessionId, decimal amount, string returnUrl, string serviceId, string cardHolderId, + string cardHolderName, string cardHolderLastName1, string cardHolderLastName2, string cardHolderMail, string cellphoneNumber, + string expirationDate, string commerceMail, bool ufFlag) + : base("/rswebpaytransaction/api/webpay/v1.0/transactions", HttpMethod.Post) + { + BuyOrder = buyOrder; + SessionId = sessionId; + Amount = amount; + ReturnUrl = returnUrl; + Details = new Detail(serviceId, cardHolderId, cardHolderName, + cardHolderLastName1, cardHolderLastName2, cardHolderMail, + cellphoneNumber, expirationDate, commerceMail, ufFlag + ); + } + } +} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Responses/CreateResponse.cs b/Transbank/PatpassRest/PatpassByWebpay/Responses/CreateResponse.cs new file mode 100644 index 0000000..a89a1eb --- /dev/null +++ b/Transbank/PatpassRest/PatpassByWebpay/Responses/CreateResponse.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Transbank.Patpass.PatpassByWebpay.Responses +{ + public class CreateResponse + { + [JsonProperty("token")] + public string Token { get; private set; } + + [JsonProperty("url")] + public string Url { get; private set; } + + public override string ToString() + { + return $"Token={Token}, Url={Url}"; + } + } +} From 9082cde2c1f02d01f644cb9c26a9480d475b4972 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 12:38:06 -0400 Subject: [PATCH 048/120] Add Transaction for Patpass --- .../PatpassByWebpay/Transaction.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Transbank/PatpassRest/PatpassByWebpay/Transaction.cs diff --git a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs new file mode 100644 index 0000000..ebe8560 --- /dev/null +++ b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs @@ -0,0 +1,66 @@ +using System; +using Newtonsoft.Json; +using Transbank.Common; +using Transbank.Patpass.Common; +using Transbank.Patpass.PatpassByWebpay.Requests; +using Transbank.Patpass.PatpassByWebpay.Responses; + +namespace Transbank.Patpass.PatpassByWebpay +{ + public static class Transaction + { + private static string _commerceCode = "597055555550"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + private static PatpassByWebpayIntegrationType _integrationType = PatpassByWebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static PatpassByWebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + + public static CreateResponse Create(string buyOrder, string sessionId, decimal amount, string returnUrl, string serviceId, string cardHolderId, + string cardHolderName, string cardHolderLastName1, string cardHolderLastName2, string cardHolderMail, string cellphoneNumber, + string expirationDate, string commerceMail, bool ufFlag) + { + return Create(buyOrder, sessionId, amount, returnUrl, serviceId, cardHolderId, + cardHolderName, cardHolderLastName1, cardHolderLastName2, cardHolderMail, cellphoneNumber, + expirationDate, commerceMail, ufFlag, DefaultOptions()); + } + + public static CreateResponse Create(string buyOrder, string sessionId, decimal amount, string returnUrl, string serviceId, string cardHolderId, + string cardHolderName, string cardHolderLastName1, string cardHolderLastName2, string cardHolderMail, string cellphoneNumber, + string expirationDate, string commerceMail, bool ufFlag, Options options) + { + var createRequest = new CreateRequest(buyOrder, sessionId, amount, returnUrl, serviceId, cardHolderId, + cardHolderName, cardHolderLastName1, cardHolderLastName2, cardHolderMail, cellphoneNumber, + expirationDate, commerceMail, ufFlag); + var response = RequestService.Perform(createRequest, options); + + return JsonConvert.DeserializeObject(response); + } + } +} From 4ed4a5d9fbc5bbd892528e231845cdf1fad8f566 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 12:57:40 -0400 Subject: [PATCH 049/120] Move ExceptionHandler to Common namespace --- Transbank/{WebpayRest => }/Common/ExceptionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Transbank/{WebpayRest => }/Common/ExceptionHandler.cs (97%) diff --git a/Transbank/WebpayRest/Common/ExceptionHandler.cs b/Transbank/Common/ExceptionHandler.cs similarity index 97% rename from Transbank/WebpayRest/Common/ExceptionHandler.cs rename to Transbank/Common/ExceptionHandler.cs index e04ae05..e7f3007 100644 --- a/Transbank/WebpayRest/Common/ExceptionHandler.cs +++ b/Transbank/Common/ExceptionHandler.cs @@ -1,7 +1,7 @@ using System; using Transbank.Exceptions; -namespace Transbank.Webpay.Common +namespace Transbank.Common { internal static class ExceptionHandler { From b2162519d8d689be22119d2a126eb5e6797f72cb Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 13:00:25 -0400 Subject: [PATCH 050/120] update Oneclick MallTransaction --- Transbank/WebpayRest/Oneclick/MallTransaction.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Transbank/WebpayRest/Oneclick/MallTransaction.cs b/Transbank/WebpayRest/Oneclick/MallTransaction.cs index 9f8364f..87397f5 100644 --- a/Transbank/WebpayRest/Oneclick/MallTransaction.cs +++ b/Transbank/WebpayRest/Oneclick/MallTransaction.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Transbank.Common; using Transbank.Webpay.Common; using Transbank.Webpay.Oneclick.Exceptions; using Transbank.Webpay.Oneclick.Requests; From f9e081a9435ff45beab06409ec696c9b97622bf5 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 19:49:27 -0400 Subject: [PATCH 051/120] Move Transaction create exception to common namespace --- .../WebpayPlus => }/Exceptions/TransactionCreateException.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Transbank/{WebpayRest/WebpayPlus => }/Exceptions/TransactionCreateException.cs (100%) diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCreateException.cs b/Transbank/Exceptions/TransactionCreateException.cs similarity index 100% rename from Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCreateException.cs rename to Transbank/Exceptions/TransactionCreateException.cs From 6d609c4bd55ffa1b2e32cb92fe8ef5fc5b70c083 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 20:03:21 -0400 Subject: [PATCH 052/120] Move Transaction create exception to common namespace --- Transbank/Exceptions/TransactionCreateException.cs | 3 +-- Transbank/PatpassRest/PatpassByWebpay/Transaction.cs | 3 ++- Transbank/WebpayRest/WebpayPlus/Transaction.cs | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Transbank/Exceptions/TransactionCreateException.cs b/Transbank/Exceptions/TransactionCreateException.cs index 496032a..c4bb74c 100644 --- a/Transbank/Exceptions/TransactionCreateException.cs +++ b/Transbank/Exceptions/TransactionCreateException.cs @@ -1,7 +1,6 @@ using System; -using Transbank.Exceptions; -namespace Transbank.Webpay.WebpayPlus.Exceptions +namespace Transbank.Exceptions { public class TransactionCreateException : TransbankException { diff --git a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs index ebe8560..721318b 100644 --- a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs +++ b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs @@ -1,6 +1,7 @@ using System; using Newtonsoft.Json; using Transbank.Common; +using Transbank.Exceptions; using Transbank.Patpass.Common; using Transbank.Patpass.PatpassByWebpay.Requests; using Transbank.Patpass.PatpassByWebpay.Responses; @@ -58,7 +59,7 @@ public static CreateResponse Create(string buyOrder, string sessionId, decimal a var createRequest = new CreateRequest(buyOrder, sessionId, amount, returnUrl, serviceId, cardHolderId, cardHolderName, cardHolderLastName1, cardHolderLastName2, cardHolderMail, cellphoneNumber, expirationDate, commerceMail, ufFlag); - var response = RequestService.Perform(createRequest, options); + var response = RequestService.Perform(createRequest, options); return JsonConvert.DeserializeObject(response); } diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs index 0cb4e4b..5d7b52d 100644 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -1,5 +1,6 @@ using System; using Transbank.Common; +using Transbank.Exceptions; using Transbank.Webpay.WebpayPlus.Requests; using Transbank.Webpay.Common; using Transbank.Webpay.WebpayPlus.Responses; From 2b067ec443c51c62331edaa3e9c1260c2206abc4 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 20:53:28 -0400 Subject: [PATCH 053/120] Add Commit to Transaction Also, move Commit exception to Common Exceptions --- .../Exceptions/TransactionCommitException.cs | 3 +- .../PatpassByWebpay/Requests/CommitRequest.cs | 12 +++++ .../Responses/CommitResponse.cs | 52 +++++++++++++++++++ .../PatpassByWebpay/Transaction.cs | 17 ++++++ 4 files changed, 82 insertions(+), 2 deletions(-) rename Transbank/{WebpayRest/WebpayPlus => }/Exceptions/TransactionCommitException.cs (84%) create mode 100644 Transbank/PatpassRest/PatpassByWebpay/Requests/CommitRequest.cs create mode 100644 Transbank/PatpassRest/PatpassByWebpay/Responses/CommitResponse.cs diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCommitException.cs b/Transbank/Exceptions/TransactionCommitException.cs similarity index 84% rename from Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCommitException.cs rename to Transbank/Exceptions/TransactionCommitException.cs index 8b04d89..6024aa4 100644 --- a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionCommitException.cs +++ b/Transbank/Exceptions/TransactionCommitException.cs @@ -1,7 +1,6 @@ using System; -using Transbank.Exceptions; -namespace Transbank.Webpay.WebpayPlus.Exceptions +namespace Transbank.Exceptions { public class TransactionCommitException : TransbankException { diff --git a/Transbank/PatpassRest/PatpassByWebpay/Requests/CommitRequest.cs b/Transbank/PatpassRest/PatpassByWebpay/Requests/CommitRequest.cs new file mode 100644 index 0000000..18b1fad --- /dev/null +++ b/Transbank/PatpassRest/PatpassByWebpay/Requests/CommitRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Net.Http; +using Transbank.Common; + +namespace Transbank.Patpass.PatpassByWebpay.Requests +{ + internal class CommitRequest : BaseRequest + { + internal CommitRequest(string token) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) {} + } +} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Responses/CommitResponse.cs b/Transbank/PatpassRest/PatpassByWebpay/Responses/CommitResponse.cs new file mode 100644 index 0000000..fdf8420 --- /dev/null +++ b/Transbank/PatpassRest/PatpassByWebpay/Responses/CommitResponse.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Patpass.PatpassByWebpay.Responses +{ + public class CommitResponse + { + [JsonProperty("vci")] + public string Vci { get; set; } + [JsonProperty("amount")] + public decimal Amount { get; set; } + [JsonProperty("status")] + public string Status { get; set; } + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + [JsonProperty("session_id")] + public string SessionId { get; set; } + [JsonProperty("card_detail")] + public CardDetail CardDetail { get; set; } + [JsonProperty("accounting_date")] + public string AccountingDate { get; set; } + [JsonProperty("transaction_date")] + public DateTime TransactionDate { get; set; } + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + [JsonProperty("payment_type_code")] + public string PaymentTypeCode { get; set; } + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + [JsonProperty("installments_amount")] + public int InstallmentsAmount { get; set; } + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; set; } + [JsonProperty("balance")] + public decimal Balance { get; set; } + + public override string ToString() + { + var properties = new List(); + foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) + { + string name = descriptor.Name; + object value = descriptor.GetValue(this); + properties.Add($"{name}={value}"); + } + return String.Join(", ", properties); + } + } +} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs index 721318b..5fe1887 100644 --- a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs +++ b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs @@ -63,5 +63,22 @@ public static CreateResponse Create(string buyOrder, string sessionId, decimal a return JsonConvert.DeserializeObject(response); } + + public static CommitResponse Commit(string token) + { + return Commit(token, DefaultOptions()); + } + + public static CommitResponse Commit(string token, Options options) + { + return ExceptionHandler.Perform(() => + { + var commitRequest = new CommitRequest(token); + var response = RequestService.Perform( + commitRequest, options); + + return JsonConvert.DeserializeObject(response); + }); + } } } From 731b8471da4a2a610c8deef1c6a85dade3106020 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 7 Aug 2019 21:56:09 -0400 Subject: [PATCH 054/120] Add Refund an Status --- .../Exceptions/TransactionRefundException.cs | 3 +- .../Exceptions/TransactionStatusException.cs | 3 +- .../PatpassByWebpay/Requests/RefundRequest.cs | 24 +++++++++++++ .../PatpassByWebpay/Requests/StatusRequest.cs | 12 +++++++ .../Responses/RefundResponse.cs | 35 +++++++++++++++++++ .../Responses/StatusResponse.cs | 5 +++ .../PatpassByWebpay/Transaction.cs | 34 ++++++++++++++++++ 7 files changed, 112 insertions(+), 4 deletions(-) rename Transbank/{WebpayRest/WebpayPlus => }/Exceptions/TransactionRefundException.cs (84%) rename Transbank/{WebpayRest/WebpayPlus => }/Exceptions/TransactionStatusException.cs (84%) create mode 100644 Transbank/PatpassRest/PatpassByWebpay/Requests/RefundRequest.cs create mode 100644 Transbank/PatpassRest/PatpassByWebpay/Requests/StatusRequest.cs create mode 100644 Transbank/PatpassRest/PatpassByWebpay/Responses/RefundResponse.cs create mode 100644 Transbank/PatpassRest/PatpassByWebpay/Responses/StatusResponse.cs diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionRefundException.cs b/Transbank/Exceptions/TransactionRefundException.cs similarity index 84% rename from Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionRefundException.cs rename to Transbank/Exceptions/TransactionRefundException.cs index bc7c214..76a5dbe 100644 --- a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionRefundException.cs +++ b/Transbank/Exceptions/TransactionRefundException.cs @@ -1,7 +1,6 @@ using System; -using Transbank.Exceptions; -namespace Transbank.Webpay.WebpayPlus.Exceptions +namespace Transbank.Exceptions { public class TransactionRefundException : TransbankException { diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionStatusException.cs b/Transbank/Exceptions/TransactionStatusException.cs similarity index 84% rename from Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionStatusException.cs rename to Transbank/Exceptions/TransactionStatusException.cs index 40eede3..bb01a41 100644 --- a/Transbank/WebpayRest/WebpayPlus/Exceptions/TransactionStatusException.cs +++ b/Transbank/Exceptions/TransactionStatusException.cs @@ -1,7 +1,6 @@ using System; -using Transbank.Exceptions; -namespace Transbank.Webpay.WebpayPlus.Exceptions +namespace Transbank.Exceptions { public class TransactionStatusException : TransbankException { diff --git a/Transbank/PatpassRest/PatpassByWebpay/Requests/RefundRequest.cs b/Transbank/PatpassRest/PatpassByWebpay/Requests/RefundRequest.cs new file mode 100644 index 0000000..c7efde7 --- /dev/null +++ b/Transbank/PatpassRest/PatpassByWebpay/Requests/RefundRequest.cs @@ -0,0 +1,24 @@ +using System; +using Transbank.Common; +using Newtonsoft.Json; +using System.Net.Http; + +namespace Transbank.Patpass.PatpassByWebpay.Requests +{ + internal class RefundRequest : BaseRequest + { + [JsonProperty("amount")] + public decimal Amount { get; set; } + + public override string ToString() + { + return $"Amount={Amount}"; + } + + internal RefundRequest(string token, decimal amount) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/refunds", HttpMethod.Post) + { + Amount = amount; + } + } +} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Requests/StatusRequest.cs b/Transbank/PatpassRest/PatpassByWebpay/Requests/StatusRequest.cs new file mode 100644 index 0000000..bbe5c24 --- /dev/null +++ b/Transbank/PatpassRest/PatpassByWebpay/Requests/StatusRequest.cs @@ -0,0 +1,12 @@ +using System; +using Transbank.Common; +using System.Net.Http; + +namespace Transbank.Patpass.PatpassByWebpay.Requests +{ + public class StatusRequest : BaseRequest + { + internal StatusRequest(string token) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Get) { } + } +} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Responses/RefundResponse.cs b/Transbank/PatpassRest/PatpassByWebpay/Responses/RefundResponse.cs new file mode 100644 index 0000000..3d90ce4 --- /dev/null +++ b/Transbank/PatpassRest/PatpassByWebpay/Responses/RefundResponse.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Newtonsoft.Json; + +namespace Transbank.Patpass.PatpassByWebpay.Responses +{ + public class RefundResponse + { + [JsonProperty("type")] + public string Type { get; set; } + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + [JsonProperty("authorization_date")] + public DateTime AuthorizationDate { get; set; } + [JsonProperty("nullified_amount")] + public decimal NullifiedAmount { get; set; } + [JsonProperty("balance")] + public decimal Balance { get; set; } + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + + public override string ToString() + { + var properties = new List(); + foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) + { + string name = descriptor.Name; + object value = descriptor.GetValue(this); + properties.Add($"{name}={value}"); + } + return String.Join(", ", properties); + } + } +} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Responses/StatusResponse.cs b/Transbank/PatpassRest/PatpassByWebpay/Responses/StatusResponse.cs new file mode 100644 index 0000000..9795b53 --- /dev/null +++ b/Transbank/PatpassRest/PatpassByWebpay/Responses/StatusResponse.cs @@ -0,0 +1,5 @@ +using System; +namespace Transbank.Patpass.PatpassByWebpay.Responses +{ + public class StatusResponse : CommitResponse { } +} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs index 5fe1887..060de2d 100644 --- a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs +++ b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs @@ -80,5 +80,39 @@ public static CommitResponse Commit(string token, Options options) return JsonConvert.DeserializeObject(response); }); } + + public static RefundResponse Refund(string token, decimal amount) + { + return Refund(token, amount, DefaultOptions()); + } + + public static RefundResponse Refund(string token, decimal amount, Options options) + { + return ExceptionHandler.Perform(() => + { + var refundRequest = new RefundRequest(token, amount); + var response = RequestService.Perform( + refundRequest, options); + + return JsonConvert.DeserializeObject(response); + }); + } + + public static StatusResponse Status(string token) + { + return Status(token, DefaultOptions()); + } + + public static StatusResponse Status(string token, Options options) + { + return ExceptionHandler.Perform(() => + { + var statusRequest = new StatusRequest(token); + var response = RequestService.Perform( + statusRequest, options); + + return JsonConvert.DeserializeObject(response); + }); + } } } From 2bbe52c02f74ee5a9bd22cb6add890bf6d4b6afb Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Thu, 8 Aug 2019 11:55:23 -0400 Subject: [PATCH 055/120] Add Webpay Plus Mall Transaction Create --- .gitignore | 2 + .../WebpayPlus/MallDeferredTransaction.cs | 55 +++++++++++++++++++ TransbankSDK.sln | 6 ++ 3 files changed, 63 insertions(+) create mode 100644 Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs diff --git a/.gitignore b/.gitignore index fd984e8..91e7e1c 100644 --- a/.gitignore +++ b/.gitignore @@ -337,3 +337,5 @@ coverage/ opencover.xml .[Dd][Ss]_[Ss][Tt][Oo][Rr][Ee] + +ConsoleIntegrationTest \ No newline at end of file diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs new file mode 100644 index 0000000..3643a45 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using Transbank.Webpay.Common; +using Transbank.Webpay.WebpayPlus.Responses; + +namespace Transbank.Webpay.WebpayPlus +{ + public class MallDeferredTransaction + { + private static string _commerceCode = "597055555544"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + + public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, + List transactions) + { + return Create(buyOrder, sessionId, returnUrl, transactions, DefaultOptions()); + } + + public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, + List transactions, Options options) + { + return MallTransaction.Create(buyOrder, sessionId, returnUrl, transactions, options); + } + } +} diff --git a/TransbankSDK.sln b/TransbankSDK.sln index 31f962e..14355b0 100644 --- a/TransbankSDK.sln +++ b/TransbankSDK.sln @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleIntegrationTest", "ConsoleIntegrationTest\ConsoleIntegrationTest.csproj", "{0073916B-62AF-4CFF-9F32-0FC6610E6F89}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -28,6 +30,10 @@ Global {3575F64E-4B5D-423B-890F-C267790CD303}.Debug|Any CPU.Build.0 = Debug|Any CPU {3575F64E-4B5D-423B-890F-C267790CD303}.Release|Any CPU.ActiveCfg = Release|Any CPU {3575F64E-4B5D-423B-890F-C267790CD303}.Release|Any CPU.Build.0 = Release|Any CPU + {0073916B-62AF-4CFF-9F32-0FC6610E6F89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0073916B-62AF-4CFF-9F32-0FC6610E6F89}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0073916B-62AF-4CFF-9F32-0FC6610E6F89}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0073916B-62AF-4CFF-9F32-0FC6610E6F89}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 979f0be4cf5dbdbef9d23addd30cc7e94d8207b1 Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 8 Aug 2019 13:39:17 -0400 Subject: [PATCH 056/120] Remove Refund from Transaction --- .../PatpassByWebpay/Requests/RefundRequest.cs | 24 ------------- .../Responses/RefundResponse.cs | 35 ------------------- .../PatpassByWebpay/Transaction.cs | 17 --------- 3 files changed, 76 deletions(-) delete mode 100644 Transbank/PatpassRest/PatpassByWebpay/Requests/RefundRequest.cs delete mode 100644 Transbank/PatpassRest/PatpassByWebpay/Responses/RefundResponse.cs diff --git a/Transbank/PatpassRest/PatpassByWebpay/Requests/RefundRequest.cs b/Transbank/PatpassRest/PatpassByWebpay/Requests/RefundRequest.cs deleted file mode 100644 index c7efde7..0000000 --- a/Transbank/PatpassRest/PatpassByWebpay/Requests/RefundRequest.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using Transbank.Common; -using Newtonsoft.Json; -using System.Net.Http; - -namespace Transbank.Patpass.PatpassByWebpay.Requests -{ - internal class RefundRequest : BaseRequest - { - [JsonProperty("amount")] - public decimal Amount { get; set; } - - public override string ToString() - { - return $"Amount={Amount}"; - } - - internal RefundRequest(string token, decimal amount) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/refunds", HttpMethod.Post) - { - Amount = amount; - } - } -} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Responses/RefundResponse.cs b/Transbank/PatpassRest/PatpassByWebpay/Responses/RefundResponse.cs deleted file mode 100644 index 3d90ce4..0000000 --- a/Transbank/PatpassRest/PatpassByWebpay/Responses/RefundResponse.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using Newtonsoft.Json; - -namespace Transbank.Patpass.PatpassByWebpay.Responses -{ - public class RefundResponse - { - [JsonProperty("type")] - public string Type { get; set; } - [JsonProperty("authorization_code")] - public string AuthorizationCode { get; set; } - [JsonProperty("authorization_date")] - public DateTime AuthorizationDate { get; set; } - [JsonProperty("nullified_amount")] - public decimal NullifiedAmount { get; set; } - [JsonProperty("balance")] - public decimal Balance { get; set; } - [JsonProperty("response_code")] - public int ResponseCode { get; set; } - - public override string ToString() - { - var properties = new List(); - foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) - { - string name = descriptor.Name; - object value = descriptor.GetValue(this); - properties.Add($"{name}={value}"); - } - return String.Join(", ", properties); - } - } -} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs index 060de2d..4fc5d42 100644 --- a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs +++ b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs @@ -81,23 +81,6 @@ public static CommitResponse Commit(string token, Options options) }); } - public static RefundResponse Refund(string token, decimal amount) - { - return Refund(token, amount, DefaultOptions()); - } - - public static RefundResponse Refund(string token, decimal amount, Options options) - { - return ExceptionHandler.Perform(() => - { - var refundRequest = new RefundRequest(token, amount); - var response = RequestService.Perform( - refundRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - public static StatusResponse Status(string token) { return Status(token, DefaultOptions()); From 85df9960e92958cef22b62d6562bc90c320f8a4e Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 8 Aug 2019 13:39:42 -0400 Subject: [PATCH 057/120] Rename Common Namespace --- Transbank/PatpassRest/Common/Detail.cs | 5 ++--- .../PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Transbank/PatpassRest/Common/Detail.cs b/Transbank/PatpassRest/Common/Detail.cs index d0ec17b..03458b6 100644 --- a/Transbank/PatpassRest/Common/Detail.cs +++ b/Transbank/PatpassRest/Common/Detail.cs @@ -1,7 +1,6 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; -namespace Transbank.PatpassRest.Common +namespace Transbank.Patpass.Common { internal class Detail { diff --git a/Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs b/Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs index 471e96b..a98c52f 100644 --- a/Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs +++ b/Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using Transbank.Common; using System.Net.Http; -using Transbank.PatpassRest.Common; +using Transbank.Patpass.Common; namespace Transbank.Patpass.PatpassByWebpay.Requests { From 1c3c433c19fb84c300d6af6acfe17d668081119f Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Thu, 8 Aug 2019 15:40:34 -0400 Subject: [PATCH 058/120] Remove bad project reference --- TransbankSDK.sln | 6 ------ 1 file changed, 6 deletions(-) diff --git a/TransbankSDK.sln b/TransbankSDK.sln index 14355b0..31f962e 100644 --- a/TransbankSDK.sln +++ b/TransbankSDK.sln @@ -14,8 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleIntegrationTest", "ConsoleIntegrationTest\ConsoleIntegrationTest.csproj", "{0073916B-62AF-4CFF-9F32-0FC6610E6F89}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -30,10 +28,6 @@ Global {3575F64E-4B5D-423B-890F-C267790CD303}.Debug|Any CPU.Build.0 = Debug|Any CPU {3575F64E-4B5D-423B-890F-C267790CD303}.Release|Any CPU.ActiveCfg = Release|Any CPU {3575F64E-4B5D-423B-890F-C267790CD303}.Release|Any CPU.Build.0 = Release|Any CPU - {0073916B-62AF-4CFF-9F32-0FC6610E6F89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0073916B-62AF-4CFF-9F32-0FC6610E6F89}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0073916B-62AF-4CFF-9F32-0FC6610E6F89}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0073916B-62AF-4CFF-9F32-0FC6610E6F89}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From e35c43c35181c9a092da4ec6bfeb062da3af64e3 Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Thu, 8 Aug 2019 15:53:03 -0400 Subject: [PATCH 059/120] Remove the ConsoleIntegrationTest --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 91e7e1c..bca2790 100644 --- a/.gitignore +++ b/.gitignore @@ -336,6 +336,4 @@ ASALocalRun/ coverage/ opencover.xml -.[Dd][Ss]_[Ss][Tt][Oo][Rr][Ee] - -ConsoleIntegrationTest \ No newline at end of file +.[Dd][Ss]_[Ss][Tt][Oo][Rr][Ee] \ No newline at end of file From 22c1a20c509b91a0dc260d4d53cc9baa806ebf0e Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Thu, 8 Aug 2019 16:21:28 -0400 Subject: [PATCH 060/120] Set identical .gitignore as destiny branch --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bca2790..fd984e8 100644 --- a/.gitignore +++ b/.gitignore @@ -336,4 +336,4 @@ ASALocalRun/ coverage/ opencover.xml -.[Dd][Ss]_[Ss][Tt][Oo][Rr][Ee] \ No newline at end of file +.[Dd][Ss]_[Ss][Tt][Oo][Rr][Ee] From 477964b2685c2bcfc4a55ed2d5497fe4aee7813a Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Thu, 8 Aug 2019 16:55:37 -0400 Subject: [PATCH 061/120] Change file encoding --- .../WebpayPlus/MallDeferredTransaction.cs | Bin 2059 -> 4120 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index 3643a45ab964be664938d57ed8be12a99feb5a04..8818ce88197a2346aa98335cc80eb731415bd99d 100644 GIT binary patch literal 4120 zcmeH~+iwy<6voeU|B6jtq=_L&Zz0|Sv@wm>XpN5zw1~u(5qDTw3c1jW80cJRawzE zFX-v=^yxd#$T+3H;bu17_bV$tF}rC!+9O($dqt7FX$uywj%B^WI_<4!@6j+ogSSz2 zN!~(315JLcfwe6VSWm~6{X||eEOBJw}98 z&>6lxCwp1l4Y2RnOSFxU6!aaUv4*x?D_a%a(pI9U#=Fi~iM|R*9rIKeJ7VS|T2u(AUPAp*ziIyl3+(k3B)g zU`ZLCGh&-OT3mllNznfV^sns)b;TTgtMs&)CBN1Qy`e6TJGL9g`yPG%tO_~24wkL= z4e{g}-!3@M^!D!9LoC~NKBw3gkXLL7UU<&#y7s_f+H`yDjx8^;GJ7`bS-6wy&A*VJ z)v!FHs*!(Z<*dS@I8v;_oOs=RX3HXmcqEg5vGVR%u_-1jAHfovA2V;q9Nl!YqwOkO znlI@-vnv}D7V$0rL=;)WJ$82t%v!rCPQE1`g($DA%V%2+7f**aIa;utoY*%nW+`JE zBC8MM(tBrG>a1H|Jkq!HVElSk4?zL;;3=Es1STD{hN&0sK4CU U%kGj-)4R&M36=i^e^Z_3FGzr1t^fc4 literal 2059 zcmdUwTW{Jh6vyB5DUNs2ttfjxuB`qrPIc=$I66L7R@-3?X*J`-+gvM5=f!Y zX?vL89M1K3{yyX)VJrB$5faxEBj3AOVM-~+GD(@R-XTMt#FfRI6DAgf{j|R0A|o4R zyI!a4YhE9u~)SJCh>D3*ID4-s7h5 z8;ygZGw?^QYX^ZHj_uJnnnhzba{4pB@AZd)AI^fI=k;yJ84NtvbL_|+M7HmEK|eg5 zt8D&;NnCMNddlXT4B;+meVD>gLu-ygD!RG}eRkvyDd>S!5NgW?o%UOygz42GuLh5{ z5JxN&nFm61gzIaNKY02G3?ISgt9*@2e#$AG{faTuU3KfkI@k+G>meR7fX4A55%TTcMvhRDgkFKve;DPG7H3-Cm9keulf21#5Yc=_^*_L1LM4f`l*Sn@ XdTM)Qtv}*arD`7GwwT}6*c!h9(nDOa From 7d12e4131dc85797a5c440cc9aef77d8156495a8 Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Thu, 8 Aug 2019 17:00:07 -0400 Subject: [PATCH 062/120] Set encoding to UTF-8 --- .../WebpayPlus/MallDeferredTransaction.cs | Bin 4120 -> 2059 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index 8818ce88197a2346aa98335cc80eb731415bd99d..3643a45ab964be664938d57ed8be12a99feb5a04 100644 GIT binary patch literal 2059 zcmdUwTW{Jh6vyB5DUNs2ttfjxuB`qrPIc=$I66L7R@-3?X*J`-+gvM5=f!Y zX?vL89M1K3{yyX)VJrB$5faxEBj3AOVM-~+GD(@R-XTMt#FfRI6DAgf{j|R0A|o4R zyI!a4YhE9u~)SJCh>D3*ID4-s7h5 z8;ygZGw?^QYX^ZHj_uJnnnhzba{4pB@AZd)AI^fI=k;yJ84NtvbL_|+M7HmEK|eg5 zt8D&;NnCMNddlXT4B;+meVD>gLu-ygD!RG}eRkvyDd>S!5NgW?o%UOygz42GuLh5{ z5JxN&nFm61gzIaNKY02G3?ISgt9*@2e#$AG{faTuU3KfkI@k+G>meR7fX4A55%TTcMvhRDgkFKve;DPG7H3-Cm9keulf21#5Yc=_^*_L1LM4f`l*Sn@ XdTM)Qtv}*arD`7GwwT}6*c!h9(nDOa literal 4120 zcmeH~+iwy<6voeU|B6jtq=_L&Zz0|Sv@wm>XpN5zw1~u(5qDTw3c1jW80cJRawzE zFX-v=^yxd#$T+3H;bu17_bV$tF}rC!+9O($dqt7FX$uywj%B^WI_<4!@6j+ogSSz2 zN!~(315JLcfwe6VSWm~6{X||eEOBJw}98 z&>6lxCwp1l4Y2RnOSFxU6!aaUv4*x?D_a%a(pI9U#=Fi~iM|R*9rIKeJ7VS|T2u(AUPAp*ziIyl3+(k3B)g zU`ZLCGh&-OT3mllNznfV^sns)b;TTgtMs&)CBN1Qy`e6TJGL9g`yPG%tO_~24wkL= z4e{g}-!3@M^!D!9LoC~NKBw3gkXLL7UU<&#y7s_f+H`yDjx8^;GJ7`bS-6wy&A*VJ z)v!FHs*!(Z<*dS@I8v;_oOs=RX3HXmcqEg5vGVR%u_-1jAHfovA2V;q9Nl!YqwOkO znlI@-vnv}D7V$0rL=;)WJ$82t%v!rCPQE1`g($DA%V%2+7f**aIa;utoY*%nW+`JE zBC8MM(tBrG>a1H|Jkq!HVElSk4?zL;;3=Es1STD{hN&0sK4CU U%kGj-)4R&M36=i^e^Z_3FGzr1t^fc4 From 4e90783b5d4d4b26614172ec3b57ad5483bd913d Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Thu, 8 Aug 2019 17:08:18 -0400 Subject: [PATCH 063/120] Add BOM to UTF-8 encoding --- Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index 3643a45..5b9ed29 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Transbank.Webpay.Common; using Transbank.Webpay.WebpayPlus.Responses; From 6d7e8a2299e4dbca6e9839a7093cc09da5cdf5ae Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Thu, 8 Aug 2019 17:34:35 -0400 Subject: [PATCH 064/120] Remove logic for class MallDeferredTransaction --- .../WebpayPlus/MallDeferredTransaction.cs | 52 +------------------ 1 file changed, 2 insertions(+), 50 deletions(-) diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index 5b9ed29..ff930b5 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs @@ -1,55 +1,7 @@ -using System; -using System.Collections.Generic; -using Transbank.Webpay.Common; -using Transbank.Webpay.WebpayPlus.Responses; - -namespace Transbank.Webpay.WebpayPlus +namespace Transbank.Webpay.WebpayPlus { public class MallDeferredTransaction { - private static string _commerceCode = "597055555544"; - private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; - - public static string CommerceCode - { - get => _commerceCode; - set => _commerceCode = value ?? throw new ArgumentNullException( - nameof(value), "Commerce code can't be null." - ); - } - - public static string ApiKey - { - get => _apiKey; - set => _apiKey = value ?? throw new ArgumentNullException( - nameof(value), "Api Key can't be null." - ); - } - - public static WebpayIntegrationType IntegrationType - { - get => _integrationType; - set => _integrationType = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null." - ); - } - - public static Options DefaultOptions() - { - return new Options(CommerceCode, ApiKey, IntegrationType); - } - - public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, - List transactions) - { - return Create(buyOrder, sessionId, returnUrl, transactions, DefaultOptions()); - } - - public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, - List transactions, Options options) - { - return MallTransaction.Create(buyOrder, sessionId, returnUrl, transactions, options); - } + } } From 5ce1e5ebf7d4e1ea5c0caa0f2d5ba26410711faf Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Thu, 8 Aug 2019 17:36:38 -0400 Subject: [PATCH 065/120] WIP: Working on MallDeferredTransaction --- .../WebpayPlus/MallDeferredTransaction.cs | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index ff930b5..562a8e3 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs @@ -1,7 +1,36 @@ -namespace Transbank.Webpay.WebpayPlus +using System; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.WebpayPlus { public class MallDeferredTransaction { - + private static string _commerceCode = "597055555544"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } } } From c7d8bb325ba58a0cad2800bdc35151436957680d Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Thu, 8 Aug 2019 17:41:57 -0400 Subject: [PATCH 066/120] WIP: Working on MallDeferredTransaction --- .../WebpayPlus/MallDeferredTransaction.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index 562a8e3..5b9ed29 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using Transbank.Webpay.Common; +using Transbank.Webpay.WebpayPlus.Responses; namespace Transbank.Webpay.WebpayPlus { @@ -32,5 +34,22 @@ public static WebpayIntegrationType IntegrationType nameof(value), "Integration type can't be null." ); } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + + public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, + List transactions) + { + return Create(buyOrder, sessionId, returnUrl, transactions, DefaultOptions()); + } + + public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, + List transactions, Options options) + { + return MallTransaction.Create(buyOrder, sessionId, returnUrl, transactions, options); + } } } From 54c6d3d7d78b1269e371ba435f8b53b01c9417af Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Thu, 8 Aug 2019 17:48:39 -0400 Subject: [PATCH 067/120] WIP: Add static to the class MallDeferredTransaction --- Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index 5b9ed29..a53fe4c 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs @@ -5,7 +5,7 @@ namespace Transbank.Webpay.WebpayPlus { - public class MallDeferredTransaction + public static class MallDeferredTransaction { private static string _commerceCode = "597055555544"; private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; From 1e3c1eb1d1fcf489046732a73fe2284cb5115a68 Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Mon, 12 Aug 2019 14:43:28 -0400 Subject: [PATCH 068/120] Fix the invocation to Options now in the new place --- Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index a53fe4c..b13a9b1 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Transbank.Common; using Transbank.Webpay.Common; using Transbank.Webpay.WebpayPlus.Responses; From 37e3a5db2b9f31b514d50328914fc08d80f97c5d Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 12 Aug 2019 17:18:36 -0400 Subject: [PATCH 069/120] add inscription start commercio --- .editorconfig | 2 +- .../Exceptions/InscriptionStartException.cs | 13 +++ .../Common/PatpassComercioIntegrationType.cs | 23 +++++ .../PatpassComercio/Inscription.cs | 99 +++++++++++++++++++ .../PatpassComercio/Requests/FInishRequest.cs | 7 ++ .../PatpassComercio/Requests/StartRequest.cs | 94 ++++++++++++++++++ .../PatpassComercio/Requests/StatusRequest.cs | 7 ++ .../Responses/FinishResponse.cs | 7 ++ .../Responses/StartResponse.cs | 7 ++ .../Responses/StatusResponse.cs | 7 ++ 10 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 Transbank/Exceptions/InscriptionStartException.cs create mode 100644 Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs create mode 100644 Transbank/PatpassRest/PatpassComercio/Inscription.cs create mode 100644 Transbank/PatpassRest/PatpassComercio/Requests/FInishRequest.cs create mode 100644 Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs create mode 100644 Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs create mode 100644 Transbank/PatpassRest/PatpassComercio/Responses/FinishResponse.cs create mode 100644 Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs create mode 100644 Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs diff --git a/.editorconfig b/.editorconfig index 9b02015..7d5e7df 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,7 +11,7 @@ indent_style = space [*.{cs,csx,vb,vbx}] indent_size = 4 insert_final_newline = true -charset = utf-8-bom +charset = utf-8 ############################### # .NET Coding Conventions # diff --git a/Transbank/Exceptions/InscriptionStartException.cs b/Transbank/Exceptions/InscriptionStartException.cs new file mode 100644 index 0000000..ad474c9 --- /dev/null +++ b/Transbank/Exceptions/InscriptionStartException.cs @@ -0,0 +1,13 @@ +using System; + +namespace Transbank.Exceptions +{ + public class InscriptionStartException : TransbankException + { + public InscriptionStartException(string message) : base(-1, message) { } + + public InscriptionStartException(int code, string message) : base(code, message) { } + + public InscriptionStartException(int code, string message, Exception innerException) : base(code, message, innerException) { } + } +} diff --git a/Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs b/Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs new file mode 100644 index 0000000..1efe133 --- /dev/null +++ b/Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs @@ -0,0 +1,23 @@ +using System; +using Transbank.Common; + +namespace Transbank.Patpass.Common +{ + public class PatpassComercioIntegrationType : IIntegrationType + { + + public string Key { get; private set; } + public string ApiBase { get; private set; } + + private PatpassComercioIntegrationType(string key, string apiBase) + { + Key = key; + ApiBase = apiBase; + } + + public static readonly PatpassComercioIntegrationType Live = + new PatpassComercioIntegrationType("LIVE", "https://www.pagoautomaticocontarjetas.cl/"); + public static readonly PatpassComercioIntegrationType Test = + new PatpassComercioIntegrationType("TEST", "https://webpay3gint.transbank.cl"); + } +} diff --git a/Transbank/PatpassRest/PatpassComercio/Inscription.cs b/Transbank/PatpassRest/PatpassComercio/Inscription.cs new file mode 100644 index 0000000..f3beb76 --- /dev/null +++ b/Transbank/PatpassRest/PatpassComercio/Inscription.cs @@ -0,0 +1,99 @@ +using System; +using System.CodeDom; +using System.Net; +using Newtonsoft.Json; +using Transbank.Common; +using Transbank.Exceptions; +using Transbank.Patpass.Common; +using Transbank.Patpass.PatpassComercio.Requests; +using Transbank.Patpass.PatpassComercio.Responses; + +namespace Transbank.Patpass.PatpassComercio +{ + public static class Inscription + { + private static string _commerceCode = ""; + private static string _apiKey = ""; + private static PatpassComercioIntegrationType _integrationType = PatpassComercioIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce Code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null."); + } + + public static PatpassComercioIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null"); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + + public static StartResponse Start( + string url, + string name, + string fLastname, + string sLastname, + string rut, + string serviceId, + string finalUrl, + string commerceCode, + int maxAmount, + string phoneNumber, + string mobileNumber, + string patpassName, + string personEmail, + string commerceEmail, + string address, + string city + ) + { + return Start(url, name, fLastname, sLastname, rut, serviceId, finalUrl, commerceCode, maxAmount, + phoneNumber, mobileNumber, patpassName, personEmail, commerceEmail, address, city, DefaultOptions()); + } + + public static StartResponse Start( + string url, + string name, + string fLastname, + string sLastname, + string rut, + string serviceId, + string finalUrl, + string commerceCode, + int maxAmount, + string phoneNumber, + string mobileNumber, + string patpassName, + string personEmail, + string commerceEmail, + string address, + string city, + Options options + ) + { + var startRequest = new StartRequest( + url, name, fLastname, sLastname, rut, serviceId, finalUrl, commerceCode, maxAmount, + phoneNumber, mobileNumber, patpassName, personEmail, commerceEmail, address, city + ); + var response = RequestService.Perform(startRequest, options); + + return JsonConvert.DeserializeObject(response); + } + } + +} diff --git a/Transbank/PatpassRest/PatpassComercio/Requests/FInishRequest.cs b/Transbank/PatpassRest/PatpassComercio/Requests/FInishRequest.cs new file mode 100644 index 0000000..efb340a --- /dev/null +++ b/Transbank/PatpassRest/PatpassComercio/Requests/FInishRequest.cs @@ -0,0 +1,7 @@ +namespace Transbank.Patpass.PatpassComercio.Requests +{ + public class FInishRequest + { + + } +} diff --git a/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs b/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs new file mode 100644 index 0000000..036c591 --- /dev/null +++ b/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs @@ -0,0 +1,94 @@ +using Newtonsoft.Json; +using Transbank.Common; +using System.Net.Http; + +namespace Transbank.Patpass.PatpassComercio.Requests +{ + internal class StartRequest : BaseRequest + { + [JsonProperty("url")] + public string Url { get; set; } + + [JsonProperty("nombre")] + public string Name { get; set; } + + [JsonProperty("pApellido")] + public string FLastname { get; set; } + + [JsonProperty("sApellido")] + public string SLastname { get; set; } + + [JsonProperty("rut")] + public string Rut { get; set; } + + [JsonProperty("serviceId")] + public string ServiceId { get; set; } + + [JsonProperty("finalUrl")] + public string FinalUrl { get; set; } + + [JsonProperty("commerceCode")] + public string CommerceCode { get; set; } + + [JsonProperty("montoMaximo")] + public int MaxAmount { get; set; } + + [JsonProperty("telefonoFijo")] + public string PhoneNumber { get; set; } + + [JsonProperty("telefonoCelular")] + public string MobileNumber { get; set; } + + [JsonProperty("nombrePatpPass")] + public string PatpassName { get; set; } + + [JsonProperty("correoPersona")] + public string PersonEmail { get; set; } + + [JsonProperty("correoComercio")] + public string CommerceEmail { get; set; } + + [JsonProperty("direccion")] + public string Address { get; set; } + + [JsonProperty("ciudad")] + public string City { get; set; } + + internal StartRequest( + string url, + string name, + string fLastname, + string sLastname, + string rut, + string serviceId, + string finalUrl, + string commerceCode, + int maxAmount, + string phoneNumber, + string mobileNumber, + string patpassName, + string personEmail, + string commerceEmail, + string address, + string city + ) : base("/restpatpass/v1/services/patInscription", HttpMethod.Post) + { + Url = url; + Name = name; + FLastname = fLastname; + SLastname = sLastname; + Rut = rut; + ServiceId = serviceId; + FinalUrl = finalUrl; + CommerceCode = commerceCode; + MaxAmount = maxAmount; + PhoneNumber = phoneNumber; + MobileNumber = mobileNumber; + PatpassName = patpassName; + PersonEmail = personEmail; + CommerceEmail = commerceEmail; + Address = address; + City = city; + } + } +} diff --git a/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs b/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs new file mode 100644 index 0000000..b316a4e --- /dev/null +++ b/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs @@ -0,0 +1,7 @@ +namespace Transbank.Patpass.PatpassComercio.Requests +{ + public class StatusRequest + { + + } +} diff --git a/Transbank/PatpassRest/PatpassComercio/Responses/FinishResponse.cs b/Transbank/PatpassRest/PatpassComercio/Responses/FinishResponse.cs new file mode 100644 index 0000000..dd0c2a1 --- /dev/null +++ b/Transbank/PatpassRest/PatpassComercio/Responses/FinishResponse.cs @@ -0,0 +1,7 @@ +namespace Transbank.Patpass.PatpassComercio.Responses +{ + public class FinishResponse + { + + } +} diff --git a/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs b/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs new file mode 100644 index 0000000..01d0233 --- /dev/null +++ b/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs @@ -0,0 +1,7 @@ +namespace Transbank.Patpass.PatpassComercio.Responses +{ + public class StartResponse + { + + } +} diff --git a/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs b/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs new file mode 100644 index 0000000..a9fcc07 --- /dev/null +++ b/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs @@ -0,0 +1,7 @@ +namespace Transbank.Patpass.PatpassComercio.Responses +{ + public class StatusResponse + { + + } +} From ebbad31d33cdfc5434d7513f94323ed56ae1abbf Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 12 Aug 2019 17:50:45 -0400 Subject: [PATCH 070/120] fix exceptions errors and double using of them --- .../Exceptions/InscriptionDeleteException.cs | 3 +-- .../Exceptions/InscriptionFinishException.cs | 3 +-- .../MallTransactionAuthorizeException.cs | 6 ++--- .../Responses/StartResponse.cs | 12 +++++++++ Transbank/Transbank.csproj | 2 -- .../Exceptions/InscriptionStartException.cs | 27 ------------------- Transbank/WebpayRest/Oneclick/Inscription.cs | 1 - .../WebpayRest/Oneclick/MallTransaction.cs | 2 +- 8 files changed, 18 insertions(+), 38 deletions(-) rename Transbank/{WebpayRest/Oneclick => }/Exceptions/InscriptionDeleteException.cs (88%) rename Transbank/{WebpayRest/Oneclick => }/Exceptions/InscriptionFinishException.cs (88%) rename Transbank/{WebpayRest/Oneclick => }/Exceptions/MallTransactionAuthorizeException.cs (82%) delete mode 100644 Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs diff --git a/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionDeleteException.cs b/Transbank/Exceptions/InscriptionDeleteException.cs similarity index 88% rename from Transbank/WebpayRest/Oneclick/Exceptions/InscriptionDeleteException.cs rename to Transbank/Exceptions/InscriptionDeleteException.cs index f97ffb2..f3d23c5 100644 --- a/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionDeleteException.cs +++ b/Transbank/Exceptions/InscriptionDeleteException.cs @@ -1,7 +1,6 @@ using System; -using Transbank.Exceptions; -namespace Transbank.Webpay.Oneclick.Exceptions +namespace Transbank.Exceptions { public class InscriptionDeleteException : TransbankException { diff --git a/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionFinishException.cs b/Transbank/Exceptions/InscriptionFinishException.cs similarity index 88% rename from Transbank/WebpayRest/Oneclick/Exceptions/InscriptionFinishException.cs rename to Transbank/Exceptions/InscriptionFinishException.cs index 77b3ee6..fbd135e 100644 --- a/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionFinishException.cs +++ b/Transbank/Exceptions/InscriptionFinishException.cs @@ -1,7 +1,6 @@ using System; -using Transbank.Exceptions; -namespace Transbank.Webpay.Oneclick.Exceptions +namespace Transbank.Exceptions { public class InscriptionFinishException : TransbankException { diff --git a/Transbank/WebpayRest/Oneclick/Exceptions/MallTransactionAuthorizeException.cs b/Transbank/Exceptions/MallTransactionAuthorizeException.cs similarity index 82% rename from Transbank/WebpayRest/Oneclick/Exceptions/MallTransactionAuthorizeException.cs rename to Transbank/Exceptions/MallTransactionAuthorizeException.cs index d24916d..8ed7640 100644 --- a/Transbank/WebpayRest/Oneclick/Exceptions/MallTransactionAuthorizeException.cs +++ b/Transbank/Exceptions/MallTransactionAuthorizeException.cs @@ -1,7 +1,6 @@ -using System; -using Transbank.Exceptions; +using System; -namespace Transbank.Webpay.Oneclick.Exceptions +namespace Transbank.Exceptions { public class MallTransactionAuthorizeException : TransbankException { @@ -11,5 +10,6 @@ public MallTransactionAuthorizeException(int code, string message) : base(code, public MallTransactionAuthorizeException(int code, string message, Exception innerException) : base(code, message, innerException) { } + } } diff --git a/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs b/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs index 01d0233..8b8afb1 100644 --- a/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs +++ b/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs @@ -1,7 +1,19 @@ +using Newtonsoft.Json; + namespace Transbank.Patpass.PatpassComercio.Responses { public class StartResponse { + [JsonProperty("token")] + public string Token { get; private set; } + + [JsonProperty("url")] + public string Url { get; private set; } + + public override string ToString() + { + return $"Token={Token}, Url={Url}"; + } } } diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 513989b..650022b 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -119,9 +119,7 @@ - - diff --git a/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs b/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs deleted file mode 100644 index ab0a716..0000000 --- a/Transbank/WebpayRest/Oneclick/Exceptions/InscriptionStartException.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using Transbank.Exceptions; - -namespace Transbank.Webpay.Oneclick.Exceptions -{ - public class InscriptionStartException : TransbankException - { - public InscriptionStartException() : base() - { - } - - public InscriptionStartException(string message) - : base(-1, message) - { - } - - public InscriptionStartException(int code, string message) - : base(code, message) - { - } - - public InscriptionStartException(int code, string message, - Exception innerException) : base(code, message, innerException) - { - } - } -} diff --git a/Transbank/WebpayRest/Oneclick/Inscription.cs b/Transbank/WebpayRest/Oneclick/Inscription.cs index 21a739c..dbd3532 100644 --- a/Transbank/WebpayRest/Oneclick/Inscription.cs +++ b/Transbank/WebpayRest/Oneclick/Inscription.cs @@ -4,7 +4,6 @@ using Transbank.Exceptions; using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.Oneclick.Responses; -using Transbank.Webpay.Oneclick.Exceptions; namespace Transbank.Webpay.Oneclick { diff --git a/Transbank/WebpayRest/Oneclick/MallTransaction.cs b/Transbank/WebpayRest/Oneclick/MallTransaction.cs index 87397f5..7c9af80 100644 --- a/Transbank/WebpayRest/Oneclick/MallTransaction.cs +++ b/Transbank/WebpayRest/Oneclick/MallTransaction.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using Transbank.Common; using Transbank.Webpay.Common; -using Transbank.Webpay.Oneclick.Exceptions; +using Transbank.Exceptions; using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.Oneclick.Responses; From 632e9fdc2fbba9a32fa983d98f053ff2f06a84f1 Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Tue, 13 Aug 2019 16:41:16 -0400 Subject: [PATCH 071/120] Add Commit to MallDeferredTransactions --- .../WebpayRest/WebpayPlus/MallDeferredTransaction.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index b13a9b1..9ca6b59 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs @@ -52,5 +52,15 @@ public static MallCreateResponse Create(string buyOrder, string sessionId, strin { return MallTransaction.Create(buyOrder, sessionId, returnUrl, transactions, options); } + + public static MallCommitResponse Commit(string token) + { + return Commit(token, DefaultOptions()); + } + + public static MallCommitResponse Commit(string token, Options options) + { + return MallTransaction.Commit(token, options); + } } } From 31210821384730a6541197570f1f57683834f1c6 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Tue, 13 Aug 2019 18:10:10 -0400 Subject: [PATCH 072/120] add transaction status --- .../Exceptions/InscriptionStatusException.cs | 14 ++++++++++++++ .../PatpassComercio/Inscription.cs | 19 +++++++++++++++++-- .../PatpassComercio/Requests/FInishRequest.cs | 7 ------- .../PatpassComercio/Requests/StatusRequest.cs | 17 ++++++++++++++++- .../Responses/FinishResponse.cs | 7 ------- .../Responses/StatusResponse.cs | 12 ++++++++++++ 6 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 Transbank/Exceptions/InscriptionStatusException.cs delete mode 100644 Transbank/PatpassRest/PatpassComercio/Requests/FInishRequest.cs delete mode 100644 Transbank/PatpassRest/PatpassComercio/Responses/FinishResponse.cs diff --git a/Transbank/Exceptions/InscriptionStatusException.cs b/Transbank/Exceptions/InscriptionStatusException.cs new file mode 100644 index 0000000..93a6ce3 --- /dev/null +++ b/Transbank/Exceptions/InscriptionStatusException.cs @@ -0,0 +1,14 @@ +using System; + +namespace Transbank.Exceptions +{ + public class InscriptionStatusException : TransbankException + { + public InscriptionStatusException(string message) : base(-1, message){ } + + public InscriptionStatusException(int code, string message) : base(code, message){} + + public InscriptionStatusException(int code, string message, Exception innerException) : base(code, message, + innerException){} + } +} diff --git a/Transbank/PatpassRest/PatpassComercio/Inscription.cs b/Transbank/PatpassRest/PatpassComercio/Inscription.cs index f3beb76..ad43ba5 100644 --- a/Transbank/PatpassRest/PatpassComercio/Inscription.cs +++ b/Transbank/PatpassRest/PatpassComercio/Inscription.cs @@ -1,6 +1,4 @@ using System; -using System.CodeDom; -using System.Net; using Newtonsoft.Json; using Transbank.Common; using Transbank.Exceptions; @@ -94,6 +92,23 @@ Options options return JsonConvert.DeserializeObject(response); } + + public static StatusResponse Status(string token) + { + return Status(token, DefaultOptions()); + } + + public static StatusResponse Status(string token, Options options) + { + return ExceptionHandler.Perform(() => + { + var statusRequest = new StatusRequest(token); + var response = RequestService.Perform( + statusRequest, options); + + return JsonConvert.DeserializeObject(response); + }); + } } } diff --git a/Transbank/PatpassRest/PatpassComercio/Requests/FInishRequest.cs b/Transbank/PatpassRest/PatpassComercio/Requests/FInishRequest.cs deleted file mode 100644 index efb340a..0000000 --- a/Transbank/PatpassRest/PatpassComercio/Requests/FInishRequest.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Transbank.Patpass.PatpassComercio.Requests -{ - public class FInishRequest - { - - } -} diff --git a/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs b/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs index b316a4e..fa3059d 100644 --- a/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs +++ b/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs @@ -1,7 +1,22 @@ +using System.Net.Http; +using Transbank.Common; +using Newtonsoft.Json; + namespace Transbank.Patpass.PatpassComercio.Requests { - public class StatusRequest + internal class StatusRequest : BaseRequest { + [JsonProperty("token")] + public string Token { get; set; } + + + internal StatusRequest( + string token + ) : base($"/restpatpass/v1/services/status", + HttpMethod.Post) + { + Token = token; + } } } diff --git a/Transbank/PatpassRest/PatpassComercio/Responses/FinishResponse.cs b/Transbank/PatpassRest/PatpassComercio/Responses/FinishResponse.cs deleted file mode 100644 index dd0c2a1..0000000 --- a/Transbank/PatpassRest/PatpassComercio/Responses/FinishResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Transbank.Patpass.PatpassComercio.Responses -{ - public class FinishResponse - { - - } -} diff --git a/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs b/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs index a9fcc07..c85c009 100644 --- a/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs +++ b/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs @@ -1,7 +1,19 @@ +using Newtonsoft.Json; + namespace Transbank.Patpass.PatpassComercio.Responses { public class StatusResponse { + [JsonProperty("status")] + public string Status { get; set; } + [JsonProperty("urlVoucher")] + public string UrlVoucher { get; set; } + + public override string ToString() + { + return $"status: {Status}\n" + + $"url voucher: {UrlVoucher}"; + } } } From 15d8e7d66bcb96eb4ccca0aa8833e5f7d827473c Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Wed, 14 Aug 2019 10:47:57 -0400 Subject: [PATCH 073/120] fix add commerce code and apikey --- Transbank/PatpassRest/PatpassComercio/Inscription.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Transbank/PatpassRest/PatpassComercio/Inscription.cs b/Transbank/PatpassRest/PatpassComercio/Inscription.cs index ad43ba5..6053465 100644 --- a/Transbank/PatpassRest/PatpassComercio/Inscription.cs +++ b/Transbank/PatpassRest/PatpassComercio/Inscription.cs @@ -10,8 +10,8 @@ namespace Transbank.Patpass.PatpassComercio { public static class Inscription { - private static string _commerceCode = ""; - private static string _apiKey = ""; + private static string _commerceCode = "28299257"; + private static string _apiKey = "cxxXQgGD9vrVe4M41FIt"; private static PatpassComercioIntegrationType _integrationType = PatpassComercioIntegrationType.Test; public static string CommerceCode From 37166cafa7bc3daabdd247aefbf9b24405bf5249 Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Wed, 14 Aug 2019 17:09:30 -0400 Subject: [PATCH 074/120] Add refund and status for Webpay Plus Mall Diferido --- .../WebpayPlus/MallDeferredTransaction.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index 9ca6b59..945c730 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs @@ -62,5 +62,26 @@ public static MallCommitResponse Commit(string token, Options options) { return MallTransaction.Commit(token, options); } + + public static MallRefundResponse Refund(string token, string buyOrder, string commerceCode, decimal amount) + { + return Refund(token, buyOrder, commerceCode, amount, DefaultOptions()); + } + + public static MallRefundResponse Refund(string token, string buyOrder, string commerceCode, decimal amount, + Options options) + { + return MallTransaction.Refund(token, buyOrder, commerceCode, amount, options); + } + + public static MallStatusResponse Status(string token) + { + return Status(token, DefaultOptions()); + } + + public static MallStatusResponse Status(string token, Options options) + { + return MallTransaction.Status(token, options); + } } } From 6ac0e1a6d7d90e377ae75e46ccea7c5a5ef6e019 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 19 Aug 2019 10:52:06 -0400 Subject: [PATCH 075/120] add transaccion completa create method --- .../TransaccionCompleta/Common/Detail.cs | 26 ++++++ .../Requests/CreateRequest.cs | 44 ++++++++++ .../Responses/CreateResponse.cs | 15 ++++ .../TransaccionCompleta/Transaction.cs | 81 +++++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Common/Detail.cs create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Requests/CreateRequest.cs create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Transaction.cs diff --git a/Transbank/WebpayRest/TransaccionCompleta/Common/Detail.cs b/Transbank/WebpayRest/TransaccionCompleta/Common/Detail.cs new file mode 100644 index 0000000..2f58c8d --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Common/Detail.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompleta.Common +{ + public class Detail + { + [JsonProperty("amount")] + internal int Amount { get; } + + [JsonProperty("commerce_code")] + internal int CommerceCode { get; } + + [JsonProperty("buy_order")] + internal string BuyOrder { get; } + + public Detail( + int amount, + int commerceCode, + string buyOrder) + { + Amount = amount; + CommerceCode = commerceCode; + BuyOrder = buyOrder; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/CreateRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/CreateRequest.cs new file mode 100644 index 0000000..767d428 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/CreateRequest.cs @@ -0,0 +1,44 @@ +using Newtonsoft.Json; +using Transbank.Common; +using System.Net.Http; + +namespace Transbank.Webpay.TransaccionCompleta.Requests +{ + public class CreateRequest : BaseRequest + { + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + [JsonProperty("session_id")] + public string SessionId { get; set; } + + [JsonProperty("amount")] + public int Amount { get; set; } + + [JsonProperty("cvv")] + public int Cvv { get; set; } + + [JsonProperty("card_number")] + public string CardNumber { get; set; } + + [JsonProperty("card_expiration_date")] + public string CardExpirationDate { get; set; } + + internal CreateRequest( + string buyOrder, + string sessionId, + int amount, + int cvv, + string cardNumber, + string cardExpirationDate) + : base(" /rswebpaytransaction/api/webpay/v1.0/transactions", HttpMethod.Post) + { + BuyOrder = buyOrder; + SessionId = sessionId; + Amount = amount; + Cvv = cvv; + CardNumber = cardNumber; + CardExpirationDate = cardExpirationDate; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs new file mode 100644 index 0000000..780e674 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompleta.Responses +{ + public class CreateResponse + { + [JsonProperty("token")] + public string Token { get; private set; } + + public override string ToString() + { + return $"Token={Token}"; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs b/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs new file mode 100644 index 0000000..4fb913b --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs @@ -0,0 +1,81 @@ +using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using Transbank.Common; +using Transbank.Exceptions; +using Transbank.Webpay.Common; +using Transbank.Webpay.Oneclick.Requests; +using Transbank.Webpay.TransaccionCompleta.Requests; +using Transbank.Webpay.TransaccionCompleta.Responses; + +namespace Transbank.Webpay.TransaccionCompleta +{ + public static class Transaction + { + + private static string _commerceCode = "597055555530"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null" + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null" + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + + public static CreateResponse Create( + string buyOrder, + string sessionId, + int amount, + int cvv, + string cardNumber, + string cardExpirationDate) + { + return Create(buyOrder, sessionId, amount, cvv, cardNumber, cardExpirationDate, DefaultOptions()); + } + + public static CreateResponse Create( + string buyOrder, + string sessionId, + int amount, + int cvv, + string cardNumber, + string cardExpirationDate, + Options options) + { + var createRequest = new CreateRequest( + buyOrder, + sessionId, + amount, + cvv, + cardNumber, + cardExpirationDate); + var response = RequestService.Perform(createRequest, options); + + return JsonConvert.DeserializeObject(response); + } + } +} From 15678a216bcb704ab4c36791269c36e7ccc9b758 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 19 Aug 2019 11:00:31 -0400 Subject: [PATCH 076/120] fix change class name to FullTransaction --- Transbank/WebpayRest/TransaccionCompleta/Transaction.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs b/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs index 4fb913b..3586621 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs @@ -8,7 +8,7 @@ using Transbank.Webpay.TransaccionCompleta.Requests; using Transbank.Webpay.TransaccionCompleta.Responses; -namespace Transbank.Webpay.TransaccionCompleta +namespace Transbank.Webpay.FullTransaction { public static class Transaction { From a9c6d983426fe187ad09c05e4543e181c8346969 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 19 Aug 2019 11:05:05 -0400 Subject: [PATCH 077/120] fix change class name to FullTransaction rollback change of namespace --- Transbank/WebpayRest/TransaccionCompleta/Transaction.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs b/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs index 3586621..b73f6a7 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs @@ -8,9 +8,9 @@ using Transbank.Webpay.TransaccionCompleta.Requests; using Transbank.Webpay.TransaccionCompleta.Responses; -namespace Transbank.Webpay.FullTransaction +namespace Transbank.Webpay.TransaccionCompleta { - public static class Transaction + public static class FullTransaction { private static string _commerceCode = "597055555530"; From 662b8c91f61c4989536454a568c1781334bc677d Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 19 Aug 2019 13:41:43 -0400 Subject: [PATCH 078/120] fix call function and endpoint to call --- .../Requests/CreateRequest.cs | 4 +- .../TransaccionCompleta.cs | 43 +++++++++++++ .../TransaccionCompleta/Transaction.cs | 63 +++++-------------- 3 files changed, 61 insertions(+), 49 deletions(-) create mode 100644 Transbank/WebpayRest/TransaccionCompleta/TransaccionCompleta.cs diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/CreateRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/CreateRequest.cs index 767d428..12002c5 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Requests/CreateRequest.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/CreateRequest.cs @@ -4,7 +4,7 @@ namespace Transbank.Webpay.TransaccionCompleta.Requests { - public class CreateRequest : BaseRequest + internal class CreateRequest : BaseRequest { [JsonProperty("buy_order")] public string BuyOrder { get; set; } @@ -31,7 +31,7 @@ internal CreateRequest( int cvv, string cardNumber, string cardExpirationDate) - : base(" /rswebpaytransaction/api/webpay/v1.0/transactions", HttpMethod.Post) + : base("/rswebpaytransaction/api/webpay/v1.0/transactions", HttpMethod.Post) { BuyOrder = buyOrder; SessionId = sessionId; diff --git a/Transbank/WebpayRest/TransaccionCompleta/TransaccionCompleta.cs b/Transbank/WebpayRest/TransaccionCompleta/TransaccionCompleta.cs new file mode 100644 index 0000000..ecf7656 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/TransaccionCompleta.cs @@ -0,0 +1,43 @@ +using System; +using Transbank.Common; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.TransaccionCompleta +{ + public class TransaccionCompleta + { + private static string _commerceCode = "597055555530"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs b/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs index b73f6a7..77de341 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs @@ -1,10 +1,7 @@ -using System; using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; using Transbank.Common; using Transbank.Exceptions; using Transbank.Webpay.Common; -using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.TransaccionCompleta.Requests; using Transbank.Webpay.TransaccionCompleta.Responses; @@ -12,40 +9,7 @@ namespace Transbank.Webpay.TransaccionCompleta { public static class FullTransaction { - - private static string _commerceCode = "597055555530"; - private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; - - public static string CommerceCode - { - get => _commerceCode; - set => _commerceCode = value ?? throw new ArgumentNullException( - nameof(value), "Commerce code can't be null" - ); - } - - public static string ApiKey - { - get => _apiKey; - set => _apiKey = value ?? throw new ArgumentNullException( - nameof(value), "Api Key can't be null" - ); - } - - public static WebpayIntegrationType IntegrationType - { - get => _integrationType; - set => _integrationType = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null." - ); - } - - public static Options DefaultOptions() - { - return new Options(CommerceCode, ApiKey, IntegrationType); - } - + public static CreateResponse Create( string buyOrder, string sessionId, @@ -54,7 +18,7 @@ public static CreateResponse Create( string cardNumber, string cardExpirationDate) { - return Create(buyOrder, sessionId, amount, cvv, cardNumber, cardExpirationDate, DefaultOptions()); + return Create(buyOrder, sessionId, amount, cvv, cardNumber, cardExpirationDate, TransaccionCompleta.DefaultOptions()); } public static CreateResponse Create( @@ -66,16 +30,21 @@ public static CreateResponse Create( string cardExpirationDate, Options options) { - var createRequest = new CreateRequest( - buyOrder, - sessionId, - amount, - cvv, - cardNumber, - cardExpirationDate); - var response = RequestService.Perform(createRequest, options); + return ExceptionHandler.Perform(() => + { + var createRequest = new CreateRequest( + buyOrder, + sessionId, + amount, + cvv, + cardNumber, + cardExpirationDate); + var response = RequestService.Perform(createRequest, options); + + return JsonConvert.DeserializeObject(response); + + }); - return JsonConvert.DeserializeObject(response); } } } From 71f3587df2b37f5cfa33ef400ceb3023c8192621 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 19 Aug 2019 15:41:40 -0400 Subject: [PATCH 079/120] fix refactor add default options to Full Transaction class --- .../{Transaction.cs => FullTransaction.cs} | 37 +++++++++++++++- .../TransaccionCompleta.cs | 43 ------------------- 2 files changed, 35 insertions(+), 45 deletions(-) rename Transbank/WebpayRest/TransaccionCompleta/{Transaction.cs => FullTransaction.cs} (51%) delete mode 100644 Transbank/WebpayRest/TransaccionCompleta/TransaccionCompleta.cs diff --git a/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs similarity index 51% rename from Transbank/WebpayRest/TransaccionCompleta/Transaction.cs rename to Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs index 77de341..b5e4233 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Transaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs @@ -1,3 +1,4 @@ +using System; using Newtonsoft.Json; using Transbank.Common; using Transbank.Exceptions; @@ -9,7 +10,39 @@ namespace Transbank.Webpay.TransaccionCompleta { public static class FullTransaction { - + private static string _commerceCode = "597055555530"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } public static CreateResponse Create( string buyOrder, string sessionId, @@ -18,7 +51,7 @@ public static CreateResponse Create( string cardNumber, string cardExpirationDate) { - return Create(buyOrder, sessionId, amount, cvv, cardNumber, cardExpirationDate, TransaccionCompleta.DefaultOptions()); + return Create(buyOrder, sessionId, amount, cvv, cardNumber, cardExpirationDate, DefaultOptions()); } public static CreateResponse Create( diff --git a/Transbank/WebpayRest/TransaccionCompleta/TransaccionCompleta.cs b/Transbank/WebpayRest/TransaccionCompleta/TransaccionCompleta.cs deleted file mode 100644 index ecf7656..0000000 --- a/Transbank/WebpayRest/TransaccionCompleta/TransaccionCompleta.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using Transbank.Common; -using Transbank.Webpay.Common; - -namespace Transbank.Webpay.TransaccionCompleta -{ - public class TransaccionCompleta - { - private static string _commerceCode = "597055555530"; - private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - - private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; - - public static string CommerceCode - { - get => _commerceCode; - set => _commerceCode = value ?? throw new ArgumentNullException( - nameof(value), "Commerce code can't be null." - ); - } - - public static string ApiKey - { - get => _apiKey; - set => _apiKey = value ?? throw new ArgumentNullException( - nameof(value), "Api Key can't be null." - ); - } - - public static WebpayIntegrationType IntegrationType - { - get => _integrationType; - set => _integrationType = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null." - ); - } - - public static Options DefaultOptions() - { - return new Options(CommerceCode, ApiKey, IntegrationType); - } - } -} From a1fb72aeb5f6cee4c8a141459e93eaa0f3dc6981 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 19 Aug 2019 16:24:42 -0400 Subject: [PATCH 080/120] add transaction installments functions --- .../TransactionInstallmentsException.cs | 15 +++++++++++ .../Common/DeferredPeriods.cs | 19 ++++++++++++++ .../TransaccionCompleta/FullTransaction.cs | 19 ++++++++++++++ .../Requests/InstallmentsRequest.cs | 11 ++++++++ .../Responses/InstallmentsResponse.cs | 25 +++++++++++++++++++ 5 files changed, 89 insertions(+) create mode 100644 Transbank/Exceptions/TransactionInstallmentsException.cs create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Common/DeferredPeriods.cs create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs diff --git a/Transbank/Exceptions/TransactionInstallmentsException.cs b/Transbank/Exceptions/TransactionInstallmentsException.cs new file mode 100644 index 0000000..4af19bc --- /dev/null +++ b/Transbank/Exceptions/TransactionInstallmentsException.cs @@ -0,0 +1,15 @@ +using System; + +namespace Transbank.Exceptions +{ + public class TransactionInstallmentsException : TransbankException + { + public TransactionInstallmentsException(string message) : base(-1, message) { } + + public TransactionInstallmentsException(int code, string message) : base(code, message) { } + + public TransactionInstallmentsException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Common/DeferredPeriods.cs b/Transbank/WebpayRest/TransaccionCompleta/Common/DeferredPeriods.cs new file mode 100644 index 0000000..9452404 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Common/DeferredPeriods.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompleta.Common +{ + public class DeferredPeriods + { + [JsonProperty("amount")] + internal int Amount { get; } + + [JsonProperty("period")] + internal int Period { get; } + + public DeferredPeriods(int amount, int period) + { + Amount= amount; + Period = period; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs index b5e4233..630b4ca 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs @@ -79,5 +79,24 @@ public static CreateResponse Create( }); } + + public static InstallmentsResponse Installments( + string token) + { + return Installments(token, DefaultOptions()); + } + + public static InstallmentsResponse Installments( + string token, + Options options) + { + return ExceptionHandler.Perform(() => + { + var installmentsRequest = new InstallmentsRequest(token); + var response = RequestService.Perform(installmentsRequest, options); + + return JsonConvert.DeserializeObject(response); + }); + } } } diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs new file mode 100644 index 0000000..d715507 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs @@ -0,0 +1,11 @@ +using System.Net.Http; +using Transbank.Common; + +namespace Transbank.Webpay.TransaccionCompleta.Requests +{ + internal class InstallmentsRequest : BaseRequest + { + internal InstallmentsRequest(string token) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Post) {} + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs new file mode 100644 index 0000000..d0b7a0a --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Transbank.Webpay.TransaccionCompleta.Common; + +namespace Transbank.Webpay.TransaccionCompleta.Responses +{ + public class InstallmentsResponse + { + [JsonProperty("installments_amount")] + public int InstallmentsAmount { get; set; } + + [JsonProperty("id_query_installments")] + public int IdQueryInstallments { get; set; } + + [JsonProperty("deferred_periods")] + public List DeferredPeriods { get; set; } + + public InstallmentsResponse(int installmentsAmount, int idQueryInstallments, List deferredPeriods) + { + InstallmentsAmount = installmentsAmount; + IdQueryInstallments = idQueryInstallments; + DeferredPeriods = deferredPeriods; + } + } +} From f2897485f1dd91c81910cc0ed72e608cee4cbf4c Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 19 Aug 2019 16:34:20 -0400 Subject: [PATCH 081/120] fix add installments number in class --- .../WebpayRest/TransaccionCompleta/FullTransaction.cs | 8 +++++--- .../Requests/InstallmentsRequest.cs | 11 +++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs index 630b4ca..ab4a17e 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs @@ -81,18 +81,20 @@ public static CreateResponse Create( } public static InstallmentsResponse Installments( - string token) + string token, + int installmentsNumber) { - return Installments(token, DefaultOptions()); + return Installments(token, installmentsNumber, DefaultOptions()); } public static InstallmentsResponse Installments( string token, + int installmentsNumber, Options options) { return ExceptionHandler.Perform(() => { - var installmentsRequest = new InstallmentsRequest(token); + var installmentsRequest = new InstallmentsRequest(token, installmentsNumber); var response = RequestService.Perform(installmentsRequest, options); return JsonConvert.DeserializeObject(response); diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs index d715507..a6d4e20 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs @@ -1,11 +1,18 @@ using System.Net.Http; +using Newtonsoft.Json; using Transbank.Common; namespace Transbank.Webpay.TransaccionCompleta.Requests { internal class InstallmentsRequest : BaseRequest { - internal InstallmentsRequest(string token) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Post) {} + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; set; } + + internal InstallmentsRequest(string token, int installmentsNumber) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Post) + { + InstallmentsNumber = installmentsNumber; + } } } From 70351c7c4622d0bf73098cbe16279b1dbbfc9a45 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Tue, 20 Aug 2019 10:06:00 -0400 Subject: [PATCH 082/120] add commit transaction method --- .../TransaccionCompleta/Common/CardDetail.cs | 15 +++++ .../TransaccionCompleta/FullTransaction.cs | 29 +++++++++ .../Requests/CommitRequest.cs | 29 +++++++++ .../Responses/CommitResponse.cs | 61 +++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Common/CardDetail.cs create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Requests/CommitRequest.cs create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs diff --git a/Transbank/WebpayRest/TransaccionCompleta/Common/CardDetail.cs b/Transbank/WebpayRest/TransaccionCompleta/Common/CardDetail.cs new file mode 100644 index 0000000..cbfa5b2 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Common/CardDetail.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompleta.Common +{ + public class CardDetail + { + [JsonProperty("card_number")] + internal string CardNumber { get; } + + public CardDetail(string cardNumber) + { + CardNumber = cardNumber; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs index ab4a17e..6a1b7f6 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs @@ -100,5 +100,34 @@ public static InstallmentsResponse Installments( return JsonConvert.DeserializeObject(response); }); } + + public static CommitResponse Commit( + string token, + int idQueryInstallments, + int deferredPeriods, + bool gracePeriod) + { + return Commit(token, idQueryInstallments, deferredPeriods, gracePeriod, DefaultOptions()); + } + + public static CommitResponse Commit( + string token, + int idQueryInstallments, + int deferredPeriodsIndex, + bool gracePeriods, + Options options) + { + return ExceptionHandler.Perform(() => + { + var commitRequest = new CommitRequest( + token, + idQueryInstallments, + deferredPeriodsIndex, + gracePeriods, + options); + var response = RequestService.Perform(commitRequest, options); + return JsonConvert.DeserializeObject(response); + }); + } } } diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/CommitRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/CommitRequest.cs new file mode 100644 index 0000000..f9c521e --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/CommitRequest.cs @@ -0,0 +1,29 @@ +using Newtonsoft.Json; +using Transbank.Common; +using System.Net.Http; + +namespace Transbank.Webpay.TransaccionCompleta.Requests +{ + internal class CommitRequest : BaseRequest + { + [JsonProperty("id_query_installments")] + public int IdQueryInstallments { get; set; } + + [JsonProperty("deferred_period_index")] + public int DeferredPeriodIndex { get; set; } + + [JsonProperty("grace_period")] + public bool GracePeriod { get; set; } + + internal CommitRequest(string token, + int idQueryInstallments, + int deferredPeriodIndex, + bool gracePeriod, Options options) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) + { + IdQueryInstallments = idQueryInstallments; + DeferredPeriodIndex = deferredPeriodIndex; + GracePeriod = gracePeriod; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs new file mode 100644 index 0000000..5d1ac0b --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs @@ -0,0 +1,61 @@ +using Newtonsoft.Json; +using Transbank.Webpay.TransaccionCompleta.Common; + +namespace Transbank.Webpay.TransaccionCompleta.Responses +{ + public class CommitResponse + { + [JsonProperty("amount")] + public int Amount { get; private set; } + + [JsonProperty("status")] + public string Status { get; private set; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; private set; } + + [JsonProperty("session_id")] + public string SessionId { get; private set; } + + [JsonProperty("card_detail")] + public CardDetail CardDetail { get; private set; } + + [JsonProperty("accounting_date")] + public string AccountingDate { get; private set; } + + [JsonProperty("transaction_date")] + public string TransactionDate { get; private set; } + + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; private set; } + + [JsonProperty("payment_type_code")] + public string PaymentTypeCode { get; private set; } + + [JsonProperty("response_code")] + public int ResponseCode { get; private set; } + + [JsonProperty("installments_amount")] + public int InstallmentsAmount { get; private set; } + + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; private set; } + + public override string ToString() + { + return $"Amount={Amount}\n" + + $"Status={Status}\n" + + $"Buy Order={BuyOrder}\n" + + $"Session Id={SessionId}\n" + + $"Card Detail={CardDetail}\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"; + } + + } +} From 1fc782b59b9aa1dc747239b4e4d16ed534a9c9dc Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Tue, 20 Aug 2019 11:40:45 -0400 Subject: [PATCH 083/120] fix refactor code --- .../TransaccionCompleta/FullTransaction.cs | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs index 6a1b7f6..2b082ce 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs @@ -95,7 +95,8 @@ public static InstallmentsResponse Installments( return ExceptionHandler.Perform(() => { var installmentsRequest = new InstallmentsRequest(token, installmentsNumber); - var response = RequestService.Perform(installmentsRequest, options); + var response = RequestService.Perform( + installmentsRequest, options); return JsonConvert.DeserializeObject(response); }); @@ -117,17 +118,15 @@ public static CommitResponse Commit( bool gracePeriods, Options options) { - return ExceptionHandler.Perform(() => - { - var commitRequest = new CommitRequest( - token, - idQueryInstallments, - deferredPeriodsIndex, - gracePeriods, - options); - var response = RequestService.Perform(commitRequest, options); - return JsonConvert.DeserializeObject(response); - }); + var commitRequest = new CommitRequest( + token, + idQueryInstallments, + deferredPeriodsIndex, + gracePeriods, + options); + var response = RequestService.Perform(commitRequest, options); + return JsonConvert.DeserializeObject(response); + } } } From 523a541a813aac5f0e6bafa55098ffdcbb35c6ad Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Tue, 20 Aug 2019 11:46:56 -0400 Subject: [PATCH 084/120] fix add custom request service to patpasscomercio --- .../PatpassRest/Common/RequestService.cs | 50 +++++++++++++++++++ .../PatpassByWebpay/Transaction.cs | 1 + .../PatpassComercio/Inscription.cs | 1 + 3 files changed, 52 insertions(+) create mode 100644 Transbank/PatpassRest/Common/RequestService.cs diff --git a/Transbank/PatpassRest/Common/RequestService.cs b/Transbank/PatpassRest/Common/RequestService.cs new file mode 100644 index 0000000..56167ce --- /dev/null +++ b/Transbank/PatpassRest/Common/RequestService.cs @@ -0,0 +1,50 @@ +using System; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Transbank.Common; +using Transbank.Exceptions; + +namespace Transbank.Patpass.Common +{ + public class RequestService + { + private static readonly string CONTENT_TYPE = "application/json"; + + private static void AddRequiredHeaders(HttpClient client, string commerceCode, string apiKey) + { + var header = new MediaTypeWithQualityHeaderValue(CONTENT_TYPE); + client.DefaultRequestHeaders.Accept.Add(header); + client.DefaultRequestHeaders.Add("commercecode", commerceCode); + client.DefaultRequestHeaders.Add("Authorization", apiKey); + } + + public static string Perform(BaseRequest request, Options options) where T : TransbankException + { + var message = new HttpRequestMessage(request.Method, new Uri(options.IntegrationType.ApiBase + request.Endpoint)); + if (request.Method != HttpMethod.Get) + message.Content = new StringContent(JsonConvert.SerializeObject(request), + Encoding.UTF8, CONTENT_TYPE); + + using (var client = new HttpClient()) + { + AddRequiredHeaders(client, options.CommerceCode, options.ApiKey); + var response = client.SendAsync(message).ConfigureAwait(false) + .GetAwaiter().GetResult(); + var jsonResponse = response.Content.ReadAsStringAsync() + .ConfigureAwait(false).GetAwaiter().GetResult(); + if (!response.IsSuccessStatusCode) + { + var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonResponse); + throw (T)Activator.CreateInstance(typeof(T), new object[] { + (int)response.StatusCode, $"Error message: {jsonObject.Value("error_message")}" + }); + } + return jsonResponse; + } + } + } +} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs index 4fc5d42..8888825 100644 --- a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs +++ b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs @@ -5,6 +5,7 @@ using Transbank.Patpass.Common; using Transbank.Patpass.PatpassByWebpay.Requests; using Transbank.Patpass.PatpassByWebpay.Responses; +using RequestService = Transbank.Common.RequestService; namespace Transbank.Patpass.PatpassByWebpay { diff --git a/Transbank/PatpassRest/PatpassComercio/Inscription.cs b/Transbank/PatpassRest/PatpassComercio/Inscription.cs index 6053465..5bb8460 100644 --- a/Transbank/PatpassRest/PatpassComercio/Inscription.cs +++ b/Transbank/PatpassRest/PatpassComercio/Inscription.cs @@ -5,6 +5,7 @@ using Transbank.Patpass.Common; using Transbank.Patpass.PatpassComercio.Requests; using Transbank.Patpass.PatpassComercio.Responses; +using RequestService = Transbank.Patpass.Common.RequestService; namespace Transbank.Patpass.PatpassComercio { From 3d8f6b9add4a62dd28009cf57a88196dc357b11e Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Wed, 21 Aug 2019 15:23:00 -0400 Subject: [PATCH 085/120] Add method Capture for WP Plus Mall Diferido --- Transbank/Common/Options.cs | 5 +++ .../Onepay/Model/TransactionCommitResponse.cs | 1 - .../WebpayPlus/DeferredTransaction.cs | 4 +- .../MallTransactionCaptureException.cs | 15 ++++++++ .../WebpayPlus/MallDeferredTransaction.cs | 22 +++++++++++ .../WebpayPlus/Requests/MallCaptureRequest.cs | 37 +++++++++++++++++++ .../Responses/MallCaptureResponse.cs | 8 ++++ 7 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCaptureException.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/MallCaptureRequest.cs create mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/MallCaptureResponse.cs diff --git a/Transbank/Common/Options.cs b/Transbank/Common/Options.cs index 77d3229..af8f2bb 100644 --- a/Transbank/Common/Options.cs +++ b/Transbank/Common/Options.cs @@ -38,5 +38,10 @@ public Options(string commerceCode, string apiKey, IIntegrationType integrationT ApiKey = apiKey; IntegrationType = integrationType; } + + public override string ToString() + { + return $"{nameof(CommerceCode)}: {CommerceCode}, {nameof(ApiKey)}: {ApiKey}, {nameof(IntegrationType)}: {IntegrationType}"; + } } } 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; } diff --git a/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs index 0c8c0d6..a628254 100644 --- a/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs @@ -92,9 +92,9 @@ public static CaptureResponse Capture(string token, string buyOrder, string auth } public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, - decimal captureAmount, Options options) + decimal captureAmount) { - return Capture(token, buyOrder, authorizationCode, captureAmount, null, options); + return Capture(token, buyOrder, authorizationCode, captureAmount, null, DefaultOptions()); } public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, diff --git a/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCaptureException.cs b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCaptureException.cs new file mode 100644 index 0000000..53da7a6 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Exceptions/MallTransactionCaptureException.cs @@ -0,0 +1,15 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.WebpayRest.WebpayPlus.Exceptions +{ + public class MallTransactionCaptureException : TransbankException + { + public MallTransactionCaptureException(string message) : base(-1, message) { } + + public MallTransactionCaptureException(int code, string message) : base(code, message) { } + + public MallTransactionCaptureException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index 945c730..f73ccff 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs @@ -1,8 +1,13 @@ using System; using System.Collections.Generic; +using Newtonsoft.Json; using Transbank.Common; +using Transbank.Onepay.Exceptions; using Transbank.Webpay.Common; using Transbank.Webpay.WebpayPlus.Responses; +using Transbank.WebpayRest.WebpayPlus.Exceptions; +using Transbank.WebpayRest.WebpayPlus.Requests; +using Transbank.WebpayRest.WebpayPlus.Responses; namespace Transbank.Webpay.WebpayPlus { @@ -83,5 +88,22 @@ public static MallStatusResponse Status(string token, Options options) { return MallTransaction.Status(token, options); } + + public static MallCaptureResponse Capture(string token, string commerceCode, string buyOrder, + string authorizationCode, decimal amount) + { + return Capture(token, commerceCode, buyOrder, authorizationCode, amount, DefaultOptions()); + } + + public static MallCaptureResponse Capture(string token, string commerceCode, string buyOrder, + string authorizationCode, decimal amount, Options options) + { + return ExceptionHandler.Perform(() => + { + var mallCaptureRequest = new MallCaptureRequest(token, commerceCode, buyOrder, authorizationCode, amount); + var response = RequestService.Perform(mallCaptureRequest, options); + return JsonConvert.DeserializeObject(response); + }); + } } } diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallCaptureRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallCaptureRequest.cs new file mode 100644 index 0000000..a66a8b3 --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Requests/MallCaptureRequest.cs @@ -0,0 +1,37 @@ +using System.Net.Http; +using Newtonsoft.Json; +using Transbank.Common; + +namespace Transbank.WebpayRest.WebpayPlus.Requests +{ + public class MallCaptureRequest : BaseRequest + { + [JsonProperty("commerce_code")] + private string CommerceCode { get; set; } + + [JsonProperty("buy_order")] + private string BuyOrder { get; set; } + + [JsonProperty("authorization_code")] + private string AuthorizationCode { get; set; } + + [JsonProperty("capture_amount")] + private decimal CaptureAmount { get; set; } + + public MallCaptureRequest(string token, string commerceCode, string buyOrder, string authorizationCode, + decimal captureAmount) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/capture", HttpMethod.Put) + { + CommerceCode = commerceCode; + BuyOrder = buyOrder; + AuthorizationCode = authorizationCode; + CaptureAmount = captureAmount; + } + + public override string ToString() + { + return + $"{nameof(CommerceCode)}: {CommerceCode}, {nameof(BuyOrder)}: {BuyOrder}, {nameof(AuthorizationCode)}: {AuthorizationCode}, {nameof(CaptureAmount)}: {CaptureAmount}"; + } + } +} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/MallCaptureResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/MallCaptureResponse.cs new file mode 100644 index 0000000..7be562f --- /dev/null +++ b/Transbank/WebpayRest/WebpayPlus/Responses/MallCaptureResponse.cs @@ -0,0 +1,8 @@ +using Transbank.Webpay.WebpayPlus.Responses; + +namespace Transbank.WebpayRest.WebpayPlus.Responses +{ + public class MallCaptureResponse : CaptureResponse + { + } +} From bd196847488538260d24f44bf4bc5bc2b478204c Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 31 Jul 2019 10:43:27 -0400 Subject: [PATCH 086/120] Throw Exception if mall authorization fails --- .../MallTransactionAuthorizeException.cs | 27 +++++++++++++++++++ .../WebpayRest/Oneclick/MallTransaction.cs | 17 ++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 Transbank/WebpayRest/Oneclick/Exceptions/MallTransactionAuthorizeException.cs diff --git a/Transbank/WebpayRest/Oneclick/Exceptions/MallTransactionAuthorizeException.cs b/Transbank/WebpayRest/Oneclick/Exceptions/MallTransactionAuthorizeException.cs new file mode 100644 index 0000000..f715f31 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Exceptions/MallTransactionAuthorizeException.cs @@ -0,0 +1,27 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.Webpay.Oneclick.Exceptions +{ + public class MallTransactionAuthorizeException : TransbankException + { + public MallTransactionAuthorizeException() : base() + { + } + + public MallTransactionAuthorizeException(string message) + : base(-1, message) + { + } + + public MallTransactionAuthorizeException(int code, string message) + : base(code, message) + { + } + + public MallTransactionAuthorizeException(int code, string message, + Exception innerException) : base(code, message, innerException) + { + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/MallTransaction.cs b/Transbank/WebpayRest/Oneclick/MallTransaction.cs index 7c9af80..5995f22 100644 --- a/Transbank/WebpayRest/Oneclick/MallTransaction.cs +++ b/Transbank/WebpayRest/Oneclick/MallTransaction.cs @@ -1,9 +1,11 @@ +using System; using Newtonsoft.Json; using Transbank.Common; -using Transbank.Webpay.Common; using Transbank.Exceptions; +using Transbank.Webpay.Common; using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.Oneclick.Responses; +using Transbank.Webpay.Oneclick.Exceptions; namespace Transbank.Webpay.Oneclick { @@ -17,14 +19,19 @@ public static AuthorizeResponse Authorize(string userName, string email, string public static AuthorizeResponse Authorize(string userName, string email, string responseUrl, Options options) { - return ExceptionHandler.Perform(() => + try { var startRequest = new StartRequest(userName, email, responseUrl); - var response = RequestService.Perform( - startRequest, options); + var response = RequestService.Perform(startRequest, options); return JsonConvert.DeserializeObject(response); - }); + } + catch (Exception e) + { + int code = e.GetType().Equals(typeof(TransbankException)) ? + ((TransbankException)e).Code : -1; + throw new MallTransactionAuthorizeException(code, e.Message, e); + } } } } From 8c101f264b34570584f971de4d88b45c7ae3495b Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 31 Jul 2019 11:07:15 -0400 Subject: [PATCH 087/120] Rename AuthorizeRequest to AuthorizeMallRequest --- .../Requests/{AuthorizeRequest.cs => AuthorizeMallRequest.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Transbank/WebpayRest/Oneclick/Requests/{AuthorizeRequest.cs => AuthorizeMallRequest.cs} (100%) diff --git a/Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs similarity index 100% rename from Transbank/WebpayRest/Oneclick/Requests/AuthorizeRequest.cs rename to Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs From fab8d8972f813632236385a21e1e249edbe1702c Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 31 Jul 2019 11:07:43 -0400 Subject: [PATCH 088/120] Rename TBKUser to TbkUser --- .../WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs | 5 ++--- Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs index e86027a..6a6bb7b 100644 --- a/Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs @@ -8,12 +8,11 @@ namespace Transbank.Webpay.Oneclick.Requests { internal class AuthorizeRequest : BaseRequest { - [JsonProperty("username")] internal string UserName { get; set; } [JsonProperty("tbk_user")] - internal string TBKUser { get; set; } + internal string TbkUser { get; set; } [JsonProperty("buy_order")] internal string BuyOrder { get; set; } @@ -25,7 +24,7 @@ internal AuthorizeRequest(string userName, string tbkUser, string buyOrder, List : base("/rswebpaytransaction/api/oneclick/v1.0/transactions", HttpMethod.Post) { UserName = userName; - TBKUser = tbkUser; + TbkUser = tbkUser; BuyOrder = buyOrder; Details = details; } diff --git a/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs index 3d391d8..fb89a11 100644 --- a/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs @@ -10,13 +10,13 @@ internal class DeleteRequest : BaseRequest internal string UserName { get; set; } [JsonProperty("tbk_user")] - internal string TBKUser { get; set; } + internal string TbkUser { get; set; } internal DeleteRequest(string userName, string tbkUser) : base("/rswebpaytransaction/api/oneclick/v1.0/inscriptions", HttpMethod.Delete) { UserName = userName; - TBKUser = tbkUser; + TbkUser = tbkUser; } } } From 8d43eb3215401e3fcfdc122590ef5dda21fdce09 Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 31 Jul 2019 11:18:35 -0400 Subject: [PATCH 089/120] Rename AuthorizeRequest to AuthorizeMallRequest --- .../WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs index 6a6bb7b..d376ba5 100644 --- a/Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs @@ -6,7 +6,7 @@ namespace Transbank.Webpay.Oneclick.Requests { - internal class AuthorizeRequest : BaseRequest + internal class AuthorizeMallRequest : BaseRequest { [JsonProperty("username")] internal string UserName { get; set; } @@ -20,7 +20,7 @@ internal class AuthorizeRequest : BaseRequest [JsonProperty("details")] internal List Details { get; set; } - internal AuthorizeRequest(string userName, string tbkUser, string buyOrder, List details) + internal AuthorizeMallRequest(string userName, string tbkUser, string buyOrder, List details) : base("/rswebpaytransaction/api/oneclick/v1.0/transactions", HttpMethod.Post) { UserName = userName; From b9640745524ae0dd19c43c5b691b124c446bf0be Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 31 Jul 2019 11:24:17 -0400 Subject: [PATCH 090/120] Execute Authorize Mall Transaction request --- .../WebpayRest/Oneclick/MallTransaction.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/MallTransaction.cs b/Transbank/WebpayRest/Oneclick/MallTransaction.cs index 5995f22..4367482 100644 --- a/Transbank/WebpayRest/Oneclick/MallTransaction.cs +++ b/Transbank/WebpayRest/Oneclick/MallTransaction.cs @@ -1,28 +1,33 @@ using System; using Newtonsoft.Json; using Transbank.Common; +using System.Collections.Generic; using Transbank.Exceptions; using Transbank.Webpay.Common; using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.Oneclick.Responses; using Transbank.Webpay.Oneclick.Exceptions; + namespace Transbank.Webpay.Oneclick { public static class MallTransaction { - public static AuthorizeResponse Authorize(string userName, string email, string responseUrl) + public static AuthorizeResponse Authorize(string userName, string tbkUser, + string buyOrder, List details) { - return Authorize(userName, email, responseUrl, Oneclick.DefaultOptions()); + return Authorize(userName, tbkUser, buyOrder, details, Oneclick.DefaultOptions()); } - public static AuthorizeResponse Authorize(string userName, string email, - string responseUrl, Options options) + public static AuthorizeResponse Authorize(string userName, + string tbkUser, string buyOrder, List details, + Options options) { try { - var startRequest = new StartRequest(userName, email, responseUrl); - var response = RequestService.Perform(startRequest, options); + var authorizeRequest = new AuthorizeMallRequest(userName, tbkUser, buyOrder, + details); + var response = RequestService.Perform(authorizeRequest, options); return JsonConvert.DeserializeObject(response); } From a887f3c8584b23e5a62517f144f2b6b3e669433e Mon Sep 17 00:00:00 2001 From: afiebig Date: Wed, 31 Jul 2019 11:38:21 -0400 Subject: [PATCH 091/120] Rename AuthorizeResponse to AuthorizeMallResponse --- Transbank/WebpayRest/Common/PaymentResponse.cs | 9 +++++++-- Transbank/WebpayRest/Oneclick/MallTransaction.cs | 6 +++--- .../{AuthorizeResponse.cs => AuthorizeMallResponse.cs} | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) rename Transbank/WebpayRest/Oneclick/Responses/{AuthorizeResponse.cs => AuthorizeMallResponse.cs} (91%) diff --git a/Transbank/WebpayRest/Common/PaymentResponse.cs b/Transbank/WebpayRest/Common/PaymentResponse.cs index b51ae62..0dd26bc 100644 --- a/Transbank/WebpayRest/Common/PaymentResponse.cs +++ b/Transbank/WebpayRest/Common/PaymentResponse.cs @@ -16,13 +16,17 @@ public class PaymentResponse : PaymentRequest [JsonProperty("installments_amount")] public int InstallmentsAmount { get; private set; } + [JsonProperty("status")] + public string Status { get; private set; } + public PaymentResponse (string comerceCode, string buyOrder, int ammount, int autorizationCode, - string paymentTypeCode, int responseCode, int installmentsAmmount) : base(comerceCode, buyOrder, ammount) + string paymentTypeCode, int responseCode, int installmentsAmmount, string status) : base(comerceCode, buyOrder, ammount) { AuthorizationCode = autorizationCode; PaymentTypeCode = paymentTypeCode; ResponseCode = responseCode; InstallmentsAmount = installmentsAmmount; + Status = status; } public override string ToString() @@ -31,7 +35,8 @@ public override string ToString() $"InstallmentsAmount= {InstallmentsAmount}\n" + $"AuthorizationCode= {AuthorizationCode}\n" + $"PaymentTypeCode= {PaymentTypeCode}\n" + - $"ResponseCode= {ResponseCode}\n"; + $"ResponseCode= {ResponseCode}\n" + + $"Status= {Status}\n"; } } } diff --git a/Transbank/WebpayRest/Oneclick/MallTransaction.cs b/Transbank/WebpayRest/Oneclick/MallTransaction.cs index 4367482..1988dd2 100644 --- a/Transbank/WebpayRest/Oneclick/MallTransaction.cs +++ b/Transbank/WebpayRest/Oneclick/MallTransaction.cs @@ -13,13 +13,13 @@ namespace Transbank.Webpay.Oneclick { public static class MallTransaction { - public static AuthorizeResponse Authorize(string userName, string tbkUser, + public static AuthorizeMallResponse Authorize(string userName, string tbkUser, string buyOrder, List details) { return Authorize(userName, tbkUser, buyOrder, details, Oneclick.DefaultOptions()); } - public static AuthorizeResponse Authorize(string userName, + public static AuthorizeMallResponse Authorize(string userName, string tbkUser, string buyOrder, List details, Options options) { @@ -29,7 +29,7 @@ public static AuthorizeResponse Authorize(string userName, details); var response = RequestService.Perform(authorizeRequest, options); - return JsonConvert.DeserializeObject(response); + return JsonConvert.DeserializeObject(response); } catch (Exception e) { diff --git a/Transbank/WebpayRest/Oneclick/Responses/AuthorizeResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/AuthorizeMallResponse.cs similarity index 91% rename from Transbank/WebpayRest/Oneclick/Responses/AuthorizeResponse.cs rename to Transbank/WebpayRest/Oneclick/Responses/AuthorizeMallResponse.cs index 37114fa..be31a86 100644 --- a/Transbank/WebpayRest/Oneclick/Responses/AuthorizeResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Responses/AuthorizeMallResponse.cs @@ -4,7 +4,7 @@ namespace Transbank.Webpay.Oneclick.Responses { - public class AuthorizeResponse + public class AuthorizeMallResponse { [JsonProperty("buy_order")] public string BuyOrder { get; private set; } @@ -28,7 +28,7 @@ public class AuthorizeResponse [JsonProperty("details")] public PaymentResponse Details{get; private set; } - public AuthorizeResponse(string buyOrder, string sessionId, string cardNumber, DateTime expirationDate, + public AuthorizeMallResponse(string buyOrder, string sessionId, string cardNumber, DateTime expirationDate, DateTime accountingDate, DateTime transactionDate, PaymentResponse details) { BuyOrder = buyOrder; From 4f3ac5022fd3dd8dcdc1805315caadda6e2f8431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20C=C3=A1rdenas?= Date: Wed, 21 Aug 2019 17:03:36 -0400 Subject: [PATCH 092/120] Update mall transaction to use the new classes structure --- .../WebpayRest/Oneclick/MallTransaction.cs | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/MallTransaction.cs b/Transbank/WebpayRest/Oneclick/MallTransaction.cs index 1988dd2..73020fe 100644 --- a/Transbank/WebpayRest/Oneclick/MallTransaction.cs +++ b/Transbank/WebpayRest/Oneclick/MallTransaction.cs @@ -1,42 +1,68 @@ using System; using Newtonsoft.Json; -using Transbank.Common; using System.Collections.Generic; -using Transbank.Exceptions; +using Transbank.Common; using Transbank.Webpay.Common; using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.Oneclick.Responses; using Transbank.Webpay.Oneclick.Exceptions; - namespace Transbank.Webpay.Oneclick { public static class MallTransaction { + private static string _commerceCode = "597055555541"; + private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + private static string[] _storeCodes = { "597055555542", "597055555543" }; + + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + public static AuthorizeMallResponse Authorize(string userName, string tbkUser, string buyOrder, List details) { - return Authorize(userName, tbkUser, buyOrder, details, Oneclick.DefaultOptions()); + return Authorize(userName, tbkUser, buyOrder, details, DefaultOptions()); } - public static AuthorizeMallResponse Authorize(string userName, - string tbkUser, string buyOrder, List details, - Options options) + public static AuthorizeMallResponse Authorize(string userName, string tbkUser, string buyOrder, + List details, Options options) { - try + return ExceptionHandler.Perform(() => { var authorizeRequest = new AuthorizeMallRequest(userName, tbkUser, buyOrder, details); - var response = RequestService.Perform(authorizeRequest, options); + var response = RequestService.Perform(authorizeRequest, options); return JsonConvert.DeserializeObject(response); - } - catch (Exception e) - { - int code = e.GetType().Equals(typeof(TransbankException)) ? - ((TransbankException)e).Code : -1; - throw new MallTransactionAuthorizeException(code, e.Message, e); - } + }); } } } From a44d8bcfb440e9ba3147efdfcf0bb4239bfc4de8 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Thu, 22 Aug 2019 16:47:42 -0400 Subject: [PATCH 093/120] remove system priunt --- .../TransaccionCompleta/FullTransaction.cs | 16 ++++++++++++---- .../Requests/InstallmentsRequest.cs | 9 ++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs index 2b082ce..b5da998 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs @@ -94,12 +94,15 @@ public static InstallmentsResponse Installments( { return ExceptionHandler.Perform(() => { - var installmentsRequest = new InstallmentsRequest(token, installmentsNumber); - var response = RequestService.Perform( - installmentsRequest, options); + var installmentsRequest = new InstallmentsRequest( + token, + installmentsNumber); + var response = RequestService.Perform(installmentsRequest, options); return JsonConvert.DeserializeObject(response); + }); + } public static CommitResponse Commit( @@ -108,7 +111,12 @@ public static CommitResponse Commit( int deferredPeriods, bool gracePeriod) { - return Commit(token, idQueryInstallments, deferredPeriods, gracePeriod, DefaultOptions()); + return Commit( + token, + idQueryInstallments, + deferredPeriods, + gracePeriod, + DefaultOptions()); } public static CommitResponse Commit( diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs index a6d4e20..fece953 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs @@ -9,10 +9,17 @@ internal class InstallmentsRequest : BaseRequest [JsonProperty("installments_number")] public int InstallmentsNumber { get; set; } - internal InstallmentsRequest(string token, int installmentsNumber) + internal InstallmentsRequest( + string token, + int installmentsNumber) : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Post) { InstallmentsNumber = installmentsNumber; } + + public override string ToString() + { + return $"Installments Number={InstallmentsNumber}"; + } } } From 83a205be02b759dc6bd5fc251b6768cce929f4b6 Mon Sep 17 00:00:00 2001 From: Gonzalo Castillo Fajardo Date: Mon, 26 Aug 2019 09:37:40 -0400 Subject: [PATCH 094/120] Add Authorize, Refund and Status Implement the Authorize, Refund and Status for Oneclick Mall --- Transbank/WebpayRest/Common/PaymentRequest.cs | 21 +++--- .../WebpayRest/Common/PaymentResponse.cs | 35 +++++++--- .../WebpayRest/Oneclick/MallTransaction.cs | 45 +++++++++++-- ...MallRequest.cs => MallAuthorizeRequest.cs} | 4 +- .../Oneclick/Requests/MallRefundRequest.cs | 26 +++++++ .../Oneclick/Requests/MallStatusRequest.cs | 14 ++++ ...llResponse.cs => MallAuthorizeResponse.cs} | 13 ++-- .../Oneclick/Responses/MallRefundResponse.cs | 35 ++++++++++ .../Oneclick/Responses/MallStatusResponse.cs | 67 +++++++++++++++++++ 9 files changed, 227 insertions(+), 33 deletions(-) rename Transbank/WebpayRest/Oneclick/Requests/{AuthorizeMallRequest.cs => MallAuthorizeRequest.cs} (87%) create mode 100644 Transbank/WebpayRest/Oneclick/Requests/MallRefundRequest.cs create mode 100644 Transbank/WebpayRest/Oneclick/Requests/MallStatusRequest.cs rename Transbank/WebpayRest/Oneclick/Responses/{AuthorizeMallResponse.cs => MallAuthorizeResponse.cs} (81%) create mode 100644 Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs create mode 100644 Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs diff --git a/Transbank/WebpayRest/Common/PaymentRequest.cs b/Transbank/WebpayRest/Common/PaymentRequest.cs index 6f79a0c..7248a9e 100644 --- a/Transbank/WebpayRest/Common/PaymentRequest.cs +++ b/Transbank/WebpayRest/Common/PaymentRequest.cs @@ -5,30 +5,31 @@ namespace Transbank.Webpay.Common public class PaymentRequest { [JsonProperty("commerce_code")] - public string ComerceCode { get; private set; } + public string CommerceCode { get; private set; } [JsonProperty("buy_order")] public string BuyOrder { get; private set; } [JsonProperty("amount")] - public int Amount { get; private set; } + public decimal Amount { get; private set; } [JsonProperty("installments_number")] - public int Installments { get; private set; } + public int InstallmentsNumber { get; private set; } - public PaymentRequest (string comerceCode, string buyOrder, int amount) + public PaymentRequest (string commerceCode, string buyOrder, decimal amount, int installmentsNumber) { - ComerceCode = comerceCode; + CommerceCode = commerceCode; BuyOrder = buyOrder; Amount = amount; + InstallmentsNumber = installmentsNumber; } public override string ToString() { - return $"Comerce Code= {ComerceCode}\n" + - $"Buy Order= {BuyOrder}\n" + - $"Amount= {Amount}\n" + - $"Installments= {Installments}"; + return $"Commerce Code= {CommerceCode}\n" + + $"Buy Order= {BuyOrder}\n" + + $"Amount= {Amount}\n" + + $"InstallmentsNumber= {InstallmentsNumber}"; } } -} \ No newline at end of file +} diff --git a/Transbank/WebpayRest/Common/PaymentResponse.cs b/Transbank/WebpayRest/Common/PaymentResponse.cs index 0dd26bc..50e0d8a 100644 --- a/Transbank/WebpayRest/Common/PaymentResponse.cs +++ b/Transbank/WebpayRest/Common/PaymentResponse.cs @@ -2,7 +2,7 @@ namespace Transbank.Webpay.Common { - public class PaymentResponse : PaymentRequest + public class PaymentResponse { [JsonProperty("authorization_code")] public int AuthorizationCode { get; private set; } @@ -13,30 +13,45 @@ public class PaymentResponse : PaymentRequest [JsonProperty("response_code")] public int ResponseCode { get; private set; } - [JsonProperty("installments_amount")] - public int InstallmentsAmount { get; private set; } + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; private set; } [JsonProperty("status")] public string Status { get; private set; } + + [JsonProperty("commerce_code")] + public string CommerceCode { get; private set; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; private set; } + + [JsonProperty("amount")] + public decimal Amount { get; private set; } public PaymentResponse (string comerceCode, string buyOrder, int ammount, int autorizationCode, - string paymentTypeCode, int responseCode, int installmentsAmmount, string status) : base(comerceCode, buyOrder, ammount) + string paymentTypeCode, int responseCode, int installmentsAmmount, string status) { AuthorizationCode = autorizationCode; PaymentTypeCode = paymentTypeCode; ResponseCode = responseCode; - InstallmentsAmount = installmentsAmmount; + InstallmentsNumber = installmentsAmmount; Status = status; + CommerceCode = comerceCode; + BuyOrder = buyOrder; + Amount = ammount; } public override string ToString() { return base.ToString() + "\n" + - $"InstallmentsAmount= {InstallmentsAmount}\n" + - $"AuthorizationCode= {AuthorizationCode}\n" + - $"PaymentTypeCode= {PaymentTypeCode}\n" + - $"ResponseCode= {ResponseCode}\n" + - $"Status= {Status}\n"; + $"InstallmentsAmount= {InstallmentsNumber}\n" + + $"AuthorizationCode= {AuthorizationCode}\n" + + $"PaymentTypeCode= {PaymentTypeCode}\n" + + $"ResponseCode= {ResponseCode}\n" + + $"Status= {Status}\n" + + $"CommerceCode= {CommerceCode}\n" + + $"BuyOrder= {BuyOrder}\n" + + $"Amount= {Amount}\n"; } } } diff --git a/Transbank/WebpayRest/Oneclick/MallTransaction.cs b/Transbank/WebpayRest/Oneclick/MallTransaction.cs index 73020fe..7ae2e27 100644 --- a/Transbank/WebpayRest/Oneclick/MallTransaction.cs +++ b/Transbank/WebpayRest/Oneclick/MallTransaction.cs @@ -6,6 +6,9 @@ using Transbank.Webpay.Oneclick.Requests; using Transbank.Webpay.Oneclick.Responses; using Transbank.Webpay.Oneclick.Exceptions; +using Transbank.Webpay.WebpayPlus.Exceptions; +using Transbank.WebpayRest.Oneclick.Requests; +using Transbank.WebpayRest.Oneclick.Responses; namespace Transbank.Webpay.Oneclick { @@ -46,22 +49,54 @@ public static Options DefaultOptions() return new Options(CommerceCode, ApiKey, IntegrationType); } - public static AuthorizeMallResponse Authorize(string userName, string tbkUser, + public static MallAuthorizeResponse Authorize(string userName, string tbkUser, string buyOrder, List details) { return Authorize(userName, tbkUser, buyOrder, details, DefaultOptions()); } - public static AuthorizeMallResponse Authorize(string userName, string tbkUser, string buyOrder, + public static MallAuthorizeResponse Authorize(string userName, string tbkUser, string buyOrder, List details, Options options) { - return ExceptionHandler.Perform(() => + return ExceptionHandler.Perform(() => { - var authorizeRequest = new AuthorizeMallRequest(userName, tbkUser, buyOrder, + var authorizeRequest = new MallAuthorizeRequest(userName, tbkUser, buyOrder, details); var response = RequestService.Perform(authorizeRequest, options); - return JsonConvert.DeserializeObject(response); + return JsonConvert.DeserializeObject(response); + }); + } + + public static MallRefundResponse Refund(string buyOrder, string childCommerceCode, string childBuyOrder, + decimal amount) + { + return Refund(buyOrder, childCommerceCode, childBuyOrder, amount, DefaultOptions()); + } + + public static MallRefundResponse Refund(string buyOrder, string childCommerceCode, string childBuyOrder, + decimal amount, Options options) + { + return ExceptionHandler.Perform(() => + { + var mallRefundRequest = new MallRefundRequest(buyOrder, childCommerceCode, childBuyOrder, amount); + var response = RequestService.Perform(mallRefundRequest, options); + return JsonConvert.DeserializeObject(response); + }); + } + + public static MallStatusResponse Status(string buyOrder) + { + return Status(buyOrder, DefaultOptions()); + } + + public static MallStatusResponse Status(string buyOrder, Options options) + { + return ExceptionHandler.Perform(() => + { + var mallStatusRequest = new MallStatusRequest(buyOrder); + var response = RequestService.Perform(mallStatusRequest, options); + return JsonConvert.DeserializeObject(response); }); } } diff --git a/Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/MallAuthorizeRequest.cs similarity index 87% rename from Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs rename to Transbank/WebpayRest/Oneclick/Requests/MallAuthorizeRequest.cs index d376ba5..7437a90 100644 --- a/Transbank/WebpayRest/Oneclick/Requests/AuthorizeMallRequest.cs +++ b/Transbank/WebpayRest/Oneclick/Requests/MallAuthorizeRequest.cs @@ -6,7 +6,7 @@ namespace Transbank.Webpay.Oneclick.Requests { - internal class AuthorizeMallRequest : BaseRequest + internal class MallAuthorizeRequest : BaseRequest { [JsonProperty("username")] internal string UserName { get; set; } @@ -20,7 +20,7 @@ internal class AuthorizeMallRequest : BaseRequest [JsonProperty("details")] internal List Details { get; set; } - internal AuthorizeMallRequest(string userName, string tbkUser, string buyOrder, List details) + internal MallAuthorizeRequest(string userName, string tbkUser, string buyOrder, List details) : base("/rswebpaytransaction/api/oneclick/v1.0/transactions", HttpMethod.Post) { UserName = userName; diff --git a/Transbank/WebpayRest/Oneclick/Requests/MallRefundRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/MallRefundRequest.cs new file mode 100644 index 0000000..d669f82 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Requests/MallRefundRequest.cs @@ -0,0 +1,26 @@ +using System.Net.Http; +using Newtonsoft.Json; +using Transbank.Common; + +namespace Transbank.WebpayRest.Oneclick.Requests +{ + public class MallRefundRequest : BaseRequest + { + [JsonProperty("commerce_code")] + internal string CommerceCode { get; set; } + + [JsonProperty("detail_buy_order")] + internal string DetailBuyOrder { get; set; } + + [JsonProperty("amount")] + internal decimal Amount { get; set; } + + public MallRefundRequest(string buyOrder, string childCommerceCode, string childBuyOrder, decimal amount) + : base($"/rswebpaytransaction/api/oneclick/v1.0/transactions/{buyOrder}/refunds", HttpMethod.Post) + { + CommerceCode = childCommerceCode; + DetailBuyOrder = childBuyOrder; + Amount = amount; + } + } +} \ No newline at end of file diff --git a/Transbank/WebpayRest/Oneclick/Requests/MallStatusRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/MallStatusRequest.cs new file mode 100644 index 0000000..7cc1ca8 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Requests/MallStatusRequest.cs @@ -0,0 +1,14 @@ +using System.Net.Http; +using Transbank.Common; + +namespace Transbank.WebpayRest.Oneclick.Requests +{ + public class MallStatusRequest : BaseRequest + { + public MallStatusRequest(string buyOrder) + : base($"/rswebpaytransaction/api/oneclick/v1.0/transactions/{buyOrder}", HttpMethod.Get) + { + + } + } +} \ No newline at end of file diff --git a/Transbank/WebpayRest/Oneclick/Responses/AuthorizeMallResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/MallAuthorizeResponse.cs similarity index 81% rename from Transbank/WebpayRest/Oneclick/Responses/AuthorizeMallResponse.cs rename to Transbank/WebpayRest/Oneclick/Responses/MallAuthorizeResponse.cs index be31a86..f778acd 100644 --- a/Transbank/WebpayRest/Oneclick/Responses/AuthorizeMallResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Responses/MallAuthorizeResponse.cs @@ -1,10 +1,11 @@ -using System; +using System; +using System.Collections.Generic; using Newtonsoft.Json; using Transbank.Webpay.Common; namespace Transbank.Webpay.Oneclick.Responses { - public class AuthorizeMallResponse + public class MallAuthorizeResponse { [JsonProperty("buy_order")] public string BuyOrder { get; private set; } @@ -20,16 +21,16 @@ public class AuthorizeMallResponse public DateTime ExpirationDate { get; private set; } [JsonProperty("accounting_date")] - public DateTime AccountingDate { get; private set; } + public string AccountingDate { get; private set; } [JsonProperty("transaction_date")] public DateTime TransactionDate { get; private set; } [JsonProperty("details")] - public PaymentResponse Details{get; private set; } + public List Details{get; private set; } - public AuthorizeMallResponse(string buyOrder, string sessionId, string cardNumber, DateTime expirationDate, - DateTime accountingDate, DateTime transactionDate, PaymentResponse details) + public MallAuthorizeResponse(string buyOrder, string sessionId, string cardNumber, DateTime expirationDate, + string accountingDate, DateTime transactionDate, List details) { BuyOrder = buyOrder; SessionId = sessionId; diff --git a/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs new file mode 100644 index 0000000..5d54dca --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs @@ -0,0 +1,35 @@ +using Newtonsoft.Json; + +namespace Transbank.WebpayRest.Oneclick.Responses +{ + public class MallRefundResponse + { + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("balance")] + public decimal Balance { get; set; } + + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + + [JsonProperty("authorization_date")] + public string AuthorizationDate { get; set; } + + [JsonProperty("nullified_amount")] + public decimal NullifiedAmount { get; set; } + + public MallRefundResponse(string type, decimal balance, string authorizationCode, int responseCode, string authorizationDate, decimal nullifiedAmount) + { + Type = type; + Balance = balance; + AuthorizationCode = authorizationCode; + ResponseCode = responseCode; + AuthorizationDate = authorizationDate; + NullifiedAmount = nullifiedAmount; + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs new file mode 100644 index 0000000..fe189eb --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs @@ -0,0 +1,67 @@ +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.WebpayRest.Oneclick.Responses +{ + public class MallStatusResponse + { + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + [JsonProperty("card_detail")] + public CardDetail CardDetail { get; set; } + + [JsonProperty("accounting_date")] + public string AccountingDate { get; set; } + + [JsonProperty("transaction_date")] + public string TransactionDate { get; set; } + + public MallStatusResponse(string buyOrder, CardDetail cardDetail, string accountingDate, string transactionDate) + { + BuyOrder = buyOrder; + CardDetail = cardDetail; + AccountingDate = accountingDate; + TransactionDate = transactionDate; + } + + public class Detail + { + [JsonProperty("amount")] + public decimal Amount { get; set; } + + [JsonProperty("status")] + public string Status { get; set; } + + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + + [JsonProperty("payment_type_code")] + public string PaymentTypeCode { get; set; } + + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; set; } + + [JsonProperty("commerce_code")] + public string CommerceCode { get; set; } + + [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) + { + Amount = amount; + Status = status; + AuthorizationCode = authorizationCode; + PaymentTypeCode = paymentTypeCode; + ResponseCode = responseCode; + InstallmentsNumber = installmentsNumber; + CommerceCode = commerceCode; + BuyOrder = buyOrder; + } + } + } +} \ No newline at end of file From 070a7e91c94e2180003c947f3e7718414c52f9df Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 26 Aug 2019 11:28:17 -0400 Subject: [PATCH 095/120] add installments and commit methods --- .../MallTransactionCommitException.cs | 14 ++ .../MallTransactionCreateException.cs | 14 ++ .../MallTransactionInstallmentsExceptions.cs | 14 ++ .../Common/CommitDetails.cs | 36 +++++ .../Common/CommitResponseDetails.cs | 56 +++++++ .../Common/CreateDetails.cs | 26 ++++ .../MallFullTransaction.cs | 143 ++++++++++++++++++ .../Requests/MallCommitRequest.cs | 23 +++ .../Requests/MallCreateRequest.cs | 40 +++++ .../Requests/MallInstallmentsRequest.cs | 30 ++++ .../Requests/MallRefundRequest.cs | 7 + .../Responses/MallCommitResponse.cs | 46 ++++++ .../Responses/MallCreateResponse.cs | 17 +++ .../Responses/MallInstallmentsResponse.cs | 26 ++++ .../Responses/MallRefundResponse.cs | 7 + 15 files changed, 499 insertions(+) create mode 100644 Transbank/Exceptions/MallTransactionCommitException.cs create mode 100644 Transbank/Exceptions/MallTransactionCreateException.cs create mode 100644 Transbank/Exceptions/MallTransactionInstallmentsExceptions.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitDetails.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitResponseDetails.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/CreateDetails.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCreateRequest.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCommitResponse.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCreateResponse.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs diff --git a/Transbank/Exceptions/MallTransactionCommitException.cs b/Transbank/Exceptions/MallTransactionCommitException.cs new file mode 100644 index 0000000..8ca5dba --- /dev/null +++ b/Transbank/Exceptions/MallTransactionCommitException.cs @@ -0,0 +1,14 @@ +using System; + +namespace Transbank.Exceptions +{ + public class MallTransactionCommitException : TransbankException + { + public MallTransactionCommitException(string message) : base(-1, message) { } + + public MallTransactionCommitException(int code, string message) : base(code, message) { } + + public MallTransactionCommitException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/Exceptions/MallTransactionCreateException.cs b/Transbank/Exceptions/MallTransactionCreateException.cs new file mode 100644 index 0000000..eaa2b4f --- /dev/null +++ b/Transbank/Exceptions/MallTransactionCreateException.cs @@ -0,0 +1,14 @@ +using System; + +namespace Transbank.Exceptions +{ + public class MallTransactionCreateException : TransbankException + { + public MallTransactionCreateException(string message) : base(-1, message) { } + + public MallTransactionCreateException(int code, string message) : base(code, message) { } + + public MallTransactionCreateException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/Exceptions/MallTransactionInstallmentsExceptions.cs b/Transbank/Exceptions/MallTransactionInstallmentsExceptions.cs new file mode 100644 index 0000000..3b05881 --- /dev/null +++ b/Transbank/Exceptions/MallTransactionInstallmentsExceptions.cs @@ -0,0 +1,14 @@ +using System; + +namespace Transbank.Exceptions +{ + public class MallTransactionInstallmentsExceptions : TransbankException + { + public MallTransactionInstallmentsExceptions(string message) : base(-1, message) { } + + public MallTransactionInstallmentsExceptions(int code, string message) : base(code, message) { } + + public MallTransactionInstallmentsExceptions(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitDetails.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitDetails.cs new file mode 100644 index 0000000..65edf5b --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitDetails.cs @@ -0,0 +1,36 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompletaMall.Common +{ + public class CommitDetails + { + [JsonProperty("commerce_code")] + public string CommerceCode { get; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; } + + [JsonProperty("id_query_installments")] + public int IdQueryInstallments { get; } + + [JsonProperty("deferred_period_index")] + public int DeferredPeriodIndex { get; } + + [JsonProperty("grace_period")] + public int GracePeriod { get; } + + public CommitDetails( + string commerceCode, + string buyOrder, + int idQueryInstallments, + int deferredPeriodIndex, + int gracePeriod) + { + CommerceCode = commerceCode; + BuyOrder = buyOrder; + IdQueryInstallments = idQueryInstallments; + DeferredPeriodIndex = deferredPeriodIndex; + GracePeriod = gracePeriod; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitResponseDetails.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitResponseDetails.cs new file mode 100644 index 0000000..9b6c758 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitResponseDetails.cs @@ -0,0 +1,56 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompletaMall.Common +{ + public class CommitResponseDetails + { + [JsonProperty("amount")] + public int Amount { get; set; } + + [JsonProperty("status")] + public string Status { get; set; } + + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + + [JsonProperty("payment_type_code")] + public string PaymentTypeCode { get; set; } + + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + + [JsonProperty("installments_amount")] + public int InstallmentsAmount { get; set; } + + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; set; } + + [JsonProperty("commerce_code")] + public string CommerceCode { get; set; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + public CommitResponseDetails( + int amount, + string status, + string authorizationCode, + string paymentTypeCode, + int responseCode, + int installmentsAmount, + int installmentsNumber, + string commerceCode, + string buyOrder) + { + Amount = amount; + Status = status; + AuthorizationCode = authorizationCode; + PaymentTypeCode = paymentTypeCode; + ResponseCode = responseCode; + InstallmentsAmount = installmentsAmount; + InstallmentsNumber = installmentsNumber; + CommerceCode = commerceCode; + BuyOrder = buyOrder; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/CreateDetails.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/CreateDetails.cs new file mode 100644 index 0000000..379b737 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Common/CreateDetails.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompletaMall.Common +{ + public class CreateDetails + { + [JsonProperty("amount")] + public int Amount { get; } + + [JsonProperty("commerce_code")] + public string CommerceCode { get; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; } + + public CreateDetails( + int amount, + string commerceCode, + string buyOrder) + { + Amount = amount; + CommerceCode = commerceCode; + BuyOrder = buyOrder; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs new file mode 100644 index 0000000..74e3f15 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; +using Transbank.Common; +using Transbank.Exceptions; +using Transbank.Patpass.Common; +using Transbank.Webpay.Common; +using Transbank.Webpay.TransaccionCompletaMall.Common; +using Transbank.Webpay.TransaccionCompletaMall.Requests; +using Transbank.Webpay.TransaccionCompletaMall.Responses; + +namespace Transbank.Webpay.TransaccionCompletaMall +{ + public class MallFullTransaction + { + private static string _commerceCode = ""; + private static string _apiKey = ""; + + private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; + + public static string CommerceCode + { + get => _commerceCode; + set => _commerceCode = value ?? throw new ArgumentNullException( + nameof(value), "Commerce code can't be null." + ); + } + + public static string ApiKey + { + get => _apiKey; + set => _apiKey = value ?? throw new ArgumentNullException( + nameof(value), "Api Key can't be null." + ); + } + + public static WebpayIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "Integration type can't be null." + ); + } + + public static Options DefaultOptions() + { + return new Options(CommerceCode, ApiKey, IntegrationType); + } + + public static MallCreateResponse MallCreate( + string buyOrder, + string sessionId, + string cardNumber, + string cardExpirationDate, + List details) + { + return MallCreate(buyOrder, sessionId, cardNumber, cardExpirationDate, details); + } + + public static MallCreateResponse MallCreate( + string buyOrder, + string sessionId, + string cardNumber, + string cardExpirationDate, + List details, + Options options) + { + return ExceptionHandler.Perform(() => + { + var mallCreateRequest = new MallCreateRequest( + buyOrder, + sessionId, + cardNumber, + cardExpirationDate, + details); + var response = RequestService.Perform(mallCreateRequest, options); + + return JsonConvert.DeserializeObject(response); + }); + } + + public static MallInstallmentsResponse MallInstallments( + string token, + string commerceCode, + string buyOrder, + int installmentsAmount) + { + return MallInstallments( + token, + commerceCode, + buyOrder, + installmentsAmount); + } + + public static MallInstallmentsResponse MallInstallments( + string token, + string commerceCode, + string buyOrder, + int installmentsAmount, + Options options) + { + return ExceptionHandler.Perform(() => + { + var mallInstallmentsResponse = new MallInstallmentsRequest( + token, + commerceCode, + buyOrder, + installmentsAmount); + var response = RequestService.Perform(mallInstallmentsResponse, options); + + return JsonConvert.DeserializeObject(response); + }); + } + + public static MallCommitResponse MallCommit( + string token, + CommitDetails details) + { + return MallCommit( + token, + details); + } + + public static MallCommitResponse MallCommit( + string token, + List details, + Options options) + { + return ExceptionHandler.Perform(() => + { + var mallCommitRequest = new MallCommitRequest( + token, + details); + var response = RequestService.Perform(mallCommitRequest, options); + + return JsonConvert.DeserializeObject(response); + }); + } + + } + + +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs new file mode 100644 index 0000000..608e33c --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Transbank.Common; +using System.Net.Http; +using Transbank.Webpay.TransaccionCompletaMall.Common; +using Transbank.Webpay.WebpayPlus.Responses; + +namespace Transbank.Webpay.TransaccionCompletaMall.Requests +{ + internal class MallCommitRequest : BaseRequest + { + [JsonProperty("details")] + public List Details { get; set; } + + internal MallCommitRequest( + string token, + List details) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) + { + Details = details; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCreateRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCreateRequest.cs new file mode 100644 index 0000000..1deca7d --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCreateRequest.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Net.Http; +using Newtonsoft.Json; +using Transbank.Common; +using Transbank.Webpay.TransaccionCompletaMall.Common; + +namespace Transbank.Webpay.TransaccionCompletaMall.Requests +{ + internal class MallCreateRequest : BaseRequest + { + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + [JsonProperty("session_id")] + public string SessionId { get; set; } + + [JsonProperty("card_number")] + public string CardNumber { get; set; } + + [JsonProperty("card_expiration_date")] + public string CardExpirationDate { get; set; } + + [JsonProperty("details")] + public List Details { get; set; } + + internal MallCreateRequest(string buyOrder, + string sessionId, + string cardNumber, + string cardExpirationDate, + List details) + : base("/rswebpaytransaction/api/webpay/v1.0/transactions", HttpMethod.Post) + { + BuyOrder = buyOrder; + SessionId = sessionId; + CardNumber = cardNumber; + CardExpirationDate = cardExpirationDate; + Details = details; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs new file mode 100644 index 0000000..197d783 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs @@ -0,0 +1,30 @@ +using Newtonsoft.Json; +using Transbank.Common; +using System.Net.Http; + +namespace Transbank.Webpay.TransaccionCompletaMall.Requests +{ + internal class MallInstallmentsRequest : BaseRequest + { + [JsonProperty("commerce_code")] + public string CommerceCode { get; set; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; set; } + + internal MallInstallmentsRequest( + string token, + string commerceCode, + string buyOrder, + int installmentsNumber) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/installments", HttpMethod.Post) + { + CommerceCode = commerceCode; + BuyOrder = buyOrder; + InstallmentsNumber = installmentsNumber; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs new file mode 100644 index 0000000..b48388a --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs @@ -0,0 +1,7 @@ +namespace Transbank.Webpay.TransaccionCompletaMall.Requests +{ + public class MallRefundRequest + { + + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCommitResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCommitResponse.cs new file mode 100644 index 0000000..de6bed8 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCommitResponse.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Transbank.Patpass.Common; +using Transbank.Webpay.Common; +using Transbank.Webpay.TransaccionCompletaMall.Common; + +namespace Transbank.Webpay.TransaccionCompletaMall.Responses +{ + public class MallCommitResponse + { + [JsonProperty("details")] + public List Details { get; set; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + [JsonProperty("session_id")] + public string SessionId { get; set; } + + [JsonProperty("card_detail")] + public CardDetail CardDetail { get; set; } + + [JsonProperty("accounting_date")] + public string AccountingDate { get; set; } + + [JsonProperty("transaction_date")] + public string TransactionDate { get; set; } + + public MallCommitResponse( + List details, + string buyOrder, + string sessionId, + CardDetail cardDetail, + string accountingDate, + string transactionDate + ) + { + Details = details; + BuyOrder = buyOrder; + SessionId = sessionId; + CardDetail = cardDetail; + AccountingDate = accountingDate; + TransactionDate = transactionDate; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCreateResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCreateResponse.cs new file mode 100644 index 0000000..6ad8db7 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCreateResponse.cs @@ -0,0 +1,17 @@ +using Microsoft.Web.Services3.Addressing; +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompletaMall.Responses +{ + public class MallCreateResponse + { + [JsonProperty("token")] + public string Token { get; set; } + + public MallCreateResponse( + string token) + { + Token = token; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs new file mode 100644 index 0000000..c2d6f00 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Transbank.Webpay.TransaccionCompleta.Common; + +namespace Transbank.Webpay.TransaccionCompletaMall.Responses +{ + public class MallInstallmentsResponse + { + [JsonProperty("installments_amount")] + public int InstallmentsAmount { get; set; } + + [JsonProperty("id_query_installments")] + public int IdQueryInstallments { get; set; } + + [JsonProperty("deferred_periods")] + public List DeferredPeriods { get; set; } + + public MallInstallmentsResponse(int installmentsAmount, int idQueryInstallments, List deferredPeriods) + { + InstallmentsAmount = installmentsAmount; + IdQueryInstallments = idQueryInstallments; + DeferredPeriods = deferredPeriods; + } + + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs new file mode 100644 index 0000000..2d5f6f4 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs @@ -0,0 +1,7 @@ +namespace Transbank.Webpay.TransaccionCompletaMall.Responses +{ + public class MallRefundResponse + { + + } +} From a7f83161b58f9e34e6ee420321eb2c9f9c7a964a Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 26 Aug 2019 11:49:39 -0400 Subject: [PATCH 096/120] add mall transaction refund method --- .../MallTransactionRefundException.cs | 14 ++++++++ .../Common/CommitDetails.cs | 4 +-- .../MallFullTransaction.cs | 34 +++++++++++++++++-- .../Requests/MallRefundRequest.cs | 26 +++++++++++++- .../Responses/MallRefundResponse.cs | 34 +++++++++++++++++++ 5 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 Transbank/Exceptions/MallTransactionRefundException.cs diff --git a/Transbank/Exceptions/MallTransactionRefundException.cs b/Transbank/Exceptions/MallTransactionRefundException.cs new file mode 100644 index 0000000..dac95fa --- /dev/null +++ b/Transbank/Exceptions/MallTransactionRefundException.cs @@ -0,0 +1,14 @@ +using System; + +namespace Transbank.Exceptions +{ + public class MallTransactionRefundException : TransbankException + { + public MallTransactionRefundException(string message) : base(-1, message) { } + + public MallTransactionRefundException(int code, string message) : base(code, message) { } + + public MallTransactionRefundException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitDetails.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitDetails.cs index 65edf5b..2532d01 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitDetails.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitDetails.cs @@ -17,14 +17,14 @@ public class CommitDetails public int DeferredPeriodIndex { get; } [JsonProperty("grace_period")] - public int GracePeriod { get; } + public bool GracePeriod { get; } public CommitDetails( string commerceCode, string buyOrder, int idQueryInstallments, int deferredPeriodIndex, - int gracePeriod) + bool gracePeriod) { CommerceCode = commerceCode; BuyOrder = buyOrder; diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs index 74e3f15..ff4c77c 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Microsoft.Web.Services3.Security; using Newtonsoft.Json; using Transbank.Common; using Transbank.Exceptions; @@ -114,7 +115,7 @@ public static MallInstallmentsResponse MallInstallments( public static MallCommitResponse MallCommit( string token, - CommitDetails details) + List details) { return MallCommit( token, @@ -136,7 +137,36 @@ public static MallCommitResponse MallCommit( return JsonConvert.DeserializeObject(response); }); } - + + public static MallRefundResponse MallRefund( + string token, + string buyOrder, + string commerceCode, + int amount) + { + return MallRefund(token, buyOrder, commerceCode, amount); + } + + public static MallRefundResponse MallRefund( + string token, + string buyOrder, + string commerceCode, + int amount, + Options options) + { + return ExceptionHandler.Perform(() => + { + var mallRefundRequest = new MallRefundRequest( + token, + buyOrder, + commerceCode, + amount); + var response = RequestService.Perform(mallRefundRequest, options); + + return JsonConvert.DeserializeObject(response); + + }); + } } diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs index b48388a..0ff7541 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs @@ -1,7 +1,31 @@ +using Newtonsoft.Json; +using Transbank.Common; +using System.Net.Http; + namespace Transbank.Webpay.TransaccionCompletaMall.Requests { - public class MallRefundRequest + internal class MallRefundRequest : BaseRequest { + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + [JsonProperty("commerce_code")] + public string CommerceCode { get; set; } + + [JsonProperty("amount")] + public int Amount { get; set; } + + internal MallRefundRequest( + string token, + string buyOrder, + string commerceCode, + int amount) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/refunds", HttpMethod.Post) + { + BuyOrder = buyOrder; + CommerceCode = commerceCode; + Amount = amount; + } + } } diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs index 2d5f6f4..aaeca7f 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs @@ -1,7 +1,41 @@ +using Newtonsoft.Json; + namespace Transbank.Webpay.TransaccionCompletaMall.Responses { public class MallRefundResponse { + [JsonProperty("type")] + public string Type { get; set; } + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + + [JsonProperty("authorization_date")] + public string AuthorizationDate { get; set; } + + [JsonProperty("nullified_amount")] + public double NullifiedAmount { get; set; } + + [JsonProperty("balance")] + public double Balance { get; set; } + + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + + public MallRefundResponse( + string type, + string authorizationCode, + string authorizationDate, + double nullifiedAmount, + double balance, + int responseCode) + { + Type = type; + AuthorizationCode = authorizationCode; + AuthorizationDate = authorizationDate; + NullifiedAmount = nullifiedAmount; + Balance = balance; + ResponseCode = responseCode; + } } } From 203cafced8483edbcdbc5427e89e7ea9a27eeade Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 26 Aug 2019 11:59:15 -0400 Subject: [PATCH 097/120] add status method --- .../MallTransactionStatusException.cs | 14 ++++++ .../MallFullTransaction.cs | 20 ++++++++ .../Requests/MallStatusRequest.cs | 12 +++++ .../Responses/MallStatusResponse.cs | 46 +++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 Transbank/Exceptions/MallTransactionStatusException.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallStatusRequest.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallStatusResponse.cs diff --git a/Transbank/Exceptions/MallTransactionStatusException.cs b/Transbank/Exceptions/MallTransactionStatusException.cs new file mode 100644 index 0000000..df20131 --- /dev/null +++ b/Transbank/Exceptions/MallTransactionStatusException.cs @@ -0,0 +1,14 @@ +using System; + +namespace Transbank.Exceptions +{ + public class MallTransactionStatusException : TransbankException + { + public MallTransactionStatusException(string message) : base(-1, message) { } + + public MallTransactionStatusException(int code, string message) : base(code, message) { } + + public MallTransactionStatusException(int code, string message, Exception innerException) + : base(code, message, innerException) { } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs index ff4c77c..13522b1 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs @@ -167,6 +167,26 @@ public static MallRefundResponse MallRefund( }); } + + public static MallStatusResponse MallStatus( + string token) + { + return MallStatus(token); + } + + public static MallStatusResponse MallStatus( + string token, + Options options) + { + return ExceptionHandler.Perform(() => + { + var mallStatusRequest = new MallStatusRequest( + token); + var response = RequestService.Perform(mallStatusRequest, options); + + return JsonConvert.DeserializeObject(response); + }); + } } diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallStatusRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallStatusRequest.cs new file mode 100644 index 0000000..75fb69f --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallStatusRequest.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; +using Transbank.Common; +using System.Net.Http; + +namespace Transbank.Webpay.TransaccionCompletaMall.Requests +{ + public class MallStatusRequest : BaseRequest + { + internal MallStatusRequest(string token) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Get){} + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallStatusResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallStatusResponse.cs new file mode 100644 index 0000000..f8c3be6 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallStatusResponse.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Transbank.Patpass.Common; +using Transbank.Webpay.Common; +using Transbank.Webpay.TransaccionCompletaMall.Common; + +namespace Transbank.Webpay.TransaccionCompletaMall.Responses +{ + public class MallStatusResponse + { + [JsonProperty("details")] + public List Details { get; set; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + [JsonProperty("session_id")] + public string SessionId { get; set; } + + [JsonProperty("card_detail")] + public CardDetail CardDetail { get; set; } + + [JsonProperty("accounting_date")] + public string AccountingDate { get; set; } + + [JsonProperty("transaction_date")] + public string TransactionDate { get; set; } + + public MallStatusResponse( + List details, + string buyOrder, + string sessionId, + CardDetail cardDetail, + string accountingDate, + string transactionDate + ) + { + Details = details; + BuyOrder = buyOrder; + SessionId = sessionId; + CardDetail = cardDetail; + AccountingDate = accountingDate; + TransactionDate = transactionDate; + } + } +} From c9d93c6a4082d7c1e2ff9e34272e76de8ecd8edb Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 26 Aug 2019 17:00:59 -0400 Subject: [PATCH 098/120] wip transaction installments method list --- .../Common/DeferredPeriods.cs | 19 ++++++++++ .../Common/MallInstallmentsDetails.cs | 26 ++++++++++++++ .../Common/MallInstallmentsDetailsResponse.cs | 28 +++++++++++++++ .../MallFullTransaction.cs | 35 ++++++++++++++++--- .../Requests/MallInstallmentsRequest.cs | 3 +- .../Responses/MallInstallmentsResponse.cs | 11 ++++-- 6 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/DeferredPeriods.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetails.cs create mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/DeferredPeriods.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/DeferredPeriods.cs new file mode 100644 index 0000000..bca358c --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Common/DeferredPeriods.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompletaMall.Common +{ + public class DeferredPeriods + { + [JsonProperty("amount")] + internal int Amount { get; } + + [JsonProperty("period")] + internal int Period { get; } + + public DeferredPeriods(int amount, int period) + { + Amount= amount; + Period = period; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetails.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetails.cs new file mode 100644 index 0000000..9c2ed58 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetails.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompletaMall.Common +{ + public class MallInstallmentsDetails + { + [JsonProperty("commerce_code")] + public string CommerceCode { get; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; } + + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; } + + public MallInstallmentsDetails( + string commerceCode, + string buyOrder, + int installmentsNumber) + { + CommerceCode = commerceCode; + BuyOrder = buyOrder; + InstallmentsNumber = installmentsNumber; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs new file mode 100644 index 0000000..8d377f3 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompletaMall.Common +{ + public class MallInstallmentsDetailsResponse + { + [JsonProperty("installments_amount")] + public int InstallmentsAmount { get; set; } + + [JsonProperty("id_query_installments")] + public int IdQueryInstallments { get; set; } + + [JsonProperty("deferred_periods")] + public List DeferredPeriods { get; set; } + + public MallInstallmentsDetailsResponse( + int installmentsAmount, + int idQueryInstallments, + List deferredPeriods + ) + { + InstallmentsAmount = installmentsAmount; + IdQueryInstallments = idQueryInstallments; + DeferredPeriods = deferredPeriods; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs index 13522b1..bd47ba6 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; -using Microsoft.Web.Services3.Security; +using System.Runtime.InteropServices.WindowsRuntime; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using Transbank.Common; using Transbank.Exceptions; -using Transbank.Patpass.Common; using Transbank.Webpay.Common; using Transbank.Webpay.TransaccionCompletaMall.Common; using Transbank.Webpay.TransaccionCompletaMall.Requests; @@ -113,6 +113,33 @@ public static MallInstallmentsResponse MallInstallments( }); } + public static MallInstallmentsResponse MallInstallments( + string token, + List details) + { + return MallInstallments(token, details); + } + + public static MallInstallmentsResponse MallInstallmentsResponse( + string token, + List details, + Options options) + { + return ExceptionHandler.Perform(() => + { + List detailsResponse = new List(); + foreach (MallInstallmentsDetails detail in details) + { + var mallInstallmentsResponse = new MallInstallmentsRequest( + token, + detail.CommerceCode, + detail.BuyOrder, + detail.InstallmentsNumber); + + } + }); + } + public static MallCommitResponse MallCommit( string token, List details) @@ -188,6 +215,4 @@ public static MallStatusResponse MallStatus( }); } } - - -} + } diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs index 197d783..d2dfad9 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Transbank.Common; using System.Net.Http; +using Transbank.Webpay.TransaccionCompletaMall.Common; namespace Transbank.Webpay.TransaccionCompletaMall.Requests { @@ -14,7 +15,7 @@ internal class MallInstallmentsRequest : BaseRequest [JsonProperty("installments_number")] public int InstallmentsNumber { get; set; } - + internal MallInstallmentsRequest( string token, string commerceCode, diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs index c2d6f00..8e6da0f 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; -using Transbank.Webpay.TransaccionCompleta.Common; +using Transbank.Webpay.TransaccionCompletaMall.Common; namespace Transbank.Webpay.TransaccionCompletaMall.Responses { @@ -14,6 +14,9 @@ public class MallInstallmentsResponse [JsonProperty("deferred_periods")] public List DeferredPeriods { get; set; } + + [JsonProperty("details")] + public List Details { get; set; } public MallInstallmentsResponse(int installmentsAmount, int idQueryInstallments, List deferredPeriods) { @@ -21,6 +24,10 @@ public MallInstallmentsResponse(int installmentsAmount, int idQueryInstallments, IdQueryInstallments = idQueryInstallments; DeferredPeriods = deferredPeriods; } - + + public MallInstallmentsResponse(List details) + { + Details = details; + } } } From cd062f9547e356a451e661fc9d6a12620ed355cc Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 26 Aug 2019 19:11:50 -0400 Subject: [PATCH 099/120] change add overload to function installments --- ...{CommitDetails.cs => MallCommitDetails.cs} | 14 +++--- .../Common/MallInstallmentsDetailsResponse.cs | 19 ++------ .../MallFullTransaction.cs | 46 +++++++++++-------- .../Requests/MallCommitRequest.cs | 5 +- .../Responses/MallInstallmentsResponse.cs | 6 --- 5 files changed, 41 insertions(+), 49 deletions(-) rename Transbank/WebpayRest/TransaccionCompletaMall/Common/{CommitDetails.cs => MallCommitDetails.cs} (70%) diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitDetails.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallCommitDetails.cs similarity index 70% rename from Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitDetails.cs rename to Transbank/WebpayRest/TransaccionCompletaMall/Common/MallCommitDetails.cs index 2532d01..cc5182f 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitDetails.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallCommitDetails.cs @@ -2,24 +2,24 @@ namespace Transbank.Webpay.TransaccionCompletaMall.Common { - public class CommitDetails + public class MallCommitDetails { [JsonProperty("commerce_code")] - public string CommerceCode { get; } + public string CommerceCode { get; set; } [JsonProperty("buy_order")] - public string BuyOrder { get; } + public string BuyOrder { get; set; } [JsonProperty("id_query_installments")] - public int IdQueryInstallments { get; } + public int IdQueryInstallments { get; set; } [JsonProperty("deferred_period_index")] - public int DeferredPeriodIndex { get; } + public int DeferredPeriodIndex { get; set; } [JsonProperty("grace_period")] - public bool GracePeriod { get; } + public bool GracePeriod { get; set; } - public CommitDetails( + public MallCommitDetails( string commerceCode, string buyOrder, int idQueryInstallments, diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs index 8d377f3..9ab6fa3 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs @@ -1,28 +1,19 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Transbank.Webpay.TransaccionCompletaMall.Responses; namespace Transbank.Webpay.TransaccionCompletaMall.Common { public class MallInstallmentsDetailsResponse { - [JsonProperty("installments_amount")] - public int InstallmentsAmount { get; set; } - - [JsonProperty("id_query_installments")] - public int IdQueryInstallments { get; set; } - - [JsonProperty("deferred_periods")] - public List DeferredPeriods { get; set; } + [JsonProperty("details")] + public List Details { get; set; } public MallInstallmentsDetailsResponse( - int installmentsAmount, - int idQueryInstallments, - List deferredPeriods + List details ) { - InstallmentsAmount = installmentsAmount; - IdQueryInstallments = idQueryInstallments; - DeferredPeriods = deferredPeriods; + Details = details; } } } diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs index bd47ba6..3a93b43 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Runtime.InteropServices.WindowsRuntime; using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; using Transbank.Common; using Transbank.Exceptions; using Transbank.Webpay.Common; @@ -97,7 +95,7 @@ public static MallInstallmentsResponse MallInstallments( string token, string commerceCode, string buyOrder, - int installmentsAmount, + int installmentsNumber, Options options) { return ExceptionHandler.Perform(() => @@ -106,43 +104,53 @@ public static MallInstallmentsResponse MallInstallments( token, commerceCode, buyOrder, - installmentsAmount); + installmentsNumber); var response = RequestService.Perform(mallInstallmentsResponse, options); return JsonConvert.DeserializeObject(response); }); } - public static MallInstallmentsResponse MallInstallments( + public static MallInstallmentsDetailsResponse MallInstallments( string token, List details) { return MallInstallments(token, details); } - public static MallInstallmentsResponse MallInstallmentsResponse( + public static MallInstallmentsDetailsResponse MallInstallments( string token, - List details, + List detailsGroup, Options options) { return ExceptionHandler.Perform(() => { - List detailsResponse = new List(); - foreach (MallInstallmentsDetails detail in details) - { - var mallInstallmentsResponse = new MallInstallmentsRequest( - token, - detail.CommerceCode, - detail.BuyOrder, - detail.InstallmentsNumber); - - } + List details = new List(); + + foreach (MallInstallmentsDetails req in detailsGroup) + { + var request = new MallInstallmentsRequest( + token, + req.CommerceCode, + req.BuyOrder, + req.InstallmentsNumber); + + var response = RequestService.Perform(request, options); + var json = JsonConvert.DeserializeObject(response); + + details.Add(new MallInstallmentsResponse(json.InstallmentsAmount, json.IdQueryInstallments, json.DeferredPeriods)); + + } + + + + return JsonConvert.DeserializeObject(details.ToString()); }); } public static MallCommitResponse MallCommit( string token, - List details) + List details) { return MallCommit( token, @@ -151,7 +159,7 @@ public static MallCommitResponse MallCommit( public static MallCommitResponse MallCommit( string token, - List details, + List details, Options options) { return ExceptionHandler.Perform(() => diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs index 608e33c..0a800e2 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs @@ -3,18 +3,17 @@ using Transbank.Common; using System.Net.Http; using Transbank.Webpay.TransaccionCompletaMall.Common; -using Transbank.Webpay.WebpayPlus.Responses; namespace Transbank.Webpay.TransaccionCompletaMall.Requests { internal class MallCommitRequest : BaseRequest { [JsonProperty("details")] - public List Details { get; set; } + public List Details { get; set; } internal MallCommitRequest( string token, - List details) + List details) : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) { Details = details; diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs index 8e6da0f..db941e2 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs @@ -15,8 +15,6 @@ public class MallInstallmentsResponse [JsonProperty("deferred_periods")] public List DeferredPeriods { get; set; } - [JsonProperty("details")] - public List Details { get; set; } public MallInstallmentsResponse(int installmentsAmount, int idQueryInstallments, List deferredPeriods) { @@ -25,9 +23,5 @@ public MallInstallmentsResponse(int installmentsAmount, int idQueryInstallments, DeferredPeriods = deferredPeriods; } - public MallInstallmentsResponse(List details) - { - Details = details; - } } } From 24658bca7e3522735c97b338ab3db21cce425f35 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 26 Aug 2019 22:11:37 -0400 Subject: [PATCH 100/120] change refactor methods names --- .../MallFullTransaction.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs index 3a93b43..648dedc 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs @@ -46,17 +46,17 @@ public static Options DefaultOptions() return new Options(CommerceCode, ApiKey, IntegrationType); } - public static MallCreateResponse MallCreate( + public static MallCreateResponse Create( string buyOrder, string sessionId, string cardNumber, string cardExpirationDate, List details) { - return MallCreate(buyOrder, sessionId, cardNumber, cardExpirationDate, details); + return Create(buyOrder, sessionId, cardNumber, cardExpirationDate, details); } - public static MallCreateResponse MallCreate( + public static MallCreateResponse Create( string buyOrder, string sessionId, string cardNumber, @@ -78,20 +78,20 @@ public static MallCreateResponse MallCreate( }); } - public static MallInstallmentsResponse MallInstallments( + public static MallInstallmentsResponse Installments( string token, string commerceCode, string buyOrder, int installmentsAmount) { - return MallInstallments( + return Installments( token, commerceCode, buyOrder, installmentsAmount); } - public static MallInstallmentsResponse MallInstallments( + public static MallInstallmentsResponse Installments( string token, string commerceCode, string buyOrder, @@ -111,14 +111,14 @@ public static MallInstallmentsResponse MallInstallments( }); } - public static MallInstallmentsDetailsResponse MallInstallments( + public static MallInstallmentsDetailsResponse Installments( string token, List details) { - return MallInstallments(token, details); + return Installments(token, details); } - public static MallInstallmentsDetailsResponse MallInstallments( + public static MallInstallmentsDetailsResponse Installments( string token, List detailsGroup, Options options) @@ -148,16 +148,16 @@ public static MallInstallmentsDetailsResponse MallInstallments( }); } - public static MallCommitResponse MallCommit( + public static MallCommitResponse Commit( string token, List details) { - return MallCommit( + return Commit( token, details); } - public static MallCommitResponse MallCommit( + public static MallCommitResponse Commit( string token, List details, Options options) @@ -173,16 +173,16 @@ public static MallCommitResponse MallCommit( }); } - public static MallRefundResponse MallRefund( + public static MallRefundResponse Refund( string token, string buyOrder, string commerceCode, int amount) { - return MallRefund(token, buyOrder, commerceCode, amount); + return Refund(token, buyOrder, commerceCode, amount); } - public static MallRefundResponse MallRefund( + public static MallRefundResponse Refund( string token, string buyOrder, string commerceCode, @@ -203,13 +203,13 @@ public static MallRefundResponse MallRefund( }); } - public static MallStatusResponse MallStatus( + public static MallStatusResponse Status( string token) { - return MallStatus(token); + return Status(token); } - public static MallStatusResponse MallStatus( + public static MallStatusResponse Status( string token, Options options) { From 7e45af04491ee93723f85ce557da471ab26cbec8 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Mon, 26 Aug 2019 22:51:39 -0400 Subject: [PATCH 101/120] add methods status and refund --- .../TransaccionCompleta/FullTransaction.cs | 40 +++++++++++++ .../Requests/RefundRequest.cs | 18 ++++++ .../Requests/StatusRequest.cs | 12 ++++ .../Responses/RefundResponse.cs | 36 +++++++++++ .../Responses/StatusResponse.cs | 60 +++++++++++++++++++ 5 files changed, 166 insertions(+) create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Requests/RefundRequest.cs create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Requests/StatusRequest.cs create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Responses/RefundResponse.cs create mode 100644 Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs diff --git a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs index b5da998..61d68bb 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs @@ -1,5 +1,7 @@ using System; +using System.Net.NetworkInformation; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using Transbank.Common; using Transbank.Exceptions; using Transbank.Webpay.Common; @@ -136,5 +138,43 @@ public static CommitResponse Commit( return JsonConvert.DeserializeObject(response); } + + public static StatusResponse Status( + string token) + { + return Status(token, DefaultOptions()); + } + + public static StatusResponse Status( + string token, + Options options) + { + return ExceptionHandler.Perform(() => + { + var request = new StatusRequest(token); + var response = RequestService.Perform(request, options); + + return JsonConvert.DeserializeObject(response); + }); + } + + public static RefundResponse Refund( + string token, + int amount) + { + return Refund(token, amount, DefaultOptions()); + } + + public static RefundResponse Refund( + string token, int amount, Options options) + { + return ExceptionHandler.Perform(() => + { + var request = new RefundRequest(token, amount); + var response = RequestService.Perform(request, options); + + return JsonConvert.DeserializeObject(response); + }); + } } } diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/RefundRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/RefundRequest.cs new file mode 100644 index 0000000..4dc2d11 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/RefundRequest.cs @@ -0,0 +1,18 @@ +using System.Net.Http; +using System.Net.NetworkInformation; +using Newtonsoft.Json; +using Transbank.Common; + +namespace Transbank.Webpay.TransaccionCompleta.Requests +{ + public class RefundRequest : BaseRequest + { + [JsonProperty("amount")] + public int Amount { get; set; } + + public RefundRequest(string token, int amount) : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/refunds", HttpMethod.Post) + { + Amount = amount; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/StatusRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/StatusRequest.cs new file mode 100644 index 0000000..cd216ed --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/StatusRequest.cs @@ -0,0 +1,12 @@ +using Transbank.Common; +using System.Net.Http; + +namespace Transbank.Webpay.TransaccionCompleta.Requests +{ + public class StatusRequest : BaseRequest + { + public StatusRequest(string token) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Get){} + + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/RefundResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/RefundResponse.cs new file mode 100644 index 0000000..c9eae62 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/RefundResponse.cs @@ -0,0 +1,36 @@ +using Newtonsoft.Json; +using Transbank.Webpay.TransaccionCompleta.Common; + +namespace Transbank.Webpay.TransaccionCompleta.Responses +{ + public class RefundResponse + { + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + + [JsonProperty("authorization_date")] + public string AuthorizationDate { get; set; } + + [JsonProperty("nullified_amount")] + public double NullifiedAmount { get; set; } + + [JsonProperty("balance")] + public double Balance { get; set; } + + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + + public RefundResponse(string type, string authorizationCode, string authorizationDate, double nullifiedAmount, double balance, int responseCode) + { + Type = type; + AuthorizationCode = authorizationCode; + AuthorizationDate = authorizationDate; + NullifiedAmount = nullifiedAmount; + Balance = balance; + ResponseCode = responseCode; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs new file mode 100644 index 0000000..48db85d --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs @@ -0,0 +1,60 @@ +using Newtonsoft.Json; +using Transbank.Webpay.TransaccionCompleta.Common; + +namespace Transbank.Webpay.TransaccionCompleta.Responses +{ + public class StatusResponse + { + [JsonProperty("amount")] + public int Amount { get; set; } + + [JsonProperty("status")] + public string Status { get; set; } + + [JsonProperty("buy_order")] + public string BuyOrder { get; set; } + + [JsonProperty("session_id")] + public string SessionId { get; set; } + + [JsonProperty("card_details")] + public CardDetail CardDetail { get; set; } + + [JsonProperty("accounting_date")] + public string AccountingDate { get; set; } + + [JsonProperty("transaction_date")] + public string TransactionDate { get; set; } + + [JsonProperty("authorization_code")] + public string AuthorizationCode { get; set; } + + [JsonProperty("payment_type_code")] + public string PaymentTypeCode { get; set; } + + [JsonProperty("response_code")] + public int ResponseCode { get; set; } + + [JsonProperty("installments_amount")] + public int InstallmentsAmount { get; set; } + + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; set; } + + public StatusResponse(int amount, string status, string buyOrder, string sessionId, CardDetail cardDetail, string accountingDate, string transactionDate, string authorizationCode, string paymentTypeCode, int responseCode, int installmentsAmount, int installmentsNumber) + { + Amount = amount; + Status = status; + BuyOrder = buyOrder; + SessionId = sessionId; + CardDetail = cardDetail; + AccountingDate = accountingDate; + TransactionDate = transactionDate; + AuthorizationCode = authorizationCode; + PaymentTypeCode = paymentTypeCode; + ResponseCode = responseCode; + InstallmentsAmount = installmentsAmount; + InstallmentsNumber = installmentsNumber; + } + } +} From 307c025e8be0e21b22970f1c034bb18169253abe Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Tue, 27 Aug 2019 09:37:32 -0400 Subject: [PATCH 102/120] fix endpoint installments method --- .../TransaccionCompleta/Requests/InstallmentsRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs index fece953..4bcdc84 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs @@ -12,7 +12,7 @@ internal class InstallmentsRequest : BaseRequest internal InstallmentsRequest( string token, int installmentsNumber) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Post) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/installments", HttpMethod.Post) { InstallmentsNumber = installmentsNumber; } From ecd6667506caef20f75474509321f94d57d27fa1 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Tue, 27 Aug 2019 10:01:35 -0400 Subject: [PATCH 103/120] fix add override string method --- .../TransaccionCompleta/Common/CardDetail.cs | 5 +++++ .../Common/DeferredPeriods.cs | 6 ++++++ .../TransaccionCompleta/Common/Detail.cs | 7 +++++++ .../Responses/CommitResponse.cs | 2 +- .../Responses/InstallmentsResponse.cs | 7 +++++++ .../Responses/RefundResponse.cs | 10 ++++++++++ .../Responses/StatusResponse.cs | 16 ++++++++++++++++ 7 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Transbank/WebpayRest/TransaccionCompleta/Common/CardDetail.cs b/Transbank/WebpayRest/TransaccionCompleta/Common/CardDetail.cs index cbfa5b2..65ea471 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Common/CardDetail.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Common/CardDetail.cs @@ -11,5 +11,10 @@ public CardDetail(string cardNumber) { CardNumber = cardNumber; } + + public override string ToString() + { + return $"CardNumber={CardNumber}"; + } } } diff --git a/Transbank/WebpayRest/TransaccionCompleta/Common/DeferredPeriods.cs b/Transbank/WebpayRest/TransaccionCompleta/Common/DeferredPeriods.cs index 9452404..e721d1f 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Common/DeferredPeriods.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Common/DeferredPeriods.cs @@ -15,5 +15,11 @@ public DeferredPeriods(int amount, int period) Amount= amount; Period = period; } + + public override string ToString() + { + return $"Amount={Amount}\n" + + $"Period={Period}"; + } } } diff --git a/Transbank/WebpayRest/TransaccionCompleta/Common/Detail.cs b/Transbank/WebpayRest/TransaccionCompleta/Common/Detail.cs index 2f58c8d..5a75b10 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Common/Detail.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Common/Detail.cs @@ -22,5 +22,12 @@ public Detail( CommerceCode = commerceCode; BuyOrder = buyOrder; } + + public override string ToString() + { + return $"Amount={Amount}\n" + + $"CommerceCode={CommerceCode}\n" + + $"BuyOrder={BuyOrder}"; + } } } diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs index 5d1ac0b..b6f2953 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs @@ -47,7 +47,7 @@ public override string ToString() $"Status={Status}\n" + $"Buy Order={BuyOrder}\n" + $"Session Id={SessionId}\n" + - $"Card Detail={CardDetail}\n" + + $"Card Detail={CardDetail.ToString()}\n" + $"Accounting Date={AccountingDate}\n" + $"Transaction Date={TransactionDate}\n" + $"Authorization Code={AuthorizationCode}\n" + diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs index d0b7a0a..fd347f8 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs @@ -21,5 +21,12 @@ public InstallmentsResponse(int installmentsAmount, int idQueryInstallments, Lis IdQueryInstallments = idQueryInstallments; DeferredPeriods = deferredPeriods; } + + public override string 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 c9eae62..d36d2df 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/RefundResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/RefundResponse.cs @@ -32,5 +32,15 @@ public RefundResponse(string type, string authorizationCode, string authorizatio Balance = balance; ResponseCode = responseCode; } + + public override string ToString() + { + 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 48db85d..c8e09f4 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs @@ -56,5 +56,21 @@ public StatusResponse(int amount, string status, string buyOrder, string session InstallmentsAmount = installmentsAmount; InstallmentsNumber = installmentsNumber; } + + public override string ToString() + { + 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"; + } } } From 4c88d356ea200cefca45ee832fb863bd6672e687 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Tue, 27 Aug 2019 15:42:03 -0400 Subject: [PATCH 104/120] fix add responses and override string to responses --- .../TransaccionCompleta/FullTransaction.cs | 21 +++++++++---------- .../Requests/CommitRequest.cs | 2 +- .../Requests/RefundRequest.cs | 3 +-- .../Responses/CommitResponse.cs | 15 +++++++++++++ .../Responses/CreateResponse.cs | 7 ++++++- .../Responses/StatusResponse.cs | 4 ++-- 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs index 61d68bb..5f46225 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs @@ -1,7 +1,5 @@ using System; -using System.Net.NetworkInformation; using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; using Transbank.Common; using Transbank.Exceptions; using Transbank.Webpay.Common; @@ -128,15 +126,16 @@ public static CommitResponse Commit( bool gracePeriods, Options options) { - var commitRequest = new CommitRequest( - token, - idQueryInstallments, - deferredPeriodsIndex, - gracePeriods, - options); - var response = RequestService.Perform(commitRequest, options); - return JsonConvert.DeserializeObject(response); - + return ExceptionHandler.Perform(() => + { + var commitRequest = new CommitRequest( + token, + idQueryInstallments, + deferredPeriodsIndex, + gracePeriods); + var response = RequestService.Perform(commitRequest, options); + return JsonConvert.DeserializeObject(response); + }); } public static StatusResponse Status( diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/CommitRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/CommitRequest.cs index f9c521e..ff501b9 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Requests/CommitRequest.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/CommitRequest.cs @@ -18,7 +18,7 @@ internal class CommitRequest : BaseRequest internal CommitRequest(string token, int idQueryInstallments, int deferredPeriodIndex, - bool gracePeriod, Options options) + bool gracePeriod) : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) { IdQueryInstallments = idQueryInstallments; diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/RefundRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/RefundRequest.cs index 4dc2d11..966853e 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Requests/RefundRequest.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/RefundRequest.cs @@ -1,5 +1,4 @@ using System.Net.Http; -using System.Net.NetworkInformation; using Newtonsoft.Json; using Transbank.Common; @@ -15,4 +14,4 @@ public RefundRequest(string token, int amount) : base($"/rswebpaytransaction/api Amount = amount; } } -} +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs index b6f2953..66caee6 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs @@ -41,6 +41,21 @@ public class CommitResponse [JsonProperty("installments_number")] public int InstallmentsNumber { get; private set; } + public CommitResponse(int amount, string status, string buyOrder, string sessionId, CardDetail cardDetail, string accountingDate, string transactionDate, string authorizationCode, string paymentTypeCode, int responseCode, int installmentsAmount, int installmentsNumber) + { + Amount = amount; + Status = status; + BuyOrder = buyOrder; + SessionId = sessionId; + CardDetail = cardDetail; + AccountingDate = accountingDate; + TransactionDate = transactionDate; + AuthorizationCode = authorizationCode; + PaymentTypeCode = paymentTypeCode; + ResponseCode = responseCode; + InstallmentsAmount = installmentsAmount; + } + public override string ToString() { return $"Amount={Amount}\n" + diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs index 780e674..5814598 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs @@ -6,7 +6,12 @@ public class CreateResponse { [JsonProperty("token")] public string Token { get; private set; } - + + public CreateResponse(string token) + { + Token = token; + } + public override string ToString() { return $"Token={Token}"; diff --git a/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs index c8e09f4..658a019 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs @@ -63,14 +63,14 @@ public override string ToString() $"Status={Status}\n" + $"BuyOrder={BuyOrder}\n" + $"SessionId={SessionId}\n" + - $"CardDetail={CardDetail.ToString()}\n" + + $"CardDetail={CardDetail}\n" + $"AccountingDate={AccountingDate}\n" + $"TransactionDate={TransactionDate}\n" + $"AuthorizationCode={AuthorizationCode}\n" + $"PaymentTypeCode={PaymentTypeCode}\n" + $"ResponseCode={ResponseCode}\n" + $"InstallmentsAmount={InstallmentsAmount}\n" + - $"InstallmentsNumber={InstallmentsNumber}\n"; + $"InstallmentsAmount={InstallmentsAmount}\n"; } } } From 2a3472e3b88634ce7d3bbee9dd4126369a6c8542 Mon Sep 17 00:00:00 2001 From: iescaida Date: Wed, 11 Sep 2019 17:18:28 -0300 Subject: [PATCH 105/120] Add toString method on MallRefundResponse --- .../Oneclick/Responses/MallRefundResponse.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs index 5d54dca..3e244fb 100644 --- a/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs @@ -31,5 +31,15 @@ public MallRefundResponse(string type, decimal balance, string authorizationCode AuthorizationDate = authorizationDate; NullifiedAmount = nullifiedAmount; } + + public override string ToString() + { + return $"\"Type\": {Type}\"\n" + + $"\"Balance\": {Balance}\"\n" + + $"\"AuthorizationCode\": {AuthorizationCode}\"\n" + + $"\"ResponseCode\": {ResponseCode}\"\n" + + $"\"AuthorizationDate\": {AuthorizationDate}\"\n" + + $"\"NullifiedAmount\": {NullifiedAmount}\"\n" ; + } } } From 02643d58b562010d2f03b2ac7a7d376d14d2fc54 Mon Sep 17 00:00:00 2001 From: iescaida Date: Wed, 11 Sep 2019 17:25:34 -0300 Subject: [PATCH 106/120] Revert "Add toString method on MallRefundResponse" This reverts commit 2a3472e3b88634ce7d3bbee9dd4126369a6c8542. --- .../Oneclick/Responses/MallRefundResponse.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs index 3e244fb..5d54dca 100644 --- a/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs @@ -31,15 +31,5 @@ public MallRefundResponse(string type, decimal balance, string authorizationCode AuthorizationDate = authorizationDate; NullifiedAmount = nullifiedAmount; } - - public override string ToString() - { - return $"\"Type\": {Type}\"\n" + - $"\"Balance\": {Balance}\"\n" + - $"\"AuthorizationCode\": {AuthorizationCode}\"\n" + - $"\"ResponseCode\": {ResponseCode}\"\n" + - $"\"AuthorizationDate\": {AuthorizationDate}\"\n" + - $"\"NullifiedAmount\": {NullifiedAmount}\"\n" ; - } } } From 2e3101c02303c3fe16973ea9dc2cc48db4192755 Mon Sep 17 00:00:00 2001 From: iescaida Date: Wed, 11 Sep 2019 18:04:32 -0300 Subject: [PATCH 107/120] Add toString method on MallRefundResponse --- .../WebpayRest/Oneclick/Responses/MallRefundResponse.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs index 5d54dca..29b8e30 100644 --- a/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs +++ b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs @@ -31,5 +31,14 @@ public MallRefundResponse(string type, decimal balance, string authorizationCode AuthorizationDate = authorizationDate; NullifiedAmount = nullifiedAmount; } + public override string ToString() + { + return $"\"Type\": {Type}\"\n" + + $"\"Balance\": {Balance}\"\n" + + $"\"AuthorizationCode\": {AuthorizationCode}\"\n" + + $"\"ResponseCode\": {ResponseCode}\"\n" + + $"\"AuthorizationDate\": {AuthorizationDate}\"\n" + + $"\"NullifiedAmount\": {NullifiedAmount}\"\n" ; + } } } From 3f3186d5d45f68c2880e0e3a35054b9779574b0a Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Thu, 12 Sep 2019 01:45:58 -0300 Subject: [PATCH 108/120] wip abstract method to request service --- .../AbstractRequestService.cs} | 36 +++++++----------- Transbank/Common/RequestService.cs | 37 ++----------------- .../Common/PatpassComercioIntegrationType.cs | 3 +- .../Common/PatpassComercioRequestService.cs | 18 +++++++++ .../PatpassComercio/Inscription.cs | 16 +++++--- 5 files changed, 45 insertions(+), 65 deletions(-) rename Transbank/{PatpassRest/Common/RequestService.cs => Common/AbstractRequestService.cs} (60%) create mode 100644 Transbank/PatpassRest/Common/PatpassComercioRequestService.cs diff --git a/Transbank/PatpassRest/Common/RequestService.cs b/Transbank/Common/AbstractRequestService.cs similarity index 60% rename from Transbank/PatpassRest/Common/RequestService.cs rename to Transbank/Common/AbstractRequestService.cs index 56167ce..9b90fd3 100644 --- a/Transbank/PatpassRest/Common/RequestService.cs +++ b/Transbank/Common/AbstractRequestService.cs @@ -1,45 +1,35 @@ using System; -using System.Linq; using System.Net.Http; -using System.Net.Http.Headers; using System.Text; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Transbank.Common; using Transbank.Exceptions; -namespace Transbank.Patpass.Common +namespace Transbank.Common { - public class RequestService + public abstract class AbstractRequestService { private static readonly string CONTENT_TYPE = "application/json"; - - private static void AddRequiredHeaders(HttpClient client, string commerceCode, string apiKey) - { - var header = new MediaTypeWithQualityHeaderValue(CONTENT_TYPE); - client.DefaultRequestHeaders.Accept.Add(header); - client.DefaultRequestHeaders.Add("commercecode", commerceCode); - client.DefaultRequestHeaders.Add("Authorization", apiKey); - } + private static void AddRequiredHeaders(HttpClient client, string commerceCode, string apiKey) { } public static string Perform(BaseRequest request, Options options) where T : TransbankException { var message = new HttpRequestMessage(request.Method, new Uri(options.IntegrationType.ApiBase + request.Endpoint)); if (request.Method != HttpMethod.Get) - message.Content = new StringContent(JsonConvert.SerializeObject(request), - Encoding.UTF8, CONTENT_TYPE); + { + message.Content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, CONTENT_TYPE); + } using (var client = new HttpClient()) { AddRequiredHeaders(client, options.CommerceCode, options.ApiKey); - var response = client.SendAsync(message).ConfigureAwait(false) - .GetAwaiter().GetResult(); - var jsonResponse = response.Content.ReadAsStringAsync() - .ConfigureAwait(false).GetAwaiter().GetResult(); - if (!response.IsSuccessStatusCode) - { - var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonResponse); - throw (T)Activator.CreateInstance(typeof(T), new object[] { + var response = client.SendAsync(message).ConfigureAwait(false).GetAwaiter().GetResult(); + var jsonResponse = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + if (!response.IsSuccessStatusCode) + { + var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonResponse); + throw (T)Activator.CreateInstance(typeof(T), new Object[] + { (int)response.StatusCode, $"Error message: {jsonObject.Value("error_message")}" }); } diff --git a/Transbank/Common/RequestService.cs b/Transbank/Common/RequestService.cs index 787679f..76dca7a 100644 --- a/Transbank/Common/RequestService.cs +++ b/Transbank/Common/RequestService.cs @@ -1,18 +1,12 @@ -using System; -using System.Linq; -using System.Net.Http; +using System.Net.Http; using System.Net.Http.Headers; -using System.Text; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Transbank.Exceptions; + namespace Transbank.Common { - public static class RequestService + public class RequestService : AbstractRequestService { private static readonly string CONTENT_TYPE = "application/json"; - private static void AddRequiredHeaders(HttpClient client, string commerceCode, string apiKey) { var header = new MediaTypeWithQualityHeaderValue(CONTENT_TYPE); @@ -20,30 +14,5 @@ private static void AddRequiredHeaders(HttpClient client, string commerceCode, s client.DefaultRequestHeaders.Add("Tbk-Api-Key-Id", commerceCode); client.DefaultRequestHeaders.Add("Tbk-Api-Key-Secret", apiKey); } - - public static string Perform(BaseRequest request, Options options) where T : TransbankException - { - var message = new HttpRequestMessage(request.Method, new Uri(options.IntegrationType.ApiBase + request.Endpoint)); - if (request.Method != HttpMethod.Get) - message.Content = new StringContent(JsonConvert.SerializeObject(request), - Encoding.UTF8, CONTENT_TYPE); - - using (var client = new HttpClient()) - { - AddRequiredHeaders(client, options.CommerceCode, options.ApiKey); - var response = client.SendAsync(message).ConfigureAwait(false) - .GetAwaiter().GetResult(); - var jsonResponse = response.Content.ReadAsStringAsync() - .ConfigureAwait(false).GetAwaiter().GetResult(); - if (!response.IsSuccessStatusCode) - { - var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonResponse); - throw (T)Activator.CreateInstance(typeof(T), new object[] { - (int)response.StatusCode, $"Error message: {jsonObject.Value("error_message")}" - }); - } - return jsonResponse; - } - } } } diff --git a/Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs b/Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs index 1efe133..34b8ba0 100644 --- a/Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs +++ b/Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs @@ -5,7 +5,6 @@ namespace Transbank.Patpass.Common { public class PatpassComercioIntegrationType : IIntegrationType { - public string Key { get; private set; } public string ApiBase { get; private set; } @@ -18,6 +17,6 @@ private PatpassComercioIntegrationType(string key, string apiBase) public static readonly PatpassComercioIntegrationType Live = new PatpassComercioIntegrationType("LIVE", "https://www.pagoautomaticocontarjetas.cl/"); public static readonly PatpassComercioIntegrationType Test = - new PatpassComercioIntegrationType("TEST", "https://webpay3gint.transbank.cl"); + new PatpassComercioIntegrationType("TEST", "https://pagoautomaticocontarjetasint.transbank.cl/"); } } diff --git a/Transbank/PatpassRest/Common/PatpassComercioRequestService.cs b/Transbank/PatpassRest/Common/PatpassComercioRequestService.cs new file mode 100644 index 0000000..3e44e54 --- /dev/null +++ b/Transbank/PatpassRest/Common/PatpassComercioRequestService.cs @@ -0,0 +1,18 @@ +using System.Net.Http; +using System.Net.Http.Headers; +using Transbank.Common; + +namespace Transbank.Patpass.Common +{ + public class PatpassComercioRequestService : AbstractRequestService + { + private static readonly string CONTENT_TYPE = "application/json"; + private void AddRequiredHeaders(HttpClient client, string commerceCode, string apiKey) + { + var header = new MediaTypeWithQualityHeaderValue(CONTENT_TYPE); + client.DefaultRequestHeaders.Accept.Add(header); + client.DefaultRequestHeaders.Add("commerceCode", commerceCode); + client.DefaultRequestHeaders.Add("Authorization", apiKey); + } + } +} diff --git a/Transbank/PatpassRest/PatpassComercio/Inscription.cs b/Transbank/PatpassRest/PatpassComercio/Inscription.cs index 5bb8460..77a198b 100644 --- a/Transbank/PatpassRest/PatpassComercio/Inscription.cs +++ b/Transbank/PatpassRest/PatpassComercio/Inscription.cs @@ -5,7 +5,7 @@ using Transbank.Patpass.Common; using Transbank.Patpass.PatpassComercio.Requests; using Transbank.Patpass.PatpassComercio.Responses; -using RequestService = Transbank.Patpass.Common.RequestService; +using RequestService = Transbank.Patpass.Common.PatpassComercioRequestService; namespace Transbank.Patpass.PatpassComercio { @@ -85,13 +85,17 @@ public static StartResponse Start( Options options ) { - var startRequest = new StartRequest( - url, name, fLastname, sLastname, rut, serviceId, finalUrl, commerceCode, maxAmount, - phoneNumber, mobileNumber, patpassName, personEmail, commerceEmail, address, city + return ExceptionHandler.Perform(() => + { + var startRequest = new StartRequest( + url, name, fLastname, sLastname, rut, serviceId, finalUrl, commerceCode, maxAmount, + phoneNumber, mobileNumber, patpassName, personEmail, commerceEmail, address, city ); - var response = RequestService.Perform(startRequest, options); + var response = RequestService.Perform(startRequest, options); - return JsonConvert.DeserializeObject(response); + return JsonConvert.DeserializeObject(response); + }); + } public static StatusResponse Status(string token) From 7570fbe1a6a1d465870536fc4a9946e215d2c1d3 Mon Sep 17 00:00:00 2001 From: iescaida Date: Thu, 12 Sep 2019 16:59:58 -0300 Subject: [PATCH 109/120] Fix a few typos --- Transbank/WebpayRest/Common/PaymentResponse.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Transbank/WebpayRest/Common/PaymentResponse.cs b/Transbank/WebpayRest/Common/PaymentResponse.cs index 50e0d8a..2bab04e 100644 --- a/Transbank/WebpayRest/Common/PaymentResponse.cs +++ b/Transbank/WebpayRest/Common/PaymentResponse.cs @@ -28,17 +28,17 @@ public class PaymentResponse [JsonProperty("amount")] public decimal Amount { get; private set; } - public PaymentResponse (string comerceCode, string buyOrder, int ammount, int autorizationCode, - string paymentTypeCode, int responseCode, int installmentsAmmount, string status) + public PaymentResponse (string commerceCode, string buyOrder, int amount, int authorizationCode, + string paymentTypeCode, int responseCode, int installmentsAmount, string status) { - AuthorizationCode = autorizationCode; + AuthorizationCode = authorizationCode; PaymentTypeCode = paymentTypeCode; ResponseCode = responseCode; - InstallmentsNumber = installmentsAmmount; + InstallmentsNumber = installmentsAmount; Status = status; - CommerceCode = comerceCode; + CommerceCode = commerceCode; BuyOrder = buyOrder; - Amount = ammount; + Amount = amount; } public override string ToString() From f540887540f74ff20ffda3af152fa76e46d5fab9 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Thu, 12 Sep 2019 21:53:44 -0300 Subject: [PATCH 110/120] add dynamic request headers --- Transbank/Common/AbstractRequestService.cs | 40 ------------ Transbank/Common/Options.cs | 17 ++++- Transbank/Common/RequestService.cs | 42 ++++++++++-- Transbank/Common/RequestServiceHeaders.cs | 22 +++++++ .../Common/PatpassComercioRequestService.cs | 18 ----- .../PatpassByWebpay/Transaction.cs | 16 ++++- .../PatpassComercio/Inscription.cs | 65 +++++++++++++++---- .../PatpassComercio/Requests/StartRequest.cs | 8 +-- .../Responses/StartResponse.cs | 8 ++- .../Responses/StatusResponse.cs | 6 ++ Transbank/WebpayRest/Oneclick/Oneclick.cs | 16 ++++- .../WebpayPlus/DeferredTransaction.cs | 2 +- .../WebpayRest/WebpayPlus/MallTransaction.cs | 14 +++- .../WebpayRest/WebpayPlus/Transaction.cs | 14 +++- .../WebpayRest/WebpayPlus/OptionsTest.cs | 21 +++++- 15 files changed, 220 insertions(+), 89 deletions(-) delete mode 100644 Transbank/Common/AbstractRequestService.cs create mode 100644 Transbank/Common/RequestServiceHeaders.cs delete mode 100644 Transbank/PatpassRest/Common/PatpassComercioRequestService.cs diff --git a/Transbank/Common/AbstractRequestService.cs b/Transbank/Common/AbstractRequestService.cs deleted file mode 100644 index 9b90fd3..0000000 --- a/Transbank/Common/AbstractRequestService.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Net.Http; -using System.Text; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Transbank.Exceptions; - -namespace Transbank.Common -{ - public abstract class AbstractRequestService - { - private static readonly string CONTENT_TYPE = "application/json"; - private static void AddRequiredHeaders(HttpClient client, string commerceCode, string apiKey) { } - - public static string Perform(BaseRequest request, Options options) where T : TransbankException - { - var message = new HttpRequestMessage(request.Method, new Uri(options.IntegrationType.ApiBase + request.Endpoint)); - if (request.Method != HttpMethod.Get) - { - message.Content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, CONTENT_TYPE); - } - - using (var client = new HttpClient()) - { - AddRequiredHeaders(client, options.CommerceCode, options.ApiKey); - var response = client.SendAsync(message).ConfigureAwait(false).GetAwaiter().GetResult(); - var jsonResponse = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - if (!response.IsSuccessStatusCode) - { - var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonResponse); - throw (T)Activator.CreateInstance(typeof(T), new Object[] - { - (int)response.StatusCode, $"Error message: {jsonObject.Value("error_message")}" - }); - } - return jsonResponse; - } - } - } -} diff --git a/Transbank/Common/Options.cs b/Transbank/Common/Options.cs index 77d3229..c58db1d 100644 --- a/Transbank/Common/Options.cs +++ b/Transbank/Common/Options.cs @@ -1,4 +1,5 @@ using System; +using Newtonsoft.Json; namespace Transbank.Common { @@ -7,6 +8,19 @@ public class Options private string _commerceCode; private string _apiKey; private IIntegrationType _integrationType; + + 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 RequestServiceHeaders Headers + { + get => _headers; + set => _headers = value ?? throw new ArgumentNullException( + nameof(value), "headers can't be null." + ); + } public string CommerceCode { @@ -32,11 +46,12 @@ public IIntegrationType IntegrationType ); } - public Options(string commerceCode, string apiKey, IIntegrationType integrationType) + public Options(string commerceCode, string apiKey, IIntegrationType integrationType, RequestServiceHeaders headers) { CommerceCode = commerceCode; ApiKey = apiKey; IntegrationType = integrationType; + Headers = headers; } } } diff --git a/Transbank/Common/RequestService.cs b/Transbank/Common/RequestService.cs index 76dca7a..91966d7 100644 --- a/Transbank/Common/RequestService.cs +++ b/Transbank/Common/RequestService.cs @@ -1,18 +1,48 @@ -using System.Net.Http; +using System; +using System.Net.Http; using System.Net.Http.Headers; - +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Transbank.Exceptions; namespace Transbank.Common { - public class RequestService : AbstractRequestService + public static class RequestService { private static readonly string CONTENT_TYPE = "application/json"; - private static void AddRequiredHeaders(HttpClient client, string commerceCode, string apiKey) + + private static void AddRequiredHeaders(HttpClient client, string commerceCode, string apiKey, RequestServiceHeaders headers) { var header = new MediaTypeWithQualityHeaderValue(CONTENT_TYPE); client.DefaultRequestHeaders.Accept.Add(header); - client.DefaultRequestHeaders.Add("Tbk-Api-Key-Id", commerceCode); - client.DefaultRequestHeaders.Add("Tbk-Api-Key-Secret", apiKey); + client.DefaultRequestHeaders.Add(headers.CommerceCodeHeaderName, commerceCode); + client.DefaultRequestHeaders.Add(headers.ApiKeyHeaderName, apiKey); + } + + public static string Perform(BaseRequest request, Options options) where T : TransbankException + { + var message = new HttpRequestMessage(request.Method, new Uri(options.IntegrationType.ApiBase + request.Endpoint)); + if (request.Method != HttpMethod.Get) + message.Content = new StringContent(JsonConvert.SerializeObject(request), + Encoding.UTF8, CONTENT_TYPE); + + using (var client = new HttpClient()) + { + AddRequiredHeaders(client, options.CommerceCode, options.ApiKey, options.Headers); + var response = client.SendAsync(message) + .ConfigureAwait(false).GetAwaiter().GetResult(); + var jsonResponse = response.Content.ReadAsStringAsync() + .ConfigureAwait(false).GetAwaiter().GetResult(); + if (!response.IsSuccessStatusCode) + { + var jsonObject = (JObject)JsonConvert.DeserializeObject(jsonResponse); + throw (T)Activator.CreateInstance(typeof(T), new object[] { + (int)response.StatusCode, $"Error message: {jsonObject.Value("error_message")}" + }); + } + return jsonResponse; + } } } } diff --git a/Transbank/Common/RequestServiceHeaders.cs b/Transbank/Common/RequestServiceHeaders.cs new file mode 100644 index 0000000..9710f5d --- /dev/null +++ b/Transbank/Common/RequestServiceHeaders.cs @@ -0,0 +1,22 @@ +using System.ComponentModel; +using Newtonsoft.Json; + +namespace Transbank.Common +{ + public class RequestServiceHeaders + { + [DefaultValue("Tbk-Api-Key-Id")] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + public string ApiKeyHeaderName { get; set; } + + [DefaultValue("Tbk-Api-Key-Secret")] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + public string CommerceCodeHeaderName { get; set; } + + public RequestServiceHeaders(string apiKeyHeaderName, string commerceCodeHeaderName) + { + ApiKeyHeaderName = apiKeyHeaderName; + CommerceCodeHeaderName = commerceCodeHeaderName; + } + } +} diff --git a/Transbank/PatpassRest/Common/PatpassComercioRequestService.cs b/Transbank/PatpassRest/Common/PatpassComercioRequestService.cs deleted file mode 100644 index 3e44e54..0000000 --- a/Transbank/PatpassRest/Common/PatpassComercioRequestService.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Net.Http; -using System.Net.Http.Headers; -using Transbank.Common; - -namespace Transbank.Patpass.Common -{ - public class PatpassComercioRequestService : AbstractRequestService - { - private static readonly string CONTENT_TYPE = "application/json"; - private void AddRequiredHeaders(HttpClient client, string commerceCode, string apiKey) - { - var header = new MediaTypeWithQualityHeaderValue(CONTENT_TYPE); - client.DefaultRequestHeaders.Accept.Add(header); - client.DefaultRequestHeaders.Add("commerceCode", commerceCode); - client.DefaultRequestHeaders.Add("Authorization", apiKey); - } - } -} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs index 8888825..f18fc7e 100644 --- a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs +++ b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs @@ -14,7 +14,19 @@ public static class Transaction private static string _commerceCode = "597055555550"; private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; private static PatpassByWebpayIntegrationType _integrationType = PatpassByWebpayIntegrationType.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." + ); + } public static string CommerceCode { get => _commerceCode; @@ -39,9 +51,11 @@ public static PatpassByWebpayIntegrationType IntegrationType ); } + + public static Options DefaultOptions() { - return new Options(CommerceCode, ApiKey, IntegrationType); + return new Options(CommerceCode, ApiKey, IntegrationType, Headers); } public static CreateResponse Create(string buyOrder, string sessionId, decimal amount, string returnUrl, string serviceId, string cardHolderId, diff --git a/Transbank/PatpassRest/PatpassComercio/Inscription.cs b/Transbank/PatpassRest/PatpassComercio/Inscription.cs index 77a198b..2098fba 100644 --- a/Transbank/PatpassRest/PatpassComercio/Inscription.cs +++ b/Transbank/PatpassRest/PatpassComercio/Inscription.cs @@ -1,11 +1,12 @@ using System; +using System.Dynamic; +using System.Runtime.Remoting.Messaging; using Newtonsoft.Json; using Transbank.Common; using Transbank.Exceptions; using Transbank.Patpass.Common; using Transbank.Patpass.PatpassComercio.Requests; using Transbank.Patpass.PatpassComercio.Responses; -using RequestService = Transbank.Patpass.Common.PatpassComercioRequestService; namespace Transbank.Patpass.PatpassComercio { @@ -14,7 +15,11 @@ public static class Inscription private static string _commerceCode = "28299257"; private static string _apiKey = "cxxXQgGD9vrVe4M41FIt"; private static PatpassComercioIntegrationType _integrationType = PatpassComercioIntegrationType.Test; - + private static string _apiKeyHeaderName = "Authorization"; + private static string _commerceCodeHeaderName = "commerceCode"; + + private static RequestServiceHeaders _headers = new RequestServiceHeaders(_apiKeyHeaderName, _commerceCodeHeaderName); + public static string CommerceCode { get => _commerceCode; @@ -37,9 +42,16 @@ public static PatpassComercioIntegrationType IntegrationType nameof(value), "Integration type can't be null"); } + public static RequestServiceHeaders Headers + { + get => _headers; + set => _headers = value ?? throw new ArgumentNullException( + nameof(value), " Headers can't be null"); + } + public static Options DefaultOptions() { - return new Options(CommerceCode, ApiKey, IntegrationType); + return new Options(CommerceCode, ApiKey, IntegrationType, Headers); } public static StartResponse Start( @@ -51,7 +63,7 @@ public static StartResponse Start( string serviceId, string finalUrl, string commerceCode, - int maxAmount, + decimal maxAmount, string phoneNumber, string mobileNumber, string patpassName, @@ -61,8 +73,25 @@ public static StartResponse Start( string city ) { - return Start(url, name, fLastname, sLastname, rut, serviceId, finalUrl, commerceCode, maxAmount, - phoneNumber, mobileNumber, patpassName, personEmail, commerceEmail, address, city, DefaultOptions()); + return Start( + url, + name, + fLastname, + sLastname, + rut, + serviceId, + finalUrl, + commerceCode, + maxAmount, + phoneNumber, + mobileNumber, + patpassName, + personEmail, + commerceEmail, + address, + city, + DefaultOptions() + ); } public static StartResponse Start( @@ -74,7 +103,7 @@ public static StartResponse Start( string serviceId, string finalUrl, string commerceCode, - int maxAmount, + decimal maxAmount, string phoneNumber, string mobileNumber, string patpassName, @@ -87,11 +116,25 @@ Options options { return ExceptionHandler.Perform(() => { - var startRequest = new StartRequest( - url, name, fLastname, sLastname, rut, serviceId, finalUrl, commerceCode, maxAmount, - phoneNumber, mobileNumber, patpassName, personEmail, commerceEmail, address, city + var request = new StartRequest( + url, + name, + fLastname, + sLastname, + rut, + serviceId, + finalUrl, + commerceCode, + maxAmount, + phoneNumber, + mobileNumber, + patpassName, + personEmail, + commerceEmail, + address, + city ); - var response = RequestService.Perform(startRequest, options); + var response = RequestService.Perform(request, options); return JsonConvert.DeserializeObject(response); }); diff --git a/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs b/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs index 036c591..a702db6 100644 --- a/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs +++ b/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs @@ -31,7 +31,7 @@ internal class StartRequest : BaseRequest public string CommerceCode { get; set; } [JsonProperty("montoMaximo")] - public int MaxAmount { get; set; } + public decimal MaxAmount { get; set; } [JsonProperty("telefonoFijo")] public string PhoneNumber { get; set; } @@ -39,7 +39,7 @@ internal class StartRequest : BaseRequest [JsonProperty("telefonoCelular")] public string MobileNumber { get; set; } - [JsonProperty("nombrePatpPass")] + [JsonProperty("nombrePatPass")] public string PatpassName { get; set; } [JsonProperty("correoPersona")] @@ -63,7 +63,7 @@ internal StartRequest( string serviceId, string finalUrl, string commerceCode, - int maxAmount, + decimal maxAmount, string phoneNumber, string mobileNumber, string patpassName, @@ -71,7 +71,7 @@ internal StartRequest( string commerceEmail, string address, string city - ) : base("/restpatpass/v1/services/patInscription", HttpMethod.Post) + ) : base("restpatpass/v1/services/patInscription", HttpMethod.Post) { Url = url; Name = name; diff --git a/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs b/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs index 8b8afb1..e0c5aa8 100644 --- a/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs +++ b/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs @@ -9,7 +9,13 @@ public class StartResponse [JsonProperty("url")] public string Url { get; private set; } - + + public StartResponse(string token, string url) + { + Token = token; + Url = url; + } + public override string ToString() { return $"Token={Token}, Url={Url}"; diff --git a/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs b/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs index c85c009..97be3d3 100644 --- a/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs +++ b/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs @@ -10,6 +10,12 @@ public class StatusResponse [JsonProperty("urlVoucher")] public string UrlVoucher { get; set; } + public StatusResponse(string status, string urlVoucher) + { + Status = status; + UrlVoucher = urlVoucher; + } + public override string ToString() { return $"status: {Status}\n" + diff --git a/Transbank/WebpayRest/Oneclick/Oneclick.cs b/Transbank/WebpayRest/Oneclick/Oneclick.cs index 9f382b3..4930677 100644 --- a/Transbank/WebpayRest/Oneclick/Oneclick.cs +++ b/Transbank/WebpayRest/Oneclick/Oneclick.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.Remoting.Messaging; using Transbank.Common; using Transbank.Webpay.Common; namespace Transbank.Webpay.Oneclick @@ -8,6 +9,19 @@ public static class Oneclick private static string _commerceCode = "597055555541"; private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; private static string[] _storeCodes = { "597055555542", "597055555543" }; + + 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." + ); + } private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; @@ -37,7 +51,7 @@ public static WebpayIntegrationType IntegrationType public static Options DefaultOptions() { - return new Options(CommerceCode, ApiKey, IntegrationType); + return new Options(CommerceCode, ApiKey, IntegrationType, Headers); } } } diff --git a/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs index 0c8c0d6..d727871 100644 --- a/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs @@ -40,7 +40,7 @@ public static WebpayIntegrationType IntegrationType public static Options DefaultOptions() { - return new Options(CommerceCode, ApiKey, IntegrationType); + return new Options(CommerceCode, ApiKey, IntegrationType, null); } public static CreateResponse Create(string buyOrder, string sessionId, diff --git a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs index 04fa1b6..efc953f 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs @@ -15,6 +15,18 @@ public static class MallTransaction private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; private static WebpayIntegrationType _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." + ); + } public static string CommerceCode { get => _commerceCode; @@ -41,7 +53,7 @@ public static WebpayIntegrationType IntegrationType public static Options DefaultOptions() { - return new Options(CommerceCode, ApiKey, IntegrationType); + return new Options(CommerceCode, ApiKey, IntegrationType, Headers); } public static MallCreateResponse Create(string buyOrder, string sessionId, diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs index 5d7b52d..0784550 100644 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/Transaction.cs @@ -15,6 +15,18 @@ public static class Transaction private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; private static WebpayIntegrationType _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." + ); + } public static string CommerceCode { get => _commerceCode; @@ -41,7 +53,7 @@ public static WebpayIntegrationType IntegrationType public static Options DefaultOptions() { - return new Options(CommerceCode, ApiKey, IntegrationType); + return new Options(CommerceCode, ApiKey, IntegrationType, Headers); } public static CreateResponse Create(string buyOrder, string sessionId, diff --git a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs index 6c55c1d..2cbdaa3 100644 --- a/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs +++ b/TransbankTest/WebpayRest/WebpayPlus/OptionsTest.cs @@ -15,15 +15,30 @@ public void TestDefaultConfiguration() 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)); + public void TestCommerceCodeNotNull() => Assert.ThrowsException(() => new Options(null, "someapikey", WebpayIntegrationType.Test, Headers)); [TestMethod] - public void TestApiKeyNotNull() => Assert.ThrowsException(() => new Options("somecommercecode", null, WebpayIntegrationType.Test)); + public void TestApiKeyNotNull() => Assert.ThrowsException(() => new Options("somecommercecode", null, WebpayIntegrationType.Test, Headers)); [TestMethod] - public void TestIntegrationTypeNotNull() => Assert.ThrowsException(() => new Options("someapikey", "somecommercecode", null)); + public void TestIntegrationTypeNotNull() => Assert.ThrowsException(() => new Options("someapikey", "somecommercecode", null, Headers)); } } From 94cca27725854caf257ef3b88ab62d8d528ce882 Mon Sep 17 00:00:00 2001 From: iescaida Date: Mon, 16 Sep 2019 13:27:49 -0300 Subject: [PATCH 111/120] Remove commercecode as parameter and changed maxAmmount type --- Transbank/PatpassRest/PatpassComercio/Inscription.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Transbank/PatpassRest/PatpassComercio/Inscription.cs b/Transbank/PatpassRest/PatpassComercio/Inscription.cs index 2098fba..dbd8617 100644 --- a/Transbank/PatpassRest/PatpassComercio/Inscription.cs +++ b/Transbank/PatpassRest/PatpassComercio/Inscription.cs @@ -62,8 +62,7 @@ public static StartResponse Start( string rut, string serviceId, string finalUrl, - string commerceCode, - decimal maxAmount, + string maxAmount, string phoneNumber, string mobileNumber, string patpassName, @@ -81,7 +80,6 @@ string city rut, serviceId, finalUrl, - commerceCode, maxAmount, phoneNumber, mobileNumber, @@ -102,8 +100,7 @@ public static StartResponse Start( string rut, string serviceId, string finalUrl, - string commerceCode, - decimal maxAmount, + string maxAmount, string phoneNumber, string mobileNumber, string patpassName, @@ -124,7 +121,7 @@ Options options rut, serviceId, finalUrl, - commerceCode, + options.CommerceCode, maxAmount, phoneNumber, mobileNumber, From 336a463d3a496928175be461bcd47bb9ce8a65c8 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez Date: Tue, 24 Sep 2019 17:12:11 -0300 Subject: [PATCH 112/120] fix replace headers after merge others methods --- .../PatpassComercio/Requests/StatusRequest.cs | 2 +- Transbank/WebpayRest/Oneclick/MallTransaction.cs | 15 ++++++++++++++- .../TransaccionCompleta/FullTransaction.cs | 15 ++++++++++++++- .../MallFullTransaction.cs | 15 ++++++++++++++- .../WebpayPlus/MallDeferredTransaction.cs | 15 ++++++++++++++- 5 files changed, 57 insertions(+), 5 deletions(-) diff --git a/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs b/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs index fa3059d..c7cbb2b 100644 --- a/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs +++ b/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs @@ -12,7 +12,7 @@ internal class StatusRequest : BaseRequest internal StatusRequest( string token - ) : base($"/restpatpass/v1/services/status", + ) : base($"restpatpass/v1/services/status", HttpMethod.Post) { Token = token; diff --git a/Transbank/WebpayRest/Oneclick/MallTransaction.cs b/Transbank/WebpayRest/Oneclick/MallTransaction.cs index 7ae2e27..a74e90d 100644 --- a/Transbank/WebpayRest/Oneclick/MallTransaction.cs +++ b/Transbank/WebpayRest/Oneclick/MallTransaction.cs @@ -19,6 +19,19 @@ public static class MallTransaction private static string[] _storeCodes = { "597055555542", "597055555543" }; private static WebpayIntegrationType _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." + ); + } public static string CommerceCode { @@ -46,7 +59,7 @@ public static WebpayIntegrationType IntegrationType public static Options DefaultOptions() { - return new Options(CommerceCode, ApiKey, IntegrationType); + return new Options(CommerceCode, ApiKey, IntegrationType, Headers); } public static MallAuthorizeResponse Authorize(string userName, string tbkUser, diff --git a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs index 5f46225..48b1d63 100644 --- a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs @@ -14,6 +14,19 @@ public static class FullTransaction private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; private static WebpayIntegrationType _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." + ); + } public static string CommerceCode { @@ -41,7 +54,7 @@ public static WebpayIntegrationType IntegrationType public static Options DefaultOptions() { - return new Options(CommerceCode, ApiKey, IntegrationType); + return new Options(CommerceCode, ApiKey, IntegrationType, Headers); } public static CreateResponse Create( string buyOrder, diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs index 648dedc..e0f25c2 100644 --- a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs +++ b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs @@ -17,6 +17,19 @@ public class MallFullTransaction private static WebpayIntegrationType _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." + ); + } + public static string CommerceCode { get => _commerceCode; @@ -43,7 +56,7 @@ public static WebpayIntegrationType IntegrationType public static Options DefaultOptions() { - return new Options(CommerceCode, ApiKey, IntegrationType); + return new Options(CommerceCode, ApiKey, IntegrationType, Headers); } public static MallCreateResponse Create( diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs index f73ccff..597fa3b 100644 --- a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs +++ b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs @@ -16,6 +16,19 @@ public static class MallDeferredTransaction private static string _commerceCode = "597055555544"; private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; private static WebpayIntegrationType _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." + ); + } public static string CommerceCode { @@ -43,7 +56,7 @@ public static WebpayIntegrationType IntegrationType public static Options DefaultOptions() { - return new Options(CommerceCode, ApiKey, IntegrationType); + return new Options(CommerceCode, ApiKey, IntegrationType, Headers); } public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, From 45f28411b6d4764d15646480a8f117b3cf0e1bf0 Mon Sep 17 00:00:00 2001 From: iescaida Date: Wed, 25 Sep 2019 18:57:02 -0300 Subject: [PATCH 113/120] Add validation when max amount is less or equal zero --- .../PatpassComercio/Inscription.cs | 10 +++++--- .../PatpassComercio/Requests/StartRequest.cs | 5 ++-- Transbank/Transbank.csproj | 24 +++++++++---------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Transbank/PatpassRest/PatpassComercio/Inscription.cs b/Transbank/PatpassRest/PatpassComercio/Inscription.cs index dbd8617..163a47e 100644 --- a/Transbank/PatpassRest/PatpassComercio/Inscription.cs +++ b/Transbank/PatpassRest/PatpassComercio/Inscription.cs @@ -1,5 +1,6 @@ using System; using System.Dynamic; +using System.Globalization; using System.Runtime.Remoting.Messaging; using Newtonsoft.Json; using Transbank.Common; @@ -62,7 +63,7 @@ public static StartResponse Start( string rut, string serviceId, string finalUrl, - string maxAmount, + decimal maxAmount, string phoneNumber, string mobileNumber, string patpassName, @@ -100,7 +101,7 @@ public static StartResponse Start( string rut, string serviceId, string finalUrl, - string maxAmount, + decimal maxAmount, string phoneNumber, string mobileNumber, string patpassName, @@ -111,6 +112,9 @@ public static StartResponse Start( Options options ) { + // set culture to es-CL, since webpay only works with clp we are forcing to anyone to use clp currency standard. + CultureInfo myCiIntl = new CultureInfo("es-CL", false); + string mAmount = maxAmount <= 0 ? "" : maxAmount.ToString(myCiIntl); return ExceptionHandler.Perform(() => { var request = new StartRequest( @@ -122,7 +126,7 @@ Options options serviceId, finalUrl, options.CommerceCode, - maxAmount, + mAmount, phoneNumber, mobileNumber, patpassName, diff --git a/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs b/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs index a702db6..a84e363 100644 --- a/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs +++ b/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs @@ -1,3 +1,4 @@ +using System; using Newtonsoft.Json; using Transbank.Common; using System.Net.Http; @@ -31,7 +32,7 @@ internal class StartRequest : BaseRequest public string CommerceCode { get; set; } [JsonProperty("montoMaximo")] - public decimal MaxAmount { get; set; } + public string MaxAmount { get; set; } [JsonProperty("telefonoFijo")] public string PhoneNumber { get; set; } @@ -63,7 +64,7 @@ internal StartRequest( string serviceId, string finalUrl, string commerceCode, - decimal maxAmount, + string maxAmount, string phoneNumber, string mobileNumber, string patpassName, diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 650022b..add166c 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -1,4 +1,4 @@ - + net452 @@ -109,7 +109,7 @@ - + @@ -124,16 +124,6 @@ - - - - - - - - - - True @@ -149,4 +139,14 @@ + + + + + + + + + + From d5d8a783b16b472d98515532172ce68bcb89ed2c Mon Sep 17 00:00:00 2001 From: iescaida Date: Tue, 1 Oct 2019 11:45:43 -0300 Subject: [PATCH 114/120] Fix version on lib loaded at csproj file --- Transbank/Transbank.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index add166c..21ee234 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -109,7 +109,7 @@ - + From 3c4fe8869a10d9ebb8fc740c1c49da2e1d7bac1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20C=C3=A1rdenas?= Date: Wed, 18 Dec 2019 14:25:41 -0300 Subject: [PATCH 115/120] Clean to leave only oneclick mall and full transaction rest --- Transbank/PatpassRest/Common/Detail.cs | 53 ---- .../Common/PatpassByWebpayIntegrationType.cs | 22 -- .../Common/PatpassComercioIntegrationType.cs | 22 -- .../PatpassByWebpay/Requests/CommitRequest.cs | 12 - .../PatpassByWebpay/Requests/CreateRequest.cs | 40 --- .../PatpassByWebpay/Requests/StatusRequest.cs | 12 - .../Responses/CommitResponse.cs | 52 ---- .../Responses/CreateResponse.cs | 18 -- .../Responses/StatusResponse.cs | 5 - .../PatpassByWebpay/Transaction.cs | 116 --------- .../PatpassComercio/Inscription.cs | 163 ------------ .../PatpassComercio/Requests/StartRequest.cs | 95 ------- .../PatpassComercio/Requests/StatusRequest.cs | 22 -- .../Responses/StartResponse.cs | 25 -- .../Responses/StatusResponse.cs | 25 -- Transbank/Transbank.csproj | 4 - .../Common/CommitResponseDetails.cs | 56 ---- .../Common/CreateDetails.cs | 26 -- .../Common/DeferredPeriods.cs | 19 -- .../Common/MallCommitDetails.cs | 36 --- .../Common/MallInstallmentsDetails.cs | 26 -- .../Common/MallInstallmentsDetailsResponse.cs | 19 -- .../MallFullTransaction.cs | 239 ------------------ .../Requests/MallCommitRequest.cs | 22 -- .../Requests/MallCreateRequest.cs | 40 --- .../Requests/MallInstallmentsRequest.cs | 31 --- .../Requests/MallRefundRequest.cs | 31 --- .../Requests/MallStatusRequest.cs | 12 - .../Responses/MallCommitResponse.cs | 46 ---- .../Responses/MallCreateResponse.cs | 17 -- .../Responses/MallInstallmentsResponse.cs | 27 -- .../Responses/MallRefundResponse.cs | 41 --- .../Responses/MallStatusResponse.cs | 46 ---- .../WebpayPlus/DeferredTransaction.cs | 114 --------- .../WebpayPlus/MallDeferredTransaction.cs | 122 --------- .../WebpayRest/WebpayPlus/MallTransaction.cs | 133 ---------- .../WebpayPlus/Requests/CaptureRequest.cs | 34 --- .../WebpayPlus/Requests/CommitRequest.cs | 12 - .../WebpayPlus/Requests/CreateRequest.cs | 36 --- .../WebpayPlus/Requests/MallCaptureRequest.cs | 37 --- .../WebpayPlus/Requests/MallCommitRequest.cs | 12 - .../WebpayPlus/Requests/MallCreateRequest.cs | 30 --- .../WebpayPlus/Requests/MallRefundRequest.cs | 27 -- .../WebpayPlus/Requests/MallStatusRequest.cs | 10 - .../WebpayPlus/Requests/RefundRequest.cs | 24 -- .../WebpayPlus/Requests/StatusRequest.cs | 12 - .../WebpayPlus/Responses/CaptureResponse.cs | 34 --- .../WebpayPlus/Responses/CommitResponse.cs | 52 ---- .../WebpayPlus/Responses/CreateResponse.cs | 18 -- .../Responses/MallCaptureResponse.cs | 8 - .../Responses/MallCommitResponse.cs | 80 ------ .../Responses/MallCreateResponse.cs | 5 - .../Responses/MallRefundResponse.cs | 9 - .../Responses/MallStatusResponse.cs | 5 - .../WebpayPlus/Responses/RefundResponse.cs | 35 --- .../WebpayPlus/Responses/StatusResponse.cs | 5 - .../WebpayRest/WebpayPlus/Transaction.cs | 129 ---------- 57 files changed, 2403 deletions(-) delete mode 100644 Transbank/PatpassRest/Common/Detail.cs delete mode 100644 Transbank/PatpassRest/Common/PatpassByWebpayIntegrationType.cs delete mode 100644 Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs delete mode 100644 Transbank/PatpassRest/PatpassByWebpay/Requests/CommitRequest.cs delete mode 100644 Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs delete mode 100644 Transbank/PatpassRest/PatpassByWebpay/Requests/StatusRequest.cs delete mode 100644 Transbank/PatpassRest/PatpassByWebpay/Responses/CommitResponse.cs delete mode 100644 Transbank/PatpassRest/PatpassByWebpay/Responses/CreateResponse.cs delete mode 100644 Transbank/PatpassRest/PatpassByWebpay/Responses/StatusResponse.cs delete mode 100644 Transbank/PatpassRest/PatpassByWebpay/Transaction.cs delete mode 100644 Transbank/PatpassRest/PatpassComercio/Inscription.cs delete mode 100644 Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs delete mode 100644 Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs delete mode 100644 Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs delete mode 100644 Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitResponseDetails.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/CreateDetails.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/DeferredPeriods.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/MallCommitDetails.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetails.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCreateRequest.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallStatusRequest.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCommitResponse.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCreateResponse.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs delete mode 100644 Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallStatusResponse.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/MallTransaction.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/MallCaptureRequest.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/MallRefundRequest.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/MallStatusRequest.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/CommitResponse.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/MallCaptureResponse.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/MallCommitResponse.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/MallCreateResponse.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/MallRefundResponse.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/MallStatusResponse.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/RefundResponse.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Responses/StatusResponse.cs delete mode 100644 Transbank/WebpayRest/WebpayPlus/Transaction.cs diff --git a/Transbank/PatpassRest/Common/Detail.cs b/Transbank/PatpassRest/Common/Detail.cs deleted file mode 100644 index 03458b6..0000000 --- a/Transbank/PatpassRest/Common/Detail.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Newtonsoft.Json; - -namespace Transbank.Patpass.Common -{ - internal class Detail - { - [JsonProperty("service_id")] - internal string ServiceId { get; } - - [JsonProperty("card_holder_id")] - internal string CardHolderId { get; } - - [JsonProperty("card_holder_name")] - internal string CardHolderName { get; } - - [JsonProperty("card_holder_last_name1")] - internal string CardHolderLastName1 { get; } - - [JsonProperty("card_holder_last_name2")] - internal string CardHolderLastName2 { get; } - - [JsonProperty("card_holder_mail")] - internal string CardHolderMail { get; } - - [JsonProperty("cellphone_number")] - internal string CellphoneNumber { get; } - - [JsonProperty("expiration_date")] - internal string ExpirationDate { get; } - - [JsonProperty("commerce_mail")] - internal string CommerceMail { get; } - - [JsonProperty("uf_flag")] - internal bool UfFlag { get; } - - public Detail(string serviceId, string cardHolderId, string cardHolderName, - string cardHolderLastName1, string cardHolderLastName2, string cardHolderMail, - string cellphoneNumber, string expirationDate, string commerceMail, bool ufFlag) - { - ServiceId = serviceId; - CardHolderId = cardHolderId; - CardHolderName = cardHolderName; - CardHolderLastName1 = cardHolderLastName1; - CardHolderLastName2 = cardHolderLastName2; - CardHolderMail = cardHolderMail; - CellphoneNumber = cellphoneNumber; - ExpirationDate = expirationDate; - CommerceMail = commerceMail; - UfFlag = ufFlag; - } - } -} diff --git a/Transbank/PatpassRest/Common/PatpassByWebpayIntegrationType.cs b/Transbank/PatpassRest/Common/PatpassByWebpayIntegrationType.cs deleted file mode 100644 index 3dfa6db..0000000 --- a/Transbank/PatpassRest/Common/PatpassByWebpayIntegrationType.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using Transbank.Common; - -namespace Transbank.Patpass.Common -{ - public class PatpassByWebpayIntegrationType : IIntegrationType - { - public string Key { get; private set; } - public string ApiBase { get; private set; } - - private PatpassByWebpayIntegrationType(string key, string apiBase) - { - Key = key; - ApiBase = apiBase; - } - - public static readonly PatpassByWebpayIntegrationType Live = - new PatpassByWebpayIntegrationType("LIVE", "https://webpay3g.transbank.cl"); - public static readonly PatpassByWebpayIntegrationType Test = - new PatpassByWebpayIntegrationType("TEST", "https://webpay3gint.transbank.cl"); - } -} diff --git a/Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs b/Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs deleted file mode 100644 index 34b8ba0..0000000 --- a/Transbank/PatpassRest/Common/PatpassComercioIntegrationType.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using Transbank.Common; - -namespace Transbank.Patpass.Common -{ - public class PatpassComercioIntegrationType : IIntegrationType - { - public string Key { get; private set; } - public string ApiBase { get; private set; } - - private PatpassComercioIntegrationType(string key, string apiBase) - { - Key = key; - ApiBase = apiBase; - } - - public static readonly PatpassComercioIntegrationType Live = - new PatpassComercioIntegrationType("LIVE", "https://www.pagoautomaticocontarjetas.cl/"); - public static readonly PatpassComercioIntegrationType Test = - new PatpassComercioIntegrationType("TEST", "https://pagoautomaticocontarjetasint.transbank.cl/"); - } -} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Requests/CommitRequest.cs b/Transbank/PatpassRest/PatpassByWebpay/Requests/CommitRequest.cs deleted file mode 100644 index 18b1fad..0000000 --- a/Transbank/PatpassRest/PatpassByWebpay/Requests/CommitRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Net.Http; -using Transbank.Common; - -namespace Transbank.Patpass.PatpassByWebpay.Requests -{ - internal class CommitRequest : BaseRequest - { - internal CommitRequest(string token) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) {} - } -} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs b/Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs deleted file mode 100644 index a98c52f..0000000 --- a/Transbank/PatpassRest/PatpassByWebpay/Requests/CreateRequest.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Newtonsoft.Json; -using Transbank.Common; -using System.Net.Http; -using Transbank.Patpass.Common; - -namespace Transbank.Patpass.PatpassByWebpay.Requests -{ - internal class CreateRequest : BaseRequest - { - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - - [JsonProperty("session_id")] - public string SessionId { get; set; } - - [JsonProperty("amount")] - public decimal Amount { get; set; } - - [JsonProperty("return_url")] - public string ReturnUrl { get; set; } - - [JsonProperty("wpm_detail")] - public Detail Details { get; set; } - - internal CreateRequest(string buyOrder, string sessionId, decimal amount, string returnUrl, string serviceId, string cardHolderId, - string cardHolderName, string cardHolderLastName1, string cardHolderLastName2, string cardHolderMail, string cellphoneNumber, - string expirationDate, string commerceMail, bool ufFlag) - : base("/rswebpaytransaction/api/webpay/v1.0/transactions", HttpMethod.Post) - { - BuyOrder = buyOrder; - SessionId = sessionId; - Amount = amount; - ReturnUrl = returnUrl; - Details = new Detail(serviceId, cardHolderId, cardHolderName, - cardHolderLastName1, cardHolderLastName2, cardHolderMail, - cellphoneNumber, expirationDate, commerceMail, ufFlag - ); - } - } -} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Requests/StatusRequest.cs b/Transbank/PatpassRest/PatpassByWebpay/Requests/StatusRequest.cs deleted file mode 100644 index bbe5c24..0000000 --- a/Transbank/PatpassRest/PatpassByWebpay/Requests/StatusRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using Transbank.Common; -using System.Net.Http; - -namespace Transbank.Patpass.PatpassByWebpay.Requests -{ - public class StatusRequest : BaseRequest - { - internal StatusRequest(string token) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Get) { } - } -} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Responses/CommitResponse.cs b/Transbank/PatpassRest/PatpassByWebpay/Responses/CommitResponse.cs deleted file mode 100644 index fdf8420..0000000 --- a/Transbank/PatpassRest/PatpassByWebpay/Responses/CommitResponse.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using Newtonsoft.Json; -using Transbank.Webpay.Common; - -namespace Transbank.Patpass.PatpassByWebpay.Responses -{ - public class CommitResponse - { - [JsonProperty("vci")] - public string Vci { get; set; } - [JsonProperty("amount")] - public decimal Amount { get; set; } - [JsonProperty("status")] - public string Status { get; set; } - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - [JsonProperty("session_id")] - public string SessionId { get; set; } - [JsonProperty("card_detail")] - public CardDetail CardDetail { get; set; } - [JsonProperty("accounting_date")] - public string AccountingDate { get; set; } - [JsonProperty("transaction_date")] - public DateTime TransactionDate { get; set; } - [JsonProperty("authorization_code")] - public string AuthorizationCode { get; set; } - [JsonProperty("payment_type_code")] - public string PaymentTypeCode { get; set; } - [JsonProperty("response_code")] - public int ResponseCode { get; set; } - [JsonProperty("installments_amount")] - public int InstallmentsAmount { get; set; } - [JsonProperty("installments_number")] - public int InstallmentsNumber { get; set; } - [JsonProperty("balance")] - public decimal Balance { get; set; } - - public override string ToString() - { - var properties = new List(); - foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) - { - string name = descriptor.Name; - object value = descriptor.GetValue(this); - properties.Add($"{name}={value}"); - } - return String.Join(", ", properties); - } - } -} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Responses/CreateResponse.cs b/Transbank/PatpassRest/PatpassByWebpay/Responses/CreateResponse.cs deleted file mode 100644 index a89a1eb..0000000 --- a/Transbank/PatpassRest/PatpassByWebpay/Responses/CreateResponse.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Newtonsoft.Json; - -namespace Transbank.Patpass.PatpassByWebpay.Responses -{ - public class CreateResponse - { - [JsonProperty("token")] - public string Token { get; private set; } - - [JsonProperty("url")] - public string Url { get; private set; } - - public override string ToString() - { - return $"Token={Token}, Url={Url}"; - } - } -} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Responses/StatusResponse.cs b/Transbank/PatpassRest/PatpassByWebpay/Responses/StatusResponse.cs deleted file mode 100644 index 9795b53..0000000 --- a/Transbank/PatpassRest/PatpassByWebpay/Responses/StatusResponse.cs +++ /dev/null @@ -1,5 +0,0 @@ -using System; -namespace Transbank.Patpass.PatpassByWebpay.Responses -{ - public class StatusResponse : CommitResponse { } -} diff --git a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs b/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs deleted file mode 100644 index f18fc7e..0000000 --- a/Transbank/PatpassRest/PatpassByWebpay/Transaction.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using Newtonsoft.Json; -using Transbank.Common; -using Transbank.Exceptions; -using Transbank.Patpass.Common; -using Transbank.Patpass.PatpassByWebpay.Requests; -using Transbank.Patpass.PatpassByWebpay.Responses; -using RequestService = Transbank.Common.RequestService; - -namespace Transbank.Patpass.PatpassByWebpay -{ - public static class Transaction - { - private static string _commerceCode = "597055555550"; - private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - private static PatpassByWebpayIntegrationType _integrationType = PatpassByWebpayIntegrationType.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." - ); - } - public static string CommerceCode - { - get => _commerceCode; - set => _commerceCode = value ?? throw new ArgumentNullException( - nameof(value), "Commerce code can't be null." - ); - } - - public static string ApiKey - { - get => _apiKey; - set => _apiKey = value ?? throw new ArgumentNullException( - nameof(value), "Api Key can't be null." - ); - } - - public static PatpassByWebpayIntegrationType IntegrationType - { - get => _integrationType; - set => _integrationType = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null." - ); - } - - - - public static Options DefaultOptions() - { - return new Options(CommerceCode, ApiKey, IntegrationType, Headers); - } - - public static CreateResponse Create(string buyOrder, string sessionId, decimal amount, string returnUrl, string serviceId, string cardHolderId, - string cardHolderName, string cardHolderLastName1, string cardHolderLastName2, string cardHolderMail, string cellphoneNumber, - string expirationDate, string commerceMail, bool ufFlag) - { - return Create(buyOrder, sessionId, amount, returnUrl, serviceId, cardHolderId, - cardHolderName, cardHolderLastName1, cardHolderLastName2, cardHolderMail, cellphoneNumber, - expirationDate, commerceMail, ufFlag, DefaultOptions()); - } - - public static CreateResponse Create(string buyOrder, string sessionId, decimal amount, string returnUrl, string serviceId, string cardHolderId, - string cardHolderName, string cardHolderLastName1, string cardHolderLastName2, string cardHolderMail, string cellphoneNumber, - string expirationDate, string commerceMail, bool ufFlag, Options options) - { - var createRequest = new CreateRequest(buyOrder, sessionId, amount, returnUrl, serviceId, cardHolderId, - cardHolderName, cardHolderLastName1, cardHolderLastName2, cardHolderMail, cellphoneNumber, - expirationDate, commerceMail, ufFlag); - var response = RequestService.Perform(createRequest, options); - - return JsonConvert.DeserializeObject(response); - } - - public static CommitResponse Commit(string token) - { - return Commit(token, DefaultOptions()); - } - - public static CommitResponse Commit(string token, Options options) - { - return ExceptionHandler.Perform(() => - { - var commitRequest = new CommitRequest(token); - var response = RequestService.Perform( - commitRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - - public static StatusResponse Status(string token) - { - return Status(token, DefaultOptions()); - } - - public static StatusResponse Status(string token, Options options) - { - return ExceptionHandler.Perform(() => - { - var statusRequest = new StatusRequest(token); - var response = RequestService.Perform( - statusRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - } -} diff --git a/Transbank/PatpassRest/PatpassComercio/Inscription.cs b/Transbank/PatpassRest/PatpassComercio/Inscription.cs deleted file mode 100644 index 163a47e..0000000 --- a/Transbank/PatpassRest/PatpassComercio/Inscription.cs +++ /dev/null @@ -1,163 +0,0 @@ -using System; -using System.Dynamic; -using System.Globalization; -using System.Runtime.Remoting.Messaging; -using Newtonsoft.Json; -using Transbank.Common; -using Transbank.Exceptions; -using Transbank.Patpass.Common; -using Transbank.Patpass.PatpassComercio.Requests; -using Transbank.Patpass.PatpassComercio.Responses; - -namespace Transbank.Patpass.PatpassComercio -{ - public static class Inscription - { - private static string _commerceCode = "28299257"; - private static string _apiKey = "cxxXQgGD9vrVe4M41FIt"; - private static PatpassComercioIntegrationType _integrationType = PatpassComercioIntegrationType.Test; - private static string _apiKeyHeaderName = "Authorization"; - private static string _commerceCodeHeaderName = "commerceCode"; - - private static RequestServiceHeaders _headers = new RequestServiceHeaders(_apiKeyHeaderName, _commerceCodeHeaderName); - - public static string CommerceCode - { - get => _commerceCode; - set => _commerceCode = value ?? throw new ArgumentNullException( - nameof(value), "Commerce Code can't be null." - ); - } - - public static string ApiKey - { - get => _apiKey; - set => _apiKey = value ?? throw new ArgumentNullException( - nameof(value), "Api Key can't be null."); - } - - public static PatpassComercioIntegrationType IntegrationType - { - get => _integrationType; - set => _integrationType = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null"); - } - - public static RequestServiceHeaders Headers - { - get => _headers; - set => _headers = value ?? throw new ArgumentNullException( - nameof(value), " Headers can't be null"); - } - - public static Options DefaultOptions() - { - return new Options(CommerceCode, ApiKey, IntegrationType, Headers); - } - - public static StartResponse Start( - string url, - string name, - string fLastname, - string sLastname, - string rut, - string serviceId, - string finalUrl, - decimal maxAmount, - string phoneNumber, - string mobileNumber, - string patpassName, - string personEmail, - string commerceEmail, - string address, - string city - ) - { - return Start( - url, - name, - fLastname, - sLastname, - rut, - serviceId, - finalUrl, - maxAmount, - phoneNumber, - mobileNumber, - patpassName, - personEmail, - commerceEmail, - address, - city, - DefaultOptions() - ); - } - - public static StartResponse Start( - string url, - string name, - string fLastname, - string sLastname, - string rut, - string serviceId, - string finalUrl, - decimal maxAmount, - string phoneNumber, - string mobileNumber, - string patpassName, - string personEmail, - string commerceEmail, - string address, - string city, - Options options - ) - { - // set culture to es-CL, since webpay only works with clp we are forcing to anyone to use clp currency standard. - CultureInfo myCiIntl = new CultureInfo("es-CL", false); - string mAmount = maxAmount <= 0 ? "" : maxAmount.ToString(myCiIntl); - return ExceptionHandler.Perform(() => - { - var request = new StartRequest( - url, - name, - fLastname, - sLastname, - rut, - serviceId, - finalUrl, - options.CommerceCode, - mAmount, - phoneNumber, - mobileNumber, - patpassName, - personEmail, - commerceEmail, - address, - city - ); - var response = RequestService.Perform(request, options); - - return JsonConvert.DeserializeObject(response); - }); - - } - - public static StatusResponse Status(string token) - { - return Status(token, DefaultOptions()); - } - - public static StatusResponse Status(string token, Options options) - { - return ExceptionHandler.Perform(() => - { - var statusRequest = new StatusRequest(token); - var response = RequestService.Perform( - statusRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - } - -} diff --git a/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs b/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs deleted file mode 100644 index a84e363..0000000 --- a/Transbank/PatpassRest/PatpassComercio/Requests/StartRequest.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System; -using Newtonsoft.Json; -using Transbank.Common; -using System.Net.Http; - -namespace Transbank.Patpass.PatpassComercio.Requests -{ - internal class StartRequest : BaseRequest - { - [JsonProperty("url")] - public string Url { get; set; } - - [JsonProperty("nombre")] - public string Name { get; set; } - - [JsonProperty("pApellido")] - public string FLastname { get; set; } - - [JsonProperty("sApellido")] - public string SLastname { get; set; } - - [JsonProperty("rut")] - public string Rut { get; set; } - - [JsonProperty("serviceId")] - public string ServiceId { get; set; } - - [JsonProperty("finalUrl")] - public string FinalUrl { get; set; } - - [JsonProperty("commerceCode")] - public string CommerceCode { get; set; } - - [JsonProperty("montoMaximo")] - public string MaxAmount { get; set; } - - [JsonProperty("telefonoFijo")] - public string PhoneNumber { get; set; } - - [JsonProperty("telefonoCelular")] - public string MobileNumber { get; set; } - - [JsonProperty("nombrePatPass")] - public string PatpassName { get; set; } - - [JsonProperty("correoPersona")] - public string PersonEmail { get; set; } - - [JsonProperty("correoComercio")] - public string CommerceEmail { get; set; } - - [JsonProperty("direccion")] - public string Address { get; set; } - - [JsonProperty("ciudad")] - public string City { get; set; } - - internal StartRequest( - string url, - string name, - string fLastname, - string sLastname, - string rut, - string serviceId, - string finalUrl, - string commerceCode, - string maxAmount, - string phoneNumber, - string mobileNumber, - string patpassName, - string personEmail, - string commerceEmail, - string address, - string city - ) : base("restpatpass/v1/services/patInscription", HttpMethod.Post) - { - Url = url; - Name = name; - FLastname = fLastname; - SLastname = sLastname; - Rut = rut; - ServiceId = serviceId; - FinalUrl = finalUrl; - CommerceCode = commerceCode; - MaxAmount = maxAmount; - PhoneNumber = phoneNumber; - MobileNumber = mobileNumber; - PatpassName = patpassName; - PersonEmail = personEmail; - CommerceEmail = commerceEmail; - Address = address; - City = city; - } - } -} diff --git a/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs b/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs deleted file mode 100644 index c7cbb2b..0000000 --- a/Transbank/PatpassRest/PatpassComercio/Requests/StatusRequest.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Net.Http; -using Transbank.Common; -using Newtonsoft.Json; - -namespace Transbank.Patpass.PatpassComercio.Requests -{ - internal class StatusRequest : BaseRequest - { - [JsonProperty("token")] - public string Token { get; set; } - - - internal StatusRequest( - string token - ) : base($"restpatpass/v1/services/status", - HttpMethod.Post) - { - Token = token; - } - - } -} diff --git a/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs b/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs deleted file mode 100644 index e0c5aa8..0000000 --- a/Transbank/PatpassRest/PatpassComercio/Responses/StartResponse.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Newtonsoft.Json; - -namespace Transbank.Patpass.PatpassComercio.Responses -{ - public class StartResponse - { - [JsonProperty("token")] - public string Token { get; private set; } - - [JsonProperty("url")] - public string Url { get; private set; } - - public StartResponse(string token, string url) - { - Token = token; - Url = url; - } - - public override string ToString() - { - return $"Token={Token}, Url={Url}"; - } - - } -} diff --git a/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs b/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs deleted file mode 100644 index 97be3d3..0000000 --- a/Transbank/PatpassRest/PatpassComercio/Responses/StatusResponse.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Newtonsoft.Json; - -namespace Transbank.Patpass.PatpassComercio.Responses -{ - public class StatusResponse - { - [JsonProperty("status")] - public string Status { get; set; } - - [JsonProperty("urlVoucher")] - public string UrlVoucher { get; set; } - - public StatusResponse(string status, string urlVoucher) - { - Status = status; - UrlVoucher = urlVoucher; - } - - public override string ToString() - { - return $"status: {Status}\n" + - $"url voucher: {UrlVoucher}"; - } - } -} diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index 21ee234..275d185 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -116,12 +116,8 @@ - - - - diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitResponseDetails.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitResponseDetails.cs deleted file mode 100644 index 9b6c758..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Common/CommitResponseDetails.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Newtonsoft.Json; - -namespace Transbank.Webpay.TransaccionCompletaMall.Common -{ - public class CommitResponseDetails - { - [JsonProperty("amount")] - public int Amount { get; set; } - - [JsonProperty("status")] - public string Status { get; set; } - - [JsonProperty("authorization_code")] - public string AuthorizationCode { get; set; } - - [JsonProperty("payment_type_code")] - public string PaymentTypeCode { get; set; } - - [JsonProperty("response_code")] - public int ResponseCode { get; set; } - - [JsonProperty("installments_amount")] - public int InstallmentsAmount { get; set; } - - [JsonProperty("installments_number")] - public int InstallmentsNumber { get; set; } - - [JsonProperty("commerce_code")] - public string CommerceCode { get; set; } - - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - - public CommitResponseDetails( - int amount, - string status, - string authorizationCode, - string paymentTypeCode, - int responseCode, - int installmentsAmount, - int installmentsNumber, - string commerceCode, - string buyOrder) - { - Amount = amount; - Status = status; - AuthorizationCode = authorizationCode; - PaymentTypeCode = paymentTypeCode; - ResponseCode = responseCode; - InstallmentsAmount = installmentsAmount; - InstallmentsNumber = installmentsNumber; - CommerceCode = commerceCode; - BuyOrder = buyOrder; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/CreateDetails.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/CreateDetails.cs deleted file mode 100644 index 379b737..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Common/CreateDetails.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Newtonsoft.Json; - -namespace Transbank.Webpay.TransaccionCompletaMall.Common -{ - public class CreateDetails - { - [JsonProperty("amount")] - public int Amount { get; } - - [JsonProperty("commerce_code")] - public string CommerceCode { get; } - - [JsonProperty("buy_order")] - public string BuyOrder { get; } - - public CreateDetails( - int amount, - string commerceCode, - string buyOrder) - { - Amount = amount; - CommerceCode = commerceCode; - BuyOrder = buyOrder; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/DeferredPeriods.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/DeferredPeriods.cs deleted file mode 100644 index bca358c..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Common/DeferredPeriods.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Newtonsoft.Json; - -namespace Transbank.Webpay.TransaccionCompletaMall.Common -{ - public class DeferredPeriods - { - [JsonProperty("amount")] - internal int Amount { get; } - - [JsonProperty("period")] - internal int Period { get; } - - public DeferredPeriods(int amount, int period) - { - Amount= amount; - Period = period; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallCommitDetails.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallCommitDetails.cs deleted file mode 100644 index cc5182f..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallCommitDetails.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Newtonsoft.Json; - -namespace Transbank.Webpay.TransaccionCompletaMall.Common -{ - public class MallCommitDetails - { - [JsonProperty("commerce_code")] - public string CommerceCode { get; set; } - - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - - [JsonProperty("id_query_installments")] - public int IdQueryInstallments { get; set; } - - [JsonProperty("deferred_period_index")] - public int DeferredPeriodIndex { get; set; } - - [JsonProperty("grace_period")] - public bool GracePeriod { get; set; } - - public MallCommitDetails( - string commerceCode, - string buyOrder, - int idQueryInstallments, - int deferredPeriodIndex, - bool gracePeriod) - { - CommerceCode = commerceCode; - BuyOrder = buyOrder; - IdQueryInstallments = idQueryInstallments; - DeferredPeriodIndex = deferredPeriodIndex; - GracePeriod = gracePeriod; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetails.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetails.cs deleted file mode 100644 index 9c2ed58..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetails.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Newtonsoft.Json; - -namespace Transbank.Webpay.TransaccionCompletaMall.Common -{ - public class MallInstallmentsDetails - { - [JsonProperty("commerce_code")] - public string CommerceCode { get; } - - [JsonProperty("buy_order")] - public string BuyOrder { get; } - - [JsonProperty("installments_number")] - public int InstallmentsNumber { get; } - - public MallInstallmentsDetails( - string commerceCode, - string buyOrder, - int installmentsNumber) - { - CommerceCode = commerceCode; - BuyOrder = buyOrder; - InstallmentsNumber = installmentsNumber; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs deleted file mode 100644 index 9ab6fa3..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Common/MallInstallmentsDetailsResponse.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; -using Transbank.Webpay.TransaccionCompletaMall.Responses; - -namespace Transbank.Webpay.TransaccionCompletaMall.Common -{ - public class MallInstallmentsDetailsResponse - { - [JsonProperty("details")] - public List Details { get; set; } - - public MallInstallmentsDetailsResponse( - List details - ) - { - Details = details; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs b/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs deleted file mode 100644 index e0f25c2..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/MallFullTransaction.cs +++ /dev/null @@ -1,239 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; -using Transbank.Common; -using Transbank.Exceptions; -using Transbank.Webpay.Common; -using Transbank.Webpay.TransaccionCompletaMall.Common; -using Transbank.Webpay.TransaccionCompletaMall.Requests; -using Transbank.Webpay.TransaccionCompletaMall.Responses; - -namespace Transbank.Webpay.TransaccionCompletaMall -{ - public class MallFullTransaction - { - private static string _commerceCode = ""; - private static string _apiKey = ""; - - private static WebpayIntegrationType _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." - ); - } - - public static string CommerceCode - { - get => _commerceCode; - set => _commerceCode = value ?? throw new ArgumentNullException( - nameof(value), "Commerce code can't be null." - ); - } - - public static string ApiKey - { - get => _apiKey; - set => _apiKey = value ?? throw new ArgumentNullException( - nameof(value), "Api Key can't be null." - ); - } - - public static WebpayIntegrationType IntegrationType - { - get => _integrationType; - set => _integrationType = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null." - ); - } - - public static Options DefaultOptions() - { - return new Options(CommerceCode, ApiKey, IntegrationType, Headers); - } - - public static MallCreateResponse Create( - string buyOrder, - string sessionId, - string cardNumber, - string cardExpirationDate, - List details) - { - return Create(buyOrder, sessionId, cardNumber, cardExpirationDate, details); - } - - public static MallCreateResponse Create( - string buyOrder, - string sessionId, - string cardNumber, - string cardExpirationDate, - List details, - Options options) - { - return ExceptionHandler.Perform(() => - { - var mallCreateRequest = new MallCreateRequest( - buyOrder, - sessionId, - cardNumber, - cardExpirationDate, - details); - var response = RequestService.Perform(mallCreateRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - - public static MallInstallmentsResponse Installments( - string token, - string commerceCode, - string buyOrder, - int installmentsAmount) - { - return Installments( - token, - commerceCode, - buyOrder, - installmentsAmount); - } - - public static MallInstallmentsResponse Installments( - string token, - string commerceCode, - string buyOrder, - int installmentsNumber, - Options options) - { - return ExceptionHandler.Perform(() => - { - var mallInstallmentsResponse = new MallInstallmentsRequest( - token, - commerceCode, - buyOrder, - installmentsNumber); - var response = RequestService.Perform(mallInstallmentsResponse, options); - - return JsonConvert.DeserializeObject(response); - }); - } - - public static MallInstallmentsDetailsResponse Installments( - string token, - List details) - { - return Installments(token, details); - } - - public static MallInstallmentsDetailsResponse Installments( - string token, - List detailsGroup, - Options options) - { - return ExceptionHandler.Perform(() => - { - List details = new List(); - - foreach (MallInstallmentsDetails req in detailsGroup) - { - var request = new MallInstallmentsRequest( - token, - req.CommerceCode, - req.BuyOrder, - req.InstallmentsNumber); - - var response = RequestService.Perform(request, options); - var json = JsonConvert.DeserializeObject(response); - - details.Add(new MallInstallmentsResponse(json.InstallmentsAmount, json.IdQueryInstallments, json.DeferredPeriods)); - - } - - - - return JsonConvert.DeserializeObject(details.ToString()); - }); - } - - public static MallCommitResponse Commit( - string token, - List details) - { - return Commit( - token, - details); - } - - public static MallCommitResponse Commit( - string token, - List details, - Options options) - { - return ExceptionHandler.Perform(() => - { - var mallCommitRequest = new MallCommitRequest( - token, - details); - var response = RequestService.Perform(mallCommitRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - - public static MallRefundResponse Refund( - string token, - string buyOrder, - string commerceCode, - int amount) - { - return Refund(token, buyOrder, commerceCode, amount); - } - - public static MallRefundResponse Refund( - string token, - string buyOrder, - string commerceCode, - int amount, - Options options) - { - return ExceptionHandler.Perform(() => - { - var mallRefundRequest = new MallRefundRequest( - token, - buyOrder, - commerceCode, - amount); - var response = RequestService.Perform(mallRefundRequest, options); - - return JsonConvert.DeserializeObject(response); - - }); - } - - public static MallStatusResponse Status( - string token) - { - return Status(token); - } - - public static MallStatusResponse Status( - string token, - Options options) - { - return ExceptionHandler.Perform(() => - { - var mallStatusRequest = new MallStatusRequest( - token); - var response = RequestService.Perform(mallStatusRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - } - } diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs deleted file mode 100644 index 0a800e2..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCommitRequest.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; -using Transbank.Common; -using System.Net.Http; -using Transbank.Webpay.TransaccionCompletaMall.Common; - -namespace Transbank.Webpay.TransaccionCompletaMall.Requests -{ - internal class MallCommitRequest : BaseRequest - { - [JsonProperty("details")] - public List Details { get; set; } - - internal MallCommitRequest( - string token, - List details) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) - { - Details = details; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCreateRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCreateRequest.cs deleted file mode 100644 index 1deca7d..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallCreateRequest.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Collections.Generic; -using System.Net.Http; -using Newtonsoft.Json; -using Transbank.Common; -using Transbank.Webpay.TransaccionCompletaMall.Common; - -namespace Transbank.Webpay.TransaccionCompletaMall.Requests -{ - internal class MallCreateRequest : BaseRequest - { - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - - [JsonProperty("session_id")] - public string SessionId { get; set; } - - [JsonProperty("card_number")] - public string CardNumber { get; set; } - - [JsonProperty("card_expiration_date")] - public string CardExpirationDate { get; set; } - - [JsonProperty("details")] - public List Details { get; set; } - - internal MallCreateRequest(string buyOrder, - string sessionId, - string cardNumber, - string cardExpirationDate, - List details) - : base("/rswebpaytransaction/api/webpay/v1.0/transactions", HttpMethod.Post) - { - BuyOrder = buyOrder; - SessionId = sessionId; - CardNumber = cardNumber; - CardExpirationDate = cardExpirationDate; - Details = details; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs deleted file mode 100644 index d2dfad9..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallInstallmentsRequest.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Newtonsoft.Json; -using Transbank.Common; -using System.Net.Http; -using Transbank.Webpay.TransaccionCompletaMall.Common; - -namespace Transbank.Webpay.TransaccionCompletaMall.Requests -{ - internal class MallInstallmentsRequest : BaseRequest - { - [JsonProperty("commerce_code")] - public string CommerceCode { get; set; } - - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - - [JsonProperty("installments_number")] - public int InstallmentsNumber { get; set; } - - internal MallInstallmentsRequest( - string token, - string commerceCode, - string buyOrder, - int installmentsNumber) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/installments", HttpMethod.Post) - { - CommerceCode = commerceCode; - BuyOrder = buyOrder; - InstallmentsNumber = installmentsNumber; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs deleted file mode 100644 index 0ff7541..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallRefundRequest.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Newtonsoft.Json; -using Transbank.Common; -using System.Net.Http; - -namespace Transbank.Webpay.TransaccionCompletaMall.Requests -{ - internal class MallRefundRequest : BaseRequest - { - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - - [JsonProperty("commerce_code")] - public string CommerceCode { get; set; } - - [JsonProperty("amount")] - public int Amount { get; set; } - - internal MallRefundRequest( - string token, - string buyOrder, - string commerceCode, - int amount) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/refunds", HttpMethod.Post) - { - BuyOrder = buyOrder; - CommerceCode = commerceCode; - Amount = amount; - } - - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallStatusRequest.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallStatusRequest.cs deleted file mode 100644 index 75fb69f..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Requests/MallStatusRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Newtonsoft.Json; -using Transbank.Common; -using System.Net.Http; - -namespace Transbank.Webpay.TransaccionCompletaMall.Requests -{ - public class MallStatusRequest : BaseRequest - { - internal MallStatusRequest(string token) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Get){} - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCommitResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCommitResponse.cs deleted file mode 100644 index de6bed8..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCommitResponse.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; -using Transbank.Patpass.Common; -using Transbank.Webpay.Common; -using Transbank.Webpay.TransaccionCompletaMall.Common; - -namespace Transbank.Webpay.TransaccionCompletaMall.Responses -{ - public class MallCommitResponse - { - [JsonProperty("details")] - public List Details { get; set; } - - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - - [JsonProperty("session_id")] - public string SessionId { get; set; } - - [JsonProperty("card_detail")] - public CardDetail CardDetail { get; set; } - - [JsonProperty("accounting_date")] - public string AccountingDate { get; set; } - - [JsonProperty("transaction_date")] - public string TransactionDate { get; set; } - - public MallCommitResponse( - List details, - string buyOrder, - string sessionId, - CardDetail cardDetail, - string accountingDate, - string transactionDate - ) - { - Details = details; - BuyOrder = buyOrder; - SessionId = sessionId; - CardDetail = cardDetail; - AccountingDate = accountingDate; - TransactionDate = transactionDate; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCreateResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCreateResponse.cs deleted file mode 100644 index 6ad8db7..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallCreateResponse.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.Web.Services3.Addressing; -using Newtonsoft.Json; - -namespace Transbank.Webpay.TransaccionCompletaMall.Responses -{ - public class MallCreateResponse - { - [JsonProperty("token")] - public string Token { get; set; } - - public MallCreateResponse( - string token) - { - Token = token; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs deleted file mode 100644 index db941e2..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallInstallmentsResponse.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; -using Transbank.Webpay.TransaccionCompletaMall.Common; - -namespace Transbank.Webpay.TransaccionCompletaMall.Responses -{ - public class MallInstallmentsResponse - { - [JsonProperty("installments_amount")] - public int InstallmentsAmount { get; set; } - - [JsonProperty("id_query_installments")] - public int IdQueryInstallments { get; set; } - - [JsonProperty("deferred_periods")] - public List DeferredPeriods { get; set; } - - - public MallInstallmentsResponse(int installmentsAmount, int idQueryInstallments, List deferredPeriods) - { - InstallmentsAmount = installmentsAmount; - IdQueryInstallments = idQueryInstallments; - DeferredPeriods = deferredPeriods; - } - - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs deleted file mode 100644 index aaeca7f..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallRefundResponse.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Newtonsoft.Json; - -namespace Transbank.Webpay.TransaccionCompletaMall.Responses -{ - public class MallRefundResponse - { - [JsonProperty("type")] - public string Type { get; set; } - - [JsonProperty("authorization_code")] - public string AuthorizationCode { get; set; } - - [JsonProperty("authorization_date")] - public string AuthorizationDate { get; set; } - - [JsonProperty("nullified_amount")] - public double NullifiedAmount { get; set; } - - [JsonProperty("balance")] - public double Balance { get; set; } - - [JsonProperty("response_code")] - public int ResponseCode { get; set; } - - public MallRefundResponse( - string type, - string authorizationCode, - string authorizationDate, - double nullifiedAmount, - double balance, - int responseCode) - { - Type = type; - AuthorizationCode = authorizationCode; - AuthorizationDate = authorizationDate; - NullifiedAmount = nullifiedAmount; - Balance = balance; - ResponseCode = responseCode; - } - } -} diff --git a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallStatusResponse.cs b/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallStatusResponse.cs deleted file mode 100644 index f8c3be6..0000000 --- a/Transbank/WebpayRest/TransaccionCompletaMall/Responses/MallStatusResponse.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; -using Transbank.Patpass.Common; -using Transbank.Webpay.Common; -using Transbank.Webpay.TransaccionCompletaMall.Common; - -namespace Transbank.Webpay.TransaccionCompletaMall.Responses -{ - public class MallStatusResponse - { - [JsonProperty("details")] - public List Details { get; set; } - - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - - [JsonProperty("session_id")] - public string SessionId { get; set; } - - [JsonProperty("card_detail")] - public CardDetail CardDetail { get; set; } - - [JsonProperty("accounting_date")] - public string AccountingDate { get; set; } - - [JsonProperty("transaction_date")] - public string TransactionDate { get; set; } - - public MallStatusResponse( - List details, - string buyOrder, - string sessionId, - CardDetail cardDetail, - string accountingDate, - string transactionDate - ) - { - Details = details; - BuyOrder = buyOrder; - SessionId = sessionId; - CardDetail = cardDetail; - AccountingDate = accountingDate; - TransactionDate = transactionDate; - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs deleted file mode 100644 index 253f5f5..0000000 --- a/Transbank/WebpayRest/WebpayPlus/DeferredTransaction.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using Newtonsoft.Json; -using Transbank.Common; -using Transbank.Webpay.Common; -using Transbank.Webpay.WebpayPlus.Exceptions; -using Transbank.Webpay.WebpayPlus.Requests; -using Transbank.Webpay.WebpayPlus.Responses; - -namespace Transbank.Webpay.WebpayPlus -{ - public static class DeferredTransaction - { - private static string _commerceCode = "597055555540"; - private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test; - - public static string CommerceCode - { - get => _commerceCode; - set => _commerceCode = value ?? throw new ArgumentNullException( - nameof(value), "Commerce code can't be null." - ); - } - - public static string ApiKey - { - get => _apiKey; - set => _apiKey = value ?? throw new ArgumentNullException( - nameof(value), "Api Key can't be null." - ); - } - - public static WebpayIntegrationType IntegrationType - { - get => _integrationType; - set => _integrationType = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null." - ); - } - - public static Options DefaultOptions() - { - return new Options(CommerceCode, ApiKey, IntegrationType, null); - } - - public static CreateResponse Create(string buyOrder, string sessionId, - decimal amount, string returnUrl) - { - return Create(buyOrder, sessionId, amount, returnUrl, DefaultOptions()); - } - - public static CreateResponse Create(string buyOrder, string sessionId, - decimal amount, string returnUrl, Options options) - { - return Transaction.Create(buyOrder, sessionId, amount, returnUrl, options); - } - - public static CommitResponse Commit(string token) - { - return Commit(token, DefaultOptions()); - } - - public static CommitResponse Commit(string token, Options options) - { - return Transaction.Commit(token, options); - } - - public static RefundResponse Refund(string token, decimal amount) - { - return Refund(token, amount, DefaultOptions()); - } - - public static RefundResponse Refund(string token, decimal amount, Options options) - { - return Transaction.Refund(token, amount, options); - } - - public static StatusResponse Status(string token) - { - return Status(token, DefaultOptions()); - } - - public static StatusResponse Status(string token, Options options) - { - return Transaction.Status(token, options); - } - - public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, - decimal captureAmount, string commerceCode = null) - { - return Capture(token, buyOrder, authorizationCode, captureAmount, commerceCode, DefaultOptions()); - } - - public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, - decimal captureAmount) - { - return Capture(token, buyOrder, authorizationCode, captureAmount, null, DefaultOptions()); - } - - public static CaptureResponse Capture(string token, string buyOrder, string authorizationCode, - decimal captureAmount, string commerceCode, Options options) - { - return ExceptionHandler.Perform(() => - { - var captureRequest = new CaptureRequest(token, buyOrder, - authorizationCode, captureAmount, commerceCode); - var response = RequestService.Perform( - captureRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs deleted file mode 100644 index 597fa3b..0000000 --- a/Transbank/WebpayRest/WebpayPlus/MallDeferredTransaction.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; -using Transbank.Common; -using Transbank.Onepay.Exceptions; -using Transbank.Webpay.Common; -using Transbank.Webpay.WebpayPlus.Responses; -using Transbank.WebpayRest.WebpayPlus.Exceptions; -using Transbank.WebpayRest.WebpayPlus.Requests; -using Transbank.WebpayRest.WebpayPlus.Responses; - -namespace Transbank.Webpay.WebpayPlus -{ - public static class MallDeferredTransaction - { - private static string _commerceCode = "597055555544"; - private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - private static WebpayIntegrationType _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." - ); - } - - public static string CommerceCode - { - get => _commerceCode; - set => _commerceCode = value ?? throw new ArgumentNullException( - nameof(value), "Commerce code can't be null." - ); - } - - public static string ApiKey - { - get => _apiKey; - set => _apiKey = value ?? throw new ArgumentNullException( - nameof(value), "Api Key can't be null." - ); - } - - public static WebpayIntegrationType IntegrationType - { - get => _integrationType; - set => _integrationType = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null." - ); - } - - public static Options DefaultOptions() - { - return new Options(CommerceCode, ApiKey, IntegrationType, Headers); - } - - public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, - List transactions) - { - return Create(buyOrder, sessionId, returnUrl, transactions, DefaultOptions()); - } - - public static MallCreateResponse Create(string buyOrder, string sessionId, string returnUrl, - List transactions, Options options) - { - return MallTransaction.Create(buyOrder, sessionId, returnUrl, transactions, options); - } - - public static MallCommitResponse Commit(string token) - { - return Commit(token, DefaultOptions()); - } - - public static MallCommitResponse Commit(string token, Options options) - { - return MallTransaction.Commit(token, options); - } - - public static MallRefundResponse Refund(string token, string buyOrder, string commerceCode, decimal amount) - { - return Refund(token, buyOrder, commerceCode, amount, DefaultOptions()); - } - - public static MallRefundResponse Refund(string token, string buyOrder, string commerceCode, decimal amount, - Options options) - { - return MallTransaction.Refund(token, buyOrder, commerceCode, amount, options); - } - - public static MallStatusResponse Status(string token) - { - return Status(token, DefaultOptions()); - } - - public static MallStatusResponse Status(string token, Options options) - { - return MallTransaction.Status(token, options); - } - - public static MallCaptureResponse Capture(string token, string commerceCode, string buyOrder, - string authorizationCode, decimal amount) - { - return Capture(token, commerceCode, buyOrder, authorizationCode, amount, DefaultOptions()); - } - - public static MallCaptureResponse Capture(string token, string commerceCode, string buyOrder, - string authorizationCode, decimal amount, Options options) - { - return ExceptionHandler.Perform(() => - { - var mallCaptureRequest = new MallCaptureRequest(token, commerceCode, buyOrder, authorizationCode, amount); - var response = RequestService.Perform(mallCaptureRequest, options); - return JsonConvert.DeserializeObject(response); - }); - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs b/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs deleted file mode 100644 index efc953f..0000000 --- a/Transbank/WebpayRest/WebpayPlus/MallTransaction.cs +++ /dev/null @@ -1,133 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; -using Transbank.Common; -using Transbank.Webpay.Common; -using Transbank.Webpay.WebpayPlus.Exceptions; -using Transbank.Webpay.WebpayPlus.Requests; -using Transbank.Webpay.WebpayPlus.Responses; - -namespace Transbank.Webpay.WebpayPlus -{ - public static class MallTransaction - { - private static string _commerceCode = "597055555535"; - private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - private static WebpayIntegrationType _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." - ); - } - public static string CommerceCode - { - get => _commerceCode; - set => _commerceCode = value ?? throw new ArgumentNullException( - nameof(value), "Commerce code can't be null." - ); - } - - public static string ApiKey - { - get => _apiKey; - set => _apiKey = value ?? throw new ArgumentNullException( - nameof(value), "Api Key can't be null." - ); - } - - public static WebpayIntegrationType IntegrationType - { - get => _integrationType; - set => _integrationType = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null." - ); - } - - public static Options DefaultOptions() - { - return new Options(CommerceCode, ApiKey, IntegrationType, Headers); - } - - public static MallCreateResponse Create(string buyOrder, string sessionId, - string returnUrl, List transactions) - { - return Create(buyOrder, sessionId, returnUrl, transactions, DefaultOptions()); - } - - public static MallCreateResponse Create(string buyOrder, string sessionId, - string returnUrl, List transactions, Options options) - { - return ExceptionHandler.Perform(() => - { - var mallCreateRequest = new MallCreateRequest(buyOrder, sessionId, - returnUrl, transactions); - var response = RequestService.Perform( - mallCreateRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - - public static MallCommitResponse Commit(string token) - { - return Commit(token, DefaultOptions()); - } - - public static MallCommitResponse Commit(string token, Options options) - { - return ExceptionHandler.Perform(() => - { - var mallCommitRequest = new MallCommitRequest(token); - var response = RequestService.Perform( - mallCommitRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - - public static MallRefundResponse Refund(string token, string buyOrder, - string commerceCode, decimal amount) - { - return Refund(token, buyOrder, commerceCode, amount, DefaultOptions()); - } - - public static MallRefundResponse Refund(string token, string buyOrder, - string commerceCode, decimal amount, Options options) - { - return ExceptionHandler.Perform(() => - { - var mallRefundRequest = new MallRefundRequest(token, buyOrder, - commerceCode, amount); - var response = RequestService.Perform( - mallRefundRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - - public static MallStatusResponse Status(string token) - { - return Status(token, DefaultOptions()); - } - - public static MallStatusResponse Status(string token, Options options) - { - return ExceptionHandler.Perform(() => - { - var mallStatusRequest = new MallStatusRequest(token); - var response = RequestService.Perform( - mallStatusRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs deleted file mode 100644 index 6fe8c39..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Requests/CaptureRequest.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Net.Http; -using Newtonsoft.Json; -using Transbank.Common; - -namespace Transbank.Webpay.WebpayPlus.Requests -{ - internal class CaptureRequest : BaseRequest - { - [JsonProperty("buy_order")] - internal string BuyOrder { get; set; } - - [JsonProperty("authorization_code")] - internal string AuthorizationCode { get; set; } - - [JsonProperty("capture_amount")] - internal decimal CaptureAmount { get; set; } - - [JsonProperty("commerce_code", NullValueHandling = NullValueHandling.Ignore)] - internal string CommerceCode { get; set; } - - internal CaptureRequest(string token, string buyOrder, string authorizationCode, - decimal captureAmount, string commerceCode = null) : - base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/capture", HttpMethod.Put) - { - BuyOrder = buyOrder; - AuthorizationCode = authorizationCode; - CaptureAmount = captureAmount; - CommerceCode = commerceCode; - } - } -} - - diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs deleted file mode 100644 index bfc8720..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Requests/CommitRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Net.Http; -using Transbank.Common; - -namespace Transbank.Webpay.WebpayPlus.Requests -{ - internal class CommitRequest : BaseRequest - { - internal CommitRequest(string token) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) {} - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs deleted file mode 100644 index cf36f51..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Requests/CreateRequest.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Newtonsoft.Json; -using Transbank.Common; -using System.Net.Http; - -namespace Transbank.Webpay.WebpayPlus.Requests -{ - internal class CreateRequest : BaseRequest - { - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - - [JsonProperty("session_id")] - public string SessionId { get; set; } - - [JsonProperty("amount")] - public decimal Amount { get; set; } - - [JsonProperty("return_url")] - public string ReturnUrl { get; set; } - - public override string ToString() - { - return $"BuyOrder={BuyOrder}, SessionId={SessionId}, " + - $"Amount={Amount}, ReturnUrl={ReturnUrl}"; - } - - internal CreateRequest(string buyOrder, string sessionId, decimal amount, string returnUrl) - : base("/rswebpaytransaction/api/webpay/v1.0/transactions", HttpMethod.Post) - { - BuyOrder = buyOrder; - SessionId = sessionId; - Amount = amount; - ReturnUrl = returnUrl; - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallCaptureRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallCaptureRequest.cs deleted file mode 100644 index a66a8b3..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Requests/MallCaptureRequest.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Net.Http; -using Newtonsoft.Json; -using Transbank.Common; - -namespace Transbank.WebpayRest.WebpayPlus.Requests -{ - public class MallCaptureRequest : BaseRequest - { - [JsonProperty("commerce_code")] - private string CommerceCode { get; set; } - - [JsonProperty("buy_order")] - private string BuyOrder { get; set; } - - [JsonProperty("authorization_code")] - private string AuthorizationCode { get; set; } - - [JsonProperty("capture_amount")] - private decimal CaptureAmount { get; set; } - - public MallCaptureRequest(string token, string commerceCode, string buyOrder, string authorizationCode, - decimal captureAmount) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/capture", HttpMethod.Put) - { - CommerceCode = commerceCode; - BuyOrder = buyOrder; - AuthorizationCode = authorizationCode; - CaptureAmount = captureAmount; - } - - public override string ToString() - { - return - $"{nameof(CommerceCode)}: {CommerceCode}, {nameof(BuyOrder)}: {BuyOrder}, {nameof(AuthorizationCode)}: {AuthorizationCode}, {nameof(CaptureAmount)}: {CaptureAmount}"; - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs deleted file mode 100644 index e59f834..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Requests/MallCommitRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Net.Http; -using Transbank.Common; - -namespace Transbank.Webpay.WebpayPlus.Requests -{ - public class MallCommitRequest : BaseRequest - { - public MallCommitRequest(string token) : - base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) { } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs deleted file mode 100644 index fff1642..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Requests/MallCreateRequest.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections.Generic; -using System.Net.Http; -using Newtonsoft.Json; -using Transbank.Common; -using Transbank.Webpay.Common; - -namespace Transbank.Webpay.WebpayPlus.Requests -{ - internal class MallCreateRequest : BaseRequest - { - [JsonProperty("buy_order")] - internal string BuyOrder { get; set; } - [JsonProperty("session_id")] - internal string SessionId { get; set; } - [JsonProperty("return_url")] - internal string ReturnUrl { get; set; } - [JsonProperty("details", ItemReferenceLoopHandling = ReferenceLoopHandling.Serialize)] - internal List Transactions { get; set; } - - internal MallCreateRequest(string buyOrder, string sessionId, string returnUrl, - List transactions) : base( - "/rswebpaytransaction/api/webpay/v1.0/transactions", HttpMethod.Post) - { - BuyOrder = buyOrder; - SessionId = sessionId; - ReturnUrl = returnUrl; - Transactions = transactions; - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallRefundRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallRefundRequest.cs deleted file mode 100644 index 7c6f823..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Requests/MallRefundRequest.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using Newtonsoft.Json; - -namespace Transbank.Webpay.WebpayPlus.Requests -{ - internal class MallRefundRequest : RefundRequest - { - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - - [JsonProperty("commerce_code")] - public string CommerceCode { get; set; } - - internal MallRefundRequest( - string token, string buyOrder, string commerceCode, - decimal amount) : base(token, amount) - { - BuyOrder = buyOrder; - CommerceCode = commerceCode; - } - - public override string ToString() - { - return $"BuyOrder={BuyOrder}, CommerceCode={CommerceCode}, Amount={Amount}"; - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/MallStatusRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/MallStatusRequest.cs deleted file mode 100644 index b88bb46..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Requests/MallStatusRequest.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using Transbank.Webpay.Common; - -namespace Transbank.Webpay.WebpayPlus.Requests -{ - public class MallStatusRequest : StatusRequest - { - internal MallStatusRequest(string token) : base(token) { } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs deleted file mode 100644 index c5ee1d5..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Requests/RefundRequest.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using Transbank.Common; -using Newtonsoft.Json; -using System.Net.Http; - -namespace Transbank.Webpay.WebpayPlus.Requests -{ - internal class RefundRequest : BaseRequest - { - [JsonProperty("amount")] - public decimal Amount { get; set; } - - public override string ToString() - { - return $"Amount={Amount}"; - } - - internal RefundRequest(string token, decimal amount) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/refunds", HttpMethod.Post) - { - Amount = amount; - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs b/Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs deleted file mode 100644 index 501d66f..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Requests/StatusRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using Transbank.Common; -using System.Net.Http; - -namespace Transbank.Webpay.WebpayPlus.Requests -{ - public class StatusRequest : BaseRequest - { - internal StatusRequest(string token) - : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Get) { } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs deleted file mode 100644 index fe5ca95..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Responses/CaptureResponse.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using Newtonsoft.Json; -using Transbank.Webpay.Common; - -namespace Transbank.Webpay.WebpayPlus.Responses -{ - public class CaptureResponse - { - [JsonProperty("token")] - public string Token { get; set; } - [JsonProperty("authorization_code")] - public string AuthorizationCode { get; set; } - [JsonProperty("authorization_date")] - public DateTime AuthorizationDate { get; set; } - [JsonProperty("captured_amount")] - public decimal CapturedAmount { get; set; } - [JsonProperty("response_code")] - public int ResponseCode { get; set; } - - public override string ToString() - { - var properties = new List(); - foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) - { - string name = descriptor.Name; - object value = descriptor.GetValue(this); - properties.Add($"{name}={value}"); - } - return String.Join(", ", properties); - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/CommitResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/CommitResponse.cs deleted file mode 100644 index ef7bbe9..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Responses/CommitResponse.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using Newtonsoft.Json; -using Transbank.Webpay.Common; - -namespace Transbank.Webpay.WebpayPlus.Responses -{ - public class CommitResponse - { - [JsonProperty("vci")] - public string Vci { get; set; } - [JsonProperty("amount")] - public decimal Amount { get; set; } - [JsonProperty("status")] - public string Status { get; set; } - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - [JsonProperty("session_id")] - public string SessionId { get; set; } - [JsonProperty("card_detail")] - public CardDetail CardDetail { get; set; } - [JsonProperty("accounting_date")] - public string AccountingDate { get; set; } - [JsonProperty("transaction_date")] - public DateTime TransactionDate { get; set; } - [JsonProperty("authorization_code")] - public string AuthorizationCode { get; set; } - [JsonProperty("payment_type_code")] - public string PaymentTypeCode { get; set; } - [JsonProperty("response_code")] - public int ResponseCode { get; set; } - [JsonProperty("installments_amount")] - public int InstallmentsAmount { get; set; } - [JsonProperty("installments_number")] - public int InstallmentsNumber { get; set; } - [JsonProperty("balance")] - public decimal Balance { get; set; } - - public override string ToString() - { - var properties = new List(); - foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) - { - string name = descriptor.Name; - object value = descriptor.GetValue(this); - properties.Add($"{name}={value}"); - } - return String.Join(", ", properties); - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs deleted file mode 100644 index a3e1e38..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Responses/CreateResponse.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using Newtonsoft.Json; - -namespace Transbank.Webpay.WebpayPlus.Responses -{ - public class CreateResponse - { - [JsonProperty("token")] - public string Token { get; private set; } - [JsonProperty("url")] - public string Url { get; private set; } - - public override string ToString() - { - return $"Token={Token}, Url={Url}"; - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/MallCaptureResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/MallCaptureResponse.cs deleted file mode 100644 index 7be562f..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Responses/MallCaptureResponse.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Transbank.Webpay.WebpayPlus.Responses; - -namespace Transbank.WebpayRest.WebpayPlus.Responses -{ - public class MallCaptureResponse : CaptureResponse - { - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/MallCommitResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/MallCommitResponse.cs deleted file mode 100644 index fe1156e..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Responses/MallCommitResponse.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using Newtonsoft.Json; -using Transbank.Webpay.Common; - -namespace Transbank.Webpay.WebpayPlus.Responses -{ - public class MallCommitResponse - { - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - [JsonProperty("session_id")] - public string SessionId { get; set; } - [JsonProperty("vci")] - public string Vci { get; set; } - [JsonProperty("card_detail")] - public CardDetail CardDetail { get; set; } - [JsonProperty("accounting_date")] - public string AccountingDate { get; set; } - [JsonProperty("transaction_date")] - public DateTime TransactionDate { get; set; } - [JsonProperty("details")] - public List Details { get; set; } - - public override string ToString() - { - var properties = new List(); - foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) - { - string name = descriptor.Name; - object value = null; - System.Diagnostics.Debug.WriteLine($"{name}={value}"); - if (name == "Details") - { - value = string.Join(", ", (List)descriptor.GetValue(this)); - value = $" {{{value}}} "; - } else - { - value = descriptor.GetValue(this); - } - properties.Add($"{name}={value}"); - } - return String.Join(", ", properties); - } - - public class Detail - { - [JsonProperty("buy_order")] - public string BuyOrder { get; set; } - [JsonProperty("commerce_code")] - public string CommerceCode { get; set; } - [JsonProperty("amount")] - public decimal Amount { get; set; } - [JsonProperty("status")] - public string Status { get; set; } - [JsonProperty("authorization_code")] - public string AuthorizationCode { get; set; } - [JsonProperty("payment_type_code")] - public string PaymentTypeCode { get; set; } - [JsonProperty("response_code")] - public int ResponseCode { get; set; } - [JsonProperty("installments_number")] - public int InstallmentsNumber { get; set; } - - public override string ToString() - { - var properties = new List(); - foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) - { - string name = descriptor.Name; - object value = descriptor.GetValue(this); - properties.Add($"{name}={value}"); - } - return String.Join(", ", properties); - } - } - } - -} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/MallCreateResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/MallCreateResponse.cs deleted file mode 100644 index 9e51d70..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Responses/MallCreateResponse.cs +++ /dev/null @@ -1,5 +0,0 @@ -using System; -namespace Transbank.Webpay.WebpayPlus.Responses -{ - public class MallCreateResponse : CreateResponse {} -} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/MallRefundResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/MallRefundResponse.cs deleted file mode 100644 index 7513620..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Responses/MallRefundResponse.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; -using Newtonsoft.Json; - -namespace Transbank.Webpay.WebpayPlus.Responses -{ - public class MallRefundResponse : RefundResponse - { - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/MallStatusResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/MallStatusResponse.cs deleted file mode 100644 index 48f75e0..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Responses/MallStatusResponse.cs +++ /dev/null @@ -1,5 +0,0 @@ -using System; -namespace Transbank.Webpay.WebpayPlus.Responses -{ - public class MallStatusResponse : MallCommitResponse { } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/RefundResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/RefundResponse.cs deleted file mode 100644 index b6a1245..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Responses/RefundResponse.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using Newtonsoft.Json; - -namespace Transbank.Webpay.WebpayPlus.Responses -{ - public class RefundResponse - { - [JsonProperty("type")] - public string Type { get; set; } - [JsonProperty("authorization_code")] - public string AuthorizationCode { get; set; } - [JsonProperty("authorization_date")] - public DateTime AuthorizationDate { get; set; } - [JsonProperty("nullified_amount")] - public decimal NullifiedAmount { get; set; } - [JsonProperty("balance")] - public decimal Balance { get; set; } - [JsonProperty("response_code")] - public int ResponseCode { get; set; } - - public override string ToString() - { - var properties = new List(); - foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this)) - { - string name = descriptor.Name; - object value = descriptor.GetValue(this); - properties.Add($"{name}={value}"); - } - return String.Join(", ", properties); - } - } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Responses/StatusResponse.cs b/Transbank/WebpayRest/WebpayPlus/Responses/StatusResponse.cs deleted file mode 100644 index 59b8958..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Responses/StatusResponse.cs +++ /dev/null @@ -1,5 +0,0 @@ -using System; -namespace Transbank.Webpay.WebpayPlus.Responses -{ - public class StatusResponse : CommitResponse { } -} diff --git a/Transbank/WebpayRest/WebpayPlus/Transaction.cs b/Transbank/WebpayRest/WebpayPlus/Transaction.cs deleted file mode 100644 index 0784550..0000000 --- a/Transbank/WebpayRest/WebpayPlus/Transaction.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using Transbank.Common; -using Transbank.Exceptions; -using Transbank.Webpay.WebpayPlus.Requests; -using Transbank.Webpay.Common; -using Transbank.Webpay.WebpayPlus.Responses; -using Newtonsoft.Json; -using Transbank.Webpay.WebpayPlus.Exceptions; - -namespace Transbank.Webpay.WebpayPlus -{ - public static class Transaction - { - private static string _commerceCode = "597055555532"; - private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - private static WebpayIntegrationType _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." - ); - } - public static string CommerceCode - { - get => _commerceCode; - set => _commerceCode = value ?? throw new ArgumentNullException( - nameof(value), "Commerce code can't be null." - ); - } - - public static string ApiKey - { - get => _apiKey; - set => _apiKey = value ?? throw new ArgumentNullException( - nameof(value), "Api Key can't be null." - ); - } - - public static WebpayIntegrationType IntegrationType - { - get => _integrationType; - set => _integrationType = value ?? throw new ArgumentNullException( - nameof(value), "Integration type can't be null." - ); - } - - public static Options DefaultOptions() - { - return new Options(CommerceCode, ApiKey, IntegrationType, Headers); - } - - public static CreateResponse Create(string buyOrder, string sessionId, - decimal amount, string returnUrl) - { - return Create(buyOrder, sessionId, amount, returnUrl, DefaultOptions()); - } - - public static CreateResponse Create(string buyOrder, string sessionId, - decimal amount, string returnUrl, Options options) - { - return ExceptionHandler.Perform(() => - { - var createRequest = new CreateRequest(buyOrder, sessionId, amount, returnUrl); - var response = RequestService.Perform( - createRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - - public static CommitResponse Commit(string token) - { - return Commit(token, DefaultOptions()); - } - - public static CommitResponse Commit(string token, Options options) - { - return ExceptionHandler.Perform(() => - { - var commitRequest = new CommitRequest(token); - var response = RequestService.Perform( - commitRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - - public static RefundResponse Refund(string token, decimal amount) - { - return Refund(token, amount, DefaultOptions()); - } - - public static RefundResponse Refund(string token, decimal amount, Options options) - { - return ExceptionHandler.Perform(() => - { - var refundRequest = new RefundRequest(token, amount); - var response = RequestService.Perform( - refundRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - - public static StatusResponse Status(string token) - { - return Status(token, DefaultOptions()); - } - - public static StatusResponse Status(string token, Options options) - { - return ExceptionHandler.Perform(() => - { - var statusRequest = new StatusRequest(token); - var response = RequestService.Perform( - statusRequest, options); - - return JsonConvert.DeserializeObject(response); - }); - } - } -} 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 116/120] 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 117/120] 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 118/120] 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 119/120] 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 120/120] 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"; } } }