- Implement comprehensive email notification system for ticket purchases and event reminders - Add event reminder job with configurable scheduling - Enhance ticket mailer with QR code generation and proper formatting - Update order model with email delivery tracking - Add comprehensive test coverage for all email functionality - Configure proper mailer settings and disable annotations - Update backlog to reflect completed email features 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
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
|