Skip to content

Commit

Permalink
Email check for customer
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarwal4 committed Mar 4, 2024
1 parent 83454b4 commit 5662849
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 23 deletions.
4 changes: 2 additions & 2 deletions backend/core/src/Core.API/Core.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Quantoz.Nexus.Sdk.Shared" Version="1.4.0" />
<PackageReference Include="Quantoz.Nexus.Sdk.Token" Version="1.4.0" />
<PackageReference Include="Quantoz.Nexus.Sdk.Shared" Version="1.7.0" />
<PackageReference Include="Quantoz.Nexus.Sdk.Token" Version="1.7.0" />
<PackageReference Include="Quartz.Extensions.DependencyInjection" Version="3.8.1" />
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.8.1" />
<PackageReference Include="ReHackt.Extensions.Options.Validation" Version="8.0.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ITransactionRepository

public Task<Paged<Transaction>> GetAsync(string publicKey, int page, int pageSize, CancellationToken cancellationToken = default);

public Task<Paged<Transaction>> GetByCodeAsync(string code, CancellationToken cancellationToken = default);
public Task<Paged<Transaction>> GetAsync(Dictionary<string, string> parameters, int page, int pageSize, CancellationToken cancellationToken = default);

public Task<WithdrawFees> GetWithdrawFeesAsync(Withdraw withdraw, CancellationToken cancellationToken = default);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Otp.NET" Version="1.3.0" />
<PackageReference Include="Quantoz.Nexus.Sdk.Token" Version="1.4.0" />
<PackageReference Include="Quantoz.Nexus.Sdk.Token" Version="1.7.0" />
<PackageReference Include="Quartz" Version="3.8.1" />
<PackageReference Include="SendGrid" Version="9.29.2" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
Expand Down
10 changes: 8 additions & 2 deletions backend/core/src/Core.Infrastructure/Jobs/ProcessEmailsJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Core.Infrastructure.Nexus;
using Microsoft.Extensions.Logging;
using Quartz;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace Core.Infrastructure.Jobs
{
Expand Down Expand Up @@ -59,12 +60,17 @@ public async Task Execute(IJobExecutionContext context)
throw new CustomErrorsException("MailService", "TokenPaymentCode", "An error occured while sending mail.");
}

var transactions = await _transactionRepository.GetByCodeAsync(mail.References.TokenPaymentCode, context.CancellationToken);
var query = new Dictionary<string, string>
{
{ "customerCode", customerCode }
};

var transactions = await _transactionRepository.GetAsync(query, 1, 1, context.CancellationToken);

