feat(account): show next payment date with lazy Helcim refresh

Persist nextBillingDate on subscription create/update; unset on
cancel or downgrade to free. Account page displays the cached
date and lazily refreshes from Helcim when the cached value is
within 24h of now (or missing).
This commit is contained in:
Jennie Robinson Faber 2026-04-19 18:32:04 +01:00
parent 4da0265935
commit 5d6fcdd78d
8 changed files with 146 additions and 3 deletions

View file

@ -102,6 +102,10 @@ export default defineEventHandler(async (event) => {
throw new Error("No subscription returned in response");
}
const nextBillingDate = subscription.nextBillingDate
? new Date(subscription.nextBillingDate)
: null;
// Update member record
await Member.findByIdAndUpdate(
member._id,
@ -111,6 +115,9 @@ export default defineEventHandler(async (event) => {
paymentMethod: "card",
status: "active",
billingCadence: cadence,
...(nextBillingDate && !Number.isNaN(nextBillingDate.getTime())
? { nextBillingDate }
: {}),
} },
{ runValidators: false }
);
@ -152,7 +159,10 @@ export default defineEventHandler(async (event) => {
// Update member to free tier
await Member.findByIdAndUpdate(
member._id,
{ $set: { contributionTier: newTier, helcimSubscriptionId: null, paymentMethod: "none", billingCadence: "monthly" } },
{
$set: { contributionTier: newTier, helcimSubscriptionId: null, paymentMethod: "none", billingCadence: "monthly" },
$unset: { nextBillingDate: 1 },
},
{ runValidators: false }
);