Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
module Events
class GroupPaymentsController < ApplicationController
class BulkPaymentsController < ApplicationController
skip_before_action :authenticate_user!, only: [ :new, :create, :show ]
before_action :set_event
before_action :set_form, only: [ :new, :create ]

rescue_from ActionController::InvalidAuthenticityToken do
flash[:alert] = "Your session has expired. Please try submitting the form again."
redirect_to new_event_group_payment_path(@event)
redirect_to new_event_bulk_payment_path(@event)
end

def new
authorize! :group_payment, to: :new?
authorize! :bulk_payment, to: :new?

@form_fields = visible_form_fields
@event = @event.decorate

@attendee_field = @form.form_fields.find_by(field_identifier: "group_payment_attendees")
@attendee_field = @form.form_fields.find_by(field_identifier: "bulk_payment_attendees")
end

def create
authorize! :group_payment, to: :create?
authorize! :bulk_payment, to: :create?

@form_params = params.dig(:group_payment, :form_fields)&.to_unsafe_h || {}
@form_params = params.dig(:bulk_payment, :form_fields)&.to_unsafe_h || {}

@field_errors = validate_required_fields
if @field_errors.any?
@form_fields = visible_form_fields
@event = @event.decorate
@attendee_field = @form.form_fields.find_by(field_identifier: "group_payment_attendees")
@attendee_field = @form.form_fields.find_by(field_identifier: "bulk_payment_attendees")
render :new, status: :unprocessable_content
return
end

