refactor(auth): cleanup auth module and streamline the registration flow
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using Hutopy.Infrastructure.Emailer.Contracts;
|
||||
using Hutopy.Modules.Creators.Contracts;
|
||||
using Hutopy.Modules.Tipping.Contracts;
|
||||
using Hutopy.Modules.Tipping.Data;
|
||||
|
||||
@@ -5,27 +7,104 @@ namespace Hutopy.Modules.Tipping.Services;
|
||||
|
||||
public class TipPaymentNotifier(
|
||||
TippingDbContext dbContext,
|
||||
IEmailSender emailSender,
|
||||
ICreatorLookup creatorLookup,
|
||||
ILogger<TipPaymentNotifier> logger)
|
||||
: ITipPaymentNotifier
|
||||
{
|
||||
public async Task NotifyPaymentSucceedAsync(
|
||||
string sessionId,
|
||||
string invoiceUrl,
|
||||
string receiptUrl,
|
||||
string customerEmail,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var tip = await dbContext.Tips.SingleOrDefaultAsync(
|
||||
Tip? tip = await dbContext.Tips.SingleOrDefaultAsync(
|
||||
t => t.StripeSessionId == sessionId,
|
||||
cancellationToken: ct);
|
||||
ct);
|
||||
|
||||
if (tip is not null)
|
||||
{
|
||||
tip.Status = TipStatus.Paid;
|
||||
tip.StripeInvoiceUrl = invoiceUrl;
|
||||
tip.StripeInvoiceUrl = receiptUrl; // Store the receipt URL
|
||||
await dbContext.SaveChangesAsync(ct);
|
||||
|
||||
// Look up creator information
|
||||
CreatorReference? creator = await creatorLookup.GetCreatorAsync(tip.CreatorId, ct);
|
||||
|
||||
if (!string.IsNullOrEmpty(customerEmail))
|
||||
{
|
||||
await SendTipConfirmationEmailAsync(
|
||||
customerEmail,
|
||||
creator?.Name ?? "le créateur",
|
||||
tip.Amount,
|
||||
tip.Currency,
|
||||
receiptUrl); // Pass the receipt URL
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogError("Tip with session ID {SessionId} not found", sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SendTipConfirmationEmailAsync(
|
||||
string email,
|
||||
string creatorUsername,
|
||||
decimal amount,
|
||||
string currency,
|
||||
string receiptUrl) // Add receipt URL parameter
|
||||
{
|
||||
string subject = $"Merci pour votre soutien à {creatorUsername}";
|
||||
string message = $"""
|
||||
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; color: #333;">
|
||||
<h1 style="color: #2c3e50; margin-bottom: 20px;">{creatorUsername} vous remercie !</h1>
|
||||
|
||||
<p style="font-size: 16px; line-height: 1.5; margin-bottom: 15px;">
|
||||
Votre paiement de <strong>{amount} {currency}</strong> a été traité avec succès.
|
||||
</p>
|
||||
|
||||
<div style="background-color: #f8f9fa; border-radius: 4px; padding: 20px; margin: 30px 0; border-left: 4px solid #3498db;">
|
||||
<p style="font-size: 16px; margin: 0; line-height: 1.5;">
|
||||
Ce reçu confirme votre soutien à <strong>{creatorUsername}</strong>. Merci de contribuer à son travail !
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{(string.IsNullOrEmpty(receiptUrl) ? "" : $"""
|
||||
<div style="text-align: center; margin: 30px 0;">
|
||||
<a href='{receiptUrl}'
|
||||
style="background-color: #3498db;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
padding: 12px 24px;
|
||||
border-radius: 4px;
|
||||
font-weight: bold;
|
||||
display: inline-block;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.1);">
|
||||
Voir le reçu
|
||||
</a>
|
||||
</div>
|
||||
""")}
|
||||
|
||||
<p style="font-size: 14px; color: #7f8c8d; margin-top: 30px;">
|
||||
Cet email sert de reçu pour votre transaction. Nous vous conseillons de le conserver pour vos archives.
|
||||
</p>
|
||||
|
||||
<p style="font-size: 14px; color: #7f8c8d; margin-top: 20px; text-align: center; border-top: 1px solid #eee; padding-top: 20px;">
|
||||
Merci d'utiliser Hutopy pour soutenir vos créateurs préférés !
|
||||
</p>
|
||||
</div>
|
||||
""";
|
||||
|
||||
try
|
||||
{
|
||||
await emailSender.SendEmailAsync(email, subject, message);
|
||||
logger.LogInformation("Tip confirmation email sent to {Email} for tip to {Creator}", email,
|
||||
creatorUsername);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to send tip confirmation email to {Email}", email);
|
||||
// Don't throw the exception as this should not fail the payment processing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user