diff --git a/account/src/lib/couch-db.ts b/account/src/lib/couch-db.ts index dfd3343..c01c5db 100644 --- a/account/src/lib/couch-db.ts +++ b/account/src/lib/couch-db.ts @@ -106,7 +106,7 @@ export async function updateLingdocsUser(uuid: T.UUID, toUpdate: wordlistDbName: T.WordlistDbName, couchDbPassword: T.UserDbPassword, upgradeToStudentRequest: undefined, - subscriptionId: string | undefined, + subscription?: T.StripeSubscription, } | { level: "basic", diff --git a/account/src/lib/sample-users.ts b/account/src/lib/sample-users.ts index ebb1b77..9df9715 100644 --- a/account/src/lib/sample-users.ts +++ b/account/src/lib/sample-users.ts @@ -28,7 +28,7 @@ const student: AT.LingdocsUser = { "lastActive":1630414108552 as AT.TimeStamp, "couchDbPassword": "12345" as AT.UserDbPassword, "wordlistDbName": "jim-db" as AT.WordlistDbName, - subscriptionId: undefined, + subscription: undefined, }; const admin: AT.LingdocsUser = { @@ -46,7 +46,7 @@ const admin: AT.LingdocsUser = { "lastActive":1630414108552 as AT.TimeStamp, "couchDbPassword": "12345" as AT.UserDbPassword, "wordlistDbName": "jim-db" as AT.WordlistDbName, - subscriptionId: undefined, + subscription: undefined, }; const editor: AT.LingdocsUser = { @@ -63,7 +63,7 @@ const editor: AT.LingdocsUser = { "lastActive":1630414108552 as AT.TimeStamp, "couchDbPassword": "12345" as AT.UserDbPassword, "wordlistDbName": "jim-db" as AT.WordlistDbName, - subscriptionId: undefined, + subscription: undefined, }; // @ts-ignore diff --git a/account/src/lib/user-utils.ts b/account/src/lib/user-utils.ts index ce30f6a..e7e5386 100644 --- a/account/src/lib/user-utils.ts +++ b/account/src/lib/user-utils.ts @@ -57,7 +57,7 @@ export function getEmailFromGoogleProfile(profile: T.GoogleProfile): { email: st }; } -export async function upgradeUser(userId: T.UUID, subscriptionId?: string): Promise { +export async function upgradeUser(userId: T.UUID, subscription?: T.StripeSubscription): Promise { // add user to couchdb authentication db const { password, userDbName } = await addCouchDbAuthUser(userId); // // create user db @@ -67,7 +67,7 @@ export async function upgradeUser(userId: T.UUID, subscriptionId?: string): Prom wordlistDbName: userDbName, couchDbPassword: password, upgradeToStudentRequest: undefined, - subscriptionId, + subscription, }); if (user.email) { sendAccountUpgradeMessage(user).catch(console.error); diff --git a/account/src/routers/auth-router.ts b/account/src/routers/auth-router.ts index 8acb9f3..8b581eb 100644 --- a/account/src/routers/auth-router.ts +++ b/account/src/routers/auth-router.ts @@ -196,8 +196,8 @@ const authRouter = (passport: PassportStatic) => { if (!req.user) { return res.redirect("/"); } - await downgradeUser(req.user.userId, "subscriptionId" in req.user - ? req.user.subscriptionId + await downgradeUser(req.user.userId, "subscription" in req.user + ? req.user.subscription?.id : undefined); res.redirect("/"); } catch (e) { diff --git a/account/src/routers/payment-router.ts b/account/src/routers/payment-router.ts index 9217c03..626b211 100644 --- a/account/src/routers/payment-router.ts +++ b/account/src/routers/payment-router.ts @@ -54,7 +54,7 @@ paymentRouter.post( subscription = event.data.object; status = subscription.status; console.log(`Upgrading user ${userId}.`); - await upgradeUser(userId, subscription.id); + await upgradeUser(userId, subscription); // TODO: save subscription to db break; default: diff --git a/account/views/user.ejs b/account/views/user.ejs index cf3b111..371ce24 100644 --- a/account/views/user.ejs +++ b/account/views/user.ejs @@ -65,7 +65,7 @@
- +
@@ -75,6 +75,7 @@ <% } %> <% } %> <% if (user.tester && user.level === "student") { %> +

Downgrade your account to cancel your subscription