feat: new secrets
This commit is contained in:
@@ -3,17 +3,11 @@ const { HttpsError } = require('firebase-functions/https')
|
||||
const Stripe = require('stripe')
|
||||
const { URL } = require('url')
|
||||
|
||||
const {
|
||||
STRIPE_SECRET_KEY = '',
|
||||
STRIPE_RETURN_URL = '',
|
||||
STRIPE_PORTAL_CONFIGURATION = '',
|
||||
STRIPE_MODE: CONFIG_STRIPE_MODE,
|
||||
} = require('../config/keys')
|
||||
const { STRIPE_SECRET_KEY } = require('../config/secrets')
|
||||
|
||||
const STRIPE_MODE =
|
||||
typeof CONFIG_STRIPE_MODE === 'string' && CONFIG_STRIPE_MODE.trim()
|
||||
? CONFIG_STRIPE_MODE.trim()
|
||||
: 'test'
|
||||
const STRIPE_RETURN_URL = process.env.STRIPE_RETURN_URL?.trim() || ''
|
||||
const STRIPE_PORTAL_CONFIGURATION = process.env.STRIPE_PORTAL_CONFIGURATION?.trim() || ''
|
||||
const STRIPE_MODE = process.env.STRIPE_MODE?.trim() || 'test'
|
||||
|
||||
const requireEnv = (key) => {
|
||||
const value = process.env?.[key]
|
||||
@@ -31,15 +25,9 @@ let cachedStripeClient = null
|
||||
let cachedPortalConfigurationId = null
|
||||
|
||||
const resolveStripeSecretKey = () => {
|
||||
const inlineKey = typeof STRIPE_SECRET_KEY === 'string' ? STRIPE_SECRET_KEY.trim() : ''
|
||||
|
||||
if (inlineKey) {
|
||||
return inlineKey
|
||||
}
|
||||
|
||||
const required = requireEnv('STRIPE_SECRET_KEY')
|
||||
if (typeof required === 'string' && required.trim()) {
|
||||
return required.trim()
|
||||
const secretKey = STRIPE_SECRET_KEY.value().trim()
|
||||
if (secretKey) {
|
||||
return secretKey
|
||||
}
|
||||
|
||||
throw new Error('STRIPE_SECRET_KEY not configured')
|
||||
|
||||
Reference in New Issue
Block a user