Class: MerchantSidekick::Invoice

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
AASM
Defined in:
lib/merchant_sidekick/invoice.rb

Direct Known Subclasses

PurchaseInvoice, SalesInvoice

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorizationObject

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_authorizedObject



60
# File 'lib/merchant_sidekick/invoice.rb', line 60

def enter_authorized; end

#enter_paidObject



61
# File 'lib/merchant_sidekick/invoice.rb', line 61

def enter_paid; end

#enter_payment_declinedObject



64
# File 'lib/merchant_sidekick/invoice.rb', line 64

def enter_payment_declined; end

#enter_pendingObject

state transition callbacks



59
# File 'lib/merchant_sidekick/invoice.rb', line 59

def enter_pending; end

#enter_refundedObject



63
# File 'lib/merchant_sidekick/invoice.rb', line 63

def enter_refunded; end

#enter_voidedObject



62
# File 'lib/merchant_sidekick/invoice.rb', line 62

def enter_voided; end

#evaluateObject

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_authorizedObject



67
# File 'lib/merchant_sidekick/invoice.rb', line 67

def exit_authorized; end

#exit_paidObject



68
# File 'lib/merchant_sidekick/invoice.rb', line 68

def exit_paid; end

#exit_payment_declinedObject



71
# File 'lib/merchant_sidekick/invoice.rb', line 71

def exit_payment_declined; end

#exit_pendingObject



66
# File 'lib/merchant_sidekick/invoice.rb', line 66

def exit_pending; end

#exit_refundedObject



70
# File 'lib/merchant_sidekick/invoice.rb', line 70

def exit_refunded; end

#exit_voidedObject



69
# File 'lib/merchant_sidekick/invoice.rb', line 69

def exit_voided; end

#gross_totalObject

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_declinedObject



80
# File 'lib/merchant_sidekick/invoice.rb', line 80

def guard_payment_authorized_from_payment_declined; true; end

#guard_payment_authorized_from_pendingObject



81
# File 'lib/merchant_sidekick/invoice.rb', line 81

def guard_payment_authorized_from_pending; true; end

#guard_payment_captured_from_authorizedObject



79
# File 'lib/merchant_sidekick/invoice.rb', line 79

def guard_payment_captured_from_authorized; true; end

#guard_payment_paid_from_pendingObject



82
# File 'lib/merchant_sidekick/invoice.rb', line 82

def guard_payment_paid_from_pending; true; end

#guard_payment_refunded_from_paidObject



77
# File 'lib/merchant_sidekick/invoice.rb', line 77

def guard_payment_refunded_from_paid; true; end

#guard_payment_voided_from_authorizedObject



78
# File 'lib/merchant_sidekick/invoice.rb', line 78

def guard_payment_voided_from_authorized; true; end

#guard_transaction_declined_from_authorizedObject

event guard callbacks



74
# File 'lib/merchant_sidekick/invoice.rb', line 74

def guard_transaction_declined_from_authorized; true; end

#guard_transaction_declined_from_payment_declinedObject



75
# File 'lib/merchant_sidekick/invoice.rb', line 75

def guard_transaction_declined_from_payment_declined; true; end

#guard_transaction_declined_from_pendingObject



76
# File 'lib/merchant_sidekick/invoice.rb', line 76

def guard_transaction_declined_from_pending; true; end

#net_totalObject

Net total amount



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

#numberObject



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_typeObject 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_displayObject 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_totalObject

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

#totalObject

Same as gross_total



136
137
138
# File 'lib/merchant_sidekick/invoice.rb', line 136

def total
  self.gross_total
end