fiscalizer 0.0.12 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rspec +2 -0
  4. data/Gemfile +0 -4
  5. data/LICENSE.txt +1 -1
  6. data/README.md +187 -171
  7. data/bin/console +14 -0
  8. data/bin/setup +7 -0
  9. data/doc/Tehnicka specifikacija za korisnike 1.4.pdf +0 -0
  10. data/fiscalizer.gemspec +14 -13
  11. data/lib/fiscalizer.rb +33 -4
  12. data/lib/fiscalizer/constants.rb +11 -0
  13. data/lib/fiscalizer/data_objects/echo.rb +10 -0
  14. data/lib/fiscalizer/data_objects/fee.rb +18 -0
  15. data/lib/fiscalizer/data_objects/invoice.rb +79 -0
  16. data/lib/fiscalizer/data_objects/office.rb +41 -0
  17. data/lib/fiscalizer/{tax.rb → data_objects/tax.rb} +3 -5
  18. data/lib/fiscalizer/deserializers/base.rb +58 -0
  19. data/lib/fiscalizer/deserializers/echo.rb +13 -0
  20. data/lib/fiscalizer/deserializers/invoice.rb +9 -0
  21. data/lib/fiscalizer/deserializers/office.rb +6 -0
  22. data/lib/fiscalizer/fiscalizer.rb +36 -152
  23. data/lib/fiscalizer/fiscalizers/base.rb +54 -0
  24. data/lib/fiscalizer/fiscalizers/echo.rb +13 -0
  25. data/lib/fiscalizer/fiscalizers/invoice.rb +24 -0
  26. data/lib/fiscalizer/fiscalizers/office.rb +15 -0
  27. data/lib/fiscalizer/serializers/base.rb +58 -0
  28. data/lib/fiscalizer/serializers/echo.rb +21 -0
  29. data/lib/fiscalizer/serializers/invoice.rb +92 -0
  30. data/lib/fiscalizer/serializers/office.rb +85 -0
  31. data/lib/fiscalizer/serializers/signature.rb +62 -0
  32. data/lib/fiscalizer/serializers/tax.rb +81 -0
  33. data/lib/fiscalizer/services/request_sender.rb +68 -0
  34. data/lib/fiscalizer/services/security_code_generator.rb +29 -0
  35. data/lib/fiscalizer/version.rb +1 -1
  36. data/spec/fiscalizer_spec.rb +119 -0
  37. data/spec/spec_helper.rb +9 -0
  38. metadata +67 -39
  39. data/doc/README.md +0 -3
  40. data/doc/Tehnicka_specifikacija_za_korisnike_1.2.pdf +0 -0
  41. data/example/README.md +0 -25
  42. data/example/echo_P12.rb +0 -13
  43. data/example/echo_public_and_private_keys.rb +0 -16
  44. data/example/invoice_fiscalization_passing_arguments.rb +0 -44
  45. data/example/invoice_fiscalization_passing_object.rb +0 -48
  46. data/example/office_fiscalization_passing_arguments.rb +0 -22
  47. data/example/office_fiscalization_passing_object.rb +0 -26
  48. data/lib/README.md +0 -0
  49. data/lib/fiscalizer/README.md +0 -9
  50. data/lib/fiscalizer/communication.rb +0 -305
  51. data/lib/fiscalizer/echo.rb +0 -11
  52. data/lib/fiscalizer/fee.rb +0 -20
  53. data/lib/fiscalizer/invoice.rb +0 -190
  54. data/lib/fiscalizer/office.rb +0 -66
  55. data/lib/fiscalizer/response.rb +0 -124
  56. data/test/README.md +0 -13
  57. data/test/test_echo.rb +0 -20
  58. data/test/test_fee +0 -64
  59. data/test/test_fiscalizer.rb +0 -222
  60. data/test/test_fiscalizer_communication.rb +0 -28
  61. data/test/test_invoice.rb +0 -11
  62. data/test/test_office.rb +0 -11
  63. data/test/test_tax.rb +0 -89
@@ -4,22 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'fiscalizer/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "fiscalizer"
7
+ spec.name = 'fiscalizer'
8
8
  spec.version = Fiscalizer::VERSION
