diff --git a/account/src/routers/payment-router.ts b/account/src/routers/payment-router.ts index 626b211..727191c 100644 --- a/account/src/routers/payment-router.ts +++ b/account/src/routers/payment-router.ts @@ -85,14 +85,16 @@ paymentRouter.post("/create-checkout-session", async (req, res, next) => { billing_address_collection: 'auto', line_items: [ { - price, - quantity: 1, + price, + quantity: 1, }, ], subscription_data: { metadata: { userId: req.user.userId, startTime: Date.now(), + cycle: price === "price_1Lt0XdJnpCQCjf9pM9qqdyt6" + ? "monthly" : "yearly", }, }, mode: 'subscription', diff --git a/account/views/user.ejs b/account/views/user.ejs index 371ce24..6cd9250 100644 --- a/account/views/user.ejs +++ b/account/views/user.ejs @@ -65,20 +65,19 @@
- +
- +
<% } %> <% } %> - <% if (user.tester && user.level === "student") { %> + <% if (user.tester && user.level === "student" && user.subscription) { %> +

Current subscription: <% if (user.subscription.metadata.cycle === "monthly") { %>$1/month<% } else { %>$10/year<% } %>

Downgrade your account to cancel your subscription

-
- -
+ <% } %> <% if (user.email) { %>

Password

@@ -229,6 +228,19 @@ }); } } + function handleDowngrade() { + const answer = confirm("Are you sure you want to downgrade your account? Your wordlist will be deleted forever. (Export it to CSV from the dictionary if you want to keep it)"); + if (answer) { + fetch("/downgradeToBasic", { method: "POST" }).then((res) => res.json()).then((res) => { + if (res.ok) { + window.location = "/"; + } + }).catch((err) => { + alert("Error downgrading account - check your connection"); + console.error(err); + }); + } + } window.addEventListener('keydown', (e) => { // prevent an enter from submitting the form if (e.keyCode === 13) {