mirror of
https://github.com/wasp-lang/open-saas.git
synced 2025-09-26 19:46:54 +02:00
update stripe customer portal link validation
This commit is contained in:
@@ -85,7 +85,8 @@ app SaaSTemplate {
|
||||
("openai", "^4.24.1"),
|
||||
("lucide-react", "0.306.0"),
|
||||
("prettier", "3.1.1"),
|
||||
("prettier-plugin-tailwindcss", "0.5.11")
|
||||
("prettier-plugin-tailwindcss", "0.5.11"),
|
||||
("zod", "3.22.4")
|
||||
],
|
||||
}
|
||||
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export enum TierIds {
|
||||
HOBBY = 'hobby-tier',
|
||||
PRO = 'pro-tier',
|
||||
@@ -7,18 +9,42 @@ export enum TierIds {
|
||||
export const DOCS_URL = 'https://docs.opensaas.sh';
|
||||
export const BLOG_URL = 'https://docs.opensaas.sh/blog';
|
||||
|
||||
//get this link at https://dashboard.stripe.com/test/settings/billing/portal
|
||||
const isDev = process.env.NODE_ENV !== 'production';
|
||||
const customerPortalTestUrl = '<your-stripe-customer-portal-link>';
|
||||
const customerPortalProdUrl = undefined; // TODO: add before deploying to production
|
||||
const isDevEnv = process.env.NODE_ENV !== 'production';
|
||||
const customerPortalTestUrl = 'https://cool.com'; // TODO: find your test url at https://dashboard.stripe.com/test/settings/billing/portal
|
||||
const customerPortalProdUrl = 'https://cool.com'; // TODO: add before deploying to production
|
||||
|
||||
export const STRIPE_CUSTOMER_PORTAL_LINK = isDev ? customerPortalTestUrl : customerPortalProdUrl;
|
||||
export const STRIPE_CUSTOMER_PORTAL_LINK = isDevEnv
|
||||
? customerPortalTestUrl
|
||||
: customerPortalProdUrl;
|
||||
|
||||
checkStripePortalLinkExists(STRIPE_CUSTOMER_PORTAL_LINK);
|
||||
checkStripePortalLinksExist({ customerPortalTestUrl, customerPortalProdUrl });
|
||||
|
||||
function checkStripePortalLinkExists(link: string | undefined) {
|
||||
if (!link) {
|
||||
if (isDev) console.warn('\x1b[31m%s\x1b[0m', '⚠️ STRIPE_CUSTOMER_PORTAL_LINK is not defined.');
|
||||
if (!isDev) throw new Error('🚫 STRIPE_CUSTOMER_PORTAL_LINK is not defined');
|
||||
}
|
||||
type StripePortalUrls = {
|
||||
customerPortalTestUrl: string | undefined;
|
||||
customerPortalProdUrl: string | undefined;
|
||||
};
|
||||
|
||||
function checkStripePortalLinksExist(links: StripePortalUrls) {
|
||||
const schema = z.string().url();
|
||||
const testResult = schema.safeParse(links.customerPortalTestUrl);
|
||||
const prodResult = schema.safeParse(links.customerPortalProdUrl);
|
||||
let consoleMsg = {
|
||||
color: '\x1b[33m%s\x1b[0m',
|
||||
msg: '',
|
||||
};
|
||||
|
||||
if (testResult.success && prodResult.success) {
|
||||
consoleMsg.color = '\x1b[32m%s\x1b[0m';
|
||||
consoleMsg.msg =
|
||||
'✅ Both STRIPE_CUSTOMER_PORTAL_LINK links defined';
|
||||
} else if (!testResult.success && !prodResult.success) {
|
||||
consoleMsg.msg =
|
||||
'⛔️ STRIPE_CUSTOMER_PORTAL_LINK is not defined';
|
||||
} else if (!testResult.success) {
|
||||
consoleMsg.msg = '⛔️ STRIPE_CUSTOMER_PORTAL_LINK is not defined for test env';
|
||||
} else {
|
||||
consoleMsg.msg =
|
||||
'⛔️ STRIPE_CUSTOMER_PORTAL_LINK is not defined for prod env';
|
||||
}
|
||||
console.log(consoleMsg.color, consoleMsg.msg);
|
||||
}
|
||||
|
Reference in New Issue
Block a user