9
- spec.authors = ["Stanko Krtalić Rusendić"]
10
- spec.email = ["stanko.krtalic-rusendic@infinum.hr"]
11
- spec.description = %q{Automatic fiscalization}
12
- spec.summary = %q{A gem that automatically handles fiscalization}
13
- spec.homepage = "https://github.com/infinum/fiscalizer"
14
- spec.license = "MIT"
15
-
9
+ spec.authors = ['Stanko Krtalić Rusendić', 'Vladimir Rosančić']
10
+ spec.email = ['stanko.krtalic@gmail.com', 'vladimir.rosancic@infinum.hr']
11
+ spec.description = 'Automatic fiscalization'
12
+ spec.summary = 'A gem that automatically handles fiscalization'
13
+ spec.homepage = 'https://github.com/infinum/fiscalizer'
14
+ spec.license = 'MIT'
16
15
  spec.files = `git ls-files`.split($/)
17
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
20
19
 
21
- spec.add_dependency "nokogiri", "~> 1.6"
22
- spec.add_dependency "xmldsig-fiscalizer", "~> 0.2"
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake", '~> 10.3'
20
+ spec.add_dependency 'nokogiri', '~> 1.6'
21
+ spec.add_dependency 'xmldsig-fiscalizer', '~> 0.2'
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake', '~> 10.3'
24
+ spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'rspec'
25
26
  end
@@ -1,8 +1,37 @@
1
- require "bundler/setup"
2
- require "fiscalizer/version"
3
- require "fiscalizer/fiscalizer"
1
+ require 'bundler/setup'
4
2
  require 'uri'
5
3
  require 'net/http'
6
4
  require 'openssl'
7
5
  require 'nokogiri'
