Skip to content

Commit

Permalink
Merge pull request #267 from fnf-org/mfl/request_cconfirmed
Browse files Browse the repository at this point in the history
request confirmed mailer
  • Loading branch information
beingmattlevy authored Aug 23, 2024
2 parents 434c1d1 + 982fd6b commit d2be814
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.8
1.3.9
1 change: 1 addition & 0 deletions app/classes/fnf/events/ticket_request_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TicketRequestEvent < AbstractEvent

def initialize(user: nil, target: nil)
super
Rails.logger.info("TicketRequestEvent: target: #{target}")
self.ticket_request = target
end
end
Expand Down
44 changes: 21 additions & 23 deletions app/controllers/ticket_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,25 @@ def create
@ticket_request.save!
Rails.logger.info("Saved Ticket Request, ID = #{@ticket_request.id}")

FnF::Events::TicketRequestEvent.new(
user: ticket_request_user,
target: @ticket_request
).fire!
if @event.tickets_require_approval
TicketRequestMailer.request_received(@ticket_request).deliver_later

if @event.tickets_require_approval && @ticket_request.total_tickets > 1
Rails.logger.debug { "tr approval: #{@ticket_request.inspect}" }
redirect_to event_ticket_request_path(@event, @ticket_request),
notice: 'When you know your guest names, please return here and add them below.'
elsif !@ticket_request.all_guests_specified?
Rails.logger.debug { "tr NOT all guests specified: #{@ticket_request.inspect}" }
# XXX there is a bug here that flashes this when only 1 ticket being purchased.
redirect_to edit_event_ticket_request_path(@event, @ticket_request),
notice: 'Please enter the guest names before you are able to pay for the ticket.'
elsif !@event.tickets_require_approval || @ticket_request.approved?
Rails.logger.debug { "tr please pay: #{@ticket_request.inspect}" }
redirect_to event_ticket_request_payments_path(@event, @ticket_request),
notice: 'Please pay for your ticket(s).'
else
TicketRequestMailer.request_confirmed(@ticket_request).deliver_later

if !@ticket_request.all_guests_specified?
Rails.logger.debug { "tr NOT all guests specified: #{@ticket_request.inspect}" }
redirect_to edit_event_ticket_request_path(@event, @ticket_request),
notice: 'Please enter the guest names before you are able to pay for the ticket.'

elsif @ticket_request.approved?
Rails.logger.debug { "tr please pay: #{@ticket_request.inspect}" }
redirect_to event_ticket_request_payments_path(@event, @ticket_request),
notice: 'Please pay for your ticket(s).'
end
end
rescue StandardError => e
Rails.logger.error("Error Processing Ticket Send Request: #{e.message}\n\n#{@ticket_request.errors.full_messages.join(', ')}")
Expand Down Expand Up @@ -194,11 +195,10 @@ def destroy
end

def approve
# update approved
if @ticket_request.approve
::FnF::Events::TicketRequestApprovedEvent.new(
user: current_user,
target: @ticket_request
).fire!
TicketRequestMailer.request_approved(@ticket_request).deliver_later

redirect_to event_ticket_requests_path(@event),
notice: "#{@ticket_request.user.name}'s request was approved"
else
Expand All @@ -208,11 +208,9 @@ def approve
end

def decline
if @ticket_request.update(status: TicketRequest::STATUS_DECLINED)
::FnF::Events::TicketRequestDeclinedEvent.new(
user: current_user,
target: @ticket_request
).fire!
if @ticket_request.mark_declined
TicketRequestMailer.request_denied(@ticket_request).deliver_later

redirect_to event_ticket_requests_path(@event),
error: "#{@ticket_request.user.name}'s request was declined"
else
Expand Down
63 changes: 56 additions & 7 deletions app/mailers/ticket_request_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,36 @@ def request_received(ticket_request)
mail to: to_email, # The recipient of the email
from: from_email, # The sender of the email
reply_to: reply_to_email, # The email address that will receive replies
subject: "#{@event.name} ticket request confirmation" # The subject of the email
subject: "#{@event.name} ticket request received!" # The subject of the email
end

# The `request_confirmed` method is used to send an email when a ticket request is confirmed without approval.
# It sets the ticket request and then sends an email to the user who made the request.
#
# @param ticket_request [TicketRequest] The ticket request that has been confirmed
# @return [Mail::Message] The email that has been prepared to be sent.
def request_confirmed(ticket_request)
# Set the ticket request
self.ticket_request = ticket_request

# Generate an authentication token for the user
@auth_token = ticket_request&.user&.generate_auth_token!

# Return if the authentication token is blank
if @auth_token.blank?
Rails.logger.warn { "request_confirmed: no auth token for user: #{@ticket_request.inspect}" }
return
end

