75 fichiers, ~1 mois de travail depuis f222861 (17/07). Contenu :
Onboarding self-service — jamais exécuté de bout en bout
OnboardingController, StripeWebhookController, StripeService, ResendEmailService
+ IEmailService (10 templates), EmailTemplates/, TrialLifecycleService (Hangfire),
PasswordTokenHelper, SlugHelper, 5 DTOs. Essai 14 j, Stripe customer/Checkout/Tax,
mot de passe oublié + invitation user, plafond IA d'essai.
Schéma Postgres v3 — passe pendant que la base est vide
ContentEmbedding + index HNSW (vector_cosine_ops), IEmbeddingService +
GoogleEmbeddingService (gemini-embedding-001, 768 dims), Deployment/Dockerfile.postgres
(postgis 3.4.3 + pgvector 0.8.6, épinglé par digest — un tag mobile rejouerait le
warning de collation glibc). Colonnes Resource : StoragePath, FileName,
IncludeInAiKnowledge, AiIndexStatus + nouveaux ResourceType ajoutés EN FIN d'enum.
Guide IA
Champs Guide* sur Instance + InstanceDTO, AssistantService lit la configuration client
dans les 4 blocs de prompt (ton codé en dur retiré, règle hors-sujet ajoutée aux deux
variantes qui n'en avaient pas), IHttpClientFactory à la place des new HttpClient().
Table VisitorQuestion + ConversationId sur AiChatRequest.
Stats
Rétention unifiée à 13 mois (instances ET plans), VisitEventPurgeService.
Nettoyage
IsStepLocked / IsHiddenInitially / FactContent supprimés de GuidedStep — IsStepLocked
rendait une étape définitivement infranchissable même après réussite.
SectionMap allégé (-57 lignes).
Tests
SectionParcoursControllerTests, FakeConfiguration, FakeEmailService.
ContentEmbedding a cassé 116 tests sur 124 (EF InMemory ne connaît pas Vector) :
l'entité est exclue quand le provider n'est pas Npgsql. Conséquence assumée —
le vector store n'est couvert par aucun test. dotnet test 124/124.
10 migrations EF. Base locale à jour, dotnet build 0 erreur.
Rien n'est en prod : la bascule Mongo → Postgres est décrite dans DOCS/STATUS.md §1quinquies.
⚠️ appsettings.json contient les clés Stripe (test) et Resend (prod) en clair — à rotationner.
99 lines
4.0 KiB
C#
99 lines
4.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using ManagerService.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace ManagerService.Services
|
|
{
|
|
/// <summary>
|
|
/// Daily Hangfire job driving the 14-day Essentiel trial: check-in (J+7), ending reminder
|
|
/// (J+10), last-day warning (J+14), then automatic deactivation if no subscription was
|
|
/// started. Flags on <see cref="Instance"/> (TrialCheckInEmailSent, etc.) prevent sending
|
|
/// the same email twice if the job runs more than once on the same day.
|
|
/// </summary>
|
|
public class TrialLifecycleService
|
|
{
|
|
private const int CheckInAfterDays = 7;
|
|
private const int ReminderAfterDays = 10;
|
|
private const int LastDayAfterDays = 13; // day before the 14-day trial ends
|
|
|
|
private readonly ILogger<TrialLifecycleService> _logger;
|
|
private readonly IServiceScopeFactory _scopeFactory;
|
|
|
|
public TrialLifecycleService(ILogger<TrialLifecycleService> logger, IServiceScopeFactory scopeFactory)
|
|
{
|
|
_logger = logger;
|
|
_scopeFactory = scopeFactory;
|
|
}
|
|
|
|
public async Task RunAsync()
|
|
{
|
|
using var scope = _scopeFactory.CreateScope();
|
|
var db = scope.ServiceProvider.GetRequiredService<MyInfoMateDbContext>();
|
|
var emailService = scope.ServiceProvider.GetRequiredService<IEmailService>();
|
|
var configuration = scope.ServiceProvider.GetRequiredService<Microsoft.Extensions.Configuration.IConfiguration>();
|
|
|
|
var managerAppUrl = configuration["AppUrls:ManagerApp"];
|
|
var now = DateTime.UtcNow;
|
|
|
|
var trialInstances = db.Instances.Where(i => i.IsTrialActive).ToList();
|
|
|
|
foreach (var instance in trialInstances)
|
|
{
|
|
try
|
|
{
|
|
await ProcessInstanceAsync(instance, db, emailService, managerAppUrl, now);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error processing trial lifecycle for instance {InstanceId}", instance.Id);
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task ProcessInstanceAsync(Instance instance, MyInfoMateDbContext db, IEmailService emailService, string managerAppUrl, DateTime now)
|
|
{
|
|
var daysSinceCreation = (now - instance.DateCreation).TotalDays;
|
|
var user = db.Users.FirstOrDefault(u => u.InstanceId == instance.Id);
|
|
|
|
// Trial expired without an active subscription -> deactivate
|
|
if (instance.TrialEndsAt != null && instance.TrialEndsAt < now && string.IsNullOrEmpty(instance.StripeSubscriptionId))
|
|
{
|
|
instance.IsTrialActive = false;
|
|
instance.IsActive = false;
|
|
db.SaveChanges();
|
|
return;
|
|
}
|
|
|
|
if (user == null)
|
|
return;
|
|
|
|
if (daysSinceCreation >= CheckInAfterDays && !instance.TrialCheckInEmailSent)
|
|
{
|
|
await emailService.SendTrialCheckInEmailAsync(user.Email, user.FirstName);
|
|
instance.TrialCheckInEmailSent = true;
|
|
db.SaveChanges();
|
|
}
|
|
|
|
if (daysSinceCreation >= ReminderAfterDays && !instance.TrialReminderEmailSent && instance.TrialEndsAt != null)
|
|
{
|
|
var checkoutUrl = $"{managerAppUrl}/main/web";
|
|
await emailService.SendTrialEndingReminderEmailAsync(user.Email, user.FirstName, instance.TrialEndsAt.Value, checkoutUrl);
|
|
instance.TrialReminderEmailSent = true;
|
|
db.SaveChanges();
|
|
}
|
|
|
|
if (daysSinceCreation >= LastDayAfterDays && !instance.TrialLastDayEmailSent)
|
|
{
|
|
var checkoutUrl = $"{managerAppUrl}/main/web";
|
|
await emailService.SendTrialLastDayEmailAsync(user.Email, user.FirstName, checkoutUrl);
|
|
instance.TrialLastDayEmailSent = true;
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|