Class: Osm::OnlinePayment::Schedule
- Defined in:
- lib/osm/online_payment.rb
Defined Under Namespace
Classes: Payment, PaymentStatus, PaymentsForMember
Constant Summary collapse
- SORT_BY =
[:section_id, :name, :id]
- PAY_NOW_OPTIONS =
{ -1 => 'Allowed at all times', 0 => 'Permanently disabled', 7 => 'Allowed within 1 week of due day', 14 => 'Allowed within 2 weeks of due day', 21 => 'Allowed within 3 weeks of due day', 28 => 'Allowed within 4 weeks of due day', 42 => 'Allowed within 6 weeks of due day', 56 => 'Allowed within 8 weeks of due day', }
Instance Attribute Summary collapse
-
#account_id ⇒ FixNum
The ID of the bank account this schedule is tied to.
-
#annual_limit ⇒ String
The maximum amount you’ll be able to collect in a rolling 12 month period using this schedule.
-
#archived ⇒ Boolean
Whether the schedule has been archived.
-
#description ⇒ String
The description of what the schedule is for.
-
#gift_aid ⇒ Boolean
Whether payments made using this schedule are eligable for gift aid.
-
#id ⇒ FixNum
The schedule’s ID.
-
#name ⇒ String
The name of the schedule.
-
#pay_now ⇒ FixNum
Controls the use of the pay now feature in OSM, see the PAY_NOW_OPTIONS hash.
-
#payments ⇒ Array<Payment>
The payments which make up this schedule.
-
#require_all ⇒ Boolean
Whether to require all payments within the schedule by default.
-
#section_id ⇒ FixNum
The ID of the section the schedule belongs to.
Class Method Summary collapse
-
.get(api, section, schedule, options = {}) ⇒ Array<Osm::OnlinePayment::Schedule>
Get a payment schedules for a section.
-
.get_for_section(api, section, options = {}) ⇒ Array<Osm::OnlinePayment::Schedule>
Get all payment schedules for a section.
-
.get_list_for_section(api, section, options = {}) ⇒ Array<Hash>
Get a simple list of schedules for a section.
Instance Method Summary collapse
-
#archived_payments ⇒ Array<Osm::OnlinePayment::Schedule::Payment>
Get archived payments for the schedule.
-
#archived_payments? ⇒ Boolean
Check if there are any archived payments for the schedule.
-
#current_payments ⇒ Array<Osm::OnlinePayment::Schedule::Payment>
Get unarchived payments for the schedule.
-
#current_payments? ⇒ Boolean
Check if there are any unarchived payments for the schedule.
-
#get_payments_for_members(api, term = nil, options = {}) ⇒ Array<Osm::OnlinePayment::Schedule::PaymentsForMember>
Get payments made by members for the schedule.
-
#initialize ⇒ Object
constructor
Initialize a new Schedule.
- #to_s ⇒ Object
Methods inherited from Model
#<, #<=, #<=>, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new Schedule
|
# File 'lib/osm/online_payment.rb', line 74
|
Instance Attribute Details
#account_id ⇒ FixNum
Returns the ID of the bank account this schedule is tied to.
|
# File 'lib/osm/online_payment.rb', line 21
|
#annual_limit ⇒ String
Returns the maximum amount you’ll be able to collect in a rolling 12 month period using this schedule.
|
# File 'lib/osm/online_payment.rb', line 21
|
#archived ⇒ Boolean
Returns whether the schedule has been archived.
|
# File 'lib/osm/online_payment.rb', line 21
|
#description ⇒ String
Returns the description of what the schedule is for.
|
# File 'lib/osm/online_payment.rb', line 21
|
#gift_aid ⇒ Boolean
Returns whether payments made using this schedule are eligable for gift aid.
|
# File 'lib/osm/online_payment.rb', line 21
|
#id ⇒ FixNum
Returns the schedule’s ID.
|
# File 'lib/osm/online_payment.rb', line 21
|
#name ⇒ String
Returns the name of the schedule.
|
# File 'lib/osm/online_payment.rb', line 21
|
#pay_now ⇒ FixNum
Returns controls the use of the pay now feature in OSM, see the PAY_NOW_OPTIONS hash.
|
# File 'lib/osm/online_payment.rb', line 21
|
#payments ⇒ Array<Payment>
Returns the payments which make up this schedule.
|
# File 'lib/osm/online_payment.rb', line 21
|
#require_all ⇒ Boolean
Returns whether to require all payments within the schedule by default.
|
# File 'lib/osm/online_payment.rb', line 21
|
#section_id ⇒ FixNum
Returns the ID of the section the schedule belongs to.
|
# File 'lib/osm/online_payment.rb', line 21
|
Class Method Details
.get(api, section, schedule, options = {}) ⇒ Array<Osm::OnlinePayment::Schedule>
Get a payment schedules for a section
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/osm/online_payment.rb', line 123 def self.get(api, section, schedule, ={}) require_ability_to(api, :read, :finance, section, ) section_id = section.to_i schedule_id = schedule.to_i cache_key = ['online_payments', 'schedule', schedule_id] if ![:no_cache] && cache_exist?(api, cache_key) data = cache_read(api, cache_key) return data if data.section_id.eql?(section_id) end data = api.perform_query("ext/finances/onlinepayments/?action=getPaymentSchedule§ionid=#{section_id}&schemeid=#{schedule_id}&allpayments=true") schedule = new( id: Osm::to_i_or_nil(data['schemeid']), section_id: section_id, account_id: Osm::to_i_or_nil(data['accountid']), name: data['name'], description: data['description'], archived: data['archived'].eql?('1'), gift_aid: data['giftaid'].eql?('1'), require_all: data['defaulton'].eql?('1'), pay_now: data['paynow'], annual_limit: data['preauth_amount'], ) (data['payments'] || []).each do |payment_data| payment = Payment.new( amount: payment_data['amount'], archived: payment_data['archived'].eql?('1'), due_date: Osm::parse_date(payment_data['date']), name: payment_data['name'].to_s, id: Osm::to_i_or_nil(payment_data['paymentid']), schedule: schedule, ) schedule.payments.push payment end cache_write(api, cache_key, schedule) return schedule end |
.get_for_section(api, section, options = {}) ⇒ Array<Osm::OnlinePayment::Schedule>
Get all payment schedules for a section
108 109 110 111 112 113 114 |
# File 'lib/osm/online_payment.rb', line 108 def self.get_for_section(api, section, ={}) require_ability_to(api, :read, :finance, section, ) get_list_for_section(api, section, ).map do |schedule| get(api, section, schedule[:id], ) end end |
.get_list_for_section(api, section, options = {}) ⇒ Array<Hash>
Get a simple list of schedules for a section
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/osm/online_payment.rb', line 84 def self.get_list_for_section(api, section, ={}) require_ability_to(api, :read, :finance, section, ) section_id = section.to_i cache_key = ['online_payments', 'schedule_list', section_id] if ![:no_cache] && Osm::Model.cache_exist?(api, cache_key) return cache_read(api, cache_key) end data = api.perform_query("ext/finances/onlinepayments/?action=getSchemes§ionid=#{section_id}") data = data.is_a?(Hash) ? data['items'] : nil data ||= [] data.map!{ |i| {id: Osm::to_i_or_nil(i['schemeid']), name: i['name'].to_s } } cache_write(api, cache_key, data) return data end |
Instance Method Details
#archived_payments ⇒ Array<Osm::OnlinePayment::Schedule::Payment>
Get archived payments for the schedule
225 226 227 |
# File 'lib/osm/online_payment.rb', line 225 def archived_payments payments.select{ |p| p.archived? } end |
#archived_payments? ⇒ Boolean
Check if there are any archived payments for the schedule
230 231 232 |
# File 'lib/osm/online_payment.rb', line 230 def archived_payments? payments.any?{ |p| p.archived? } end |
#current_payments ⇒ Array<Osm::OnlinePayment::Schedule::Payment>
Get unarchived payments for the schedule
214 215 216 |
# File 'lib/osm/online_payment.rb', line 214 def current_payments payments.select{ |p| !p.archived? } end |
#current_payments? ⇒ Boolean
Check if there are any unarchived payments for the schedule
219 220 221 |
# File 'lib/osm/online_payment.rb', line 219 def current_payments? payments.any?{ |p| !p.archived? } end |
#get_payments_for_members(api, term = nil, options = {}) ⇒ Array<Osm::OnlinePayment::Schedule::PaymentsForMember>
Get payments made by members for the schedule
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/osm/online_payment.rb', line 170 def get_payments_for_members(api, term=nil, ={}) require_ability_to(api, :read, :finance, section_id, ) if term.nil? section = Osm::Section.get(api, section_id, ) term = section.waiting? ? -1 : Osm::Term.get_current_term_for_section(api, section) end cache_key = ['online_payments', 'for_members', id, term.to_i] if ![:no_cache] && cache_exist?(api, cache_key) return cache_read(api, cache_key) end data = api.perform_query("ext/finances/onlinepayments/?action=getPaymentStatus§ionid=#{section_id}&schemeid=#{id}&termid=#{term.to_i}") data = data['items'] || [] data.map! do |item| payments_data = {} payments.each do |payment| unless item[payment.id.to_s].nil? payments_data[payment.id] = PaymentStatus.build_from_json(item[payment.id.to_s], payment) end end PaymentsForMember.new( member_id: Osm::to_i_or_nil(item['scoutid']), section_id: section_id, grouping_id: Osm::to_i_or_nil(item['patrolid']), first_name: item['firstname'], last_name: item['lastname'], start_date: require_all ? Osm::parse_date(item['startdate']) : nil, direct_debit: item['directdebit'].downcase.to_sym, payments: payments_data, schedule: self, ) end cache_write(api, cache_key, data) return data end |
#to_s ⇒ Object
234 235 236 |
# File 'lib/osm/online_payment.rb', line 234 def to_s "#{id} -> #{name}" end |