[feat] remove unintended check; add auto-redirect to non-free ticket
This commit is contained in:
parent
1ca58961c1
commit
da8939dd3a
4 changed files with 24 additions and 21 deletions
|
|
@ -16,6 +16,7 @@ class PaymentsController < ApplicationController
|
||||||
raise CanCan::AccessDenied.new('Nothing to pay for!', :new, Payment)
|
raise CanCan::AccessDenied.new('Nothing to pay for!', :new, Payment)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@has_registration_ticket = params[:has_registration_ticket]
|
||||||
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)
|
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -24,8 +25,17 @@ class PaymentsController < ApplicationController
|
||||||
|
|
||||||
if @payment.purchase && @payment.save
|
if @payment.purchase && @payment.save
|
||||||
update_purchased_ticket_purchases
|
update_purchased_ticket_purchases
|
||||||
redirect_to conference_physical_tickets_path,
|
|
||||||
notice: 'Thanks! Your ticket is booked successfully.'
|
has_registration_ticket = params[:has_registration_ticket]
|
||||||
|
if has_registration_ticket.present? && has_registration_ticket == 'true'
|
||||||
|
redirect_to new_conference_conference_registration_path(@conference.short_title),
|
||||||
|
notice: 'Thanks! Your ticket is booked successfully. Please register for the conference.'
|
||||||
|
else
|
||||||
|
redirect_to conference_physical_tickets_path,
|
||||||
|
notice: 'Thanks! Your ticket is booked successfully.'
|
||||||
|
end
|
||||||
|
|
||||||
|
@has_registration_ticket = nil
|
||||||
else
|
else
|
||||||
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
||||||
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)
|
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)
|
||||||
|
|
|
||||||
|
|
@ -25,30 +25,25 @@ class TicketPurchasesController < ApplicationController
|
||||||
# Current user already paid for a registration ticket and the current ticket purchase contains one
|
# Current user already paid for a registration ticket and the current ticket purchase contains one
|
||||||
if count_registration_tickets_before == 1 && count_registration_tickets_after > 1
|
if count_registration_tickets_before == 1 && count_registration_tickets_after > 1
|
||||||
redirect_to conference_physical_tickets_path,
|
redirect_to conference_physical_tickets_path,
|
||||||
notice: 'You already have tickets for the conference.'
|
error: 'You already have one registration ticket for the conference.'
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# Conference requires a registration ticket but the current user wants to purchase a non-registration ticket
|
# User needs to pay for tickets if any of them is not free.
|
||||||
# and does not have a registration ticket
|
|
||||||
if @conference.registration_ticket_required? && count_registration_tickets_after == 0
|
|
||||||
redirect_to conference_tickets_path(@conference.short_title),
|
|
||||||
error: 'Please get at least one registration ticket to continue.'
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
# Ticket purchase created but not paid
|
|
||||||
if current_user.ticket_purchases.by_conference(@conference).unpaid.any?
|
if current_user.ticket_purchases.by_conference(@conference).unpaid.any?
|
||||||
redirect_to new_conference_payment_path,
|
has_registration_ticket = count_registration_tickets_before == 0 && count_registration_tickets_after == 1
|
||||||
|
redirect_to new_conference_payment_path(has_registration_ticket: has_registration_ticket),
|
||||||
notice: 'Please pay here to get tickets.'
|
notice: 'Please pay here to get tickets.'
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# Current user didn't have a registration ticket and is purchasing one
|
# Redirect to registration page for a user who didn't have a registration ticket and is purchasing one
|
||||||
if count_registration_tickets_before == 0 && count_registration_tickets_after == 1
|
if count_registration_tickets_before == 0 && count_registration_tickets_after == 1
|
||||||
redirect_to new_conference_conference_registration_path(@conference.short_title)
|
redirect_to new_conference_conference_registration_path(@conference.short_title),
|
||||||
|
notice: 'Thanks! Your ticket is booked successfully. Please register for the conference.'
|
||||||
else
|
else
|
||||||
redirect_to conference_physical_tickets_path
|
redirect_to conference_physical_tickets_path,
|
||||||
|
notice: 'Thanks! Your ticket is booked successfully.'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -349,10 +349,8 @@ class User < ApplicationRecord
|
||||||
def count_registration_tickets(conference)
|
def count_registration_tickets(conference)
|
||||||
count = 0
|
count = 0
|
||||||
ticket_purchases.by_conference(conference).each do |ticket_purchase|
|
ticket_purchases.by_conference(conference).each do |ticket_purchase|
|
||||||
ticket_purchase.physical_tickets.each do |physical_ticket|
|
if ticket_purchase.ticket.registration_ticket
|
||||||
if physical_ticket.ticket.registration_ticket
|
count += 1
|
||||||
count += 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
%td
|
%td
|
||||||
= humanized_money_with_symbol ticket.quantity * ticket.price
|
= humanized_money_with_symbol ticket.quantity * ticket.price
|
||||||
|
|
||||||
= form_tag conference_payments_path do
|
= form_tag conference_payments_path(@conference.short_title, :has_registration_ticket => @has_registration_ticket) do
|
||||||
%script.stripe-button{'src': "https://checkout.stripe.com/checkout.js",
|
%script.stripe-button{'src': "https://checkout.stripe.com/checkout.js",
|
||||||
'data': {amount: @total_amount_to_pay.cents,
|
'data': {amount: @total_amount_to_pay.cents,
|
||||||
label: "Pay #{humanized_money_with_symbol @total_amount_to_pay}",
|
label: "Pay #{humanized_money_with_symbol @total_amount_to_pay}",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue