diff --git a/JS.Enterprise.sln b/JS.Enterprise.sln index 41fb4af..da86969 100644 --- a/JS.Enterprise.sln +++ b/JS.Enterprise.sln @@ -61,6 +61,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JSE.Pedidos.Infra", "src\se EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JSE.Clientes.API", "src\services\JSE.Clientes.API\JSE.Clientes.API.csproj", "{AC75EECB-1BC5-4653-AB42-E8148D5B05D9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JSE.Pagamentos.NerdsPag", "src\services\JSE.Pagamentos.NerdsPag\JSE.Pagamentos.NerdsPag.csproj", "{3D83A7B3-B140-43CF-885C-660C043B498A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -119,6 +121,10 @@ Global {AC75EECB-1BC5-4653-AB42-E8148D5B05D9}.Debug|Any CPU.Build.0 = Debug|Any CPU {AC75EECB-1BC5-4653-AB42-E8148D5B05D9}.Release|Any CPU.ActiveCfg = Release|Any CPU {AC75EECB-1BC5-4653-AB42-E8148D5B05D9}.Release|Any CPU.Build.0 = Release|Any CPU + {3D83A7B3-B140-43CF-885C-660C043B498A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3D83A7B3-B140-43CF-885C-660C043B498A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3D83A7B3-B140-43CF-885C-660C043B498A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3D83A7B3-B140-43CF-885C-660C043B498A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -152,6 +158,7 @@ Global {42556C73-9ABF-45D0-911F-16E74D2919EB} = {856468DF-3B1E-4BAB-AD97-2D72FB744435} {2BB79FC1-2E45-486B-AC1E-F680B3C54BCD} = {856468DF-3B1E-4BAB-AD97-2D72FB744435} {AC75EECB-1BC5-4653-AB42-E8148D5B05D9} = {B89AEBFA-BA86-4AC4-A0B4-117C29036158} + {3D83A7B3-B140-43CF-885C-660C043B498A} = {68C69BFC-835D-4BD4-899B-56E0349A1895} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F19279BD-86B0-48AF-9FA4-26C84BD715EB} diff --git a/src/services/JSE.Pagamento.API/Controllers/WeatherForecastController.cs b/src/services/JSE.Pagamento.API/Controllers/WeatherForecastController.cs deleted file mode 100644 index 073d041..0000000 --- a/src/services/JSE.Pagamento.API/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace JSE.Pagamento.API.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} diff --git a/src/services/JSE.Pagamento.API/JSE.Pagamento.API.csproj b/src/services/JSE.Pagamento.API/JSE.Pagamento.API.csproj index c4cdc51..5115fd0 100644 --- a/src/services/JSE.Pagamento.API/JSE.Pagamento.API.csproj +++ b/src/services/JSE.Pagamento.API/JSE.Pagamento.API.csproj @@ -13,4 +13,15 @@ + + + + + + + + + + + diff --git a/src/services/JSE.Pagamento.API/WeatherForecast.cs b/src/services/JSE.Pagamento.API/WeatherForecast.cs deleted file mode 100644 index 8fbe89e..0000000 --- a/src/services/JSE.Pagamento.API/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace JSE.Pagamento.API -{ - public class WeatherForecast - { - public DateOnly Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -} diff --git a/src/services/JSE.Pagamentos.NerdsPag/Card.cs b/src/services/JSE.Pagamentos.NerdsPag/Card.cs new file mode 100644 index 0000000..7684b5d --- /dev/null +++ b/src/services/JSE.Pagamentos.NerdsPag/Card.cs @@ -0,0 +1,40 @@ +using System.Security.Cryptography; +using System.Text; + +namespace JSE.Pagamentos.NerdsPag +{ + public class CardHash + { + public CardHash(NerdsPagService nerdsPagService) + { + NerdsPagService = nerdsPagService; + } + + private readonly NerdsPagService NerdsPagService; + + public string CardHolderName { get; set; } + public string CardNumber { get; set; } + public string CardExpirationDate { get; set; } + public string CardCvv { get; set; } + + public string Generate() + { + using var aesAlg = Aes.Create(); + + aesAlg.IV = Encoding.Default.GetBytes(NerdsPagService.EncryptionKey); + aesAlg.Key = Encoding.Default.GetBytes(NerdsPagService.ApiKey); + + var encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); + + using var msEncrypt = new MemoryStream(); + using var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write); + + using (var swEncrypt = new StreamWriter(csEncrypt)) + { + swEncrypt.Write(CardHolderName + CardNumber + CardExpirationDate + CardCvv); + } + + return Encoding.ASCII.GetString(msEncrypt.ToArray()); + } + } +} \ No newline at end of file diff --git a/src/services/JSE.Pagamentos.NerdsPag/JSE.Pagamentos.NerdsPag.csproj b/src/services/JSE.Pagamentos.NerdsPag/JSE.Pagamentos.NerdsPag.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/src/services/JSE.Pagamentos.NerdsPag/JSE.Pagamentos.NerdsPag.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/src/services/JSE.Pagamentos.NerdsPag/NerdsPagService.cs b/src/services/JSE.Pagamentos.NerdsPag/NerdsPagService.cs new file mode 100644 index 0000000..758da79 --- /dev/null +++ b/src/services/JSE.Pagamentos.NerdsPag/NerdsPagService.cs @@ -0,0 +1,14 @@ +namespace JSE.Pagamentos.NerdsPag +{ + public class NerdsPagService + { + public readonly string ApiKey; + public readonly string EncryptionKey; + + public NerdsPagService(string apiKey, string encryptionKey) + { + ApiKey = apiKey; + EncryptionKey = encryptionKey; + } + } +} \ No newline at end of file diff --git a/src/services/JSE.Pagamentos.NerdsPag/PaymentMethod.cs b/src/services/JSE.Pagamentos.NerdsPag/PaymentMethod.cs new file mode 100644 index 0000000..d215c52 --- /dev/null +++ b/src/services/JSE.Pagamentos.NerdsPag/PaymentMethod.cs @@ -0,0 +1,8 @@ +namespace JSE.Pagamentos.NerdsPag +{ + public enum PaymentMethod + { + CreditCard = 1, + Billet + } +} \ No newline at end of file diff --git a/src/services/JSE.Pagamentos.NerdsPag/Transaction.cs b/src/services/JSE.Pagamentos.NerdsPag/Transaction.cs new file mode 100644 index 0000000..329ea3e --- /dev/null +++ b/src/services/JSE.Pagamentos.NerdsPag/Transaction.cs @@ -0,0 +1,169 @@ +namespace JSE.Pagamentos.NerdsPag +{ + public class Transaction + { + public Transaction(NerdsPagService nerdsPagService) + { + NerdsPagService = nerdsPagService; + } + + protected Transaction(){} + + private readonly NerdsPagService NerdsPagService; + + protected string Endpoint { get; set; } + + public int SubscriptionId { get; set; } + + public TransactionStatus Status { get; set; } + + public int AuthorizationAmount { get; set; } + + public int PaidAmount { get; set; } + + public int RefundedAmount { get; set; } + + public string CardHash { get; set; } + + public string CardNumber { get; set; } + + public string CardExpirationDate { get; set; } + + public string StatusReason { get; set; } + + public string AcquirerResponseCode { get; set; } + + public string AcquirerName { get; set; } + + public string AuthorizationCode { get; set; } + + public string SoftDescriptor { get; set; } + + public string RefuseReason { get; set; } + + public string Tid { get; set; } + + public string Nsu { get; set; } + + public decimal Amount { get; set; } + + public int? Installments { get; set; } + + public decimal Cost { get; set; } + + public string CardHolderName { get; set; } + + public string CardCvv { get; set; } + + public string CardLastDigits { get; set; } + + public string CardFirstDigits { get; set; } + + public string CardBrand { get; set; } + + public string CardEmvResponse { get; set; } + + public string PostbackUrl { get; set; } + + public PaymentMethod PaymentMethod { get; set; } + + public float? AntifraudScore { get; set; } + + public string BilletUrl { get; set; } + + public string BilletInstructions { get; set; } + + public DateTime? BilletExpirationDate { get; set; } + + public string BilletBarcode { get; set; } + + public string Referer { get; set; } + + public string IP { get; set; } + + public bool? ShouldCapture { get; set; } + + public bool? Async { get; set; } + + public string LocalTime { get; set; } + + public DateTime TransactionDate { get; set; } + + public Task AuthorizeCardTransaction() + { + var success = new Random().Next(2) == 0; + Transaction transaction; + + if (success) + { + transaction = new Transaction + { + AuthorizationCode = GetGenericCode(), + CardBrand = "MasterCard", + TransactionDate = DateTime.Now, + Cost = Amount * (decimal)0.03, + Amount = Amount, + Status = TransactionStatus.Authorized, + Tid = GetGenericCode(), + Nsu = GetGenericCode() + }; + + return Task.FromResult(transaction); + } + + transaction = new Transaction + { + AuthorizationCode = "", + CardBrand = "", + TransactionDate = DateTime.Now, + Cost = 0, + Amount = 0, + Status = TransactionStatus.Refused, + Tid = "", + Nsu = "" + }; + + return Task.FromResult(transaction); + } + + public Task CaptureCardTransaction() + { + var transaction = new Transaction + { + AuthorizationCode = GetGenericCode(), + CardBrand = CardBrand, + TransactionDate = DateTime.Now, + Cost = 0, + Amount = Amount, + Status = TransactionStatus.Paid, + Tid = Tid, + Nsu = Nsu + }; + + return Task.FromResult(transaction); + } + + public Task CancelAuthorization() + { + var transaction = new Transaction + { + AuthorizationCode = "", + CardBrand = CardBrand, + TransactionDate = DateTime.Now, + Cost = 0, + Amount = Amount, + Status = TransactionStatus.Cancelled, + Tid = Tid, + Nsu = Nsu + }; + + return Task.FromResult(transaction); + } + + private string GetGenericCode() + { + return new string(Enumerable.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 10) + .Select(s => s[new Random().Next(s.Length)]).ToArray()); + } + } +} diff --git a/src/services/JSE.Pagamentos.NerdsPag/TransactionStatus.cs b/src/services/JSE.Pagamentos.NerdsPag/TransactionStatus.cs new file mode 100644 index 0000000..9996bf8 --- /dev/null +++ b/src/services/JSE.Pagamentos.NerdsPag/TransactionStatus.cs @@ -0,0 +1,11 @@ +namespace JSE.Pagamentos.NerdsPag +{ + public enum TransactionStatus + { + Authorized = 1, + Paid, + Refused, + Chargedback, + Cancelled + } +} \ No newline at end of file