Class: Workarea::Payment::Tender
- Inherits:
-
Object
- Object
- Workarea::Payment::Tender
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
Defined Under Namespace
Classes: CreditCard, StoreCredit
Instance Method Summary
collapse
#guard_negative_price
#releasable?
assert_valid_config!, async, disable, enable, inline, #run_callbacks
Instance Method Details
#authorized_amount ⇒ Object
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
75
76
77
|
# File 'app/models/workarea/payment/tender.rb', line 75
def capturable?
capturable_amount > 0
end
|
#capturable_amount ⇒ Object
63
64
65
|
# File 'app/models/workarea/payment/tender.rb', line 63
def capturable_amount
guard_negative_price { authorized_amount - captured_amount }
end
|
#captured_amount ⇒ Object
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
32
33
34
|
# File 'app/models/workarea/payment/tender.rb', line 32
def has_amount?
amount > 0.to_m
end
|
#name ⇒ Object
28
29
30
|
# File 'app/models/workarea/payment/tender.rb', line 28
def name
slug.to_s.humanize
end
|
#refundable? ⇒ Boolean
71
72
73
|
# File 'app/models/workarea/payment/tender.rb', line 71
def refundable?
refundable_amount > 0
end
|
#refundable_amount ⇒ Object
67
68
69
|
# File 'app/models/workarea/payment/tender.rb', line 67
def refundable_amount
guard_negative_price { captured_amount - refunded_amount }
end
|
#refunded_amount ⇒ Object
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
|
#slug ⇒ Object
24
25
26
|
# File 'app/models/workarea/payment/tender.rb', line 24
def slug
raise NotImplementedError, "#{self.class} must implement #slug"
end
|
#uncaptured_amount ⇒ Object
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
|