many fixes and improvements - rework for modules/ and common/

feat(emailer): add Postmark and Resend providers
This commit is contained in:
2025-06-06 12:21:43 -04:00
parent 31ba18fa8d
commit 25b94d3e02
313 changed files with 6586 additions and 18260 deletions

View File

@@ -0,0 +1,109 @@
using Hutopy.Modules.Memberships.Contracts;
using Hutopy.Modules.Memberships.Data;
namespace Hutopy.Modules.Memberships.Services;
public class MembershipNotifier(
MembershipsDbContext dbContext)
: IMembershipNotifier
{
public async Task NotifyCheckoutSessionCompleted(
string stripeSessionId,
string stripeSubscriptionId,
string userId,
string creatorId,
string tierId,
CancellationToken cancellationToken = default)
{
var membership = new Membership
{
Id = Guid.CreateVersion7(),
CreatedAt = DateTimeOffset.UtcNow,
UserId = Guid.Parse(userId),
CreatorId = Guid.Parse(creatorId),
TierId = Guid.Parse(tierId),
StripeSubscriptionId = stripeSubscriptionId,
State = MembershipState.Pending,
StartDate = null,
EndDate = null
};
dbContext.Memberships.Add(membership);
await dbContext.SaveChangesAsync(cancellationToken);
}
public async Task NotifyPaymentSucceedAsync(
string stripeSubscriptionId,
string hostedInvoiceUrl,
decimal amount,
string currency,
CancellationToken cancellationToken = default)
{
var membership = await dbContext
.Memberships
.SingleOrDefaultAsync(
m => m.StripeSubscriptionId == stripeSubscriptionId,
cancellationToken: cancellationToken);
if (membership is null)
{
return;
}
var payment = new Payment
{
Id = Guid.CreateVersion7(),
CreatedAt = DateTimeOffset.UtcNow,
Amount = amount,
Currency = currency,
InvoiceUrl = hostedInvoiceUrl
};
membership.State = MembershipState.Active;
membership.StartDate = DateTimeOffset.UtcNow;
membership.Payments.Add(payment);
dbContext.Payments.Add(payment);
await dbContext.SaveChangesAsync(cancellationToken);
}
public async Task NotifySubscriptionUpdatedAsync(
string subscriptionId,
DateTimeOffset? endDate,
CancellationToken cancellationToken = default)
{
var membership = await dbContext
.Memberships
.SingleOrDefaultAsync(
s => s.StripeSubscriptionId == subscriptionId,
cancellationToken: cancellationToken);
if (membership == null)
{
return;
}
membership.EndDate = endDate;
await dbContext.SaveChangesAsync(cancellationToken);
}
public async Task NotifySubscriptionDeletedAsync(
string subscriptionId,
CancellationToken cancellationToken)
{
var membership = await dbContext
.Memberships
.SingleOrDefaultAsync(
s => s.StripeSubscriptionId == subscriptionId,
cancellationToken: cancellationToken);
if (membership == null)
{
return;
}
membership.State = MembershipState.Inactive;
await dbContext.SaveChangesAsync(cancellationToken);
}
}