Class: RSpreedly::Invoice

Inherits:
Base
  • Object
show all
Defined in:
lib/rspreedly/invoice.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#errors

Instance Method Summary collapse

Methods inherited from Base

api_request, #api_request, #attributes=, do_request, #initialize, #to_xml

Constructor Details

This class inherits a constructor from RSpreedly::Base

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



5
6
7
# File 'lib/rspreedly/invoice.rb', line 5

def amount
  @amount
end

#closedObject

Returns the value of attribute closed.



5
6
7
# File 'lib/rspreedly/invoice.rb', line 5

def closed
  @closed
end

#created_atObject

Returns the value of attribute created_at.



5
6
7
# File 'lib/rspreedly/invoice.rb', line 5

def created_at
  @created_at
end

#currency_codeObject

Returns the value of attribute currency_code.



5
6
7
# File 'lib/rspreedly/invoice.rb', line 5

def currency_code
  @currency_code
end

#line_itemsObject

Returns the value of attribute line_items.



5
6
7
# File 'lib/rspreedly/invoice.rb', line 5

def line_items
  @line_items
end

#priceObject

Returns the value of attribute price.



5
6
7
# File 'lib/rspreedly/invoice.rb', line 5

def price
  @price
end

#subscriberObject

Returns the value of attribute subscriber.



5
6
7
# File 'lib/rspreedly/invoice.rb', line 5

def subscriber
  @subscriber
end

#subscription_plan_idObject

Returns the value of attribute subscription_plan_id.



5
6
7
# File 'lib/rspreedly/invoice.rb', line 5

def subscription_plan_id
  @subscription_plan_id
end

#tokenObject

Returns the value of attribute token.



5
6
7
# File 'lib/rspreedly/invoice.rb', line 5

def token
  @token
end

#updated_atObject

Returns the value of attribute updated_at.



5
6
7
# File 'lib/rspreedly/invoice.rb', line 5

def updated_at
  @updated_at
end

Instance Method Details

#createObject Also known as: save

Create an Invoice (more) POST /api/v4/[short site name]/invoices.xml



18
19
20
21
22
23
24
# File 'lib/rspreedly/invoice.rb', line 18

def create
  begin
    create!
  rescue RSpreedly::Error::Base
    nil
  end      
end

#create!Object Also known as: save!



26
27
28
29
30
# File 'lib/rspreedly/invoice.rb', line 26

def create!
  result = api_request(:post, "/invoices.xml", :body => self.to_xml)
  self.attributes = result["invoice"]
  true      
end

#pay(payment) ⇒ Object

Pay an Invoice (more) PUT /api/v4/[short site name]/invoices/[invoice token]/pay.xml



54
55
56
57
58
59
60
# File 'lib/rspreedly/invoice.rb', line 54

def pay(payment)
  begin
    pay!(payment)
  rescue RSpreedly::Error::Base
    nil
  end
end

#pay!(payment) ⇒ Object



62
63
64
65
66
# File 'lib/rspreedly/invoice.rb', line 62

def pay!(payment)
  result = api_request(:put, "/invoices/#{self.token}/pay.xml", :body => payment.to_xml(:outer => 'payment'))
  self.attributes = result["invoice"]
  true      
end