8
- require 'xmldsig_fiscalizer'
6
+ require 'xmldsig_fiscalizer'
7
+
8
+ require 'fiscalizer/version'
9
+ require 'fiscalizer/fiscalizer'
10
+
11
+ require 'fiscalizer/constants'
12
+
13
+ require 'fiscalizer/data_objects/echo'
14
+ require 'fiscalizer/data_objects/invoice'
15
+ require 'fiscalizer/data_objects/office'
16
+ require 'fiscalizer/data_objects/tax'
17
+ require 'fiscalizer/data_objects/fee'
18
+
19
+ require 'fiscalizer/fiscalizers/base'
20
+ require 'fiscalizer/fiscalizers/echo'
21
+ require 'fiscalizer/fiscalizers/invoice'
22
+ require 'fiscalizer/fiscalizers/office'
23
+
24
+ require 'fiscalizer/serializers/base'
25
+ require 'fiscalizer/serializers/echo'
26
+ require 'fiscalizer/serializers/invoice'
27
+ require 'fiscalizer/serializers/office'
28
+ require 'fiscalizer/serializers/signature'
29
+ require 'fiscalizer/serializers/tax'
30
+
31
+ require 'fiscalizer/deserializers/base'
32
+ require 'fiscalizer/deserializers/echo'
33
+ require 'fiscalizer/deserializers/invoice'
34
+ require 'fiscalizer/deserializers/office'
35
+
36
+ require 'fiscalizer/services/request_sender'
37
+ require 'fiscalizer/services/security_code_generator'
@@ -0,0 +1,11 @@
1
+ class Fiscalizer
2
+ module Constants
3
+ DEMO_URL = 'https://cistest.apis-it.hr:8449/FiskalizacijaServiceTest'
4
+ PROD_URL = 'https://cis.porezna-uprava.hr:8449/FiskalizacijaService'
5
+ TNS = 'http://www.apis-it.hr/fin/2012/types/f73'
6
+ XSI = 'http://www.w3.org/2001/XMLSchema-instance'
7
+ SCHEMA_LOCATION = 'http://www.apis-it.hr/fin/2012/types/f73 FiskalizacijaSchema.xsd'
8
+ DEMO_CERT_ISSUER = 'OU=DEMO,O=FINA,C=HR'
9
+ PROD_CERT_ISSUER = 'OU=RDC,O=FINA,C=HR'
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ class Fiscalizer
2
+ class Echo
3
+ def initialize(message:)
4
+ @message = message
5
+ end
6
+
7
+ attr_reader :message
8
+ attr_accessor :generated_xml
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ class Fiscalizer
2
+ class Fee
3
+ def initialize(name:, value:)
4
+ @name = name
5
+ @value = value
6
+ end
7
+
8
+ attr_accessor :name, :value
9
+
10
+ def value
11
+ @value.to_f.round(2)
12
+ end
13
+
14
+ def value_str
15
+ format('%15.2f', value).strip
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,79 @@
1
+ class Fiscalizer
2
+ class Invoice
3
+ # rubocop:disable Metrics/ParameterLists, Metrics/AbcSize, Metrics/MethodLength
4
+ def initialize(uuid:, time_sent:, pin:, in_vat_system:, time_issued:, consistance_mark:,
5
+ issued_number:, issued_office:, issued_machine:, summed_total:,
6
+ payment_method:, operator_pin:, subsequent_delivery:,
7
+ tax_vat: [], tax_spending: [], tax_other: [],
8
+ value_tax_liberation: nil, value_tax_margin: nil, value_non_taxable: nil,
9
+ fees: [], paragon_label: nil, specific_purpose: nil)
10
+
11
+ @uuid = uuid
12
+ @time_sent = time_sent
13
+ @pin = pin
14
+ @in_vat_system = in_vat_system
15
+ @time_issued = time_issued
16
+ @consistance_mark = consistance_mark
17
+ @issued_number = issued_number
18
+ @issued_office = issued_office
19
+ @issued_machine = issued_machine
20
+ @tax_vat = tax_vat
21
+ @tax_spending = tax_spending
22
+ @tax_other = tax_other
23
+ @value_tax_liberation = value_tax_liberation
24
+ @value_tax_margin = value_tax_margin
25
+ @value_non_taxable = value_non_taxable
26
+ @fees = fees
27
+ @summed_total = summed_total
28
+ @payment_method = payment_method
29
+ @operator_pin = operator_pin
30
+ @subsequent_delivery = subsequent_delivery
31
+ @paragon_label = paragon_label
32
+ @specific_purpose = specific_purpose
33
+ end
34
+
35
+ attr_reader :uuid, :time_sent, :pin,
36
+ :in_vat_system, :time_issued, :consistance_mark,
37
+ :issued_number, :issued_office, :issued_machine,
38
+ :tax_vat, :tax_spending, :tax_other,
39
+ :value_tax_liberation, :value_tax_margin, :value_non_taxable,
40
+ :fees, :summed_total, :payment_method,
41
+ :operator_pin, :subsequent_delivery,
42
+ :paragon_label, :specific_purpose
43
+
44
+ attr_accessor :security_code, :generated_xml
45
+
46
+ def time_issued_str(separator = 'T')
47
+ time_issued.strftime("%d.%m.%Y#{separator}%H:%M:%S")
48
+ end
49
+
50
+ def time_sent_str(separator = 'T')
51
+ time_sent.strftime("%d.%m.%Y#{separator}%H:%M:%S")
52
+ end
53
+
54
+ def summed_total_str
55
+ format_decimal(summed_total)
56
+ end
57
+
58
+ def value_tax_liberation_str
59
+ return if value_tax_liberation.nil?
60
+ format_decimal(value_tax_liberation.round(2))
61
+ end
62
+
63
+ def value_tax_margin_str
64
+ return if value_tax_margin.nil?
65
+ format_decimal(value_tax_margin.round(2))
66
+ end
67
+
68
+ def value_non_taxable_str
69
+ return if value_non_taxable.nil?
70
+ format_decimal(value_non_taxable.round(2))
71
+ end
72
+
73
+ private
74
+
75
+ def format_decimal(value)
76
+ format('%15.2f', value).strip
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,41 @@
1
+ class Fiscalizer
2
+ class Office
3
+ # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
4
+ def initialize(uuid:, time_sent:, pin:, office_label:, office_time:, take_effect_date:,
5
+ adress_street_name: nil, adress_house_num: nil, adress_house_num_addendum: nil,
6
+ adress_post_num: nil, adress_settlement: nil, adress_township: nil,
7
+ adress_other: nil, closure_mark: nil, specific_purpose: nil)
8
+
9
+ @uuid = uuid
10
+ @time_sent = time_sent
11
+ @pin = pin
12
+ @office_label = office_label
13
+ @adress_street_name = adress_street_name
14
+ @adress_house_num = adress_house_num
15
+ @adress_house_num_addendum = adress_house_num_addendum
16
+ @adress_post_num = adress_post_num
17
+ @adress_settlement = adress_settlement
18
+ @adress_township = adress_township
19
+ @adress_other = adress_other
20
+ @office_time = office_time
21
+ @take_effect_date = take_effect_date
22
+ @closure_mark = closure_mark
23
+ @specific_purpose = specific_purpose
24
+ end
25
+
26
+ attr_reader :uuid, :time_sent, :pin, :office_label, :adress_street_name,
27
+ :adress_house_num, :adress_house_num_addendum, :adress_post_num,
28
+ :adress_settlement, :adress_township, :adress_other, :office_time,
29
+ :take_effect_date, :closure_mark, :specific_purpose
30
+
31
+ attr_accessor :generated_xml
32
+
33
+ def time_sent_str(separator = 'T')
34
+ time_sent.strftime("%d.%m.%Y#{separator}%H:%M:%S")
35
+ end
36
+
37
+ def take_effect_date_str
38
+ take_effect_date.strftime('%d.%m.%Y')
39
+ end
40
+ end
41
+ end
@@ -1,15 +1,13 @@
1
1
  class Fiscalizer
