Skip to content

Commit c7ab83f

Browse files
committed
refactor(polar): isolate sandbox conditional
1 parent 7334dff commit c7ab83f

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

.env.development

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
AUTH_BASE_URL="https://localhost:8000/api/auth"
33

44
CHECKOUT_SUCCESS_URL="https://localhost:3000/confirmation"
5+
6+
# Define whether to connect to Polar's `sandbox` environment
7+
SANDBOX="true"

src/lib/config/env.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export const {
1212
POLAR_WEBHOOK_SECRET,
1313
CHECKOUT_SUCCESS_URL,
1414
AUTH_BASE_URL,
15+
SANDBOX,
1516
} = process.env;
1617

1718
export const isDevEnv = NODE_ENV === "development";
1819
export const isProdEnv = NODE_ENV === "production";
20+
export const isSandbox = SANDBOX === "true";

src/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
SKIP_AUTH,
2020
isDevEnv,
2121
isProdEnv,
22+
isSandbox,
2223
} from "lib/config/env.config";
2324
import { dbPool as db } from "lib/db/db";
2425
import { users } from "lib/drizzle/schema";
@@ -93,7 +94,7 @@ app.get(
9394
Checkout({
9495
accessToken: POLAR_ACCESS_TOKEN,
9596
successUrl: CHECKOUT_SUCCESS_URL,
96-
server: isDevEnv ? "sandbox" : "production",
97+
server: isSandbox ? "sandbox" : "production",
9798
}),
9899
);
99100

@@ -107,7 +108,7 @@ app.get(
107108

108109
return customerId;
109110
},
110-
server: isDevEnv ? "sandbox" : "production",
111+
server: isSandbox ? "sandbox" : "production",
111112
}),
112113
);
113114

0 commit comments

Comments
 (0)