Skip to content

Commit 35d7a59

Browse files
committed
update stripe customer portal link validation
1 parent 6c98e15 commit 35d7a59

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

app/main.wasp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ app SaaSTemplate {
8585
("openai", "^4.24.1"),
8686
("lucide-react", "0.306.0"),
8787
("prettier", "3.1.1"),
88-
("prettier-plugin-tailwindcss", "0.5.11")
88+
("prettier-plugin-tailwindcss", "0.5.11"),
89+
("zod", "3.22.4")
8990
],
9091
}
9192

app/src/shared/constants.ts

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { z } from 'zod';
2+
13
export enum TierIds {
24
HOBBY = 'hobby-tier',
35
PRO = 'pro-tier',
@@ -7,18 +9,42 @@ export enum TierIds {
79
export const DOCS_URL = 'https://docs.opensaas.sh';
810
export const BLOG_URL = 'https://docs.opensaas.sh/blog';
911

10-
//get this link at https://dashboard.stripe.com/test/settings/billing/portal
11-
const isDev = process.env.NODE_ENV !== 'production';
12-
const customerPortalTestUrl = '<your-stripe-customer-portal-link>';
13-
const customerPortalProdUrl = undefined; // TODO: add before deploying to production
12+
const isDevEnv = process.env.NODE_ENV !== 'production';
13+
const customerPortalTestUrl = 'https://cool.com'; // TODO: find your test url at https://dashboard.stripe.com/test/settings/billing/portal
14+
const customerPortalProdUrl = 'https://cool.com'; // TODO: add before deploying to production
15+
16+
export const STRIPE_CUSTOMER_PORTAL_LINK = isDevEnv
17+
? customerPortalTestUrl
18+
: customerPortalProdUrl;
19+
20+
checkStripePortalLinksExist({ customerPortalTestUrl, customerPortalProdUrl });
1421

15-
export const STRIPE_CUSTOMER_PORTAL_LINK = isDev ? customerPortalTestUrl : customerPortalProdUrl;
22+
type StripePortalUrls = {
23+
customerPortalTestUrl: string | undefined;
24+
customerPortalProdUrl: string | undefined;
25+
};
1626

17-
checkStripePortalLinkExists(STRIPE_CUSTOMER_PORTAL_LINK);
27+
function checkStripePortalLinksExist(links: StripePortalUrls) {
28+
const schema = z.string().url();
29+
const testResult = schema.safeParse(links.customerPortalTestUrl);
30+
const prodResult = schema.safeParse(links.customerPortalProdUrl);
31+
let consoleMsg = {
32+
color: '\x1b[33m%s\x1b[0m',
33+
msg: '',
34+
};
1835

19-
function checkStripePortalLinkExists(link: string | undefined) {
20-
if (!link) {
21-
if (isDev) console.warn('\x1b[31m%s\x1b[0m', '⚠️ STRIPE_CUSTOMER_PORTAL_LINK is not defined.');
22-
if (!isDev) throw new Error('🚫 STRIPE_CUSTOMER_PORTAL_LINK is not defined');
23-
}
36+
if (testResult.success && prodResult.success) {
37+
consoleMsg.color = '\x1b[32m%s\x1b[0m';
38+
consoleMsg.msg =
39+
'✅ Both STRIPE_CUSTOMER_PORTAL_LINK links defined';
40+
} else if (!testResult.success && !prodResult.success) {
41+
consoleMsg.msg =
42+
'⛔️ STRIPE_CUSTOMER_PORTAL_LINK is not defined';
43+
} else if (!testResult.success) {
44+
consoleMsg.msg = '⛔️ STRIPE_CUSTOMER_PORTAL_LINK is not defined for test env';
45+
} else {
46+
consoleMsg.msg =
47+
'⛔️ STRIPE_CUSTOMER_PORTAL_LINK is not defined for prod env';
48+
}
49+
console.log(consoleMsg.color, consoleMsg.msg);
2450
}

0 commit comments

Comments
 (0)