Skip to content

Commit

Permalink
refactor code that creates recurring donation record
Browse files Browse the repository at this point in the history
  • Loading branch information
winsonwan committed Mar 11, 2024
1 parent 1c0414b commit 37be571
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
3 changes: 2 additions & 1 deletion app/controllers/store_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def process_donation
redirect_route = quick_donate_path(:customer_id => @customer.id, :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, params[:donation_frequency])
@gOrderInProgress = Order.new_from_donation(@amount, Donation.default_code, @customer)
@gOrderInProgress.add_recurring_donation() if params[:donation_frequency] == 'monthly'
@gOrderInProgress.purchasemethod = Purchasemethod.get_type_by_name('web_cc')
@gOrderInProgress.purchase_args = {:credit_card_token => params[:credit_card_token]}
@gOrderInProgress.processed_by = @customer
Expand Down
7 changes: 0 additions & 7 deletions app/models/items/recurring_donation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ class RecurringDonation < Item
belongs_to :customer
has_many :donations, foreign_key: :recurring_donation_id

validates_associated :account_code
validates_presence_of :account_code_id

def self.from_account_code(account_code)
RecurringDonation.new(:amount => 0, :account_code => account_code)
end

def one_line_description ; end
def description_for_audit_txn ; end
end
16 changes: 4 additions & 12 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,9 @@ def purchaser_name ; purchaser.full_name ; end

def purchase_medium ; Purchasemethod.get(purchasemethod).purchase_medium ; end

def self.new_from_donation(amount, account_code, donor, donation_frequency)
def self.new_from_donation(amount, account_code, donor)
order = Order.new(:purchaser => donor, :customer => donor)
if donation_frequency == 'monthly'
recurring_donation = RecurringDonation.from_account_code(account_code)
order.add_recurring_donation(recurring_donation)
donation = recurring_donation.donations.new(amount: amount, account_code: account_code)
else
donation = Donation.from_amount_and_account_code_id(amount, account_code.id)
end
order.add_donation(donation)
order.add_donation(Donation.from_amount_and_account_code_id(amount, account_code.id))
order
end

Expand Down Expand Up @@ -246,9 +239,8 @@ def includes_donation?
end
end

def add_recurring_donation(rd) ; self.recurring_donation = rd ; end
def recurring_donation=(rd)
@recurring_donation = rd
def add_recurring_donation()
@recurring_donation = @donation.build_recurring_donation(amount: 0, account_code_id: @donation.account_code_id)
end

def includes_bundle?
Expand Down

0 comments on commit 37be571

Please sign in to comment.