module StripeHelper # Check if Stripe is properly configured def stripe_configured? Rails.application.config.stripe[:secret_key].present? end # Initialize Stripe with the configured API key def initialize_stripe return false unless stripe_configured? Stripe.api_key = Rails.application.config.stripe[:secret_key] true rescue => e Rails.logger.error "Failed to initialize Stripe: #{e.message}" false end # Safely call Stripe methods with error handling def safe_stripe_call(&block) return nil unless stripe_configured? # Initialize Stripe if not already done initialize_stripe unless Stripe.api_key.present? begin yield if block_given? rescue Stripe::StripeError => e Rails.logger.error "Stripe Error: #{e.message}" nil end end end