32 lines
851 B
C#
32 lines
851 B
C#
using Hutopy.Modules.Tipping.Contracts;
|
|
using Hutopy.Modules.Tipping.Data;
|
|
|
|
namespace Hutopy.Modules.Tipping.Services;
|
|
|
|
public class TipPaymentNotifier(
|
|
TippingDbContext dbContext,
|
|
ILogger<TipPaymentNotifier> logger)
|
|
: ITipPaymentNotifier
|
|
{
|
|
public async Task NotifyPaymentSucceedAsync(
|
|
string sessionId,
|
|
string invoiceUrl,
|
|
CancellationToken ct)
|
|
{
|
|
var tip = await dbContext.Tips.SingleOrDefaultAsync(
|
|
t => t.StripeSessionId == sessionId,
|
|
cancellationToken: ct);
|
|
|
|
if (tip is not null)
|
|
{
|
|
tip.Status = TipStatus.Paid;
|
|
tip.StripeInvoiceUrl = invoiceUrl;
|
|
await dbContext.SaveChangesAsync(ct);
|
|
}
|
|
else
|
|
{
|
|
logger.LogError("Tip with session ID {SessionId} not found", sessionId);
|
|
}
|
|
}
|
|
}
|