Skip to content

Commit

Permalink
Merge pull request #127 from TransbankDevelopers/feat/add-oneclick-ma…
Browse files Browse the repository at this point in the history
…ll-deferred-capture

Add Oneclick Deferred Capture
  • Loading branch information
afiebig authored Dec 17, 2020
2 parents 4ae46d2 + 318976c commit d3227ef
Show file tree
Hide file tree
Showing 22 changed files with 518 additions and 121 deletions.
14 changes: 14 additions & 0 deletions Transbank/Exceptions/MallCaptureException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Transbank.Exceptions
{
public class MallCaptureException : TransbankException
{
public MallCaptureException(string message) : base(-1, message) { }

public MallCaptureException(int code, string message) : base(code, message) { }

public MallCaptureException(int code, string message, Exception innerException)
: base(code, message, innerException) { }
}
}
33 changes: 7 additions & 26 deletions Transbank/WebpayRest/Oneclick/Inscription.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,41 @@
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
{
[Obsolete("Use MallInscription instead", false)]
public static class Inscription
{
public static StartResponse Start(string userName, string email, string responseUrl)
{
return Start(userName, email, responseUrl, Oneclick.DefaultOptions());
return (StartResponse)MallInscription.Start(userName, email, responseUrl);
}

public static StartResponse Start(string userName, string email,
string responseUrl, Options options)
{
return ExceptionHandler.Perform<StartResponse, InscriptionStartException>(() =>
{
var startRequest = new StartRequest(userName, email, responseUrl);
var response = RequestService.Perform<InscriptionStartException>(
startRequest, options);

return JsonConvert.DeserializeObject<StartResponse>(response);
});
return (StartResponse)MallInscription.Start(userName, email, responseUrl, options);
}

public static FinishResponse Finish(string token)
{
return Finish(token, Oneclick.DefaultOptions());
return (FinishResponse)MallInscription.Finish(token);
}

public static FinishResponse Finish(string token, Options options)
{
return ExceptionHandler.Perform<FinishResponse, InscriptionFinishException>(() =>
{
var finishRequest = new FinishRequest(token);
var response = RequestService.Perform<InscriptionFinishException>(finishRequest, options);

return JsonConvert.DeserializeObject<FinishResponse>(response);
});
return (FinishResponse)MallInscription.Finish(token, options);
}

public static void Delete(string userName, string tbkUser)
{
Delete(userName, tbkUser, Oneclick.DefaultOptions());
MallInscription.Delete(userName, tbkUser);
}

public static void Delete(string userName, string tbkUser, Options options)
{
ExceptionHandler.Perform<InscriptionDeleteException>(() =>
{
var deleteRequest = new DeleteRequest(userName, tbkUser);
RequestService.Perform<InscriptionDeleteException>(deleteRequest, options);
});
MallInscription.Delete(userName, tbkUser, options);
}
}
}
69 changes: 69 additions & 0 deletions Transbank/WebpayRest/Oneclick/MallDeferredInscription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Transbank.Common;
using Transbank.Webpay.Common;
using Transbank.Webpay.Oneclick.Responses;

namespace Transbank.Webpay.Oneclick
{
public static class MallDeferredInscription
{
public static RequestServiceHeaders Headers
{
get => MallDeferredTransaction.Headers;
set => MallDeferredTransaction.Headers = value;
}

public static string CommerceCode
{
get => MallDeferredTransaction.CommerceCode;
set => MallDeferredTransaction.CommerceCode = value;
}

public static string ApiKey
{
get => MallDeferredTransaction.ApiKey;
set => MallDeferredTransaction.ApiKey = value;
}

public static WebpayIntegrationType IntegrationType
{
get => MallDeferredTransaction.IntegrationType;
set => MallDeferredTransaction.IntegrationType = value;
}

public static Options DefaultOptions()
{
return new Options(CommerceCode, ApiKey, IntegrationType, Headers);
}

public static MallStartResponse Start(string userName, string email, string responseUrl)
{
return MallInscription.Start(userName, email, responseUrl, DefaultOptions());
}

public static MallStartResponse Start(string userName, string email,
string responseUrl, Options options)
{
return MallInscription.Start(userName, email, responseUrl, options);
}

public static MallFinishResponse Finish(string token)
{
return MallInscription.Finish(token, DefaultOptions());
}

public static MallFinishResponse Finish(string token, Options options)
{
return MallInscription.Finish(token, options);
}

public static void Delete(string userName, string tbkUser)
{
MallInscription.Delete(userName, tbkUser, DefaultOptions());
}

public static void Delete(string userName, string tbkUser, Options options)
{
MallInscription.Delete(userName, tbkUser, options);
}
}
}
112 changes: 112 additions & 0 deletions Transbank/WebpayRest/Oneclick/MallDeferredTransaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using Newtonsoft.Json;
using Transbank.Common;
using Transbank.Exceptions;
using Transbank.Webpay.Common;
using System.Collections.Generic;
using Transbank.Webpay.Oneclick.Responses;
using Transbank.WebpayRest.Oneclick.Requests;
using Transbank.WebpayRest.Oneclick.Responses;