2
2
  class Tax
3
- attr_accessor :base, :rate, :name, :total, :summed
4
-
5
- def initialize(base: 0.0, rate: 0.0, name: '', total: nil, summed: nil)
3
+ def initialize(base:, rate:, name:)
6
4
  @base = base
7
5
  @rate = rate
8
6
  @name = name
9
- @total = total
10
- @summed = summed
11
7
  end
12
8
 
9
+ attr_accessor :base, :rate, :name, :total, :summed
10
+
13
11
  def total
14
12
  @total || (base.to_f * (rate.to_f / 100.0)).round(2)
15
13
  end
@@ -0,0 +1,58 @@
1
+ class Fiscalizer
2
+ module Deserializers
3
+ class Base
4
+ include Constants
5
+
6
+ def initialize(raw_response, object)
7
+ @raw_response = raw_response
8
+ @object = object
9
+ end
10
+
11
+ attr_reader :raw_response, :object
12
+
13
+ def uuid
14
+ element_value(root, 'IdPoruke')
15
+ end
16
+
17
+ def processed_at
18
+ element_value(root, 'DatumVrijeme')
19
+ end
20
+
21
+ def errors?
22
+ error_nodes.any?
23
+ end
24
+
25
+ def errors
26
+ @errors ||= begin
27
+ error_nodes.map do |error_node|
28
+ {
29
+ code: element_value(error_node, 'SifraGreske'),
30
+ message: element_value(error_node, 'PorukaGreske')
31
+ }
32
+ end
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def element_value(root_node, element)
39
+ element = find(root_node, element).first
40
+ return if element.nil?
41
+
42
+ element.text
43
+ end
44
+
45
+ def find(root_node, element)
46
+ root_node.xpath("//tns:#{element}", 'tns' => TNS)
47
+ end
48
+
49
+ def root
50
+ Nokogiri::XML(raw_response).root
51
+ end
52
+
53
+ def error_nodes
54
+ @error_nodes ||= find(root, 'Greska')
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,13 @@
1
+ class Fiscalizer
2
+ module Deserializers
3
+ class Echo < Base
4
+ def echo_response
5
+ element_value(root, 'EchoResponse')
6
+ end
7
+
8
+ def success?
9
+ echo_response == object.message
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class Fiscalizer
2
+ module Deserializers
3
+ class Invoice < Base
4
+ def unique_identifier
5
+ element_value(root, 'Jir')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ class Fiscalizer
2
+ module Deserializers
3
+ class Office < Base
4
+ end
5
+ end
6
+ end
@@ -1,153 +1,37 @@
1
- require 'fiscalizer/communication'
2
- require 'fiscalizer/echo'
3
- require 'fiscalizer/office'
4
- require 'fiscalizer/invoice'
5
- require 'fiscalizer/response'
6
-
7
1
  class Fiscalizer
