feat: Internal invoice generation
- TODO: make use of Stripe invoice
This commit is contained in:
@@ -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, :increment_payment_attempt ]
|
||||
before_action :set_order, only: [ :show, :checkout, :retry_payment, :increment_payment_attempt, :invoice ]
|
||||
before_action :set_event, only: [ :new, :create ]
|
||||
|
||||
# Display new order form with name collection
|
||||
@@ -157,6 +157,26 @@ class OrdersController < ApplicationController
|
||||
redirect_to checkout_order_path(@order)
|
||||
end
|
||||
|
||||
# Display invoice for an order
|
||||
def invoice
|
||||
unless @order.status == "paid" || @order.status == "completed"
|
||||
redirect_to order_path(@order), alert: "La facture n'est disponible qu'après le paiement de la commande"
|
||||
return
|
||||
end
|
||||
|
||||
@tickets = @order.tickets.includes(:ticket_type)
|
||||
|
||||
# Get the Stripe invoice if it exists
|
||||
begin
|
||||
@stripe_invoice_id = @order.create_stripe_invoice!
|
||||
@stripe_invoice_pdf_url = @order.stripe_invoice_pdf_url if @stripe_invoice_id
|
||||
rescue => e
|
||||
Rails.logger.error "Failed to retrieve or create Stripe invoice for order #{@order.id}: #{e.message}"
|
||||
@stripe_invoice_id = nil
|
||||
@stripe_invoice_pdf_url = nil
|
||||
end
|
||||
end
|
||||
|
||||
# Handle successful payment
|
||||
def payment_success
|
||||
session_id = params[:session_id]
|
||||
|
||||
Reference in New Issue
Block a user