Class: Workarea::Payment::Tender

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument, GuardNegativePrice
Defined in:
app/models/workarea/payment/tender.rb,
app/models/workarea/payment/tender/credit_card.rb,
app/models/workarea/payment/tender/store_credit.rb

Direct Known Subclasses

CreditCard, StoreCredit

Defined Under Namespace

Classes: CreditCard, StoreCredit

Instance Method Summary collapse

Methods included from GuardNegativePrice

#guard_negative_price

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

assert_valid_config!, async, disable, enable, inline, #run_callbacks

Methods included from Mongoid::Document

#embedded_children

Instance Method Details

#authorized_amountObject



36
37
38
# File 'app/models/workarea/payment/tender.rb', line 36

def authorized_amount
  transactions.successful.not_canceled.authorizes.sum(&:amount).to_m
end

#build_transaction(attributes) ⇒ Object



19
20
21
22
# File 'app/models/workarea/payment/tender.rb', line 19

def build_transaction(attributes)
  txn_attributes = { amount: amount }.merge(attributes)
  Transaction.new(txn_attributes.merge(tender: self, payment: payment))
end

#capturable?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'app/models/workarea/payment/tender.rb', line 75

def capturable?
  capturable_amount > 0
end

#capturable_amountObject



63
64
65
# File 'app/models/workarea/payment/tender.rb', line 63

def capturable_amount
  guard_negative_price { authorized_amount - captured_amount }
end

#captured_amountObject

Include captured or purchased to represent how much money we’ve taken from the customer on this tender.



42
43
44
45
46
47
48
49
# File 'app/models/workarea/payment/tender.rb', line 42

def captured_amount
  transactions
    .successful
    .not_canceled
    .captures_or_purchased
    .sum(&:amount)
    .to_m
end

#has_amount?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/workarea/payment/tender.rb', line 32

def has_amount?
  amount > 0.to_m
end

#nameObject



28
29
30
# File 'app/models/workarea/payment/tender.rb', line 28

def name
  slug.to_s.humanize
end

#refundable?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/workarea/payment/tender.rb', line 71

def refundable?
  refundable_amount > 0
end

#refundable_amountObject



67
68
69
# File 'app/models/workarea/payment/tender.rb', line 67

def refundable_amount
  guard_negative_price { captured_amount - refunded_amount }
end

#refunded_amountObject



59
60
61
# File 'app/models/workarea/payment/tender.rb', line 59

def refunded_amount
  transactions.successful.not_canceled.refunds.sum(&:amount).to_m
end

#slugObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'app/models/workarea/payment/tender.rb', line 24

def slug
  raise NotImplementedError, "#{self.class} must implement #slug"
end

#uncaptured_amountObject

Exclude purchases - this is the amount of authorized funds that haven’t yet been captured.



53
54
55
56
57
# File 'app/models/workarea/payment/tender.rb', line 53

def uncaptured_amount
  guard_negative_price do
    authorized_amount - transactions.successful.captures.sum(&:amount).to_m
  end
end