diff --git a/packages/pockethost/src/mothership-app/pb_hooks/mothership.js b/packages/pockethost/src/mothership-app/pb_hooks/mothership.js index a2385b35..ae7d0673 100644 --- a/packages/pockethost/src/mothership-app/pb_hooks/mothership.js +++ b/packages/pockethost/src/mothership-app/pb_hooks/mothership.js @@ -679,9 +679,14 @@ const HandleLemonSqueezySale = (c) => { audit(`LS`, `Signup processed.`, context); }; const signup_canceller = () => { - userRec.set(`subscription`, `free`); - userRec.set(`subscription_quantity`, 0); - userRec.set(`subscription_interval`, ``); + if (userRec.get(`subscription`) !== `premium`) return; + const currentQuantity = userRec.get(`subscription_quantity`); + const newQuantity = Math.max(currentQuantity - (context.quantity || 1), 0); + userRec.set(`subscription_quantity`, newQuantity); + if (newQuantity === 0) { + userRec.set(`subscription`, `free`); + userRec.set(`subscription_interval`, ``); + } dao.saveRecord(userRec); log(`saved user`); audit(`LS`, `Signup cancelled.`, context); diff --git a/packages/pockethost/src/mothership-app/pb_hooks/mothership.pb.js b/packages/pockethost/src/mothership-app/pb_hooks/mothership.pb.js index b3104002..fa6ccca7 100644 --- a/packages/pockethost/src/mothership-app/pb_hooks/mothership.pb.js +++ b/packages/pockethost/src/mothership-app/pb_hooks/mothership.pb.js @@ -9,9 +9,6 @@ routerAdd("POST", "/api/instance", (c) => { routerAdd("DELETE", "/api/instance/:id", (c) => { return require(`${__hooks}/mothership`).HandleInstanceDelete(c); }, $apis.requireRecordAuth()); -routerAdd("POST", "/api/instance/:id/webhook/test", (c) => { - return require(`${__hooks}/mothership`).HandleInstanceWebhookTest(c); -}, $apis.requireRecordAuth()); routerAdd("GET", "/api/instance/resolve", (c) => { return require(`${__hooks}/mothership`).HandleInstanceResolve(c); }, $apis.requireAdminAuth()); diff --git a/packages/pockethost/src/mothership-app/src/lib/handlers/lemon/api/HandleLemonSqueezySale.ts b/packages/pockethost/src/mothership-app/src/lib/handlers/lemon/api/HandleLemonSqueezySale.ts index 6318f16b..fdcf7331 100644 --- a/packages/pockethost/src/mothership-app/src/lib/handlers/lemon/api/HandleLemonSqueezySale.ts +++ b/packages/pockethost/src/mothership-app/src/lib/handlers/lemon/api/HandleLemonSqueezySale.ts @@ -265,9 +265,17 @@ export const HandleLemonSqueezySale = (c: echo.Context) => { } const signup_canceller = () => { - userRec.set(`subscription`, `free`) - userRec.set(`subscription_quantity`, 0) - userRec.set(`subscription_interval`, ``) + if (userRec.get(`subscription`) !== `premium`) { + return + } + const currentQuantity = userRec.get(`subscription_quantity`) + const newQuantity = Math.max(currentQuantity - (context.quantity || 1), 0) + userRec.set(`subscription_quantity`, newQuantity) + + if (newQuantity === 0) { + userRec.set(`subscription`, `free`) + userRec.set(`subscription_interval`, ``) + } dao.saveRecord(userRec) log(`saved user`) audit(`LS`, `Signup cancelled.`, context)