Class: Twocheckout::Sale
- Inherits:
-
HashObject
- Object
- HashObject
- Twocheckout::Sale
- Defined in:
- lib/twocheckout/sale.rb
Class Method Summary collapse
- .find(options) ⇒ Object
-
.list(opts) ⇒ Object
Get sale list in an array.
- .with_invoice_id(invoice_id) ⇒ Object
- .with_sale_id(sale_id) ⇒ Object
Instance Method Summary collapse
-
#active_lineitems ⇒ Object
Get active recurring lineitems from the most recent invoice.
-
#comment(opts) ⇒ Object
Add a sale comment.
-
#invoice ⇒ Object
A hash to index invoices by id.
-
#invoices ⇒ Object
An array of all invoices in this sale.
-
#refund!(opts) ⇒ Object
Refund sale.
-
#ship(opts) ⇒ Object
Mark tangible sale as shipped.
-
#stop_recurring! ⇒ Object
Stop all active recurring lineitems.
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/sale.rb', line 4 def self.find() response = Twocheckout::API.request(:get, 'sales/detail_sale', ) Sale.new(response['sale']) end |
.list(opts) ⇒ Object
Get sale list in an array
81 82 83 84 |
# File 'lib/twocheckout/sale.rb', line 81 def self.list(opts) response = Twocheckout::API.request(:get, 'sales/list_sales', opts) response['sale_summary'] end |
.with_invoice_id(invoice_id) ⇒ Object
13 14 15 |
# File 'lib/twocheckout/sale.rb', line 13 def self.with_invoice_id(invoice_id) find(:invoice_id => invoice_id) end |
.with_sale_id(sale_id) ⇒ Object
9 10 11 |
# File 'lib/twocheckout/sale.rb', line 9 def self.with_sale_id(sale_id) find(:sale_id => sale_id) end |
Instance Method Details
#active_lineitems ⇒ Object
Get active recurring lineitems from the most recent invoice
51 52 53 |
# File 'lib/twocheckout/sale.rb', line 51 def active_lineitems invoices.last.active_lineitems end |
#comment(opts) ⇒ Object
Add a sale comment
65 66 67 68 |
# File 'lib/twocheckout/sale.rb', line 65 def comment(opts) opts = opts.merge(:sale_id => self.sale_id) Twocheckout::API.request(:post, 'sales/create_comment', opts) end |
#invoice ⇒ Object
A hash to index invoices by id
31 32 33 34 35 36 37 38 |
# File 'lib/twocheckout/sale.rb', line 31 def invoice if @invoice.nil? @invoice = {} invoices.each { |inv| @invoice[inv.invoice_id] = inv } @invoice.freeze end return @invoice end |
#invoices ⇒ Object
An array of all invoices in this sale
20 21 22 23 24 25 26 |
# File 'lib/twocheckout/sale.rb', line 20 def invoices if @invoices.nil? @invoices = @hash['invoices'].map { |i| Twocheckout::Invoice.new(i) } @invoices.freeze end @invoices end |
#refund!(opts) ⇒ Object
Refund sale
43 44 45 46 |
# File 'lib/twocheckout/sale.rb', line 43 def refund!(opts) opts = opts.merge(:sale_id => self.sale_id) Twocheckout::API.request(:post, 'sales/refund_invoice', opts) end |
#ship(opts) ⇒ Object
Mark tangible sale as shipped
73 74 75 76 |
# File 'lib/twocheckout/sale.rb', line 73 def ship(opts) opts = opts.merge(:sale_id => self.sale_id) Twocheckout::API.request(:post, 'sales/mark_shipped', opts) end |
#stop_recurring! ⇒ Object
Stop all active recurring lineitems
58 59 60 |
# File 'lib/twocheckout/sale.rb', line 58 def stop_recurring! active_lineitems.each { |li| li.stop_recurring! } end |