Transaction? transaction = null;
if (transactions != null && transactions.Items.Any())
{
transaction = transactions.Items.FirstOrDefault();
transaction = transactions.Items.FirstOrDefault(t => t.TransactionCode == mail.References.TokenPaymentCode);
}

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,24 @@ public NexusCustomerRepository(ITokenServer tokenServer, TokenOptions tokenSetti

public async Task CreateAsync(Customer customer, string? ip = null, CancellationToken cancellationToken = default)
{
var exists = await _tokenServer.Customers.Exists(customer.CustomerCode);
var customerCodeExists = await _tokenServer.Customers.Exists(customer.CustomerCode);

if (exists)
if (customerCodeExists)
{
throw new CustomErrorsException(NexusErrorCodes.ExistingProperty.ToString(), customer.CustomerCode, Constants.NexusErrorMessages.ExistingProperty);
}

var query = new Dictionary<string, string>
{
{ "Email", customer.Email.TrimEnd() }
};

var existingCustomersWithEmail = await _tokenServer.Customers.Get(query);
if (existingCustomersWithEmail.Records.Any(existingCustomer => existingCustomer.Status != CustomerStatus.DELETED.ToString()))
{
throw new CustomErrorsException(NexusErrorCodes.ExistingProperty.ToString(), customer.Email, Constants.NexusErrorMessages.ExistingProperty);
}

var success = Enum.TryParse<CustomerStatus>(customer.Status.ToString(), out var status);

if (!success)
Expand All @@ -39,11 +50,17 @@ public async Task CreateAsync(Customer customer, string? ip = null, Cancellation
}

var builder = new CreateCustomerRequestBuilder(customer.CustomerCode, customer.TrustLevel, customer.CurrencyCode)
.SetIsBusiness(customer.IsMerchant)
.SetBankAccounts([
new()
{
BankAccountName = customer.GetName(),
BankAccountNumber = null
}
])
.SetEmail(customer.Email)
.SetStatus(status)
.SetCustomData(customer.Data)
.SetBusiness(customer.IsMerchant)
.AddBankAccount(new CustomerBankAccountRequest { BankAccountName = customer.GetName(), BankAccountNumber = null });
.SetCustomData(customer.Data);

await _tokenServer.Customers.Create(builder.Build(), ip);
}
Expand All @@ -64,11 +81,11 @@ public async Task UpdateAsync(Customer customer, CancellationToken cancellationT
throw new CustomErrorsException(NexusErrorCodes.InvalidStatus.ToString(), customer.Status.ToString(), "Invalid customer status");
}

var builder = new UpdateCustomerRequestBuilder(customer.CustomerCode, customer.UpdateReason)
var builder = new UpdateCustomerRequestBuilder(customer.CustomerCode)
.SetReason(customer.UpdateReason!)
.SetEmail(customer.Email)
.SetStatus(status)
.SetCustomData(customer.Data)
.SetBusiness(customer.IsMerchant);
.SetCustomData(customer.Data);

await _tokenServer.Customers.Update(builder.Build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,22 @@ public async Task<Paged<Transaction>> GetAsync(string publicKey, int page, int p
};
}

public async Task<Paged<Transaction>> GetByCodeAsync(string code, CancellationToken cancellationToken = default)
public async Task<Paged<Transaction>> GetAsync(Dictionary<string, string> parameters, int page, int pageSize, CancellationToken cancellationToken = default)
{
int page = 1; // default value
int pageSize = 10; // default value
var query = new Dictionary<string, string>
{
{ "page", page.ToString() },
{ "limit", pageSize.ToString() },
};

var response = await _tokenServer.Operations.Get(code);
foreach (var item in parameters)
{
query[item.Key] = item.Value;
}

var operations = response.Records;
var response = await _tokenServer.Operations.Get(query);

var operations = response.Records.Where(t => t.Status == "SubmissionCompleted");

var items = new List<Transaction>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static PagedResponse<T> EmptyPagedResponse<T>()

public static CustomerResponse PrivateCustomer(string customerCode)
{
return new CustomerResponse(customerCode, "PTrusted", "EUR", null, "test@test.com", "ACTIVE", "TestBankAccount", false, new Dictionary<string, string>());
return new CustomerResponse(customerCode, "FirstName", "LastName", "2020-12-12", "123456", null, "PTrusted", "EUR", "NL", "test@email.com", "ACTIVE", "TestBankAccount", false, "Low", new Dictionary<string, string>());
}

public static IDictionary<string, string> AccountQuery(string customerCode)
Expand Down Expand Up @@ -65,7 +65,7 @@ public static AccountBalancesResponse AccountBalancesResponse()
return new AccountBalancesResponse(balances);
}

public static bool AreEqual(CustomerRequest request1, CustomerRequest request2)
public static bool AreEqual(CreateCustomerRequest request1, CreateCustomerRequest request2)
{
return request1.IsBusiness == request2.IsBusiness
&& request1.CustomerCode == request2.CustomerCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task CreateCustomer_Creates_Customer_TestAsync()

await repo.CreateAsync(customer);

var expected = new CustomerRequest
var expected = new CreateCustomerRequest
{
CustomerCode = "TestCustomer",
CurrencyCode = "EUR",
Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task CreateCustomer_Creates_Business_TestAsync()
var repo = new NexusCustomerRepository(server.Object, DefaultOptions.TokenOptions);
await repo.CreateAsync(customer);

var expected = new CustomerRequest
var expected = new CreateCustomerRequest
{
CustomerCode = "TestCustomer",
CurrencyCode = "EUR",
Expand Down

0 comments on commit 5662849

Please sign in to comment.