feat(recurring_donations): add strong params
This commit is contained in:
parent
8f1b33cabd
commit
6a0a674328
2 changed files with 24 additions and 22 deletions
|
@ -65,15 +65,15 @@ module Nonprofits
|
||||||
|
|
||||||
def update
|
def update
|
||||||
json_saved UpdateRecurringDonations
|
json_saved UpdateRecurringDonations
|
||||||
.update(current_recurring_donation, params[:recurring_donation])
|
.update(current_recurring_donation, recurring_donation_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
# post /nonprofits/:nonprofit_id/recurring_donations
|
# post /nonprofits/:nonprofit_id/recurring_donations
|
||||||
def create
|
def create
|
||||||
if params[:recurring_donation][:token]
|
if recurring_donation_params[:token]
|
||||||
render_json { InsertRecurringDonation.with_stripe(params[:recurring_donation]) }
|
render_json { InsertRecurringDonation.with_stripe(recurring_donation_params) }
|
||||||
elsif params[:recurring_donation][:direct_debit_detail_id]
|
elsif recurring_donation_params[:direct_debit_detail_id]
|
||||||
render JsonResp.new(params[:recurring_donation]) do |_data|
|
render JsonResp.new(recurring_donation_params) do |_data|
|
||||||
requires(:amount).as_int
|
requires(:amount).as_int
|
||||||
requires(:supporter_id, :nonprofit_id, :direct_debit_detail_id).as_int
|
requires(:supporter_id, :nonprofit_id, :direct_debit_detail_id).as_int
|
||||||
optional(:dedication, :designation).as_string
|
optional(:dedication, :designation).as_string
|
||||||
|
@ -86,10 +86,14 @@ module Nonprofits
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def current_recurring_donation
|
def current_recurring_donation
|
||||||
@recurring_donation ||= current_nonprofit.recurring_donations.find params[:id]
|
@recurring_donation ||= current_nonprofit.recurring_donations.find params[:id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def recurring_donation_params
|
||||||
|
params.require(:recurring_donation).permit(:amount, :active, :paydate, :interval, :time_unit, :start_date, :end_date, :n_failures, :edit_token, :cancelled_by, :cancelled_at, :donation_id, :nonprofit_id, :supporter_id)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,22 +4,20 @@
|
||||||
require 'timespan'
|
require 'timespan'
|
||||||
|
|
||||||
class RecurringDonation < ApplicationRecord
|
class RecurringDonation < ApplicationRecord
|
||||||
# TODO:
|
# :amount, # int (cents)
|
||||||
# attr_accessible \
|
# :active, # bool (whether this recurring donation should still be paid)
|
||||||
# :amount, # int (cents)
|
# :paydate, # int (fixed date of the month for monthly recurring donations)
|
||||||
# :active, # bool (whether this recurring donation should still be paid)
|
# :interval, # int (interval of time, ie the '3' in '3 months')
|
||||||
# :paydate, # int (fixed date of the month for monthly recurring donations)
|
# :time_unit, # str ('month', 'day', 'week', or 'year')
|
||||||
# :interval, # int (interval of time, ie the '3' in '3 months')
|
# :start_date, # date (when to start this recurring donation)
|
||||||
# :time_unit, # str ('month', 'day', 'week', or 'year')
|
# :end_date, # date (when to deactivate this recurring donation)
|
||||||
# :start_date, # date (when to start this recurring donation)
|
# :n_failures, # int (how many times the charge has failed)
|
||||||
# :end_date, # date (when to deactivate this recurring donation)
|
# :edit_token, # str / uuid to validate the editing page, linked from their email client
|
||||||
# :n_failures, # int (how many times the charge has failed)
|
# :cancelled_by, # str email of user/supporter who made the cancellation
|
||||||
# :edit_token, # str / uuid to validate the editing page, linked from their email client
|
# :cancelled_at, # datetime of user/supporter who made the cancellation
|
||||||
# :cancelled_by, # str email of user/supporter who made the cancellation
|
# :donation_id, :donation,
|
||||||
# :cancelled_at, # datetime of user/supporter who made the cancellation
|
# :nonprofit_id, :nonprofit,
|
||||||
# :donation_id, :donation,
|
# :supporter_id #used because things are messed up in the datamodel
|
||||||
# :nonprofit_id, :nonprofit,
|
|
||||||
# :supporter_id #used because things are messed up in the datamodel
|
|
||||||
|
|
||||||
scope :active, -> { where(active: true) }
|
scope :active, -> { where(active: true) }
|
||||||
scope :inactive, -> { where(active: [false, nil]) }
|
scope :inactive, -> { where(active: [false, nil]) }
|
||||||
|
|
Loading…
Reference in a new issue