Class: Twocheckout::Invoice
- Inherits:
-
HashObject
- Object
- HashObject
- Twocheckout::Invoice
- Defined in:
- lib/twocheckout/invoice.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#active_lineitems ⇒ Object
Get active recurring lineitems.
-
#lineitem ⇒ Object
A hash to index line-items by id.
-
#lineitems ⇒ Object
An array of all line-items in this invoice.
-
#refund!(opts) ⇒ Object
Refund invoice.
- #stop_recurring! ⇒ Object
Methods inherited from HashObject
#initialize, #inspect, #method_missing
Constructor Details
This class inherits a constructor from Twocheckout::HashObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Twocheckout::HashObject
Class Method Details
.find(options) ⇒ Object
4 5 6 7 |
# File 'lib/twocheckout/invoice.rb', line 4 def self.find() response = Twocheckout::API.request(:get, 'sales/detail_sale', ) Sale.new(response['sale']).invoice[[:invoice_id]] end |
Instance Method Details
#active_lineitems ⇒ Object
Get active recurring lineitems
43 44 45 |
# File 'lib/twocheckout/invoice.rb', line 43 def active_lineitems @active_lineitems ||= lineitems.select(&:active?).freeze end |
#lineitem ⇒ Object
A hash to index line-items by id
23 24 25 26 27 28 29 30 |
# File 'lib/twocheckout/invoice.rb', line 23 def lineitem if @lineitem.nil? @lineitem = {} lineitems.each { |li| @lineitem[li.lineitem_id] = li } @lineitem.freeze end return @lineitem end |
#lineitems ⇒ Object
An array of all line-items in this invoice
12 13 14 15 16 17 18 |
# File 'lib/twocheckout/invoice.rb', line 12 def lineitems if @lineitems.nil? @lineitems = @hash['lineitems'].map { |li| Twocheckout::LineItem.new(li) } @lineitems.freeze end @lineitems end |
#refund!(opts) ⇒ Object
Refund invoice
35 36 37 38 |
# File 'lib/twocheckout/invoice.rb', line 35 def refund!(opts) opts = opts.merge(:invoice_id => self.invoice_id) Twocheckout::API.request(:post, 'sales/refund_invoice', opts) end |
#stop_recurring! ⇒ Object
47 48 49 |
# File 'lib/twocheckout/invoice.rb', line 47 def stop_recurring! active_lineitems.each { |li| li.stop_recurring! } end |