result = EventRegistrationServices::GroupPayment.call(
result = EventRegistrationServices::BulkPayment.call(
event: @event,
form: @form,
form_params: @form_params,
Expand All @@ -44,20 +44,20 @@ def create
checkout_session = create_stripe_checkout_session(result.form_submission)
redirect_to checkout_session.url, allow_other_host: true, status: :see_other
else
redirect_to event_group_payment_path(@event, submission_id: result.form_submission.id),
notice: "Your group payment information has been submitted."
redirect_to event_bulk_payment_path(@event, submission_id: result.form_submission.id),
notice: "Your bulk payment information has been submitted."
end
else
@form_fields = visible_form_fields
@event = @event.decorate
@attendee_field = @form.form_fields.find_by(field_identifier: "group_payment_attendees")
@attendee_field = @form.form_fields.find_by(field_identifier: "bulk_payment_attendees")
flash.now[:alert] = result.errors.join(", ")
render :new, status: :unprocessable_content
end
end

def show
authorize! :group_payment, to: :show?
authorize! :bulk_payment, to: :show?

@submission = FormSubmission.find(params[:submission_id])
@form = @submission.form
Expand All @@ -66,7 +66,7 @@ def show
@event = @event.decorate

attendee_answer = @responses.values.find { |a|
a.form_field&.field_identifier == "group_payment_attendees"
a.form_field&.field_identifier == "bulk_payment_attendees"
}
@attendees = parse_attendees(attendee_answer&.submitted_answer)
end
Expand All @@ -89,9 +89,9 @@ def set_event
end

def set_form
@form = @event.group_payment_form
@form = @event.bulk_payment_form
unless @form
redirect_to event_path(@event), alert: "Group payment form is not available for this event."
redirect_to event_path(@event), alert: "Bulk payment form is not available for this event."
end
end

Expand All @@ -101,7 +101,7 @@ def validate_required_fields

visible_fields.find_each do |field|
next if field.group_header?
next if field.field_identifier == "group_payment_attendees"
next if field.field_identifier == "bulk_payment_attendees"

value = @form_params[field.id.to_s]

Expand Down Expand Up @@ -148,13 +148,13 @@ def create_stripe_checkout_session(submission)
line_items: [ {
price_data: {
currency: "usd",
product_data: { name: "Group Payment (#{qty} attendees): #{@event.title}" },
product_data: { name: "Bulk Payment (#{qty} attendees): #{@event.title}" },
unit_amount: unit_amount
},
quantity: qty
} ],
success_url: event_group_payment_url(@event, submission_id: submission.id, checkout: "success"),
cancel_url: event_group_payment_url(@event, submission_id: submission.id, checkout: "cancelled")
success_url: event_bulk_payment_url(@event, submission_id: submission.id, checkout: "success"),
cancel_url: event_bulk_payment_url(@event, submission_id: submission.id, checkout: "cancelled")
)
end

Expand Down
16 changes: 8 additions & 8 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class EventsController < ApplicationController
include AhoyTracking, TagAssignable
skip_before_action :authenticate_user!, only: [ :index, :show, :staff ]
skip_before_action :verify_authenticity_token, only: [ :preview ]
before_action :set_event, only: %i[ show edit update destroy preview dashboard background registrants staff recipients group_payments preview_reminder send_reminder copy_registration_form ]
before_action :set_event, only: %i[ show edit update destroy preview dashboard background registrants staff recipients bulk_payments preview_reminder send_reminder copy_registration_form ]

def index
authorize!
Expand Down Expand Up @@ -106,12 +106,12 @@ def recipients
@dashboard = EventDashboard.new(@event)
end

def group_payments
def bulk_payments
authorize! @event

@event = @event.decorate
@submissions = FormSubmission.joins(form: :event_forms)
.where(event_forms: { event_id: @event.id, role: "group_payment" })
.where(event_forms: { event_id: @event.id, role: "bulk_payment" })
.includes(:person, form_answers: :form_field)
.order(created_at: :desc)
end
Expand Down Expand Up @@ -300,13 +300,13 @@ def assign_event_forms(event)
event.event_forms.scholarship.destroy_all
end

if params.dig(:event, :group_payment_enabled) == "1"
form = Form.standalone.find_by(role: "group_payment")
if form && !event.event_forms.group_payment.exists?
event.event_forms.create!(form: form, role: "group_payment")
if params.dig(:event, :bulk_payment_enabled) == "1"
form = Form.standalone.find_by(role: "bulk_payment")
if form && !event.event_forms.bulk_payment.exists?
event.event_forms.create!(form: form, role: "bulk_payment")
end
else
event.event_forms.group_payment.destroy_all
event.event_forms.bulk_payment.destroy_all
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class extends Controller {
const index = this.countValue++
const fragment = this.templateTarget.content.cloneNode(true)

fragment.querySelectorAll("[data-group-payment-attendees-target=\"row\"]").forEach(row => {
fragment.querySelectorAll("[data-bulk-payment-attendees-target=\"row\"]").forEach(row => {
row.dataset.index = index
})

Expand All @@ -31,7 +31,7 @@ export default class extends Controller {
}

removeRow(event) {
const row = event.target.closest("[data-group-payment-attendees-target=\"row\"]")
const row = event.target.closest("[data-bulk-payment-attendees-target=\"row\"]")
if (row) {
row.remove()
this.serialize()
Expand All @@ -40,7 +40,7 @@ export default class extends Controller {

serialize() {
const attendees = []
this.rowsTarget.querySelectorAll("[data-group-payment-attendees-target=\"row\"]").forEach(row => {
this.rowsTarget.querySelectorAll("[data-bulk-payment-attendees-target=\"row\"]").forEach(row => {
const first_name = row.querySelector("[data-attendee-field=\"first_name\"]")?.value || ""
const last_name = row.querySelector("[data-attendee-field=\"last_name\"]")?.value || ""
const email = row.querySelector("[data-attendee-field=\"email\"]")?.value || ""
Expand Down
4 changes: 2 additions & 2 deletions app/frontend/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ application.register("world-map-chart", WorldMapChartController)
import CurrencyInputController from "./currency_input_controller"
application.register("currency-input", CurrencyInputController)

import GroupPaymentAttendeesController from "./group_payment_attendees_controller"
application.register("group-payment-attendees", GroupPaymentAttendeesController)
import BulkPaymentAttendeesController from "./bulk_payment_attendees_controller"
application.register("bulk-payment-attendees", BulkPaymentAttendeesController)

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export default class extends Controller {
const sectionRole = el.dataset.sectionRole
if (role === "scholarship") {
el.classList.toggle("hidden", sectionRole !== "scholarship")
} else if (role === "group_payment") {
el.classList.toggle("hidden", sectionRole !== "group_payment")
} else if (role === "bulk_payment") {
el.classList.toggle("hidden", sectionRole !== "bulk_payment")
} else {
el.classList.toggle("hidden", sectionRole === "scholarship" || sectionRole === "group_payment")
el.classList.toggle("hidden", sectionRole === "scholarship" || sectionRole === "bulk_payment")
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions app/models/concerns/pay_charge_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create_external_processor_payment
if (event_registration_id = metadata["event_registration_id"])
create_event_registration_payment(event_registration_id)
elsif (form_submission_id = metadata["form_submission_id"])
create_group_payment(form_submission_id)
create_bulk_payment(form_submission_id)
elsif (person_id = metadata["person_id"])
create_donation_payment(person_id)
end
Expand Down Expand Up @@ -49,10 +49,10 @@ def create_event_registration_payment(event_registration_id)
)
end

def create_group_payment(form_submission_id)
def create_bulk_payment(form_submission_id)
submission = FormSubmission.find_by(id: form_submission_id)
return unless submission
return unless submission.role == "group_payment"
return unless submission.role == "bulk_payment"

person = submission.person
return unless person
Expand Down
4 changes: 2 additions & 2 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def scholarship_form
forms.find_by(event_forms: { role: "scholarship" })
end

def group_payment_form
forms.find_by(event_forms: { role: "group_payment" })
def bulk_payment_form
forms.find_by(event_forms: { role: "bulk_payment" })
end

def active_registration_for(person)
Expand Down
4 changes: 2 additions & 2 deletions app/models/event_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ class EventForm < ApplicationRecord
belongs_to :event
belongs_to :form

ROLES = %w[registration scholarship group_payment].freeze
ROLES = %w[registration scholarship bulk_payment].freeze

validates :role, presence: true, inclusion: { in: ROLES }
validates :form_id, uniqueness: { scope: [ :event_id, :role ] }

scope :registration, -> { where(role: "registration") }
scope :scholarship, -> { where(role: "scholarship") }
scope :group_payment, -> { where(role: "group_payment") }
scope :bulk_payment, -> { where(role: "bulk_payment") }
end
2 changes: 1 addition & 1 deletion app/policies/event_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def recipients?
manage?
end

def group_payments?
def bulk_payments?
manage?
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Events::GroupPaymentPolicy < ApplicationPolicy
class Events::BulkPaymentPolicy < ApplicationPolicy
def new?
true
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module EventRegistrationServices
class GroupPayment
class BulkPayment
Result = Struct.new(:success?, :form_submission, :errors, keyword_init: true)

def self.call(event:, form:, form_params:, person: nil)
Expand Down Expand Up @@ -53,7 +53,7 @@ def find_or_create_person
end

def create_form_submission(person)
submission = FormSubmission.create!(person: person, form: @form, role: "group_payment")
submission = FormSubmission.create!(person: person, form: @form, role: "bulk_payment")
save_form_answers(submission)
submission
end
Expand Down
30 changes: 15 additions & 15 deletions app/services/form_builder_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FormBuilderService
payment: { label: "Payment", method: :build_payment_fields },
consent: { label: "Consent", method: :build_consent_fields },
post_event_feedback: { label: "Post-event feedback", method: :build_post_event_feedback_fields },
group_payment: { label: "Group payment", method: :build_group_payment_fields }
bulk_payment: { label: "Bulk payment", method: :build_bulk_payment_fields }
}.freeze

def initialize(name:, sections:, role: nil)
Expand Down Expand Up @@ -49,7 +49,7 @@ def call
payment: %w[payment_method],
consent: %w[communication_consent],
post_event_feedback: %w[event_rating most_valuable improvement_suggestions],
group_payment: %w[payer_first_name payer_last_name payer_email organization_name number_of_attendees payment_method group_payment_attendees]
bulk_payment: %w[payer_first_name payer_last_name payer_email organization_name number_of_attendees payment_method bulk_payment_attendees]
}.freeze

# Header questions created by each section's builder method
Expand All @@ -63,7 +63,7 @@ def call
payment: [ "Payment Information" ],
consent: [ "Consent" ],
post_event_feedback: [ "Post-Event Feedback" ],
group_payment: [ "Payer Information", "Payment Information", "Attendees" ]
bulk_payment: [ "Payer Information", "Payment Information", "Attendees" ]
}.freeze

# Update sections on an existing form: add new sections, remove unchecked ones
Expand Down Expand Up @@ -111,7 +111,7 @@ def self.update_sections!(form, new_sections)
"scholarship" => :always_ask,
"consent" => :answers_on_file,
"post_event_feedback" => :answers_on_file,
"group_payment" => :always_ask
"bulk_payment" => :always_ask
}.freeze

# Sections where answers carry across all events (ask once ever)
Expand Down Expand Up @@ -341,33 +341,33 @@ def build_post_event_feedback_fields(form, position)
position
end

def build_group_payment_fields(form, position)
position = add_header(form, position, "Payer Information", group: "group_payment", visibility: :logged_out_only)
def build_bulk_payment_fields(form, position)
position = add_header(form, position, "Payer Information", group: "bulk_payment", visibility: :logged_out_only)

position = add_field(form, position, "Payer First Name", :free_form_input_one_line,
key: "payer_first_name", group: "group_payment", required: true,
key: "payer_first_name", group: "bulk_payment", required: true,
visibility: :logged_out_only)
position = add_field(form, position, "Payer Last Name", :free_form_input_one_line,
key: "payer_last_name", group: "group_payment", required: true,
key: "payer_last_name", group: "bulk_payment", required: true,
visibility: :logged_out_only)
position = add_field(form, position, "Payer Email", :free_form_input_one_line,
key: "payer_email", group: "group_payment", required: true,
key: "payer_email", group: "bulk_payment", required: true,
visibility: :logged_out_only)
position = add_field(form, position, "Organization Name", :free_form_input_one_line,
key: "organization_name", group: "group_payment", required: false,
key: "organization_name", group: "bulk_payment", required: false,
visibility: :logged_out_only)

position = add_header(form, position, "Payment Information", group: "group_payment")
position = add_header(form, position, "Payment Information", group: "bulk_payment")
position = add_field(form, position, "Payment Method", :multiple_choice_radio,
key: "payment_method", group: "group_payment", required: true,
key: "payment_method", group: "bulk_payment", required: true,
options: [ "Credit Card", "Check", "Purchase Order", "Other" ])

position = add_header(form, position, "Attendees", group: "group_payment")
position = add_header(form, position, "Attendees", group: "bulk_payment")
position = add_field(form, position, "Number of Attendees", :free_form_input_one_line,
key: "number_of_attendees", group: "group_payment", required: true,
key: "number_of_attendees", group: "bulk_payment", required: true,
datatype: :number_integer)
position = add_field(form, position, "Attendees", :no_user_input,
key: "group_payment_attendees", group: "group_payment", required: false)
key: "bulk_payment_attendees", group: "bulk_payment", required: false)
position
end
end
2 changes: 1 addition & 1 deletion app/views/events/_bulk_actions_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
data-dropdown-target="content"
class="hidden absolute right-0 z-10 mt-1 bg-white border border-gray-200 rounded-md shadow-lg py-1 min-w-[180px]">
<%= link_to "Send reminder emails", preview_reminder_event_path(@event), class: item_class %>
<%= link_to "Group payments", group_payments_event_path(@event), class: item_class %>
<%= link_to "Bulk payments", bulk_payments_event_path(@event), class: item_class %>
<%= link_to registrants_event_path(@event, format: :csv), class: item_class, data: { turbo_frame: "_top" } do %>
Download CSV <i class="fa-solid fa-download text-gray-400 ml-1"></i>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@
</div>
<div class="pb-4">
<label class="flex items-center gap-2 cursor-pointer">
<%= check_box_tag "event[group_payment_enabled]", "1", @event.group_payment_form.present? %>
<span class="text-sm font-medium text-gray-700">Enable group payment</span>
<%= check_box_tag "event[bulk_payment_enabled]", "1", @event.bulk_payment_form.present? %>
<span class="text-sm font-medium text-gray-700">Enable bulk payment</span>
</label>
</div>
</div>
Expand Down
Loading