Class: MerchantSidekick::Invoice
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MerchantSidekick::Invoice
show all
- Includes:
- AASM
- Defined in:
- lib/merchant_sidekick/invoice.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#authorization ⇒ Object
Returns the value of attribute authorization.
8
9
10
|
# File 'lib/merchant_sidekick/invoice.rb', line 8
def authorization
@authorization
end
|
Instance Method Details
#enter_authorized ⇒ Object
60
|
# File 'lib/merchant_sidekick/invoice.rb', line 60
def enter_authorized; end
|
#enter_paid ⇒ Object
61
|
# File 'lib/merchant_sidekick/invoice.rb', line 61
def enter_paid; end
|
#enter_payment_declined ⇒ Object
64
|
# File 'lib/merchant_sidekick/invoice.rb', line 64
def enter_payment_declined; end
|
#enter_pending ⇒ Object
state transition callbacks
59
|
# File 'lib/merchant_sidekick/invoice.rb', line 59
def enter_pending; end
|
#enter_refunded ⇒ Object
63
|
# File 'lib/merchant_sidekick/invoice.rb', line 63
def enter_refunded; end
|
#enter_voided ⇒ Object
62
|
# File 'lib/merchant_sidekick/invoice.rb', line 62
def enter_voided; end
|
#evaluate ⇒ Object
updates the order and all contained line_items after an address has changed or an order item was added or removed. The order can only be evaluated if the created state is active. The order is saved if it is an existing order. Returns true if evaluation happend, false if not.
144
145
146
147
148
149
150
|
# File 'lib/merchant_sidekick/invoice.rb', line 144
def evaluate
result = false
self.line_items.each(&:evaluate)
self.calculate
result = save(false) unless self.new_record?
result
end
|
#exit_authorized ⇒ Object
67
|
# File 'lib/merchant_sidekick/invoice.rb', line 67
def exit_authorized; end
|
#exit_paid ⇒ Object
68
|
# File 'lib/merchant_sidekick/invoice.rb', line 68
def exit_paid; end
|
#exit_payment_declined ⇒ Object
71
|
# File 'lib/merchant_sidekick/invoice.rb', line 71
def exit_payment_declined; end
|
#exit_pending ⇒ Object
66
|
# File 'lib/merchant_sidekick/invoice.rb', line 66
def exit_pending; end
|
#exit_refunded ⇒ Object
70
|
# File 'lib/merchant_sidekick/invoice.rb', line 70
def exit_refunded; end
|
#exit_voided ⇒ Object
69
|
# File 'lib/merchant_sidekick/invoice.rb', line 69
def exit_voided; end
|
#gross_total ⇒ Object
Gross amount including tax
131
132
133
|
# File 'lib/merchant_sidekick/invoice.rb', line 131
def gross_total
self.gross_amount ||= self.net_total + self.tax_total
end
|
#guard_payment_authorized_from_payment_declined ⇒ Object
80
|
# File 'lib/merchant_sidekick/invoice.rb', line 80
def guard_payment_authorized_from_payment_declined; true; end
|
#guard_payment_authorized_from_pending ⇒ Object
81
|
# File 'lib/merchant_sidekick/invoice.rb', line 81
def guard_payment_authorized_from_pending; true; end
|
#guard_payment_captured_from_authorized ⇒ Object
79
|
# File 'lib/merchant_sidekick/invoice.rb', line 79
def guard_payment_captured_from_authorized; true; end
|
#guard_payment_paid_from_pending ⇒ Object
82
|
# File 'lib/merchant_sidekick/invoice.rb', line 82
def guard_payment_paid_from_pending; true; end
|
#guard_payment_refunded_from_paid ⇒ Object
77
|
# File 'lib/merchant_sidekick/invoice.rb', line 77
def guard_payment_refunded_from_paid; true; end
|
#guard_payment_voided_from_authorized ⇒ Object
78
|
# File 'lib/merchant_sidekick/invoice.rb', line 78
def guard_payment_voided_from_authorized; true; end
|
#guard_transaction_declined_from_authorized ⇒ Object
74
|
# File 'lib/merchant_sidekick/invoice.rb', line 74
def guard_transaction_declined_from_authorized; true; end
|
#guard_transaction_declined_from_payment_declined ⇒ Object
75
|
# File 'lib/merchant_sidekick/invoice.rb', line 75
def guard_transaction_declined_from_payment_declined; true; end
|
#guard_transaction_declined_from_pending ⇒ Object
76
|
# File 'lib/merchant_sidekick/invoice.rb', line 76
def guard_transaction_declined_from_pending; true; end
|
#net_total ⇒ Object
119
120
121
|
# File 'lib/merchant_sidekick/invoice.rb', line 119
def net_total
self.net_amount ||= line_items.inject(::Money.new(0, self.currency || ::Money.default_currency.iso_code)) {|sum,line| sum + line.net_amount}
end
|
#number ⇒ Object
93
94
95
|
# File 'lib/merchant_sidekick/invoice.rb', line 93
def number
self[:number] ||= Order.generate_unique_id
end
|
#payment_options(options = {}) ⇒ Object
returns a hash of additional merchant data passed to authorize you want to pass in the following additional options
:ip => ip address of the buyer
102
103
104
|
# File 'lib/merchant_sidekick/invoice.rb', line 102
def payment_options(options={})
{}.merge(options)
end
|
#payment_type ⇒ Object
Also known as:
payment_method
From payments, returns :credit_card, etc.
107
108
109
|
# File 'lib/merchant_sidekick/invoice.rb', line 107
def payment_type
payments.first.payment_type if payments
end
|
#payment_type_display ⇒ Object
Also known as:
payment_method_display
Human readable payment type
113
114
115
|
# File 'lib/merchant_sidekick/invoice.rb', line 113
def payment_type_display
self.payment_type.to_s.titleize
end
|
#tax_total ⇒ Object
Calculates tax and sets the tax_amount attribute It adds tax_amount across all line_items
125
126
127
128
|
# File 'lib/merchant_sidekick/invoice.rb', line 125
def tax_total
self.tax_amount = line_items.inject(::Money.new(0, self.currency || ::Money.default_currency.iso_code)) {|sum,line| sum + line.tax_amount}
self.tax_amount
end
|
#total ⇒ Object
136
137
138
|
# File 'lib/merchant_sidekick/invoice.rb', line 136
def total
self.gross_total
end
|