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/Common/BaseRequest.cs b/Transbank/Common/BaseRequest.cs new file mode 100644 index 0000000..71e8d97 --- /dev/null +++ b/Transbank/Common/BaseRequest.cs @@ -0,0 +1,30 @@ +using System; +using System.Net.Http; +using Newtonsoft.Json; + +namespace Transbank.Common +{ + public abstract class BaseRequest + { + [JsonIgnore] + 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, 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/Common/ExceptionHandler.cs b/Transbank/Common/ExceptionHandler.cs new file mode 100644 index 0000000..e7f3007 --- /dev/null +++ b/Transbank/Common/ExceptionHandler.cs @@ -0,0 +1,47 @@ +using System; +using Transbank.Exceptions; + +namespace Transbank.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 }); + } + } +} 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/Common/Options.cs b/Transbank/Common/Options.cs new file mode 100644 index 0000000..9a00810 --- /dev/null +++ b/Transbank/Common/Options.cs @@ -0,0 +1,62 @@ +using System; +using Newtonsoft.Json; + +namespace Transbank.Common +{ + 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 + { + 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 IIntegrationType IntegrationType + { + get => _integrationType; + set => _integrationType = value ?? throw new ArgumentNullException( + nameof(value), "IntegrationType can't be null." + ); + } + + public Options(string commerceCode, string apiKey, IIntegrationType integrationType, RequestServiceHeaders headers) + { + CommerceCode = commerceCode; + ApiKey = apiKey; + IntegrationType = integrationType; + Headers = headers; + } + + public override string ToString() + { + return $"{nameof(CommerceCode)}: {CommerceCode}, {nameof(ApiKey)}: {ApiKey}, {nameof(IntegrationType)}: {IntegrationType}"; + } + } +} diff --git a/Transbank/Common/RequestService.cs b/Transbank/Common/RequestService.cs new file mode 100644 index 0000000..91966d7 --- /dev/null +++ b/Transbank/Common/RequestService.cs @@ -0,0 +1,48 @@ +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 static class RequestService + { + private static readonly string CONTENT_TYPE = "application/json"; + + 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(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/Exceptions/InscriptionDeleteException.cs b/Transbank/Exceptions/InscriptionDeleteException.cs new file mode 100644 index 0000000..f3d23c5 --- /dev/null +++ b/Transbank/Exceptions/InscriptionDeleteException.cs @@ -0,0 +1,26 @@ +using System; + +namespace Transbank.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/Exceptions/InscriptionFinishException.cs b/Transbank/Exceptions/InscriptionFinishException.cs new file mode 100644 index 0000000..fbd135e --- /dev/null +++ b/Transbank/Exceptions/InscriptionFinishException.cs @@ -0,0 +1,26 @@ +using System; + +namespace Transbank.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/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/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/Exceptions/MallTransactionAuthorizeException.cs b/Transbank/Exceptions/MallTransactionAuthorizeException.cs new file mode 100644 index 0000000..8ed7640 --- /dev/null +++ b/Transbank/Exceptions/MallTransactionAuthorizeException.cs @@ -0,0 +1,15 @@ +using System; + +namespace Transbank.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/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/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/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/Exceptions/TransactionCommitException.cs b/Transbank/Exceptions/TransactionCommitException.cs new file mode 100644 index 0000000..6024aa4 --- /dev/null +++ b/Transbank/Exceptions/TransactionCommitException.cs @@ -0,0 +1,14 @@ +using System; + +namespace Transbank.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/Exceptions/TransactionCreateException.cs b/Transbank/Exceptions/TransactionCreateException.cs new file mode 100644 index 0000000..c4bb74c --- /dev/null +++ b/Transbank/Exceptions/TransactionCreateException.cs @@ -0,0 +1,14 @@ +using System; + +namespace Transbank.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/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/Exceptions/TransactionRefundException.cs b/Transbank/Exceptions/TransactionRefundException.cs new file mode 100644 index 0000000..76a5dbe --- /dev/null +++ b/Transbank/Exceptions/TransactionRefundException.cs @@ -0,0 +1,14 @@ +using System; + +namespace Transbank.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/Exceptions/TransactionStatusException.cs b/Transbank/Exceptions/TransactionStatusException.cs new file mode 100644 index 0000000..bb01a41 --- /dev/null +++ b/Transbank/Exceptions/TransactionStatusException.cs @@ -0,0 +1,14 @@ +using System; + +namespace Transbank.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/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..d07d3c7 100644 --- a/Transbank/Onepay/Exceptions/AmountException.cs +++ b/Transbank/Onepay/Exceptions/AmountException.cs @@ -1,6 +1,5 @@ using System; - namespace Transbank.Onepay.Exceptions { public class AmountException : TransbankException diff --git a/Transbank/Transbank.csproj b/Transbank/Transbank.csproj index bbd7090..2281837 100644 --- a/Transbank/Transbank.csproj +++ b/Transbank/Transbank.csproj @@ -1,4 +1,4 @@ - + net452 @@ -115,16 +115,10 @@ - - - - - - - - - - + + + + @@ -142,4 +136,14 @@ + + + + + + + + + + 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}"; + } + } +} 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..7248a9e --- /dev/null +++ b/Transbank/WebpayRest/Common/PaymentRequest.cs @@ -0,0 +1,35 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.Common +{ + public class PaymentRequest + { + [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; } + + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; private set; } + + public PaymentRequest (string commerceCode, string buyOrder, decimal amount, int installmentsNumber) + { + CommerceCode = commerceCode; + BuyOrder = buyOrder; + Amount = amount; + InstallmentsNumber = installmentsNumber; + } + + public override string ToString() + { + return $"Commerce Code= {CommerceCode}\n" + + $"Buy Order= {BuyOrder}\n" + + $"Amount= {Amount}\n" + + $"InstallmentsNumber= {InstallmentsNumber}"; + } + } +} diff --git a/Transbank/WebpayRest/Common/PaymentResponse.cs b/Transbank/WebpayRest/Common/PaymentResponse.cs new file mode 100644 index 0000000..2bab04e --- /dev/null +++ b/Transbank/WebpayRest/Common/PaymentResponse.cs @@ -0,0 +1,57 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.Common +{ + public class PaymentResponse + { + [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_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 commerceCode, string buyOrder, int amount, int authorizationCode, + string paymentTypeCode, int responseCode, int installmentsAmount, string status) + { + AuthorizationCode = authorizationCode; + PaymentTypeCode = paymentTypeCode; + ResponseCode = responseCode; + InstallmentsNumber = installmentsAmount; + Status = status; + CommerceCode = commerceCode; + BuyOrder = buyOrder; + Amount = amount; + } + + public override string ToString() + { + return base.ToString() + "\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/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/Common/WebpayIntegrationType.cs b/Transbank/WebpayRest/Common/WebpayIntegrationType.cs new file mode 100644 index 0000000..afb5c1e --- /dev/null +++ b/Transbank/WebpayRest/Common/WebpayIntegrationType.cs @@ -0,0 +1,22 @@ +using System; +using Transbank.Common; + +namespace Transbank.Webpay.Common +{ + public class WebpayIntegrationType : IIntegrationType + { + 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/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/Inscription.cs b/Transbank/WebpayRest/Oneclick/Inscription.cs new file mode 100644 index 0000000..dbd3532 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Inscription.cs @@ -0,0 +1,60 @@ +using System; +using Newtonsoft.Json; +using Transbank.Common; +using Transbank.Exceptions; +using Transbank.Webpay.Oneclick.Requests; +using Transbank.Webpay.Oneclick.Responses; + +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) + { + return ExceptionHandler.Perform(() => + { + 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) + { + return ExceptionHandler.Perform(() => + { + var finishRequest = new FinishRequest(token); + var response = RequestService.Perform(finishRequest, options); + + return JsonConvert.DeserializeObject(response); + }); + } + + public static void Delete(string userName, string tbkUser) + { + Delete(userName, tbkUser, Oneclick.DefaultOptions()); + } + + public static void Delete(string userName, string tbkUser, Options options) + { + ExceptionHandler.Perform(() => + { + var deleteRequest = new DeleteRequest(userName, tbkUser); + RequestService.Perform(deleteRequest, options); + }); + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/MallTransaction.cs b/Transbank/WebpayRest/Oneclick/MallTransaction.cs new file mode 100644 index 0000000..a74e90d --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/MallTransaction.cs @@ -0,0 +1,116 @@ +using System; +using Newtonsoft.Json; +using System.Collections.Generic; +using Transbank.Common; +using Transbank.Webpay.Common; +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 +{ + 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; + + 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 MallAuthorizeResponse Authorize(string userName, string tbkUser, + string buyOrder, List details) + { + return Authorize(userName, tbkUser, buyOrder, details, DefaultOptions()); + } + + public static MallAuthorizeResponse Authorize(string userName, string tbkUser, string buyOrder, + List details, Options options) + { + return ExceptionHandler.Perform(() => + { + var authorizeRequest = new MallAuthorizeRequest(userName, tbkUser, buyOrder, + details); + var response = RequestService.Perform(authorizeRequest, options); + + 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/Oneclick.cs b/Transbank/WebpayRest/Oneclick/Oneclick.cs new file mode 100644 index 0000000..4930677 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Oneclick.cs @@ -0,0 +1,57 @@ +using System; +using System.Runtime.Remoting.Messaging; +using Transbank.Common; +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 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; + + 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); + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs new file mode 100644 index 0000000..fb89a11 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Requests/DeleteRequest.cs @@ -0,0 +1,22 @@ +using System.Net.Http; +using Newtonsoft.Json; +using Transbank.Common; + +namespace Transbank.Webpay.Oneclick.Requests +{ + internal class DeleteRequest : BaseRequest + { + [JsonProperty("username")] + internal string UserName { get; set; } + + [JsonProperty("tbk_user")] + internal string TbkUser { get; set; } + + internal DeleteRequest(string userName, string tbkUser) + : base("/rswebpaytransaction/api/oneclick/v1.0/inscriptions", HttpMethod.Delete) + { + UserName = userName; + TbkUser = tbkUser; + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Requests/FinishRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/FinishRequest.cs new file mode 100644 index 0000000..dc9243b --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Requests/FinishRequest.cs @@ -0,0 +1,12 @@ +using System.Net.Http; +using Transbank.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/Requests/MallAuthorizeRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/MallAuthorizeRequest.cs new file mode 100644 index 0000000..7437a90 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Requests/MallAuthorizeRequest.cs @@ -0,0 +1,32 @@ +using System.Net.Http; +using System.Collections.Generic; +using Newtonsoft.Json; +using Transbank.Common; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.Oneclick.Requests +{ + internal class MallAuthorizeRequest : BaseRequest + { + [JsonProperty("username")] + internal string UserName { get; set; } + + [JsonProperty("tbk_user")] + internal string TbkUser { get; set; } + + [JsonProperty("buy_order")] + internal string BuyOrder { get; set; } + + [JsonProperty("details")] + internal List Details { get; set; } + + internal MallAuthorizeRequest(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/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/Requests/StartRequest.cs b/Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs new file mode 100644 index 0000000..42e747e --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Requests/StartRequest.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; +using System.Net.Http; +using Transbank.Common; + +namespace Transbank.Webpay.Oneclick.Requests +{ + internal class StartRequest : BaseRequest + { + [JsonProperty("username")] + internal string UserName { get; set; } + + [JsonProperty("email")] + internal string Email { get; set; } + + [JsonProperty("response_url")] + internal string ResponseUrl { get; set; } + + 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/Responses/DeleteResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/DeleteResponse.cs new file mode 100644 index 0000000..5d2aa64 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Responses/DeleteResponse.cs @@ -0,0 +1,5 @@ + +namespace Transbank.Webpay.Oneclick.Responses +{ + public class DeleteResponse{} +} diff --git a/Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/FinishResponse.cs new file mode 100644 index 0000000..2013cb6 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Responses/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 TbkUser { get; private set; } + [JsonProperty("authorization_code")] + public string AuthorizationCode { 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 cardType, string cardNumber) + { + ResponseCode = responseCode; + TbkUser = transbankUser; + AuthorizationCode = authorizationCode; + CardType = cardType; + CardNumber = cardNumber; + } + + public override string ToString() + { + 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 new file mode 100644 index 0000000..1b9ec34 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Responses/MallAuthorizeResponse.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; +using Transbank.Webpay.Common; + +namespace Transbank.Webpay.Oneclick.Responses +{ + public class MallAuthorizeResponse + { + [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 string AccountingDate { get; private set; } + + [JsonProperty("transaction_date")] + public DateTime TransactionDate { get; private set; } + + [JsonProperty("details")] + public List Details{get; private set; } + + public MallAuthorizeResponse(string buyOrder, string sessionId, string cardNumber, DateTime expirationDate, + string accountingDate, DateTime transactionDate, List 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()}\""; + } + } +} diff --git a/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs new file mode 100644 index 0000000..97331f8 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Responses/MallRefundResponse.cs @@ -0,0 +1,44 @@ +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; + } + public override string ToString() + { + 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 new file mode 100644 index 0000000..5fb43b8 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Responses/MallStatusResponse.cs @@ -0,0 +1,80 @@ +using System.Collections.Generic; +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; } + + [JsonProperty("details")] + public List Details { get; private set; } + + public MallStatusResponse(string buyOrder, CardDetail cardDetail, string accountingDate, string transactionDate) + { + BuyOrder = buyOrder; + CardDetail = cardDetail; + AccountingDate = accountingDate; + TransactionDate = transactionDate; + } + + public override string ToString() + { + return $"\"BuyOrder\": \"{BuyOrder}\"\n" + + $"\"AccountingDate\": \"{AccountingDate}\"\n" + + $"\"TransactionDate\": \"{TransactionDate}\"\n" + + $"\"Details\": \"{Details.ToString()}\""; + } + + 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 diff --git a/Transbank/WebpayRest/Oneclick/Responses/StartResponse.cs b/Transbank/WebpayRest/Oneclick/Responses/StartResponse.cs new file mode 100644 index 0000000..68c6710 --- /dev/null +++ b/Transbank/WebpayRest/Oneclick/Responses/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}\"\n\"Url\": \"{Url}\""; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Common/CardDetail.cs b/Transbank/WebpayRest/TransaccionCompleta/Common/CardDetail.cs new file mode 100644 index 0000000..65ea471 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Common/CardDetail.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompleta.Common +{ + public class CardDetail + { + [JsonProperty("card_number")] + internal string CardNumber { get; } + + 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 new file mode 100644 index 0000000..e721d1f --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Common/DeferredPeriods.cs @@ -0,0 +1,25 @@ +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; + } + + 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 new file mode 100644 index 0000000..5a75b10 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Common/Detail.cs @@ -0,0 +1,33 @@ +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; + } + + public override string ToString() + { + return $"Amount={Amount}\n" + + $"CommerceCode={CommerceCode}\n" + + $"BuyOrder={BuyOrder}"; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs new file mode 100644 index 0000000..48b1d63 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/FullTransaction.cs @@ -0,0 +1,192 @@ +using System; +using Newtonsoft.Json; +using Transbank.Common; +using Transbank.Exceptions; +using Transbank.Webpay.Common; +using Transbank.Webpay.TransaccionCompleta.Requests; +using Transbank.Webpay.TransaccionCompleta.Responses; + +namespace Transbank.Webpay.TransaccionCompleta +{ + public static class FullTransaction + { + private static string _commerceCode = "597055555530"; + 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, + 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) + { + return ExceptionHandler.Perform(() => + { + var createRequest = new CreateRequest( + buyOrder, + sessionId, + amount, + cvv, + cardNumber, + cardExpirationDate); + var response = RequestService.Perform(createRequest, options); + + return JsonConvert.DeserializeObject(response); + + }); + + } + + public static InstallmentsResponse Installments( + string token, + int installmentsNumber) + { + return Installments(token, installmentsNumber, DefaultOptions()); + } + + public static InstallmentsResponse Installments( + string token, + int installmentsNumber, + Options options) + { + return ExceptionHandler.Perform(() => + { + var installmentsRequest = new InstallmentsRequest( + token, + installmentsNumber); + var response = RequestService.Perform(installmentsRequest, options); + + 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); + 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 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/CommitRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/CommitRequest.cs new file mode 100644 index 0000000..ff501b9 --- /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) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}", HttpMethod.Put) + { + IdQueryInstallments = idQueryInstallments; + DeferredPeriodIndex = deferredPeriodIndex; + GracePeriod = gracePeriod; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/CreateRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/CreateRequest.cs new file mode 100644 index 0000000..12002c5 --- /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 +{ + internal 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/Requests/InstallmentsRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs new file mode 100644 index 0000000..4bcdc84 --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/InstallmentsRequest.cs @@ -0,0 +1,25 @@ +using System.Net.Http; +using Newtonsoft.Json; +using Transbank.Common; + +namespace Transbank.Webpay.TransaccionCompleta.Requests +{ + internal class InstallmentsRequest : BaseRequest + { + [JsonProperty("installments_number")] + public int InstallmentsNumber { get; set; } + + internal InstallmentsRequest( + string token, + int installmentsNumber) + : base($"/rswebpaytransaction/api/webpay/v1.0/transactions/{token}/installments", HttpMethod.Post) + { + InstallmentsNumber = installmentsNumber; + } + + public override string ToString() + { + return $"Installments Number={InstallmentsNumber}"; + } + } +} diff --git a/Transbank/WebpayRest/TransaccionCompleta/Requests/RefundRequest.cs b/Transbank/WebpayRest/TransaccionCompleta/Requests/RefundRequest.cs new file mode 100644 index 0000000..966853e --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Requests/RefundRequest.cs @@ -0,0 +1,17 @@ +using System.Net.Http; +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/CommitResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs new file mode 100644 index 0000000..241ca7c --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/CommitResponse.cs @@ -0,0 +1,76 @@ +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 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" + + $"\"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 new file mode 100644 index 0000000..c07dd8a --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/CreateResponse.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; + +namespace Transbank.Webpay.TransaccionCompleta.Responses +{ + 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/InstallmentsResponse.cs b/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs new file mode 100644 index 0000000..b804a1a --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/InstallmentsResponse.cs @@ -0,0 +1,32 @@ +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; + } + + 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 new file mode 100644 index 0000000..66c382c --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/RefundResponse.cs @@ -0,0 +1,46 @@ +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; + } + + 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 new file mode 100644 index 0000000..7a3f07f --- /dev/null +++ b/Transbank/WebpayRest/TransaccionCompleta/Responses/StatusResponse.cs @@ -0,0 +1,76 @@ +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; + } + + 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"; + } + } +} 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/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/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 diff --git a/TransbankTest/TransbankTest.csproj b/TransbankTest/TransbankTest.csproj index 71047dd..f60b4c9 100644 --- a/TransbankTest/TransbankTest.csproj +++ b/TransbankTest/TransbankTest.csproj @@ -18,4 +18,7 @@ + + +