apps/recallassess/recallassess-api/src/config/stripe.config.ts
Methods |
Accessors |
| getDashboardAccountMode |
getDashboardAccountMode()
|
|
Stripe Dashboard deep links must use
Returns :
"test" | "live"
|
| hasPublishableKey |
hasPublishableKey()
|
|
Returns :
boolean
|
| isConfigured |
isConfigured()
|
|
Server-side Stripe API calls (subscriptions, webhooks, Checkout Sessions) only need the secret key. The publishable key is for client-side Stripe.js; missing publishable must not block jobs or webhooks.
Returns :
boolean
|
| secretKey |
getsecretKey()
|
| publishableKey |
getpublishableKey()
|
| webhookSecret |
getwebhookSecret()
|
import { optionalEnv } from "@bish-nest/core";
import { Injectable } from "@nestjs/common";
@Injectable()
export class StripeConfig {
// Stripe API Keys
get secretKey(): string {
return optionalEnv("STRIPE_SECRET_KEY", "");
}
get publishableKey(): string {
return optionalEnv("STRIPE_PUBLISHABLE_KEY", "");
}
get webhookSecret(): string {
return optionalEnv("STRIPE_WEBHOOK_SECRET", "");
}
/** One or more signing secrets (comma-separated). Stripe CLI `stripe listen` emits a new `whsec_` each run — append it without removing the Dashboard endpoint secret. */
getWebhookSecrets(): string[] {
return this.webhookSecret
.split(",")
.map((s) => s.trim())
.filter((s) => s.length > 0);
}
/**
* Server-side Stripe API calls (subscriptions, webhooks, Checkout Sessions) only need the secret key.
* The publishable key is for client-side Stripe.js; missing publishable must not block jobs or webhooks.
*/
isConfigured(): boolean {
return !!this.secretKey;
}
hasPublishableKey(): boolean {
return !!this.publishableKey;
}
/**
* Stripe Dashboard deep links must use `/test/` when the API key is test mode.
* See: https://dashboard.stripe.com/test/... vs https://dashboard.stripe.com/...
*/
getDashboardAccountMode(): "test" | "live" {
const sk = this.secretKey;
if (sk.startsWith("sk_live_") || sk.startsWith("rk_live_")) {
return "live";
}
return "test";
}
}