Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed email service and updated to latest sdk #73

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.1" />
<PackageReference Include="Quantoz.Nexus.Sdk.Token" Version="1.7.1" />
<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.1" />
<PackageReference Include="Quartz" Version="3.8.1" />
<PackageReference Include="SendGrid" Version="9.29.2" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
Expand Down
41 changes: 21 additions & 20 deletions backend/core/src/Core.Infrastructure/Jobs/ProcessEmailsJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,35 @@ public async Task Execute(IJobExecutionContext context)

var customer = await _customerRepository.GetAsync(customerCode, context.CancellationToken);

if (mail.References == null || string.IsNullOrWhiteSpace(mail.References.TokenPaymentCode))
{
throw new CustomErrorsException("MailService", "TokenPaymentCode", "An error occured while sending mail.");
}
var query = new Dictionary<string, string>
{
{ "customerCode", customerCode }
};

var transactions = await _transactionRepository.GetByCodeAsync(mail.References.TokenPaymentCode, context.CancellationToken);
var transactions = await _transactionRepository.GetAsync(query, 1, 1, context.CancellationToken);

Transaction? transaction = null;
if (transactions != null && transactions.Items.Any())
{
transaction = transactions.Items.FirstOrDefault();
}

try
{
await _sendGridMailService.SendMailAsync(mail, customer, transaction!);
}
catch (Exception ex)
if (transactions != null && transactions.Items.Any() && mail.References != null)
{
_logger.LogError("An error occured sending email {code} with message {message}", mail.Code, ex.Message);
}
transaction = transactions.Items.FirstOrDefault(t => t.TransactionCode == mail.References!.TokenPaymentCode);

try
{
await _sendGridMailService.SendMailAsync(mail, customer, transaction!);
}
catch (Exception ex)
{
_logger.LogError("An error occured sending email {code} with message {message}", mail.Code, ex.Message);
}

// once email has been sent, call nexus to update the status of this mail to 'Sent'
await _mailsRepository.UpdateMailSent(mail.Code);

// once email has been sent, call nexus to update the status of this mail to 'Sent'
await _mailsRepository.UpdateMailSent(mail.Code);
await _unitOfWork.SaveChangesAsync();
}
}
}

await _unitOfWork.SaveChangesAsync();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ 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 +71,10 @@ 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)
.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
Loading