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

#attributes, #errors, #unsaved_attributes

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

endpoint_url, #is_new?, object_base_uri, object_type, relative_url, url

Methods inherited from Object

#add_accessor, #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



16
17
18
19
20
21
22
23
24
25
# File 'lib/iugu/invoice.rb', line 16

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

#captureObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/iugu/invoice.rb', line 27

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

#customerObject



10
11
12
13
14
# File 'lib/iugu/invoice.rb', line 10

def customer
  return false unless @attributes["customer_id"]

  Customer.fetch @attributes["customer_id"]
end

#duplicate(attributes = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/iugu/invoice.rb', line 49

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

#refundObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/iugu/invoice.rb', line 38

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