Class: Workarea::Payment::Refund

Inherits:
Object
  • Object
show all
Includes:
Processing
Defined in:
app/models/workarea/payment/refund.rb,
app/models/workarea/payment/refund/credit_card.rb,
app/models/workarea/payment/refund/store_credit.rb

Defined Under Namespace

Classes: CreditCard, StoreCredit

Instance Method Summary collapse

Methods included from Processing

#complete!, #total, #transactions

Methods included from ApplicationDocument

#releasable?

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

#embedded_children

Instance Method Details

#allocate_amounts!(total:) ⇒ Object

Set amounts for tenders automatically (as opposed to custom amounts) This will reset the current amount!



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/workarea/payment/refund.rb', line 19

def allocate_amounts!(total:)
  self.amounts = {}
  allocated_amount = 0.to_m

  payment.tenders.reverse.each do |tender|
    amount_for_this_tender = total - allocated_amount

    if amount_for_this_tender > tender.refundable_amount
      amount_for_this_tender = tender.refundable_amount
    end

    allocated_amount += amount_for_this_tender
    amounts[tender.id] = amount_for_this_tender
  end
end

#find_reference_transactions_for(tender) ⇒ Object



13
14
15
# File 'app/models/workarea/payment/refund.rb', line 13

def find_reference_transactions_for(tender)
  tender.transactions.successful.not_canceled.captures_or_purchased
end

#refundable_amountsObject



35
36
37
38
39
40
41
# File 'app/models/workarea/payment/refund.rb', line 35

def refundable_amounts
  amounts_with_tenders.each do |tender, amount|
    if tender.refundable_amount < amount
      errors.add(tender.slug, I18n.t('workarea.payment.exceeds_captured_amount'))
    end
  end
end

#transaction_typeObject



9
10
11
# File 'app/models/workarea/payment/refund.rb', line 9

def transaction_type
  'refund'
end