diff --git a/nuxt.config.ts b/nuxt.config.ts index 76df722..58350d5 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -78,6 +78,7 @@ export default defineNuxtConfig({ APP_LIMIT_APPS_TESTER_GROUPS: 100, APP_LIMIT_UPLOAD_SIZE: 83886080, // 80 mb APP_LIMIT_ARTIFACT: 5, + APP_DISABLE_BILLING: false, LOCAL_AUTHS: '', JWT_KEY: '', DB_URL: '', diff --git a/pages/account-settings/billing.vue b/pages/account-settings/billing.vue index 149d6d1..317eca4 100644 --- a/pages/account-settings/billing.vue +++ b/pages/account-settings/billing.vue @@ -3,6 +3,9 @@ +
+ Billing disabled +
diff --git a/server/api/auth/sign-in-google.post.ts b/server/api/auth/sign-in-google.post.ts index 702415b..0208cd9 100644 --- a/server/api/auth/sign-in-google.post.ts +++ b/server/api/auth/sign-in-google.post.ts @@ -22,25 +22,27 @@ export default defineEventHandler(async event => { const name = payload['name'] as string const email = payload['email'] as string const { token: userToken, appUserId, pUserId } = await generateUserToken(event, 'google', payload.sub!, email, name) - const userSubLms = await getUserSubscriptionLms(email) - if (userSubLms) { - const subAttrs = userSubLms.attributes - await syncUserSubscription(event, appUserId, pUserId, userSubLms.id, { - card_brand: subAttrs.card_brand || undefined, - created_at: subAttrs.created_at, - customer_id: subAttrs.customer_id, - ends_at: subAttrs.ends_at, - product_id: subAttrs.product_id, - product_name: subAttrs.product_name, - renews_at: subAttrs.renews_at, - status: subAttrs.status, - status_formatted: subAttrs.status_formatted, - updated_at: subAttrs.updated_at, - user_email: subAttrs.user_email, - user_name: subAttrs.user_name, - variant_id: subAttrs.variant_id, - variant_name: subAttrs.variant_name, - }) + if (isBillingEnabled(event)) { + const userSubLms = await getUserSubscriptionLms(email) + if (userSubLms) { + const subAttrs = userSubLms.attributes + await syncUserSubscription(event, appUserId, pUserId, userSubLms.id, { + card_brand: subAttrs.card_brand || undefined, + created_at: subAttrs.created_at, + customer_id: subAttrs.customer_id, + ends_at: subAttrs.ends_at, + product_id: subAttrs.product_id, + product_name: subAttrs.product_name, + renews_at: subAttrs.renews_at, + status: subAttrs.status, + status_formatted: subAttrs.status_formatted, + updated_at: subAttrs.updated_at, + user_email: subAttrs.user_email, + user_name: subAttrs.user_name, + variant_id: subAttrs.variant_id, + variant_name: subAttrs.variant_name, + }) + } } signInUser(event, userToken) const param = new URLSearchParams({ diff --git a/server/api/billing/checkout.get.ts b/server/api/billing/checkout.get.ts index 30066d9..ffc4f86 100644 --- a/server/api/billing/checkout.get.ts +++ b/server/api/billing/checkout.get.ts @@ -7,6 +7,12 @@ export type CustomerMetadata = { } export default defineEventHandler(async event => { + if (!isBillingEnabled(event)) { + throw createError({ + message: 'Billing disabled', + }) + } + const { checkoutOrigin } = getQuery(event) const db = event.context.drizzle const activeSub = await getUserSubFromDb(event) diff --git a/server/api/billing/current-billing.get.ts b/server/api/billing/current-billing.get.ts index a58b73b..b6fc6d4 100644 --- a/server/api/billing/current-billing.get.ts +++ b/server/api/billing/current-billing.get.ts @@ -2,6 +2,19 @@ import { defineEventHandler } from 'h3' import { syncUserSubscription } from './subscription-sync' export default defineEventHandler(async event => { + if (!isBillingEnabled(event)) { + return { + plan: '', + planPrice: 0, + status: '', + statusFormatted: '', + endsAt: '', + renewsAt: '', + isCancelled: false, + doNotShow: true, + } + } + const userSubLms = await getUserSubscriptionLms(event.context.auth.email!) if (userSubLms) { const subAttrs = userSubLms.attributes @@ -41,5 +54,6 @@ export default defineEventHandler(async event => { endsAt: userSub?.endsAt, renewsAt: userSub?.renewsAt, isCancelled: isCancelled, + doNotShow: false, } }) diff --git a/server/api/billing/toggle-subs.get.ts b/server/api/billing/toggle-subs.get.ts index 95cfd6b..6ffca2e 100644 --- a/server/api/billing/toggle-subs.get.ts +++ b/server/api/billing/toggle-subs.get.ts @@ -1,6 +1,12 @@ import { updateSubscription } from "@lemonsqueezy/lemonsqueezy.js" export default defineEventHandler(async event => { + if (!isBillingEnabled(event)) { + throw createError({ + message: 'Billing disabled', + }) + } + const { isCancel: isCancelStr } = getQuery(event) const isCancel = isCancelStr === 'true' const subs = await getUserSubFromDb(event) diff --git a/server/api/billing/update-payment.get.ts b/server/api/billing/update-payment.get.ts index 3de326e..088c93b 100644 --- a/server/api/billing/update-payment.get.ts +++ b/server/api/billing/update-payment.get.ts @@ -1,4 +1,10 @@ export default defineEventHandler(async event => { + if (!isBillingEnabled(event)) { + throw createError({ + message: 'Billing disabled', + }) + } + const subscription = await getUserSubFromDb(event) const { updatePaymentMethod } = await getUrlsSubscription(subscription!.subscriptionId) return updatePaymentMethod diff --git a/server/utils/user-utils.ts b/server/utils/user-utils.ts index 209c5f2..e28cd31 100644 --- a/server/utils/user-utils.ts +++ b/server/utils/user-utils.ts @@ -64,4 +64,9 @@ export function checkIsExpire(gracePeriodHour: number, endsAt: Date) { const now = new Date() now.setHours(now.getHours() - gracePeriodHour) return (endsAt.getTime() - now.getTime()) <= 0 +} + +export function isBillingEnabled(event: H3Event) { + const { APP_DISABLE_BILLING } = useRuntimeConfig(event) + return !APP_DISABLE_BILLING } \ No newline at end of file