Class: Iugu::Invoice

Inherits:
APIResource show all
Includes:
APICreate, APIDelete, APIFetch, APISave
Defined in:
lib/iugu/invoice.rb

Instance Attribute Summary

Attributes inherited from Object

#errors

Instance Method Summary collapse

Methods included from APIDelete

#delete

Methods included from APISave

#save

Methods included from APICreate

included

Methods included from APIFetch

included, #refresh

Methods inherited from APIResource

#is_new?, url

Methods inherited from Object

#add_accessor, #attributes, #copy, #initialize, #method_missing, #modified_attributes, #set_attributes

Constructor Details

This class inherits a constructor from Iugu::Object

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Iugu::Object

Instance Method Details

#cancelObject



13
14
15
16
17
18
19
20
# File 'lib/iugu/invoice.rb', line 13

def cancel
  copy Iugu::Factory.create_from_response(self.class.object_type, APIRequest.request("PUT", "#{self.class.url(self.id)}/cancel"))
  self.errors = nil
  true
rescue Iugu::RequestWithErrors => ex
  self.errors = ex.errors
  false
end

#customerObject



8
9
10
11
# File 'lib/iugu/invoice.rb', line 8

def customer
  return false unless @attributes["customer_id"]
  Customer.fetch @attributes["customer_id"]
end

#refundObject



22
23
24
25
26
27
28
29
# File 'lib/iugu/invoice.rb', line 22

def refund
  copy Iugu::Factory.create_from_response(self.class.object_type, APIRequest.request("POST", "#{self.class.url(self.id)}/refund"))
  self.errors = nil
  true
rescue Iugu::RequestWithErrors => ex
  self.errors = ex.errors
  false
end