Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import Stripe from 'stripe'
|
|
|
|
/**
|
|
* Initialize Stripe client with secret key from environment
|
|
* This should only be used server-side
|
|
*/
|
|
export function getStripeClient(): Stripe {
|
|
const secretKey = process.env.STRIPE_SECRET_KEY
|
|
|
|
if (!secretKey) {
|
|
// In development, provide a helpful error message
|
|
if (process.env.NODE_ENV === 'development') {
|
|
throw new Error(
|
|
'STRIPE_SECRET_KEY is not set in environment variables.\n' +
|
|
'Please create a .env.local file with your Stripe API keys:\n' +
|
|
'STRIPE_PUBLISHABLE_KEY=pk_test_your_publishable_key_here\n' +
|
|
'STRIPE_SECRET_KEY=sk_test_your_secret_key_here'
|
|
)
|
|
}
|
|
throw new Error('STRIPE_SECRET_KEY is required for Stripe integration')
|
|
}
|
|
|
|
return new Stripe(secretKey, {
|
|
// Let Stripe use the default API version for maximum compatibility
|
|
apiVersion: '2024-12-18.acacia',
|
|
typescript: true,
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Initialize Stripe client for browser use
|
|
* This should only be used client-side
|
|
*/
|
|
export function getStripeBrowserClient() {
|
|
if (typeof window === 'undefined') {
|
|
throw new Error('getStripeBrowserClient should only be used client-side')
|
|
}
|
|
|
|
const publishableKey = process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
|
|
|
|
if (!publishableKey) {
|
|
if (process.env.NODE_ENV === 'development') {
|
|
throw new Error(
|
|
'NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY is not set in environment variables.\n' +
|
|
'Please create a .env.local file with your Stripe API keys:\n' +
|
|
'NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your_publishable_key_here'
|
|
)
|
|
}
|
|
throw new Error('Stripe publishable key is required for client-side integration')
|
|
}
|
|
|
|
return import('@stripe/stripe-js').then((stripeModule) => {
|
|
return stripeModule.loadStripe(publishableKey)
|
|
})
|
|
}
|
|
|