fix(helcim): read dateBilling on subscription CREATE to populate next-billing cache
Some checks failed
Test / playwright (push) Blocked by required conditions
Test / Notify on failure (push) Blocked by required conditions
Test / visual (push) Blocked by required conditions
Test / vitest (push) Has been cancelled

Helcim returns next-charge as `dateBilling` on POST /subscriptions, but the
two CREATE sites were reading `subscription.nextBillingDate`, leaving
`member.nextBillingDate` empty after every signup and free→paid upgrade.
The lazy refresh in subscription.get.js (which already accepts both shapes)
masked it on next account-page load, so renders eventually populated — but
the success response we returned to the client also had `nextBillingDate:
undefined`. Mirror the GET-side resolution at both CREATE sites: prefer
`dateBilling`, fall back to `nextBillingDate`. Existing Number.isNaN guard
unchanged; defensively rejects malformed strings from either field.
This commit is contained in:
Jennie Robinson Faber 2026-04-27 19:44:35 +01:00
parent 3c38333dd1
commit cf59931814
5 changed files with 65 additions and 9 deletions

View file

@ -100,9 +100,8 @@ export default defineEventHandler(async (event) => {
throw new Error("No subscription returned in response");
}
const nextBillingDate = subscription.nextBillingDate
? new Date(subscription.nextBillingDate)
: null;
const rawNextBilling = subscription.dateBilling || subscription.nextBillingDate || null;
const nextBillingDate = rawNextBilling ? new Date(rawNextBilling) : null;
// Update member record
await Member.findByIdAndUpdate(
@ -149,7 +148,7 @@ export default defineEventHandler(async (event) => {
subscription: {
subscriptionId: subscription.id,
status: subscription.status,
nextBillingDate: subscription.nextBillingDate,
nextBillingDate: rawNextBilling,
},
};
} catch (error) {