@payment_url = new_event_ticket_request_payment_url(@event, @ticket_request, @auth_token)
@ticket_request_url = event_ticket_request_url(event_id: @event.id, id: @ticket_request.id)
Rails.logger.debug { "request_confirmed: payment_url: #{@payment_url} ticket_request_url: #{@ticket_request_url}" }

# Prepare the email to be sent
mail to: to_email, # The recipient of the email
from: from_email, # The sender of the email
reply_to: reply_to_email, # The email address that will receive replies
subject: "#{@event.name} ticket confirmation!" # The subject of the email
end

# The `request_approved` method is used to send an email when a ticket request is approved.
Expand All @@ -39,18 +68,34 @@ def request_approved(ticket_request)
# Generate an authentication token for the user
@auth_token = ticket_request&.user&.generate_auth_token!

@payment_url = new_event_ticket_request_payment_url(@event, @ticket_request, @auth_token)

# Return if the authentication token is blank
return if @auth_token.blank?

@payment_url = new_event_ticket_request_payment_url(@event, @ticket_request, @auth_token)
@ticket_request_url = event_ticket_request_url(event_id: @event.id, id: @ticket_request.id)

# Prepare the email to be sent
mail to: to_email, # The recipient of the email
from: from_email, # The sender of the email
reply_to: reply_to_email, # The email address that will ¬receive replies
subject: "Your #{@event.name} ticket request has been approved!" # The subject of the email
end

# The `request_denied` method is used to send an email when a ticket request is denied for reasons.
# @param ticket_request [TicketRequest] The ticket request that has been denied.
#
# @return [Mail::Message, nil] The email that has been prepared to be sent, or nil if the authentication token is blank.
def request_denied(ticket_request)
# Set the ticket request
self.ticket_request = ticket_request

# Prepare the email to be sent
mail to: to_email, # The recipient of the email
from: from_email, # The sender of the email
reply_to: reply_to_email, # The email address that will ¬receive replies
subject: "Your #{@event.name} ticket request" # The subject of the email
end

private

def ticket_request=(ticket_request)
Expand All @@ -68,15 +113,19 @@ def mail_config
end

def ticket_request(event)
request_received(event.ticket_request).deliver_now
request_received(event.ticket_request).deliver_later
end

def ticket_request_confirmed(event)
request_confirmed(event.ticket_request).deliver_later
end

def ticket_request_approved(event)
request_approved(event.ticket_request).deliver_now
request_approved(event.ticket_request).deliver_later
end

def ticket_request_declined(_)
# Not yet implemented
def ticket_request_declined(event)
request_denied(event.ticket_request).deliver_later
end
end
end
4 changes: 4 additions & 0 deletions app/models/ticket_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ def mark_refunded
update status: STATUS_REFUNDED
end

def mark_declined
update status: STATUS_DECLINED
end

def payment_received?
payment&.status_received?
end
Expand Down
21 changes: 13 additions & 8 deletions app/views/ticket_request_mailer/request_approved.html.haml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
%p
Hi #{@ticket_request.user.first_name},

%p
Your ticket request for
%b #{@event.name}
has been approved!

%p<>
%p
- if @ticket_request.free?
You're good to go!
- else
You can now
= succeed '.' do
= link_to @payment_url do
purchase your
= 'ticket'.pluralize(@ticket_request.total_tickets)
You can
= link_to @payment_url do
buy your
= 'ticket'.pluralize(@ticket_request.total_tickets)
now!

%p
Thanks,
With love ❤️,
%br
The FnF Ticket Team
Your FnF Ticket Team

%p
P.S. You can view the status of your request at any time by visiting
= link_to 'this page', @ticket_request_url
39 changes: 39 additions & 0 deletions app/views/ticket_request_mailer/request_confirmed.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%p
Hi #{@ticket_request.user.first_name},

%p
Your
= 'ticket'.pluralize(@ticket_request.total_tickets)
for
%b #{@event.name}
- @ticket_request.total_tickets > 1 ? ' are ' : ' is '
confirmed!

%p
Total Tickets: #{@ticket_request.total_tickets}
- if @ticket_request.ticket_request_event_addons?
%br
Event Addons:
- @ticket_request.active_sorted_addons.each do |tr_event_addon|
= "#{tr_event_addon.name}: #{tr_event_addon.quantity}"
%br
%p
- if @ticket_request.free?
You're good to go!
- else
If you have not already paid for your tickets,
= link_to @payment_url do
buy your tickets now!

%p
With love ❤️,
%br
Your FnF Ticket Team

%p
P.S. You can view the status of your request at any time by visiting
= link_to 'this page', @ticket_request_url

%p
%p
%i This email was generated by a very friendly hamster at: #{Time.now}
13 changes: 13 additions & 0 deletions app/views/ticket_request_mailer/request_denied.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%p
Hi #{@ticket_request.user.first_name},
%p
Your ticket request for
%b #{@event.name}
has been declined or denied.

%p
If you feel that this is an error, or would like more information,
please reply directly to this email.

