using Hutopy.Infrastructure.Security; using Hutopy.Modules.Creators.Data; namespace Hutopy.Modules.Creators.Features; [PublicAPI] public class RemoveStripeHandler( CreatorsDbContext dbContext) : EndpointWithoutRequest { public override void Configure() { Delete("/api/stripe"); Options(o => o.WithTags("Creators")); } public override async Task HandleAsync(CancellationToken ct) { // 1. Get the creator's ID from the authenticated user Guid creatorId = HttpContext.User.GetUserId(); // 2. Retrieve the creator from the database Creator? creator = await dbContext .Creators .SingleOrDefaultAsync( c => c.Id == creatorId, ct); // 3. If the creator doesn't exist or has no Stripe account linked, return 404 if (creator is null || string.IsNullOrWhiteSpace(creator.StripeAccountId)) { await SendNotFoundAsync(ct); return; } // 4. Remove Stripe configuration creator.StripeAccountId = null; creator.IsStripeDetailsSubmitted = false; creator.IsStripeChargesEnabled = false; creator.IsStripePayoutReady = false; // 5. Persist changes await dbContext.SaveChangesAsync(ct); // 6. Respond with success await SendOkAsync(ct); } }