All files / laravel-saas/resources/js/Components/billing StripeProvider.tsx

0% Statements 0/19
100% Branches 1/1
100% Functions 1/1
0% Lines 0/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32                                                               
import React from 'react';
import { loadStripe } from '@stripe/stripe-js';
import { Elements } from '@stripe/react-stripe-js';
 
const stripeKey = import.meta.env.VITE_STRIPE_KEY;
 
if (!stripeKey) {
    console.error('Stripe publishable key is not set. Please add VITE_STRIPE_KEY to your .env file.');
}
 
const stripePromise = stripeKey ? loadStripe(stripeKey) : null;
 
interface StripeProviderProps {
    children: React.ReactNode;
    options?: any;
}
 
export default function StripeProvider({ children, options }: StripeProviderProps) {
    if (!stripePromise) {
        return (
            <div className="text-center py-8">
                <p className="text-red-600">Stripe is not configured. Please contact support.</p>
            </div>
        );
    }
 
    return (
        <Elements stripe={stripePromise} options={options}>
            {children}
        </Elements>
    );
}