class Osm::OnlinePayment::Schedule::PaymentsForMember
Public Instance Methods
Check if the member has an active direct debit for this schedule @return [Boolean]
# File lib/osm/online_payment.rb, line 353 def active_direct_debit? direct_debit.eql?(:active) end
Get the most recent status for a member's payment @param [Osm::OnlinePayment::Schedule::Payment, Fixnum, to_i
] payment The payment (or it's ID) to check @return [Boolean]
# File lib/osm/online_payment.rb, line 320 def latest_status_for(payment) @latest_status ||= Hash[ payments.map{ |k,v| [k, v.sort[0]] } ] @latest_status[payment.to_i] end
Mark a payment as not required by the member @param [Osm::Api] api The api to use to make the request @param [Osm::OnlinePayment::Schedule::Payment, Fixnum, to_i
] payment The payment (or it's ID) to update @return [Boolean] whether the update was made in OSM
# File lib/osm/online_payment.rb, line 406 def mark_payment_not_required(api, payment) update_payment_status(api, payment, :not_required) end
Mark a payment as paid by the member @param [Osm::Api] api The api to use to make the request @param [Osm::OnlinePayment::Schedule::Payment, Fixnum, to_i
] payment The payment (or it's ID) to update @param [Boolean] gift_aid Whether to update the gift aid record too @return [Boolean] whether the update was made in OSM
# File lib/osm/online_payment.rb, line 415 def mark_payment_paid_manually(api, payment, gift_aid=false) update_payment_status(api, payment, :paid_manually, gift_aid) end
Mark a payment as required by the member @param [Osm::Api] api The api to use to make the request @param [Osm::OnlinePayment::Schedule::Payment, Fixnum, to_i
] payment The payment (or it's ID) to update @return [Boolean] whether the update was made in OSM
# File lib/osm/online_payment.rb, line 398 def mark_payment_required(api, payment) update_payment_status(api, payment, :required) end
Check if a payment is over due (or will be over due on the passed date) @param [Osm::OnlinePayment::Schedule::Payment, Fixnum, to_i
] payment The payment (or it's ID) to check @param [Date] date The date to check for (defaults to today) @return [Boolean] whether the member's payment is unpaid and the payment's due date has passed
# File lib/osm/online_payment.rb, line 347 def over_due?(payment, date=nil) unpaid?(payment) && payment.past_due?(date) end
Check if the status of a member's payment is considered paid @param [Osm::OnlinePayment::Schedule::Payment, Fixnum, to_i
] payment The payment (or it's ID) to check @return [Boolean, nil]
# File lib/osm/online_payment.rb, line 328 def paid?(payment) status = latest_status_for(payment.to_i) return nil if status.nil? [:paid, :paid_manually, :received, :initiated].include?(status.status) end
Check if the status of a member's payment is considered unpaid @param [Osm::OnlinePayment::Schedule::Payment, Fixnum, to_i
] payment The payment (or it's ID) to check @return [Boolean, nil]
# File lib/osm/online_payment.rb, line 337 def unpaid?(payment) status = latest_status_for(payment.to_i) return nil if status.nil? [:required].include?(status.status) end
Update the status of a payment for the member in OSM @param [Osm::Api] api The api to use to make the request @param [Osm::OnlinePayment::Schedule::Payment, Fixnum, to_i
] payment The payment (or it's ID) to update @param [Symbol] status What to update the status to (:required, :not_required or :paid_manually) @param [Boolean] gift_aid Whether to update the gift aid record too (only relevant when setting to :paid_manually) @return [Boolean] whether the update was made in OSM
# File lib/osm/online_payment.rb, line 363 def update_payment_status(api, payment, status, gift_aid=false) payment_id = payment.to_i fail ArgumentError, "#{payment_id} is not a valid payment for the schedule." unless schedule.payments.map(&:id).include?(payment_id) fail ArgumentError, "status must be either :required, :not_required or :paid_manually. You passed in #{status.inspect}" unless [:required, :not_required, :paid_manually].include?(status) gift_aid = false unless payment.schedule.gift_aid? api_status = { required: 'Payment required', not_required: 'Payment not required', paid_manually: 'Paid manually', }[status] data = api.perform_query("ext/finances/onlinepayments/?action=updatePaymentStatus", { 'sectionid' => schedule.section_id, 'schemeid' => schedule.id, 'scoutid' => member_id, 'paymentid' => payment_id, 'giftaid' => gift_aid, 'value' => api_status, }) data = data[payment_id.to_s] return false if data.nil? # No data (at all) for this payment data = PaymentStatus.build_from_json(data) return false if data.nil? # No history for payment so it didn't get updated data = data.sort[0] return false if data.nil? # No history for payment so it didn't get updated return false unless data.status.eql?(status) # Latest status is not what we set return true end