diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index f9c6d41..5e61d2c 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -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? diff --git a/app/views/orders/checkout.html.erb b/app/views/orders/checkout.html.erb index ec96e86..98233d5 100644 --- a/app/views/orders/checkout.html.erb +++ b/app/views/orders/checkout.html.erb @@ -180,7 +180,7 @@ diff --git a/config/routes.rb b/config/routes.rb index 2b996cb..b35b17b 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,6 +43,7 @@ Rails.application.routes.draw do member do get :checkout post :retry_payment + post :increment_payment_attempt end end