feat: Implement complete ticket purchasing flow with new TicketsController
- 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
This commit is contained in:
@@ -7,7 +7,7 @@ Erreur de traitement du paiement : No API key provided. Set your API key using "
|
||||
```
|
||||
|
||||
## Root Cause
|
||||
The error occurred because Stripe was being initialized at application startup, and if there were any configuration issues, it would affect the entire application.
|
||||
The error occurred because Stripe code was being called without the API key being properly set. This could happen in development environments or when environment variables were not properly configured.
|
||||
|
||||
## Solution Implemented - Lazy Initialization
|
||||
|
||||
@@ -15,13 +15,12 @@ The error occurred because Stripe was being initialized at application startup,
|
||||
- Stripe configuration is loaded at startup but API key is NOT set
|
||||
- Stripe.api_key is only set during the checkout process when needed
|
||||
|
||||
2. **Enhanced Stripe Helper** (`app/helpers/stripe_helper.rb`):
|
||||
- Added `initialize_stripe` method to initialize Stripe only when needed
|
||||
- Updated `safe_stripe_call` to automatically initialize Stripe if not already done
|
||||
2. **Stripe Concern** (`app/controllers/concerns/stripe_concern.rb`):
|
||||
- Created `StripeConcern` module with `stripe_configured?` and `initialize_stripe` methods
|
||||
- Included in `EventsController` to provide access to Stripe functionality
|
||||
|
||||
3. **Checkout Process Updates**:
|
||||
- Added explicit Stripe initialization in `process_payment` method
|
||||
- Added explicit Stripe initialization in `payment_success` method
|
||||
3. **Direct Configuration Checks**:
|
||||
- Updated `process_payment` and `payment_success` methods to directly check Stripe configuration
|
||||
- Added proper error handling for initialization failures
|
||||
|
||||
4. **Benefits of This Approach**:
|
||||
@@ -31,7 +30,7 @@ The error occurred because Stripe was being initialized at application startup,
|
||||
- More efficient resource usage (Stripe library only fully loaded during checkout)
|
||||
|
||||
5. **Verification**:
|
||||
- Created `bin/test_stripe_config.rb` to verify the lazy initialization approach
|
||||
- Created test scripts to verify the lazy initialization approach
|
||||
- Confirmed that Stripe is not initialized at startup but can be initialized during checkout
|
||||
|
||||
## Code Changes
|
||||
@@ -40,14 +39,16 @@ The error occurred because Stripe was being initialized at application startup,
|
||||
- Removed automatic Stripe.api_key initialization
|
||||
- Added informational log message
|
||||
|
||||
### app/helpers/stripe_helper.rb
|
||||
- Added `initialize_stripe` method
|
||||
- Enhanced `safe_stripe_call` method
|
||||
### app/controllers/concerns/stripe_concern.rb
|
||||
- Created new concern with `stripe_configured?` and `initialize_stripe` methods
|
||||
|
||||
### app/controllers/events_controller.rb
|
||||
- Added Stripe initialization in `process_payment` method
|
||||
- Added Stripe initialization in `payment_success` method
|
||||
- Updated error handling to use helper methods
|
||||
- Added direct Stripe configuration checks in `process_payment` method
|
||||
- Added direct Stripe configuration checks in `payment_success` method
|
||||
- Added comprehensive logging for debugging
|
||||
|
||||
### app/helpers/stripe_helper.rb
|
||||
- Kept `safe_stripe_call` method with updated logic
|
||||
|
||||
## Testing
|
||||
The new approach has been verified to work correctly:
|
||||
|
||||
Reference in New Issue
Block a user