-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from TransbankDevelopers/feat/add-oneclick-ma…
…ll-deferred-capture Add Oneclick Deferred Capture
- Loading branch information
Showing
22 changed files
with
518 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
112
Transbank/WebpayRest/Oneclick/MallDeferredTransaction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.