octobat 0.0.12 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +20 -10
- data/History.txt +33 -0
- data/VERSION +1 -1
- data/lib/octobat.rb +95 -19
- data/lib/octobat/api_operations/delete.rb +1 -0
- data/lib/octobat/api_operations/list.rb +16 -9
- data/lib/octobat/api_operations/update.rb +7 -4
- data/lib/octobat/api_resource.rb +5 -2
- data/lib/octobat/{payment_mode.rb → checkout.rb} +1 -1
- data/lib/octobat/coupon.rb +32 -0
- data/lib/octobat/credit_note.rb +35 -0
- data/lib/octobat/credit_note_numbering_sequence.rb +13 -0
- data/lib/octobat/customer.rb +10 -2
- data/lib/octobat/document.rb +17 -0
- data/lib/octobat/document_email_template.rb +19 -0
- data/lib/octobat/document_language.rb +19 -0
- data/lib/octobat/document_template.rb +33 -0
- data/lib/octobat/emails_setting.rb +19 -0
- data/lib/octobat/errors/api_connection_error.rb +1 -1
- data/lib/octobat/errors/api_error.rb +1 -1
- data/lib/octobat/errors/authentication_error.rb +1 -1
- data/lib/octobat/errors/invalid_request_error.rb +2 -4
- data/lib/octobat/errors/octobat_error.rb +31 -5
- data/lib/octobat/errors/octobat_lib_error.rb +20 -0
- data/lib/octobat/exports_setting.rb +19 -0
- data/lib/octobat/invoice.rb +61 -12
- data/lib/octobat/invoice_numbering_sequence.rb +18 -0
- data/lib/octobat/item.rb +64 -0
- data/lib/octobat/list_object.rb +12 -4
- data/lib/octobat/octobat_object.rb +13 -4
- data/lib/octobat/payment_recipient.rb +7 -0
- data/lib/octobat/{numbering_sequence.rb → payment_recipient_reference.rb} +1 -1
- data/lib/octobat/payment_source.rb +16 -0
- data/lib/octobat/{invoice_item.rb → tax_evidence.rb} +1 -1
- data/lib/octobat/tax_evidence_request.rb +5 -0
- data/lib/octobat/tax_region_setting.rb +27 -0
- data/lib/octobat/transaction.rb +11 -0
- data/lib/octobat/util.rb +28 -10
- data/lib/octobat/version.rb +1 -1
- data/octobat.gemspec +3 -3
- metadata +33 -45
@@ -0,0 +1,35 @@
|
|
1
|
+
module Octobat
|
2
|
+
class CreditNote < APIResource
|
3
|
+
extend Octobat::APIOperations::List
|
4
|
+
include Octobat::APIOperations::Create
|
5
|
+
include Octobat::APIOperations::Update
|
6
|
+
|
7
|
+
def send_by_email(email_data = {})
|
8
|
+
response, api_key = Octobat.request(:post, send_url, @api_key, email_data)
|
9
|
+
refresh_from(response, api_key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def confirm
|
13
|
+
response, api_key = Octobat.request(:patch, confirm_url, @api_key)
|
14
|
+
refresh_from(response, api_key)
|
15
|
+
end
|
16
|
+
|
17
|
+
def items(params = {})
|
18
|
+
Item.list(params.merge({ :invoice => id }), @api_key)
|
19
|
+
end
|
20
|
+
|
21
|
+
def transactions(params = {})
|
22
|
+
Transaction.list(params.merge(invoice: id), @api_key)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def send_url
|
28
|
+
url + '/send'
|
29
|
+
end
|
30
|
+
|
31
|
+
def confirm_url
|
32
|
+
url + '/confirm'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,5 +1,18 @@
|
|
1
1
|
module Octobat
|
2
2
|
class CreditNoteNumberingSequence < APIResource
|
3
3
|
extend Octobat::APIOperations::List
|
4
|
+
include Octobat::APIOperations::Create
|
5
|
+
include Octobat::APIOperations::Update
|
6
|
+
|
7
|
+
def set_to_default
|
8
|
+
response, api_key = Octobat.request(:patch, set_to_default_url, @api_key)
|
9
|
+
refresh_from(response, api_key)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def set_to_default_url
|
15
|
+
url + '/default'
|
16
|
+
end
|
4
17
|
end
|
5
18
|
end
|
data/lib/octobat/customer.rb
CHANGED
@@ -3,10 +3,18 @@ module Octobat
|
|
3
3
|
extend Octobat::APIOperations::List
|
4
4
|
include Octobat::APIOperations::Create
|
5
5
|
include Octobat::APIOperations::Update
|
6
|
-
|
6
|
+
|
7
7
|
def invoices(params = {})
|
8
8
|
Invoice.all(params.merge({ :customer => id }), @api_key)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
|
+
def credit_notes(params = {})
|
12
|
+
CreditNote.all(params.merge({ :customer => id }), @api_key)
|
13
|
+
end
|
14
|
+
|
15
|
+
def payment_sources(params = {})
|
16
|
+
PaymentSource.all(params.merge({ :customer => id }), @api_key)
|
17
|
+
end
|
18
|
+
|
11
19
|
end
|
12
20
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Octobat
|
2
|
+
class Document < APIResource
|
3
|
+
|
4
|
+
|
5
|
+
def self.csv_export(params = {}, opts={})
|
6
|
+
api_key, headers = Util.parse_opts(opts)
|
7
|
+
api_key ||= @api_key
|
8
|
+
opts[:api_key] = api_key
|
9
|
+
|
10
|
+
instance = self.new(nil, opts)
|
11
|
+
|
12
|
+
response, api_key = Octobat.request(:post, url + '/csv_export', api_key, params)
|
13
|
+
return true
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Octobat
|
2
|
+
class DocumentEmailTemplate < APIResource
|
3
|
+
include Octobat::APIOperations::Create
|
4
|
+
include Octobat::APIOperations::Update
|
5
|
+
|
6
|
+
def self.default(params = {}, opts={})
|
7
|
+
api_key, headers = Util.parse_opts(opts)
|
8
|
+
api_key ||= @api_key
|
9
|
+
opts[:api_key] = api_key
|
10
|
+
|
11
|
+
instance = self.new(nil, opts)
|
12
|
+
|
13
|
+
response, api_key = Octobat.request(:get, url + '/default', api_key, params)
|
14
|
+
instance.refresh_from(response, api_key)
|
15
|
+
instance
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Octobat
|
2
|
+
class DocumentLanguage < APIResource
|
3
|
+
include Octobat::APIOperations::Create
|
4
|
+
include Octobat::APIOperations::Update
|
5
|
+
|
6
|
+
def self.default(params = {}, opts={})
|
7
|
+
api_key, headers = Util.parse_opts(opts)
|
8
|
+
api_key ||= @api_key
|
9
|
+
opts[:api_key] = api_key
|
10
|
+
|
11
|
+
instance = self.new(nil, opts)
|
12
|
+
|
13
|
+
response, api_key = Octobat.request(:get, url + '/default', api_key, params)
|
14
|
+
instance.refresh_from(response, api_key)
|
15
|
+
instance
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Octobat
|
2
|
+
class DocumentTemplate < APIResource
|
3
|
+
extend Octobat::APIOperations::List
|
4
|
+
include Octobat::APIOperations::Create
|
5
|
+
include Octobat::APIOperations::Update
|
6
|
+
|
7
|
+
def duplicate(params = {})
|
8
|
+
response, api_key = Octobat.request(:post, duplicate_url, @api_key, params)
|
9
|
+
refresh_from(response, api_key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def activate
|
13
|
+
response, api_key = Octobat.request(:patch, activate_url, @api_key)
|
14
|
+
refresh_from(response, api_key)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete
|
18
|
+
response, api_key = Octobat.request(:delete, url, @api_key)
|
19
|
+
refresh_from(response, api_key)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def duplicate_url
|
25
|
+
url + '/duplicate'
|
26
|
+
end
|
27
|
+
|
28
|
+
def activate_url
|
29
|
+
url + '/activate'
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Octobat
|
2
|
+
class EmailsSetting < APIResource
|
3
|
+
include Octobat::APIOperations::Create
|
4
|
+
include Octobat::APIOperations::Update
|
5
|
+
|
6
|
+
def self.default(params = {}, opts={})
|
7
|
+
api_key, headers = Util.parse_opts(opts)
|
8
|
+
api_key ||= @api_key
|
9
|
+
opts[:api_key] = api_key
|
10
|
+
|
11
|
+
instance = self.new(nil, opts)
|
12
|
+
|
13
|
+
response, api_key = Octobat.request(:get, url + '/default', api_key, params)
|
14
|
+
instance.refresh_from(response, api_key)
|
15
|
+
instance
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Octobat
|
2
2
|
class InvalidRequestError < OctobatError
|
3
|
-
attr_accessor :param
|
4
3
|
|
5
|
-
def initialize(
|
6
|
-
super(
|
7
|
-
@param = param
|
4
|
+
def initialize(error, http_status=nil, http_body=nil, json_body=nil)
|
5
|
+
super(error, http_status, http_body, json_body)
|
8
6
|
end
|
9
7
|
end
|
10
8
|
end
|
@@ -1,20 +1,46 @@
|
|
1
1
|
module Octobat
|
2
2
|
class OctobatError < StandardError
|
3
|
-
|
3
|
+
attr_accessor :message
|
4
|
+
attr_reader :error
|
4
5
|
attr_reader :http_status
|
5
6
|
attr_reader :http_body
|
6
7
|
attr_reader :json_body
|
7
8
|
|
8
|
-
def initialize(
|
9
|
-
@
|
9
|
+
def initialize(error=nil, http_status=nil, http_body=nil, json_body=nil)
|
10
|
+
@error = error
|
10
11
|
@http_status = http_status
|
11
12
|
@http_body = http_body
|
12
13
|
@json_body = json_body
|
13
14
|
end
|
15
|
+
|
16
|
+
def message
|
17
|
+
@message ||= generate_message_from_error
|
18
|
+
end
|
14
19
|
|
15
20
|
def to_s
|
16
21
|
status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
|
17
|
-
"#{status_string}#{
|
22
|
+
"#{status_string}#{message}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def generate_message_from_error
|
26
|
+
return "" if @error.nil?
|
27
|
+
a = []
|
28
|
+
|
29
|
+
@error.each_key do |k|
|
30
|
+
msg = k.eql?(:global) ? "" : "#{k.to_s}: "
|
31
|
+
msg << "#{serialize_errors_from(@error[k])}"
|
32
|
+
a << msg
|
33
|
+
end
|
34
|
+
|
35
|
+
a.join(". ")
|
36
|
+
end
|
37
|
+
|
38
|
+
def serialize_errors_from(err)
|
39
|
+
a = []
|
40
|
+
err.each do |e|
|
41
|
+
a << "#{e[:details]}"
|
42
|
+
end
|
43
|
+
a.join(', ')
|
18
44
|
end
|
19
45
|
end
|
20
|
-
end
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Octobat
|
2
|
+
class OctobatLibError < StandardError
|
3
|
+
attr_reader :message
|
4
|
+
attr_reader :http_status
|
5
|
+
attr_reader :http_body
|
6
|
+
attr_reader :json_body
|
7
|
+
|
8
|
+
def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil)
|
9
|
+
@message = message
|
10
|
+
@http_status = http_status
|
11
|
+
@http_body = http_body
|
12
|
+
@json_body = json_body
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
|
17
|
+
"#{status_string}#{@message}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Octobat
|
2
|
+
class ExportsSetting < APIResource
|
3
|
+
include Octobat::APIOperations::Create
|
4
|
+
include Octobat::APIOperations::Update
|
5
|
+
|
6
|
+
def self.default(params = {}, opts={})
|
7
|
+
api_key, headers = Util.parse_opts(opts)
|
8
|
+
api_key ||= @api_key
|
9
|
+
opts[:api_key] = api_key
|
10
|
+
|
11
|
+
instance = self.new(nil, opts)
|
12
|
+
|
13
|
+
response, api_key = Octobat.request(:get, url + '/default', api_key, params)
|
14
|
+
instance.refresh_from(response, api_key)
|
15
|
+
instance
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/octobat/invoice.rb
CHANGED
@@ -3,35 +3,84 @@ module Octobat
|
|
3
3
|
extend Octobat::APIOperations::List
|
4
4
|
include Octobat::APIOperations::Create
|
5
5
|
include Octobat::APIOperations::Update
|
6
|
+
|
7
|
+
|
8
|
+
def self.pdf_export(params = {}, opts={})
|
9
|
+
api_key, headers = Util.parse_opts(opts)
|
10
|
+
api_key ||= @api_key
|
11
|
+
opts[:api_key] = api_key
|
6
12
|
|
7
|
-
|
8
|
-
|
9
|
-
|
13
|
+
instance = self.new(nil, opts)
|
14
|
+
|
15
|
+
response, api_key = Octobat.request(:post, url + '/pdf_export', api_key, params)
|
16
|
+
return true
|
10
17
|
end
|
11
18
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
19
|
+
def self.csv_export(params = {}, opts={})
|
20
|
+
api_key, headers = Util.parse_opts(opts)
|
21
|
+
api_key ||= @api_key
|
22
|
+
opts[:api_key] = api_key
|
23
|
+
|
24
|
+
instance = self.new(nil, opts)
|
25
|
+
|
26
|
+
response, api_key = Octobat.request(:post, url + '/csv_export', api_key, params)
|
27
|
+
return true
|
15
28
|
end
|
16
29
|
|
17
|
-
|
30
|
+
|
31
|
+
def send_by_email(email_data = {})
|
32
|
+
response, api_key = Octobat.request(:post, send_url, @api_key, email_data)
|
33
|
+
refresh_from(response, api_key)
|
34
|
+
end
|
35
|
+
|
18
36
|
def confirm
|
19
37
|
response, api_key = Octobat.request(:patch, confirm_url, @api_key)
|
20
38
|
refresh_from(response, api_key)
|
21
39
|
end
|
22
40
|
|
41
|
+
def cancel
|
42
|
+
response, api_key = Octobat.request(:patch, cancel_url, @api_key)
|
43
|
+
refresh_from(response, api_key)
|
44
|
+
end
|
45
|
+
|
46
|
+
def cancel_and_replace
|
47
|
+
response, api_key = Octobat.request(:patch, cancel_and_replace_url, @api_key)
|
48
|
+
refresh_from(response, api_key)
|
49
|
+
end
|
50
|
+
|
51
|
+
def delete
|
52
|
+
response, api_key = Octobat.request(:delete, url, @api_key)
|
53
|
+
refresh_from(response, api_key)
|
54
|
+
end
|
55
|
+
|
56
|
+
def items(params = {})
|
57
|
+
Item.list(params.merge({ :invoice => id }), @api_key)
|
58
|
+
end
|
59
|
+
|
60
|
+
def transactions(params = {})
|
61
|
+
Transaction.list(params.merge(invoice: id), @api_key)
|
62
|
+
end
|
63
|
+
|
64
|
+
|
23
65
|
private
|
24
66
|
|
25
|
-
def pay_url
|
26
|
-
url + '/pay'
|
27
|
-
end
|
28
|
-
|
29
67
|
def send_url
|
30
68
|
url + '/send'
|
31
69
|
end
|
32
|
-
|
70
|
+
|
33
71
|
def confirm_url
|
34
72
|
url + '/confirm'
|
35
73
|
end
|
74
|
+
|
75
|
+
def cancel_url
|
76
|
+
url + '/cancel'
|
77
|
+
end
|
78
|
+
|
79
|
+
def cancel_and_replace_url
|
80
|
+
url + '/cancel_and_replace'
|
81
|
+
end
|
82
|
+
|
36
83
|
end
|
84
|
+
|
85
|
+
|
37
86
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Octobat
|
2
|
+
class InvoiceNumberingSequence < APIResource
|
3
|
+
extend Octobat::APIOperations::List
|
4
|
+
include Octobat::APIOperations::Create
|
5
|
+
include Octobat::APIOperations::Update
|
6
|
+
|
7
|
+
def set_to_default
|
8
|
+
response, api_key = Octobat.request(:patch, set_to_default_url, @api_key)
|
9
|
+
refresh_from(response, api_key)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def set_to_default_url
|
15
|
+
url + '/default'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/octobat/item.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module Octobat
|
2
|
+
class Item < APIResource
|
3
|
+
extend Octobat::APIOperations::List
|
4
|
+
include Octobat::APIOperations::Create
|
5
|
+
include Octobat::APIOperations::Update
|
6
|
+
include Octobat::APIOperations::Delete
|
7
|
+
|
8
|
+
|
9
|
+
def url
|
10
|
+
!parent_obj.nil? ? parentize_url : super
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def save_url
|
15
|
+
if self[:id] == nil && self.class.respond_to?(:create)
|
16
|
+
self.relative_save_url
|
17
|
+
else
|
18
|
+
url
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def parentize_url
|
24
|
+
if parent_obj.include?(:transaction)
|
25
|
+
"#{Transaction.url}/#{CGI.escape(parent_obj[:transaction])}/items/#{CGI.escape(id)}"
|
26
|
+
elsif parent_obj.include?(:invoice)
|
27
|
+
"#{Invoice.url}/#{CGI.escape(parent_obj[:invoice])}/items/#{CGI.escape(id)}"
|
28
|
+
elsif parent_obj.include?(:credit_note)
|
29
|
+
"#{CreditNote.url}/#{CGI.escape(parent_obj[:credit_note])}/items/#{CGI.escape(id)}"
|
30
|
+
else
|
31
|
+
url
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
def relative_save_url
|
38
|
+
if self[:transaction]
|
39
|
+
"#{Transaction.url}/#{CGI.escape(self[:transaction])}/items"
|
40
|
+
elsif self[:invoice]
|
41
|
+
"#{Invoice.url}/#{CGI.escape(self[:invoice])}/items"
|
42
|
+
elsif self[:credit_note]
|
43
|
+
"#{CreditNote.url}/#{CGI.escape(self[:credit_note])}/items"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def self.url
|
49
|
+
if @parent_resource.include?(:transaction)
|
50
|
+
"#{Transaction.url}/#{CGI.escape(@parent_resource[:transaction])}/items"
|
51
|
+
elsif @parent_resource.include?(:invoice)
|
52
|
+
"#{Invoice.url}/#{CGI.escape(@parent_resource[:invoice])}/items"
|
53
|
+
elsif @parent_resource.include?(:credit_note)
|
54
|
+
"#{CreditNote.url}/#{CGI.escape(@parent_resource[:credit_note])}/items"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.set_parent_resource(filters)
|
59
|
+
@parent_resource = filters.select{|k, v| [:transaction, :invoice, :credit_note].include?(k)}
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|