fix: Only increment payment attempts when user actually attempts payment

- Remove payment attempt increment from checkout page load
- Add new increment_payment_attempt action triggered only on pay button click
- Update checkout JavaScript to make AJAX call before Stripe redirect
- Add proper error handling and button state management
- Prevent inflated payment attempt counts from page refreshes

This ensures payment attempts accurately reflect actual payment tries rather than page visits.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kbe
2025-09-02 23:16:31 +02:00
parent 0ba6634e99
commit 6965eb89fd
3 changed files with 57 additions and 20 deletions

View File

@@ -4,7 +4,7 @@
# Orders group multiple tickets together for better transaction management
class OrdersController < ApplicationController
before_action :authenticate_user!
before_action :set_order, only: [:show, :checkout, :retry_payment]
before_action :set_order, only: [:show, :checkout, :retry_payment, :increment_payment_attempt]
# Display order summary
def show
@@ -31,7 +31,6 @@ class OrdersController < ApplicationController
if Rails.application.config.stripe[:secret_key].present?
begin
@checkout_session = create_stripe_session
@order.increment_payment_attempt!
rescue => e
error_message = e.message.present? ? e.message : "Erreur Stripe inconnue"
Rails.logger.error "Stripe checkout session creation failed: #{error_message}"
@@ -40,6 +39,12 @@ class OrdersController < ApplicationController
end
end
# Increment payment attempt - called via AJAX when user clicks pay button
def increment_payment_attempt
@order.increment_payment_attempt!
render json: { success: true, attempts: @order.payment_attempts }
end
# Allow users to retry payment for failed/cancelled payments
def retry_payment
unless @order.can_retry_payment?