Skip to content

Commit

Permalink
add all possible recurring donation frequencies as constants to donat…
Browse files Browse the repository at this point in the history
…ion model and serve/check form params against these constants (instead of string literals)
  • Loading branch information
winsonwan committed Apr 12, 2024
1 parent 77bca71 commit f7268b0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
7 changes: 2 additions & 5 deletions app/controllers/store_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class StoreController < ApplicationController

private

DONATION_FREQUENCIES = %w[one-time monthly]

# if order is nil or empty after checkout phase, abort. This should never happen normally,
# but can happen if customer does weird things trying to have multiple sessions open.
def order_is_not_empty
Expand Down Expand Up @@ -116,7 +114,6 @@ def donate_to_fund_redirect
# Serve quick_donate page; POST calls #process_donation
def donate
reset_shopping # even if order in progress, going to donation page cancels it
@donation_frequency_options = DONATION_FREQUENCIES
if @customer == Customer.anonymous_customer
# handle donation as a 'guest checkout', even though may end up being tied to real customer
@head = 'Login for a faster checkout!'
Expand Down Expand Up @@ -156,9 +153,9 @@ def process_donation
redirect_route = quick_donate_path(:customer_id => @customer.id, :account_code_string => @account_code.code, :donation => @amount)
@amount > 0 or return redirect_to(redirect_route, :alert => 'Donation amount must be provided')
# Given valid donation, customer, and charge token, create & place credit card order.
@gOrderInProgress = Order.new_from_donation(@amount, Donation.default_code, @customer)
@gOrderInProgress = Order.new_from_donation(@amount, @account_code, @customer)
case params[:donation_frequency]
when DONATION_FREQUENCIES[1]
when Donation.recurring_donation
@gOrderInProgress.add_recurring_donation()
end
@gOrderInProgress.purchasemethod = Purchasemethod.get_type_by_name('web_cc')
Expand Down
6 changes: 6 additions & 0 deletions app/models/items/donation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

class Donation < Item

# only possible donation frequencies (either one-time, or recurring at the specified interval)
@@one_time_donation = 'One Time'
@@recurring_donation = 'Monthly'
cattr_reader :one_time_donation
cattr_reader :recurring_donation

def self.default_code
AccountCode.find(Option.default_donation_account_code)
end
Expand Down
7 changes: 4 additions & 3 deletions app/views/store/donate.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
.form-group.form-row{id:"donation_frequency_radio"}
%label.col-form-label.text-right.col-sm-6{:for => :donation} Donation frequency
.radio-group.col-sm-6.col-md-2.form-inline
- @donation_frequency_options.each do |frequency|
= radio_button_tag 'donation_frequency', frequency, Option.default_donation_type == frequency, class: 'form-control', id: frequency
= label_tag 'donation_type_#{frequency}', frequency, class: 'form-control', for: frequency
= radio_button_tag :donation_frequency, Donation.one_time_donation, Option.default_donation_frequency == Donation.one_time_donation, class: 'form-control', id: Donation.one_time_donation
= label_tag :donation_frequency, Donation.one_time_donation, class: 'form-control', for: Donation.one_time_donation
= radio_button_tag :donation_frequency, Donation.recurring_donation, Option.default_donation_frequency == Donation.recurring_donation, class: 'form-control', id: Donation.recurring_donation
= label_tag :donation_frequency, Donation.recurring_donation, class: 'form-control', for: Donation.recurring_donation
.form-group.form-row
%label.col-form-label{:for => :donation_comments}
If you'd like to be recognized as Anonymous, or if you'd like to donate in honor
Expand Down

0 comments on commit f7268b0

Please sign in to comment.