-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a0d188
commit 6405647
Showing
10 changed files
with
269 additions
and
46 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
33 changes: 0 additions & 33 deletions
33
src/services/JSE.Pagamento.API/Controllers/WeatherForecastController.cs
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,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()); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/services/JSE.Pagamentos.NerdsPag/JSE.Pagamentos.NerdsPag.csproj
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,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
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 @@ | ||
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; | ||
} | ||
} | ||
} |
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,8 @@ | ||
namespace JSE.Pagamentos.NerdsPag | ||
{ | ||
public enum PaymentMethod | ||
{ | ||
CreditCard = 1, | ||
Billet | ||
} | ||
} |
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,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<Transaction> 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<Transaction> 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<Transaction> 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()); | ||
} | ||
} | ||
} |
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,11 @@ | ||
namespace JSE.Pagamentos.NerdsPag | ||
{ | ||
public enum TransactionStatus | ||
{ | ||
Authorized = 1, | ||
Paid, | ||
Refused, | ||
Chargedback, | ||
Cancelled | ||
} | ||
} |