- Create new TicketsController with actions for name collection, creation, and checkout - Add dedicated ticket views (new.html.erb, checkout.html.erb, show.html.erb) - Update ticket_selection_controller.js to handle form submission via AJAX - Add store_cart endpoint in EventsController for session-based cart management - Update routes to support new ticket flow: /tickets/new, /create, /checkout - Fix attribute name consistency across views (title→name, starts_at→start_time) - Add Stripe checkout integration with proper error handling - Remove deprecated collect_names flow in favor of streamlined approach The flow is now: Event selection → AJAX cart storage → Name collection → Checkout → Payment
40 lines
1.7 KiB
Ruby
Executable File
40 lines
1.7 KiB
Ruby
Executable File
Rails.application.configure do
|
|
# Load environment variables from .env file if dotenv is not available
|
|
env_file = Rails.root.join('.env')
|
|
if File.exist?(env_file) && !defined?(Dotenv)
|
|
File.readlines(env_file).each do |line|
|
|
next if line.strip.empty? || line.start_with?('#')
|
|
key, value = line.split('=', 2)
|
|
ENV[key.strip] = value.strip if key && value
|
|
end
|
|
end
|
|
|
|
# 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
|
|
}
|
|
|
|
# Initialize Stripe API key at application startup if secret key is present
|
|
if stripe_secret_key.present?
|
|
Stripe.api_key = stripe_secret_key
|
|
Rails.logger.info "Stripe initialized at application startup"
|
|
else
|
|
Rails.logger.warn "Stripe secret key not found - Stripe will not be initialized"
|
|
end
|
|
end |