Added PayfastPaymentConfirmationReceivedEvent
continuous-integration/drone/pr Build is passing

This commit is contained in:
Khwezi Mngoma
2026-06-01 22:51:49 +02:00
parent ac31c6ada8
commit 45c2e8310a
4 changed files with 144 additions and 1 deletions
@@ -7,6 +7,27 @@ namespace LiteCharms.Features.MidrandBooks.Payments;
public sealed class PaymentService(IDbContextFactory<MidrandBooksDbContext> contextFactory) : IService
{
public async ValueTask<Result<Payment>> GetOrderPaymentAsync(long orderId, CancellationToken cancellationToken = default)
{
try
{
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var payment = await context.Payments.AsNoTracking()
.Where(p => p.OrderId == orderId)
.OrderByDescending(p => p.Id)
.FirstOrDefaultAsync(cancellationToken);
return payment is not null
? Result.Ok(payment.ToModel())
: Result.Fail<Payment>("Could not find payment for the order");
}
catch (Exception ex)
{
return Result.Fail<Payment>(new Error(ex.Message).CausedBy(ex));
}
}
public async ValueTask<Result<Refund>> GetRefundAsync(long refundId, CancellationToken cancellationToken = default)
{
try
@@ -95,6 +116,25 @@ public sealed class PaymentService(IDbContextFactory<MidrandBooksDbContext> cont
}
}
public async ValueTask<Result<bool>> HasLedgerEntryAsync(long orderId, long paymentId, long gatewayId, CancellationToken cancellationToken = default)
{
try
{
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
var exists = await context.Ledger.AnyAsync(l =>
l.OrderId == orderId &&
l.PaymentId == paymentId &&
l.PaymentGatewayId == gatewayId, cancellationToken);
return Result.Ok(exists);
}
catch (Exception ex)
{
return Result.Fail(new Error(ex.Message).CausedBy(ex));
}
}
public async ValueTask<Result> WriteLedgerEntryAsync(CreateLedgerEntry request, CancellationToken cancellationToken = default)
{
try