Class: Osm::OnlinePayment::Schedule::PaymentsForMember
- Defined in:
- lib/osm/online_payment.rb
Constant Summary
Constants inherited from Model
Instance Method Summary collapse
-
#active_direct_debit? ⇒ Boolean
Check if the member has an active direct debit for this schedule.
-
#initialize ⇒ Object
constructor
Initialize a new Schedule.
-
#latest_status_for(payment) ⇒ Boolean
Get the most recent status for a member’s payment.
-
#mark_payment_not_required(api, payment) ⇒ Boolean
Mark a payment as not required by the member.
-
#mark_payment_paid_manually(api, payment, gift_aid = false) ⇒ Boolean
Mark a payment as paid by the member.
-
#mark_payment_required(api, payment) ⇒ Boolean
Mark a payment as required by the member.
-
#over_due?(payment, date = nil) ⇒ Boolean
Check if a payment is over due (or will be over due on the passed date).
-
#paid?(payment) ⇒ Boolean?
Check if the status of a member’s payment is considered paid.
-
#unpaid?(payment) ⇒ Boolean?
Check if the status of a member’s payment is considered unpaid.
-
#update_payment_status(api, payment, status, gift_aid = false) ⇒ Boolean
Update the status of a payment for the member in OSM.
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 312
|
Instance Method Details
#active_direct_debit? ⇒ Boolean
Check if the member has an active direct debit for this schedule
353 354 355 |
# File 'lib/osm/online_payment.rb', line 353 def active_direct_debit? direct_debit.eql?(:active) end |
#latest_status_for(payment) ⇒ Boolean
Get the most recent status for a member’s payment
320 321 322 323 |
# 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_payment_not_required(api, payment) ⇒ Boolean
Mark a payment as not required by the member
406 407 408 |
# File 'lib/osm/online_payment.rb', line 406 def mark_payment_not_required(api, payment) update_payment_status(api, payment, :not_required) end |
#mark_payment_paid_manually(api, payment, gift_aid = false) ⇒ Boolean
Mark a payment as paid by the member
415 416 417 |
# 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_payment_required(api, payment) ⇒ Boolean
Mark a payment as required by the member
398 399 400 |
# File 'lib/osm/online_payment.rb', line 398 def mark_payment_required(api, payment) update_payment_status(api, payment, :required) end |
#over_due?(payment, date = nil) ⇒ Boolean
Check if a payment is over due (or will be over due on the passed date)
347 348 349 |
# File 'lib/osm/online_payment.rb', line 347 def over_due?(payment, date=nil) unpaid?(payment) && payment.past_due?(date) end |
#paid?(payment) ⇒ Boolean?
Check if the status of a member’s payment is considered paid
328 329 330 331 332 |
# 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 |
#unpaid?(payment) ⇒ Boolean?
Check if the status of a member’s payment is considered unpaid
337 338 339 340 341 |
# 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_payment_status(api, payment, status, gift_aid = false) ⇒ Boolean
Update the status of a payment for the member in OSM
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# 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 |