8
-
9
- # Accessible attributes
10
- attr_accessor :url, :key_public_path, :key_private_path, :certificate_path,
11
- :key_private, :key_public, :certificate,
12
- :tns, :schemaLocation, :certificate_issued_by,
13
- :timeout
14
-
15
- # Public methods
16
- def initialize( url: "https://cis.porezna-uprava.hr:8449/FiskalizacijaService",
17
- key_public_path: nil, key_private_path: nil, certificate_path: nil,
18
- tns: "http://www.apis-it.hr/fin/2012/types/f73",
19
- schemaLocation: "http://www.apis-it.hr/fin/2012/types/f73 FiskalizacijaSchema.xsd",
20
- certificate_issued_by: "OU=RDC,O=FINA,C=HR", certificate_p12_path: nil, password: nil, timeout:3)
21
- @url = url
22
- @key_public_path = key_public_path
23
- @key_private_path = key_private_path
24
- @certificate_path = certificate_path
25
- @certificate_p12_path = certificate_p12_path
26
- @tns = tns
27
- @schemaLocation = schemaLocation
28
- @timeout = timeout
29
-
30
- # Import certificates
31
- export_keys password
32
-
33
- if @key_public_path != nil && File.exists?(@key_public_path)
34
- @key_public = OpenSSL::X509::Certificate.new(File.read(@key_public_path))
35
- end
36
-
37
- if @key_private_path != nil && File.exists?(@key_private_path)
38
- @key_private = OpenSSL::PKey::RSA.new(File.read(@key_private_path))
39
- end
40
-
41
- if @certificate_path != nil && File.exists?(@certificate_path)
42
- @certificate = OpenSSL::X509::Certificate.new(File.read(@certificate_path))
43
- end
44
- end # new
45
-
46
- def echo echo=nil, text: "Hello World!"
47
- # Build echo request
48
- echo = Fiscalizer::Echo.new text: text if echo == nil
49
- # Send it
50
- comm = Fiscalizer::Communication.new url: @url, tns: @tns, schemaLocation: @schemaLocation,
51
- key_public: @key_public, key_private: @key_private,
52
- certificate: @certificate, certificate_issued_by: @certificate_issued_by,
53
- timeout:@timeout
54
- raw_response = comm.send echo
55
- response = Fiscalizer::Response.new object: echo, html_response: raw_response, tns: @tns
56
- return response
57
- end # echo
58
-
59
- def fiscalize_office( office=nil, uuid: nil, time_sent: nil, pin: nil,
60
- office_label: nil, adress_street_name: nil, adress_house_num: nil,
61
- adress_house_num_addendum: nil, adress_post_num: nil, adress_settlement: nil,
62
- adress_township: nil, adress_other: nil, office_time: nil, take_effect_date: nil,
63
- closure_mark: nil, specific_purpose: nil, reconnect_attempts: 3 )
64
- # Test connection
65
- response_alive = echo text: "Is the server alive?"
66
- recconect_attempted = 1
67
- reconnect_attempts = 0 if reconnect_attempts < 0
68
- while recconect_attempted < reconnect_attempts && !response_alive.echo?
69
- response_alive = echo text: "Is the server alive?"
70
- recconect_attempted += 1
71
- end
72
- if !response_alive.echo?
73
- response_alive.type = 0
74
- response_alive.errors['f100'] = "Failed to connect to server"
75
- return response_alive
76
- end
77
- # Build office
78
- office = Fiscalizer::Office.new( uuid: uuid, time_sent: time_sent, pin: pin,
79
- office_label: office_label, adress_street_name: adress_street_name, adress_house_num: adress_house_num,
80
- adress_house_num_addendum: adress_house_num_addendum, adress_post_num: adress_post_num, adress_settlement: adress_settlement,
81
- adress_township: adress_township, adress_other: adress_other, office_time: office_time, take_effect_date: take_effect_date,
82
- closure_mark: closure_mark, specific_purpose: specific_purpose) if office == nil
83
- # Send it
84
- comm = Fiscalizer::Communication.new url: @url, tns: @tns, schemaLocation: @schemaLocation,
85
- key_public: @key_public, key_private: @key_private,
86
- certificate: @certificate, certificate_issued_by: @certificate_issued_by,
87
- timeout:@timeout
88
- raw_response = comm.send office
89
- response = Fiscalizer::Response.new object: office, html_response: raw_response, tns: @tns
90
- return response
91
- end # fiscalize_office
92
- alias_method :office, :fiscalize_office
93
- alias_method :fiscalize_office_space, :fiscalize_office
94
-
95
- def fiscalize_invoice( invoice=nil, uuid: nil, time_sent: nil, pin: nil,
96
- in_vat_system: nil, time_issued: nil, consistance_mark: nil,
97
- issued_number: nil, issued_office: nil, issued_machine: nil,
98
- tax_vat: [], tax_spending: [], tax_other: [],
99
- value_tax_liberation: nil, value_tax_margin: nil, value_non_taxable: nil,
100
- fees: [], summed_total: nil, payment_method: nil,
101
- operator_pin: nil, security_code: nil, subsequent_delivery: nil,
102
- paragon_label: nil, specific_purpose: nil, unique_identifier: nil,
103
- automatic: true, reconnect_attempts: 3)
104
- # Test connection
105
- response_alive = echo text: "Is the server alive"
106
- recconect_attempted = 1
107
- reconnect_attempts = 0 if reconnect_attempts < 0
108
- while recconect_attempted < reconnect_attempts && !response_alive.echo?
109
- response_alive = echo text: "Is the server alive"
110
- recconect_attempted += 1
111
- end
112
- if !response_alive.echo?
113
- response_alive.type = 0
114
- response_alive.errors['f100'] = "Failed to connect to server"
115
- return response_alive
116
- end
117
- # Build invoice
118
- invoice = Fiscalizer::Invoice.new( uuid: uuid, time_sent: time_sent, pin: pin,
119
- in_vat_system: in_vat_system, time_issued: time_issued, consistance_mark: consistance_mark,
120
- issued_number: issued_number, issued_office: issued_office, issued_machine: issued_machine,
121
- tax_vat: tax_vat, tax_spending: tax_spending, tax_other: tax_other,
122
- value_tax_liberation: value_tax_liberation, value_tax_margin: value_tax_margin, value_non_taxable: value_non_taxable,
123
- fees: fees, summed_total: summed_total, payment_method: payment_method,
124
- operator_pin: operator_pin, security_code: security_code, subsequent_delivery: subsequent_delivery,
125
- paragon_label: paragon_label, specific_purpose: specific_purpose, unique_identifier: unique_identifier,
126
- automatic: automatic) if invoice == nil
127
- # Send it
128
- comm = Fiscalizer::Communication.new url: @url, tns: @tns, schemaLocation: @schemaLocation,
129
- key_public: @key_public, key_private: @key_private,
130
- certificate: @certificate, certificate_issued_by: @certificate_issued_by,
131
- timeout:@timeout
132
- raw_response = comm.send invoice
133
- response = Fiscalizer::Response.new object: invoice, html_response: raw_response, tns: @tns
134
- return response
135
- end # fiscalize_invoice
136
- alias_method :invoice, :fiscalize_invoice
137
-
138
- def certificate_p12_path= path
139
- @certificate_p12_path = path
140
- export_keys
141
- end # certificate_p12_path
142
-
143
- private
144
- def export_keys password
145
- if @certificate_p12_path != nil && File.exists?(@certificate_p12_path) && password != nil
146
- extracted = OpenSSL::PKCS12.new(File.read(@certificate_p12_path), password)
147
- @key_public = OpenSSL::X509::Certificate.new(extracted.certificate)
148
- @key_private = OpenSSL::PKey::RSA.new(extracted.key)
149
- @certificate = OpenSSL::X509::Certificate.new(extracted.ca_certs.first.to_s) if extracted.ca_certs != nil && extracted.ca_certs.size != 0
150
- end
151
- end # export_keys
152
-
153
- end # FiscalizerRuby
2
+ def initialize(app_cert_path:, password:, timeout: 3, demo: false, ca_cert_path: nil)
3
+ @app_cert_path = app_cert_path
4
+ @password = password
5
+ @timeout = timeout
6
+ @demo = demo
7
+ @ca_cert_path = ca_cert_path
8
+ end
9
+
10
+ attr_reader :app_cert_path, :password, :timeout, :demo, :ca_cert_path
11
+
12
+ def echo(message)
13
+ echo = Echo.new(message: message)
14
+ fiscalize(Fiscalizers::Echo, echo)
15
+ end
16
+
17
+ def fiscalize_invoice(invoice)
18
+ fiscalize(Fiscalizers::Invoice, invoice)
19
+ end
20
+
21
+ def fiscalize_office(office)
22
+ fiscalize(Fiscalizers::Office, office)
23
+ end
24
+
25
+ private
26
+
27
+ def fiscalize(fiscalizer_class, object_to_fiscalize)
28
+ fiscalizer_class.new(
29
+ app_cert_path,
30
+ password,
31
+ timeout,
32
+ demo,
33
+ ca_cert_path,
34
+ object_to_fiscalize
35
+ ).call
36
+ end
37
+ end