Class: Workarea::Payment::Capture
- Inherits:
-
Object
- Object
- Workarea::Payment::Capture
- Includes:
- Processing
- Defined in:
- app/models/workarea/payment/capture.rb,
app/models/workarea/payment/capture/credit_card.rb,
app/models/workarea/payment/capture/store_credit.rb
Defined Under Namespace
Classes: CreditCard, StoreCredit
Instance Method Summary collapse
-
#allocate_amounts!(total:) ⇒ Object
Set amounts for tenders automatically (as opposed to custom amounts) This will reset the current amounts!.
- #capture_amounts ⇒ Object
- #find_reference_transactions_for(tender) ⇒ Object
- #transaction_type ⇒ Object
Methods included from Processing
#complete!, #total, #transactions
Methods included from ApplicationDocument
Methods included from Sidekiq::Callbacks
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
Methods included from Mongoid::Document
Instance Method Details
#allocate_amounts!(total:) ⇒ Object
Set amounts for tenders automatically (as opposed to custom amounts) This will reset the current amounts!
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/workarea/payment/capture.rb', line 18 def allocate_amounts!(total:) self.amounts = {} allocated_amount = 0.to_m payment.tenders.each do |tender| amount_for_this_tender = total - allocated_amount if amount_for_this_tender > tender.capturable_amount amount_for_this_tender = tender.capturable_amount end allocated_amount += amount_for_this_tender amounts[tender.id] = amount_for_this_tender end end |
#capture_amounts ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/models/workarea/payment/capture.rb', line 34 def capture_amounts amounts_with_tenders.each do |tender, amount| if tender.capturable_amount < amount errors.add(tender.slug, I18n.t('workarea.payment.exceeds_authed_amount')) end end end |
#find_reference_transactions_for(tender) ⇒ Object
12 13 14 |
# File 'app/models/workarea/payment/capture.rb', line 12 def find_reference_transactions_for(tender) tender.transactions.successful.not_canceled. end |
#transaction_type ⇒ Object
8 9 10 |
# File 'app/models/workarea/payment/capture.rb', line 8 def transaction_type 'capture' end |