Skip to content

Commit

Permalink
Fixes for payments
Browse files Browse the repository at this point in the history
Stop ticket request editing post purchase
Leave ability to set guests
fix logic and routing errors in payment process
  • Loading branch information
beingmattlevy committed May 27, 2024
1 parent e3d7e94 commit 80f4cdf
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 211 deletions.
15 changes: 9 additions & 6 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ def index
# event admin —> let them manage the event
return redirect_to events_path(most_recent_event)

elsif (ticket_request = TicketRequest.where(user: current_user)
.where(event: most_recent_event).last)

# This user already has a ticket request, so redirect there.s
return redirect_to event_ticket_request_path(event_id: most_recent_event.to_param, id: ticket_request.id)
elsif current_user.site_admin? || current_user.event_admin?

# redirect event admins to the events listing
return redirect_to events_path
end

# This user already has a ticket request, so redirect there
if (ticket_request = TicketRequest.where(user: current_user).where(event: most_recent_event).last)
return redirect_to event_ticket_request_path(event_id: most_recent_event.to_param, id: ticket_request.id)
end

# new ticket request
return redirect_to new_event_ticket_request_path(event_id: most_recent_event.to_param)

end

elsif signed_in? && current_user && (current_user.site_admin? || current_user.event_admin?)
Expand Down
14 changes: 6 additions & 8 deletions app/controllers/ticket_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def create
end

tr_params = permitted_params[:ticket_request].to_h || {}
tr_params[:donation] = 0 unless tr_params[:donation].present? && tr_params[:donation] =~ /^[\d.]+$/
if tr_params.empty?
flash.now[:error] = 'Please fill out the form below to request tickets.'
return render_flash(flash)
Expand All @@ -133,14 +132,15 @@ def create
target: @ticket_request
).fire!

if @event.tickets_require_approval || @ticket_request.free?
if (@event.tickets_require_approval || @ticket_request.free?) && @ticket_request.total_tickets > 1
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?
elsif !@ticket_request.all_guests_specified?
# 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.'
else
redirect_to new_payment_path(ticket_request_id: @ticket_request.id),
elsif @ticket_request.approved?
redirect_to event_ticket_request_payments_path(@event, @ticket_request),
notice: 'Please pay for your ticket(s).'
end
rescue StandardError => e
Expand All @@ -160,8 +160,6 @@ def update
.flatten.map(&:presence)
.compact

ticket_request_params[:donation] = 0 unless ticket_request_params[:donation].present? && ticket_request_params[:donation] =~ /^[\d.]+$/

ticket_request_params.delete(:guest_list)
ticket_request_params[:guests] = guests

Expand All @@ -188,7 +186,7 @@ def destroy

@ticket_request.destroy! if @ticket_request&.persisted?

redirect_to new_event_ticket_request_path(@event), notice: "Ticket Request ID #{ticket_request_id} was deleted."
redirect_to new_event_ticket_request_path(@event), notice: "Ticket Request was successfully deleted. (id: #{@ticket_request.id})"
end

def approve
Expand Down
10 changes: 7 additions & 3 deletions app/models/ticket_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def csv_columns
].freeze

STATUS_NAMES = {
'P' => 'Pending',
'P' => 'Pending Approval',
'A' => 'Waiting for Payment',
'D' => 'Declined',
'C' => 'Completed',
Expand Down Expand Up @@ -232,6 +232,10 @@ def approve
update status: (free? ? STATUS_COMPLETED : STATUS_AWAITING_PAYMENT)
end

def post_payment?
completed? || refunded?
end

def declined?
status == STATUS_DECLINED
end
Expand All @@ -245,12 +249,12 @@ def mark_refunded
end

def payment_received?
payment&.received?
payment&.received? || payment&.refunded?
end

# not able to purchase tickets in this state
def can_purchase?
!status.in? [STATUS_DECLINED, STATUS_PENDING]
!status.in? [STATUS_DECLINED, STATUS_REFUNDED]
end

def can_be_cancelled?(by_user:)
Expand Down
6 changes: 3 additions & 3 deletions app/views/payments/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
and are responsible for sharing these documents with your guests. You
further understand that you are responsible for the conduct of your guests
while they attend an FnF event. By making clear the values that inform our
events and setting the expectation of conduct at our events, we hope to
continue to embrace radical self-expression while continuing to invite new
and diverse people into our community.
events and setting the expectation of conduct at our events, we continue
to embrace radical self-expression while continuing to invite new and
diverse people into our community.

2 changes: 1 addition & 1 deletion app/views/shared/_nav_main.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- elsif current_user.event_admin?
= button_to "Manage Events", events_path, method: :get, class: "#{button_class}", data: { turbo: false }
- else
= button_to "Home", root_path, class: 'btn btn-primary m-1'
= button_to "Home", events_path, class: 'btn btn-primary m-1'
- else
- unless controller_name == 'sessions' && action_name == 'new' && request.path == '/users/sign_in'
= button_to "Log In", new_user_session_path, method: :get, class: "#{button_class}", data: { turbo: false }
Expand Down
Loading

0 comments on commit 80f4cdf

Please sign in to comment.