Skip to content

Commit

Permalink
Fix purchase button state
Browse files Browse the repository at this point in the history
Only allow when not in pending or declined
  • Loading branch information
beingmattlevy committed May 13, 2024
1 parent a4a70b9 commit 4a76209
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
5 changes: 5 additions & 0 deletions app/models/ticket_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ def payment_received?
payment.try(:stripe_payment_id) && payment.received?
end

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

def refund
if refunded?
errors.add(:base, 'Cannot refund a ticket that has already been refunded')
Expand Down
59 changes: 30 additions & 29 deletions app/views/ticket_requests/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,37 @@
%span.p-1{ class: text_class_for_status(@ticket_request) }
= @ticket_request.status_name

%tr
%td.text-end.small.p-2.px-4.text-nowrap= "Payment:"
%td
%strong
- if @payment&.received?
- if @ticket_request.refunded?
%span.bg-success Refunded
- else
.bg-success
= link_to 'Received', event_ticket_request_payment_path(@payment, @ticket_request)

- if @event.admin?(current_user)
= link_to 'Refund', refund_event_ticket_request_path(@event, @ticket_request),
method: :post,
class: 'btn btn-sm btn-danger',
data: { confirm: "Are you sure you want to refund #{@ticket_request.user.name}'s ticket? This cannot be undone!",
disable_with: 'Refunding...' }
- elsif @ticket_request.free?
.text-success
Free
- else
- if @event.ticket_sales_open?
= link_to 'Purchase your ticket now',
new_event_ticket_request_payment_path(@event, @ticket_request),
class: 'btn btn-primary m-0'
- if @ticket_request.can_purchase?
%tr
%td.text-end.small.p-2.px-4.text-nowrap= "Payment:"
%td
%strong
- if @ticket_request.payment_received?
- if @ticket_request.refunded?
%span.bg-success Refunded
- else
.bg-success
= link_to 'Received', event_ticket_request_payment_path(@payment, @ticket_request)

- if @event.admin?(current_user)
= link_to 'Refund', refund_event_ticket_request_path(@event, @ticket_request),
method: :post,
class: 'btn btn-sm btn-danger',
data: { confirm: "Are you sure you want to refund #{@ticket_request.user.name}'s ticket? This cannot be undone!",
disable_with: 'Refunding...' }
- elsif @ticket_request.free?
.text-success
Free
- else
%span.bg-warning
Unfortunately, ticket sales are now closed. You can no longer purchase your
= succeed '.' do
= 'ticket'.pluralize(@ticket_request.total_tickets)
- if @event.ticket_sales_open?
= link_to 'Purchase your ticket now',
new_event_ticket_request_payment_path(@event, @ticket_request),
class: 'btn btn-primary m-0'
- else
%span.bg-warning
Unfortunately, ticket sales are now closed. You can no longer purchase your
= succeed '.' do
= 'ticket'.pluralize(@ticket_request.total_tickets)

%tr
%td.text-end.small.p-2.px-4.text-nowrap= "Email:"
Expand Down

0 comments on commit 4a76209

Please sign in to comment.