Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,50 +63,48 @@ public async Task UpdatePaymentRequestWithInvoiceAsync(Guid paymentRequestId, In
try
{
// Each attempt must have a fresh UoW
using (var uow = unitOfWorkManager.Begin())
{
// Load with tracking
var paymentRequest = await paymentRequestRepository.GetAsync(paymentRequestId);

if (paymentRequest == null)
{
Logger.LogWarning("PaymentRequest {Id} not found. Skipping update.", paymentRequestId);
return;
}

// Idempotency: do not re-process
if (paymentRequest.InvoiceStatus == CasPaymentRequestStatus.SentToCas)
{
Logger.LogInformation(
"PaymentRequest {Id} already invoiced. Skipping update.",
paymentRequestId
);
return;
}

// Apply CAS response info
paymentRequest.SetCasHttpStatusCode((int)invoiceResponse.CASHttpStatusCode);
paymentRequest.SetCasResponse(invoiceResponse.CASReturnedMessages);

// Set status
paymentRequest.SetInvoiceStatus(
invoiceResponse.IsSuccess()
? CasPaymentRequestStatus.SentToCas
: CasPaymentRequestStatus.ErrorFromCas
);
using var uow = unitOfWorkManager.Begin();
// Load with tracking
var paymentRequest = await paymentRequestRepository.GetAsync(paymentRequestId);

await paymentRequestRepository.UpdateAsync(paymentRequest, autoSave: false);

// Commit this attempt
await uow.CompleteAsync();
if (paymentRequest == null)
{
Logger.LogWarning("PaymentRequest {Id} not found. Skipping update.", paymentRequestId);
return;
}

// Idempotency: do not re-process
if (paymentRequest.InvoiceStatus == CasPaymentRequestStatus.SentToCas)
{
Logger.LogInformation(
"PaymentRequest {Id} updated successfully on attempt {Attempt}.",
paymentRequestId,
attempt
"PaymentRequest {Id} already invoiced. Skipping update.",
paymentRequestId
);
return; // success
return;
}

// Apply CAS response info
paymentRequest.SetCasHttpStatusCode((int)invoiceResponse.CASHttpStatusCode);
paymentRequest.SetCasResponse(invoiceResponse.CASReturnedMessages);

// Set status
paymentRequest.SetInvoiceStatus(
invoiceResponse.IsSuccess()
? CasPaymentRequestStatus.SentToCas
: CasPaymentRequestStatus.ErrorFromCas
);

await paymentRequestRepository.UpdateAsync(paymentRequest, autoSave: false);

// Commit this attempt
await uow.CompleteAsync();

Logger.LogInformation(
"PaymentRequest {Id} updated successfully on attempt {Attempt}.",
paymentRequestId,
attempt
);
return; // success
}
catch (Exception ex) when (
ex is AbpDbConcurrencyException ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace Unity.Payments.Repositories
{
public class PaymentRequestRepository : EfCoreRepository<PaymentsDbContext, PaymentRequest, Guid>, IPaymentRequestRepository
{
private List<string> ReCheckStatusList { get; set; } = new List<string>();
private List<string> FailedStatusList { get; set; } = new List<string>();
private List<string> ReCheckStatusList { get; set; } = [];
private List<string> FailedStatusList { get; set; } = [];

public PaymentRequestRepository(IDbContextProvider<PaymentsDbContext> dbContextProvider) : base(dbContextProvider)
{
Expand Down
Loading
Loading