Class: Caren::Store::Invoice
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
- .all(session) ⇒ Object
- .all_with_filter(filter, session) ⇒ Object
- .array_root ⇒ Object
- .filter_url(filter) ⇒ Object
- .find(id, session) ⇒ Object
- .init_dependent_objects(invoice) ⇒ Object
- .keys ⇒ Object
- .mark_as_open_url(id) ⇒ Object
- .mark_as_paid_url(id) ⇒ Object
- .mark_as_paid_xml(method = nil, description = nil) ⇒ Object
- .mark_as_revoked_url(id) ⇒ Object
- .node_root ⇒ Object
- .resource_location ⇒ Object
- .search(key, value, session) ⇒ Object
Instance Method Summary collapse
- #as_xml ⇒ Object
- #create(session) ⇒ Object
- #delete(session) ⇒ Object
- #mark_as_open(session) ⇒ Object
- #mark_as_paid(method, description, session) ⇒ Object
- #mark_as_revoked(session) ⇒ Object
- #update(session) ⇒ Object
Methods inherited from Base
from_xml, hash_from_image, #initialize, #node_root, resource_url, #resource_url, search_url, to_xml, #to_xml
Constructor Details
This class inherits a constructor from Caren::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Caren::Base
Class Method Details
.all(session) ⇒ Object
40 41 42 |
# File 'lib/caren/store/invoice.rb', line 40 def self.all session from_xml session.get(self.resource_url) end |
.all_with_filter(filter, session) ⇒ Object
36 37 38 |
# File 'lib/caren/store/invoice.rb', line 36 def self.all_with_filter filter, session from_xml session.get(self.filter_url(filter)) end |
.array_root ⇒ Object
116 117 118 |
# File 'lib/caren/store/invoice.rb', line 116 def self.array_root :invoices end |
.filter_url(filter) ⇒ Object
124 125 126 |
# File 'lib/caren/store/invoice.rb', line 124 def self.filter_url filter "#{self.resource_url}?filter=#{filter}" end |
.find(id, session) ⇒ Object
32 33 34 |
# File 'lib/caren/store/invoice.rb', line 32 def self.find id, session from_xml session.get(self.resource_url(id)) end |
.init_dependent_objects(invoice) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/caren/store/invoice.rb', line 97 def self.init_dependent_objects invoice if invoice.shipping_address.is_a?(Hash) invoice.shipping_address = Caren::Store::Address.new( invoice.shipping_address.merge(:purpose => 'shipping') ) end if invoice.billing_address.is_a?(Hash) invoice.billing_address = Caren::Store::Address.new( invoice.billing_address.merge(:purpose => 'billing') ) end if invoice.line_items.is_a?(Array) invoice.line_items = invoice.line_items.map do |li| Caren::Store::LineItem.new(li) if li.is_a?(Hash) end end return invoice end |
.keys ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/caren/store/invoice.rb', line 3 def self.keys [:id, # Integer (Caren id) :external_id, # Integer (Your id) :person_id, # Integer (Caren person id) :external_person_id, # Integer (Your person id) :currency, # String :reference, # String :requires_account, # Boolean :requires_payment, # Boolean :access_token, # String :invoice_url, # String :payment_url, # String :customer_email, # String :email_status, # String (unsent,sent,reminder_sent) :status, # String (draft open paid late revoked) :payment_method, # String :payment_method_description, # String :billing_address, # Store::Address(:purpose => 'billing') :shipping_address, # Store::Address(:purpose => 'shipping') :line_items, # Array of Store::LineItem :invoiced_at, # Datetime :paid_at, # Datetime ] + super end |
.mark_as_open_url(id) ⇒ Object
132 133 134 |
# File 'lib/caren/store/invoice.rb', line 132 def self.mark_as_open_url id "#{self.resource_url(id)}/mark_as_open" end |
.mark_as_paid_url(id) ⇒ Object
136 137 138 |
# File 'lib/caren/store/invoice.rb', line 136 def self.mark_as_paid_url id "#{self.resource_url(id)}/mark_as_paid" end |
.mark_as_paid_xml(method = nil, description = nil) ⇒ Object
68 69 70 71 |
# File 'lib/caren/store/invoice.rb', line 68 def self.mark_as_paid_xml method=nil, description=nil body = { :payment_method_description => description, :payment_method => method } return body.to_xml( :root => (self.node_root || self.class.node_root) ) end |
.mark_as_revoked_url(id) ⇒ Object
128 129 130 |
# File 'lib/caren/store/invoice.rb', line 128 def self.mark_as_revoked_url id "#{self.resource_url(id)}/mark_as_revoked" end |
.node_root ⇒ Object
120 121 122 |
# File 'lib/caren/store/invoice.rb', line 120 def self.node_root :invoice end |
.resource_location ⇒ Object
140 141 142 |
# File 'lib/caren/store/invoice.rb', line 140 def self.resource_location "/api/pro/store/invoices" end |
.search(key, value, session) ⇒ Object
28 29 30 |
# File 'lib/caren/store/invoice.rb', line 28 def self.search key, value, session from_xml session.get( self.search_url(key,value) ) end |
Instance Method Details
#as_xml ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/caren/store/invoice.rb', line 73 def as_xml # make sure we have the correct address nodes here billing_address.purpose = 'billing' if billing_address shipping_address.purpose = 'shipping' if shipping_address { :status => self.status, :external_id => self.external_id, :person_id => self.person_id, :external_person_id => self.external_person_id, :reference => self.reference, :requires_account => self.requires_account, :requires_payment => self.requires_payment, :customer_email => self.customer_email, :payment_method => self.payment_method, :payment_method_description => self.payment_method_description, :billing_address => self.billing_address, :shipping_address => self.shipping_address, :line_items => self.line_items, :invoiced_at => self.invoiced_at, :paid_at => self.paid_at } end |
#create(session) ⇒ Object
44 45 46 |
# File 'lib/caren/store/invoice.rb', line 44 def create session self.class.from_xml session.post(self.resource_url, self.to_xml) end |
#delete(session) ⇒ Object
52 53 54 |
# File 'lib/caren/store/invoice.rb', line 52 def delete session session.delete self.class.resource_url(self.id) end |
#mark_as_open(session) ⇒ Object
64 65 66 |
# File 'lib/caren/store/invoice.rb', line 64 def mark_as_open session self.class.from_xml session.post(self.class.mark_as_open_url(self.id), nil) end |
#mark_as_paid(method, description, session) ⇒ Object
56 57 58 |
# File 'lib/caren/store/invoice.rb', line 56 def mark_as_paid method, description, session self.class.from_xml session.post(self.class.mark_as_paid_url(self.id), self.class.mark_as_paid_xml(method,description)) end |
#mark_as_revoked(session) ⇒ Object
60 61 62 |
# File 'lib/caren/store/invoice.rb', line 60 def mark_as_revoked session self.class.from_xml session.post(self.class.mark_as_revoked_url(self.id), nil) end |
#update(session) ⇒ Object
48 49 50 |
# File 'lib/caren/store/invoice.rb', line 48 def update session self.class.from_xml session.put(self.resource_url(self.id), self.to_xml) end |