Rails.application.configure do # Try to get Stripe keys from environment variables first, then from credentials stripe_publishable_key = ENV["STRIPE_PUBLISHABLE_KEY"] stripe_secret_key = ENV["STRIPE_SECRET_KEY"] stripe_webhook_secret = ENV["STRIPE_WEBHOOK_SECRET"] # If not in environment variables, try to get from credentials if Rails.application.respond_to?(:credentials) && Rails.application.credentials.respond_to?(:stripe) stripe_credentials = Rails.application.credentials.stripe if stripe_credentials stripe_publishable_key ||= stripe_credentials[:publishable_key] if stripe_credentials.key?(:publishable_key) stripe_secret_key ||= stripe_credentials[:secret_key] if stripe_credentials.key?(:secret_key) stripe_webhook_secret ||= stripe_credentials[:webhook_secret] if stripe_credentials.key?(:webhook_secret) end end config.stripe = { publishable_key: stripe_publishable_key, secret_key: stripe_secret_key, signing_secret: stripe_webhook_secret } end # Note: Stripe.api_key is NOT set here - it will be set during checkout process Rails.logger.info "Stripe configuration loaded - will initialize during checkout"