class Twocheckout::Sale

Public Class Methods

find(options) click to toggle source
# File lib/twocheckout/sale.rb, line 4
def self.find(options)
  response = Twocheckout::API.request(:get, 'sales/detail_sale', options)
  Sale.new(response['sale'])
end
list(opts) click to toggle source

Get sale list in an array

# 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) click to toggle source
# 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) click to toggle source
# File lib/twocheckout/sale.rb, line 9
def self.with_sale_id(sale_id)
  find(:sale_id => sale_id)
end

Public Instance Methods

active_lineitems() click to toggle source

Get active recurring lineitems from the most recent invoice

# File lib/twocheckout/sale.rb, line 51
def active_lineitems
  invoices.last.active_lineitems
end
comment(opts) click to toggle source

Add a sale comment

# 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() click to toggle source

A hash to index invoices by id

# 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() click to toggle source

An array of all invoices in this sale

# 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) click to toggle source

Refund sale

# 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) click to toggle source

Mark tangible sale as shipped

# 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!() click to toggle source

Stop all active recurring lineitems

# File lib/twocheckout/sale.rb, line 58
def stop_recurring!
  active_lineitems.each { |li| li.stop_recurring! }
end

Protected Instance Methods

_key() click to toggle source
# File lib/twocheckout/sale.rb, line 88
def _key
  self.sale_id
end