%p
\- The FnF Ticket Team
10 changes: 8 additions & 2 deletions app/views/ticket_request_mailer/request_received.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
Hi #{@ticket_request.user.first_name},

%p
We have received your ticket request for #{@event.name} for
#{@ticket_request.total_tickets} total tickets (including kids).
We have received your ticket request for #{@event.name}

%p
Total Tickets: #{@ticket_request.total_tickets}
%br
- @ticket_request.active_sorted_addons.each do |tr_event_addon|
Event Addons:
= "#{tr_event_addon.name}: #{tr_event_addon.quantity}"

%p
If your request is approved, we will send you confirmation of the approved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

%tr
%th.text-nowrap.bg-dark-subtle.text-left Tickets Status
%th.bg-dark-subtle.text-end.optional-medium Requests
%th.bg-dark-subtle.text-end Requests
%th.bg-dark-subtle.text-end Tickets
- if event.kid_ticket_price
%th.bg-dark-subtle.text-end Kids Tix
Expand All @@ -36,7 +36,7 @@
%tr.fs-6
%td.bg-success-subtle
%span.text-nowrap Paid
%td.text-end.bg-success-subtle.optional-medium
%td.text-end.bg-success-subtle
%span= stats[:completed][:requests]
%td.text-end.bg-success-subtle
%span= stats[:completed][:adults]
Expand All @@ -60,7 +60,7 @@
%tr.fs-6
%td.text-nowrap.bg-warning
Pending Approval
%td.text-end.bg-warning.optional-medium= stats[:pending][:requests]
%td.text-end.bg-warning= stats[:pending][:requests]
%td.text-end.bg-warning= stats[:pending][:adults]
- if event.kid_ticket_price
%td.text-end.bg-warning= stats[:pending][:kids]
Expand All @@ -77,7 +77,7 @@
%tr.fs-6
%td.text-nowrap.bg-warning-subtle
Awaiting Payment
%td.text-end.bg-warning-subtle.optional-medium= stats[:awaiting_payment][:requests]
%td.text-end.bg-warning-subtle= stats[:awaiting_payment][:requests]
%td.text-end.bg-warning-subtle= stats[:awaiting_payment][:adults]
- if event.kid_ticket_price
%td.text-end.bg-warning-subtle= stats[:awaiting_payment][:kids]
Expand All @@ -95,7 +95,7 @@
%td.bg-dark-subtle.text-start
%strong
Total
%td.bg-dark-subtle.text-end.optional-medium= stats[:total][:requests]
%td.bg-dark-subtle.text-end= stats[:total][:requests]
%td.bg-dark-subtle.text-end= stats[:total][:adults]
- if event.kid_ticket_price
%td.bg-dark-subtle.text-end= stats[:total][:kids]
Expand Down
20 changes: 10 additions & 10 deletions app/views/ticket_requests/_table_ticket_requests.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
%tr
%th.bg-dark-subtle Name
- if event.require_role
%th.bg-dark-subtle.optional-medium Role
%th.bg-dark-subtle Role
%th.bg-dark-subtle Notes
%th.bg-dark-subtle.text-end.optional-medium Tickets
%th.bg-dark-subtle.text-end Tickets
- if event.kid_ticket_price
%th.bg-dark-subtle.text-end.optional-medium Kids
%th.bg-dark-subtle.text-end Kids
- if event.allow_donations
%th.bg-dark-subtle.text-end.optional-medium Donation
%th.bg-dark-subtle.text-end Donation
%th.bg-dark-subtle.text-end Total
%th.bg-dark-subtle.text-end.optional-medium Date Requested
%th.bg-dark-subtle.text-end Date Requested
%th.bg-dark-subtle.text-center Status
%th.bg-dark-subtle.text-center Payment
%th.bg-dark-subtle.text-center Payments


%tbody.border-dark-subtle.border-2
Expand All @@ -31,7 +31,7 @@
-# If we role is required for the event, add the column for role
- if event.require_role
%td.muted.align-content-center.optional-medium
%td.muted.align-content-center
= TicketRequest::ROLES[ticket_request.role]
%i.icon-comment.hover-tooltip{ title: ticket_request.role_explanation }
Expand All @@ -52,13 +52,13 @@
= tooltip_box(ticket_request.admin_notes, title: "Admin Notes") do
= image_tag('icons/comments-admin.png', width: 20, class: 'hover-tooltip')
%td.align-content-center.text-end.optional-medium= ticket_request.adults
%td.align-content-center.text-end= ticket_request.adults
- if event.kid_ticket_price
%td.align-content-center.text-end.optional-medium= ticket_request.kids
%td.align-content-center.text-end= ticket_request.kids
- if event.allow_donations
%td.align-content-center.text-end.optional-medium
%td.align-content-center.text-end
= number_to_currency(ticket_request.donation, precision: 0)
%td.align-content-center.text-end
Expand Down
Loading

0 comments on commit d2be814

Please sign in to comment.