Add premium My Case MVP

This commit is contained in:
2026-05-23 10:17:34 +02:00
parent e0aeefc73e
commit 83fc71414f
33 changed files with 1275 additions and 148 deletions
+7 -1
View File
@@ -76,6 +76,10 @@ try {
handleSubscriptionDeleted($db, $object);
break;
case 'customer.subscription.trial_will_end':
// Stripe sends the customer reminder email. We mirror state on subscription.updated/deleted.
break;
case 'invoice.paid':
handleInvoicePaid($db, $object);
break;
@@ -154,8 +158,10 @@ function handleSubscriptionChange(PDO $db, array $sub): void
$periodEndTs = (int)($sub['current_period_end'] ?? 0);
$periodStartTs = (int)($sub['current_period_start'] ?? 0);
$trialEndTs = (int)($sub['trial_end'] ?? 0);
$periodEndIso = $periodEndTs > 0 ? gmdate('Y-m-d H:i:s', $periodEndTs) : null;
$periodStartIso = $periodStartTs > 0 ? gmdate('Y-m-d H:i:s', $periodStartTs) : null;
$trialEndIso = $trialEndTs > 0 ? gmdate('Y-m-d H:i:s', $trialEndTs) : null;
// Upsert subscription ledger
$db->prepare(
@@ -172,7 +178,7 @@ function handleSubscriptionChange(PDO $db, array $sub): void
// Only flip the live tier flag if subscription is active/trialing.
if (in_array($status, ['active', 'trialing'], true)) {
FreeTier::setTier($userId, $tier, $customerId, $subId, $periodEndIso);
FreeTier::setTier($userId, $tier, $customerId, $subId, $periodEndIso, $status === 'trialing' ? $trialEndIso : null);
} elseif (in_array($status, ['canceled', 'unpaid', 'incomplete_expired'], true)) {
FreeTier::clearTier($userId);
}