This fixes the 'data must be a String, QRSegment, or an Array' error that was preventing checkout completion. Changes: - Move email sending outside payment transaction to avoid rollback on email failure - Add error handling around PDF generation in mailers - Improve QR code data building with multiple fallback strategies - Use direct foreign key access instead of through associations for reliability - Add comprehensive logging for debugging QR code issues - Ensure checkout succeeds even if email/PDF generation fails The payment process will now complete successfully regardless of email issues, while still attempting to send confirmation emails with PDF attachments.
81 lines
2.2 KiB
Ruby
Executable File
81 lines
2.2 KiB
Ruby
Executable File
class TicketMailer < ApplicationMailer
|
|
def purchase_confirmation_order(order)
|
|
@order = order
|
|
@user = order.user
|
|
@event = order.event
|
|
@tickets = order.tickets
|
|
|
|
# Generate PDF attachments for all tickets
|
|
@tickets.each do |ticket|
|
|
begin
|
|
pdf = ticket.to_pdf
|
|
attachments["ticket-#{@event.name.parameterize}-#{ticket.qr_code[0..7]}.pdf"] = {
|
|
mime_type: "application/pdf",
|
|
content: pdf
|
|
}
|
|
rescue StandardError => e
|
|
Rails.logger.error "Failed to generate PDF for ticket #{ticket.id}: #{e.message}"
|
|
# Continue without PDF attachment rather than failing the entire email
|
|
end
|
|
end
|
|
|
|
mail(
|
|
to: @user.email,
|
|
subject: "Confirmation d'achat - #{@event.name}",
|
|
template_name: "purchase_confirmation"
|
|
)
|
|
end
|
|
|
|
def purchase_confirmation(ticket)
|
|
@ticket = ticket
|
|
@user = ticket.user
|
|
@event = ticket.event
|
|
|
|
# Generate PDF attachment
|
|
begin
|
|
pdf = @ticket.to_pdf
|
|
attachments["ticket-#{@event.name.parameterize}-#{@ticket.qr_code[0..7]}.pdf"] = {
|
|
mime_type: "application/pdf",
|
|
content: pdf
|
|
}
|
|
rescue StandardError => e
|
|
Rails.logger.error "Failed to generate PDF for ticket #{@ticket.id}: #{e.message}"
|
|
# Continue without PDF attachment rather than failing the entire email
|
|
end
|
|
|
|
mail(
|
|
to: @user.email,
|
|
subject: "Confirmation d'achat - #{@event.name}"
|
|
)
|
|
end
|
|
|
|
def event_reminder(user, event, days_before)
|
|
@user = user
|
|
@event = event
|
|
@days_before = days_before
|
|
|
|
# Get user's tickets for this event
|
|
@tickets = Ticket.joins(:order, :ticket_type)
|
|
.where(orders: { user: @user }, ticket_types: { event: @event }, status: "active")
|
|
|
|
return if @tickets.empty?
|
|
|
|
subject = case days_before
|
|
when 7
|
|
"Rappel : #{@event.name} dans une semaine"
|
|
when 1
|
|
"Rappel : #{@event.name} demain"
|
|
when 0
|
|
"C'est aujourd'hui : #{@event.name}"
|
|
else
|
|
"Rappel : #{@event.name} dans #{days_before} jours"
|
|
end
|
|
|
|
mail(
|
|
to: @user.email,
|
|
subject: subject,
|
|
template_name: "event_reminder"
|
|
)
|
|
end
|
|
end
|