-
Notifications
You must be signed in to change notification settings - Fork 304
Expand file tree
/
Copy pathinvoice.rb
More file actions
58 lines (48 loc) · 1.64 KB
/
Copy pathinvoice.rb
File metadata and controls
58 lines (48 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module Quickbooks
module Service
class Invoice < BaseService
def delete(invoice)
delete_by_query_string(invoice)
end
def url_for_resource(resource)
super(resource)
end
def fetch_by_id(id, params = {})
url = "#{url_for_base}/invoice/#{id}"
fetch_object(model, url, params)
end
def url_for_query(query = nil, start_position = 1, max_results = 20, options = {})
super(query, start_position, max_results, options)
end
def send(invoice, email_address=nil)
query = email_address.present? ? "?sendTo=#{email_address}" : ""
url = "#{url_for_resource(model::REST_RESOURCE)}/#{invoice.id}/send#{query}"
response = do_http_post(url, "", {}, { 'Content-Type' => 'application/octet-stream' })
if response.code.to_i == 200
model.from_xml(parse_singular_entity_response(model, response.plain_body))
else
nil
end
end
def pdf(invoice)
url = "#{url_for_resource(model::REST_RESOURCE)}/#{invoice.id}/pdf"
response = do_http_raw_get(url, {}, {'Accept' => 'application/pdf'})
response.plain_body
end
def void(invoice, options = {})
url = "#{url_for_resource(model::REST_RESOURCE)}?operation=void"
xml = invoice.to_xml_ns(options)
response = do_http_post(url, valid_xml_document(xml))
if response.code.to_i == 200
model.from_xml(parse_singular_entity_response(model, response.plain_body))
else
false
end
end
private
def model
Quickbooks::Model::Invoice
end
end
end
end