class Osm::OnlinePayment::Schedule
Constants
- PAY_NOW_OPTIONS
- SORT_BY
Public Class Methods
Get a payment schedules for a section @param [Osm::Api] api The api to use to make the request @param [Osm::Section, Fixnum, to_i
] section The section (or its ID) to get the due badges for @param [Fixnum, to_i
] schedule The ID of the payment schedule to get @!macro options_get @return [Array<Osm::OnlinePayment::Schedule>]
# File lib/osm/online_payment.rb, line 123 def self.get(api, section, schedule, options={}) require_ability_to(api, :read, :finance, section, options) section_id = section.to_i schedule_id = schedule.to_i cache_key = ['online_payments', 'schedule', schedule_id] if !options[: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 all payment schedules for a section @param [Osm::Api] api The api to use to make the request @param [Osm::Section, Fixnum, to_i
] section The section (or its ID) to get the due badges for @!macro options_get @return [Array<Osm::OnlinePayment::Schedule>]
# File lib/osm/online_payment.rb, line 108 def self.get_for_section(api, section, options={}) require_ability_to(api, :read, :finance, section, options) get_list_for_section(api, section, options).map do |schedule| get(api, section, schedule[:id], options) end end
Get a simple list of schedules for a section @param [Osm::Api] api The api to use to make the request @param [Osm::Section, Fixnum, to_i
] section The section (or its ID) to get the due badges for @!macro options_get @return [Array<Hash>]
# File lib/osm/online_payment.rb, line 84 def self.get_list_for_section(api, section, options={}) require_ability_to(api, :read, :finance, section, options) section_id = section.to_i cache_key = ['online_payments', 'schedule_list', section_id] if !options[: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
Public Instance Methods
Get archived payments for the schedule @return [Array<Osm::OnlinePayment::Schedule::Payment>]
# File lib/osm/online_payment.rb, line 225 def archived_payments payments.select{ |p| p.archived? } end
Check if there are any archived payments for the schedule @return [Boolean]
# File lib/osm/online_payment.rb, line 230 def archived_payments? payments.any?{ |p| p.archived? } end
Get unarchived payments for the schedule @return [Array<Osm::OnlinePayment::Schedule::Payment>]
# File lib/osm/online_payment.rb, line 214 def current_payments payments.select{ |p| !p.archived? } end
Check if there are any unarchived payments for the schedule @return [Boolean]
# File lib/osm/online_payment.rb, line 219 def current_payments? payments.any?{ |p| !p.archived? } end
Get payments made by members for the schedule @param [Osm::Api] api The api to use to make the request @param [Osm::Term, Fixnum, to_i
] term The term (or it's id) to get details for (defaults to current term) @!macro options_get @return [Array<Osm::OnlinePayment::Schedule::PaymentsForMember>]
# File lib/osm/online_payment.rb, line 170 def get_payments_for_members(api, term=nil, options={}) require_ability_to(api, :read, :finance, section_id, options) if term.nil? section = Osm::Section.get(api, section_id, options) 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 !options[: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
# File lib/osm/online_payment.rb, line 234 def to_s "#{id} -> #{name}" end