namespace Transbank.Webpay.Oneclick
{
public static class MallDeferredTransaction
{
private static string _commerceCode = "597055555547";
private static string _apiKey = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C";

private static WebpayIntegrationType _integrationType = WebpayIntegrationType.Test;

private static readonly string _commerceCodeHeaderName = "Tbk-Api-Key-Id";
private static readonly 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<PaymentRequest> details)
{
return MallTransaction.Authorize(userName, tbkUser, buyOrder, details, DefaultOptions());
}

public static MallAuthorizeResponse Authorize(string userName, string tbkUser, string buyOrder,
List<PaymentRequest> details, Options options)
{
return MallTransaction.Authorize(userName, tbkUser, buyOrder, details, options);
}

public static MallRefundResponse Refund(string buyOrder, string childCommerceCode, string childBuyOrder,
decimal amount)
{
return MallTransaction.Refund(buyOrder, childCommerceCode, childBuyOrder, amount, DefaultOptions());
}

public static MallRefundResponse Refund(string buyOrder, string childCommerceCode, string childBuyOrder,
decimal amount, Options options)
{
return MallTransaction.Refund(buyOrder, childCommerceCode, childBuyOrder, amount, options);
}

public static MallStatusResponse Status(string buyOrder)
{
return MallTransaction.Status(buyOrder, DefaultOptions());
}

public static MallStatusResponse Status(string buyOrder, Options options)
{
return MallTransaction.Status(buyOrder, options);
}

public static MallCaptureResponse Capture(string commerceCode, string buyOrder, decimal amount, string authorizationCode)
{
return Capture(commerceCode, buyOrder, amount, authorizationCode, DefaultOptions());
}

public static MallCaptureResponse Capture(string commerceCode, string buyOrder, decimal amount, string authorizationCode, Options options)
{
return ExceptionHandler.Perform<MallCaptureResponse, MallCaptureException>(() =>
{
long.TryParse(commerceCode, out long ccode);
var mallCaptureRequest = new MallCaptureRequest(ccode, buyOrder, amount, authorizationCode);
var response = RequestService.Perform<MallCaptureException>(mallCaptureRequest, options);
return JsonConvert.DeserializeObject<MallCaptureResponse>(response);
});
}
}
}
90 changes: 90 additions & 0 deletions Transbank/WebpayRest/Oneclick/MallInscription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using Newtonsoft.Json;
using Transbank.Common;
using Transbank.Exceptions;
using Transbank.Webpay.Common;
using Transbank.Webpay.Oneclick.Requests;
using Transbank.Webpay.Oneclick.Responses;

namespace Transbank.Webpay.Oneclick
{
public static class MallInscription
{
public static RequestServiceHeaders Headers
{
get => MallTransaction.Headers;
set => MallTransaction.Headers = value;
}

public static string CommerceCode
{
get => MallTransaction.CommerceCode;
set => MallTransaction.CommerceCode = value;
}

public static string ApiKey
{
get => MallTransaction.ApiKey;
set => MallTransaction.ApiKey = value;
}

public static WebpayIntegrationType IntegrationType
{
get => MallTransaction.IntegrationType;
set => MallTransaction.IntegrationType = value;
}

public static Options DefaultOptions()
{
return new Options(CommerceCode, ApiKey, IntegrationType, Headers);
}

public static MallStartResponse Start(string userName, string email, string responseUrl)
{
return Start(userName, email, responseUrl, DefaultOptions());
}

public static MallStartResponse Start(string userName, string email,
string responseUrl, Options options)
{
return ExceptionHandler.Perform<MallStartResponse, InscriptionStartException>(() =>
{
var startRequest = new MallStartRequest(userName, email, responseUrl);
var response = RequestService.Perform<InscriptionStartException>(
startRequest, options);

return JsonConvert.DeserializeObject<MallStartResponse>(response);
});
}

public static MallFinishResponse Finish(string token)
{
return Finish(token, DefaultOptions());
}

public static MallFinishResponse Finish(string token, Options options)
{
return ExceptionHandler.Perform<MallFinishResponse, InscriptionFinishException>(() =>
{
var finishRequest = new MallFinishRequest(token);
var response = RequestService.Perform<InscriptionFinishException>(finishRequest, options);

return JsonConvert.DeserializeObject<MallFinishResponse>(response);
});
}

public static void Delete(string userName, string tbkUser)
{
Delete(userName, tbkUser, DefaultOptions());
}

public static void Delete(string userName, string tbkUser, Options options)
{
ExceptionHandler.Perform<InscriptionDeleteException>(() =>
{
var deleteRequest = new MallDeleteRequest(userName, tbkUser);
RequestService.Perform<InscriptionDeleteException>(deleteRequest, options);
});
}
}
}
5 changes: 2 additions & 3 deletions Transbank/WebpayRest/Oneclick/MallTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ 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 readonly string _commerceCodeHeaderName = "Tbk-Api-Key-Id";
private static readonly string _apiKeyHeaderName = "Tbk-Api-Key-Secret";

private static RequestServiceHeaders _headers = new RequestServiceHeaders(_apiKeyHeaderName, _commerceCodeHeaderName);

Expand Down
8 changes: 4 additions & 4 deletions Transbank/WebpayRest/Oneclick/Oneclick.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;
using System.Runtime.Remoting.Messaging;
using Transbank.Common;
using Transbank.Webpay.Common;

namespace Transbank.Webpay.Oneclick
{
[Obsolete("Use specific method instead", false)]
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 readonly string _commerceCodeHeaderName = "Tbk-Api-Key-Id";
private static readonly string _apiKeyHeaderName = "Tbk-Api-Key-Secret";

private static RequestServiceHeaders _headers = new RequestServiceHeaders(_apiKeyHeaderName, _commerceCodeHeaderName);

Expand Down
Loading

0 comments on commit d3227ef

Please sign in to comment.