fiscalizer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b43870b32c90984a5db5c7583c2f70df01916d8d
4
- data.tar.gz: ead8268033ac53e50d2a898d346b0ea94f4fed33
3
+ metadata.gz: a28f77e9a2a9ab8611c8b9115ec048cf8380bbe2
4
+ data.tar.gz: ed956c0403bf6066779ec8176f4e1da2944693fe
5
5
  SHA512:
6
- metadata.gz: 5678038340e62778d4541a91494311be302d4ef8e56ca69de343b34d95ce3b0b330f04dfad7d3192b298b5bc1a52e89f7f07436fe798ffc22fc2beed846bf373
7
- data.tar.gz: 5dc37bd0a1437c40a445a4039f6595fec9fe21711bdc0c3c59a9cd571430cd31564910f419814288657dd8b4c661a5cdad11ac94aed0d0efebc20233b9c9e416
6
+ metadata.gz: 27c61c79639ff2642f62f91f7781d9d1553f9a78dc1b34ab60ce559e677374d3975c64de3873df32de0bcd446dd3ea914472ae0450ad397aed074dd40c8cb031
7
+ data.tar.gz: 55369a83446b63c7788ab86b1afb54e85558a3f01a6bb8f016731ec922a7b9d60db5f1f8a3b2b3efa532cc9b38b999f226bd86b3c7bcfb7b8385c3952efcb11b
data/Gemfile CHANGED
@@ -3,5 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in fiscalizer_ruby.gemspec
4
4
  gemspec
5
5
  gem 'nokogiri'
6
- gem 'xmldsig', github: 'infinum/xmldsig', branch: 'allcase-reference-id'
6
+ gem 'xmldsig-fiscalizer'
7
7
  #gem 'pry-debugger'
data/doc/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Documentation
2
+
3
+ Here are all the files that describe the fiscalization API. The Gem is based on the API described in these files.
data/example/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Examples
2
+
3
+ ### echo_12
4
+
5
+ Demonstrates how to create a Fiscalizer object with a P12 certificate. How to make an echo request and check for, and print, errors.
6
+
7
+ ### echo_public_and_private_keys
8
+
9
+ Demonstrates how to create a Fiscalizer object from public and private keys and a certificate.
10
+
11
+ ### invoice_fiscalization_passing_object
12
+
13
+ Demonstrates how to ceate an Invoice object and fiscalize it. It also demonstrates how to create tax and fee objects and add them to the invoice object.
14
+
15
+ ### invoice_fiscalization_passing_arguments
16
+
17
+ Demonstrates how to create an invoice object and fiscalize ti by passing argumentst to the fiscalize_invoice method.
18
+
19
+ ### fiscalize_office
20
+
21
+ Demonstrates how to create and fiscalize an office object.
22
+
23
+ ### fiscalize_office
24
+
25
+ Demonstrates how to create and fiscalize an office space, by passing arguments.
@@ -24,21 +24,21 @@ end
24
24
  taxes_other << tax
25
25
  end
26
26
  # Generate invoice
27
- invoice_response = fiscal.invoice uuid: UUID,
28
- time_sent: Time.now,
29
- pin: PIN,
30
- in_vat_system: true,
31
- time_issued: Time.now - 3600,
32
- consistance_mark: "P",
33
- issued_number: "1",
34
- issued_office: "Pm2",
35
- issued_machine: "3",
36
- tax_vat: taxes_vat,
37
- tax_spending: taxes_spending,
38
- tax_other: taxes_other,
39
- payment_method: "g",
40
- operator_pin: PIN_OPERATOR,
41
- subsequent_delivery: false,
42
- value_non_taxable: 200.0
27
+ invoice_response = fiscal.fiscalize_invoice uuid: UUID,
28
+ time_sent: Time.now,
29
+ pin: "00123456789",
30
+ in_vat_system: true,
31
+ time_issued: Time.now - 3600,
32
+ consistance_mark: "P",
33
+ issued_number: "1",
34
+ issued_office: "Pm2",
35
+ issued_machine: "3",
36
+ tax_vat: taxes_vat,
37
+ tax_spending: taxes_spending,
38
+ tax_other: taxes_other,
39
+ payment_method: "g",
40
+ operator_pin: "12345678900",
41
+ subsequent_delivery: false,
42
+ value_non_taxable: 200.0
43
43
 
44
44
  puts "The server returned the following JIR: " + invoice_response.unique_identifier if !invoice_response.errors?
@@ -0,0 +1,48 @@
1
+ fiscal = Fiscalizer.new certificate_p12_path: "/path/to/FISKAL 1.p12",
2
+ password: "12345678"
3
+
4
+ # Generate Invoice
5
+ invoice = Fiscalizer::Invoice.new
6
+ invoice.uuid = UUID
7
+ invoice.time_sent = Time.now
8
+ invoice.pin = "00123456789"
9
+ invoice.in_vat_system = true
10
+ invoice.time_issued = Time.now - 3600
11
+ invoice.consistance_mark = "P"
12
+ invoice.issued_number = "1"
13
+ invoice.issued_office = "Pm2"
14
+ invoice.issued_machine = "3"
15
+ invoice.payment_method = "g"
16
+ invoice.operator_pin = "12345678900"
17
+ invoice.subsequent_delivery = false
18
+ invoice.value_non_taxable = 200.0
19
+
20
+ # Generate taxes
21
+ (0..5).each do |i|
22
+ tax = Fiscalizer::Tax.new
23
+ tax.base = rand(10000 * 100).to_f / 100.0
24
+ tax.rate = rand(100 * 100).to_f / 100.0
25
+ invoice.add_tax_vat tax
26
+ end
27
+ (0..5).each do |i|
28
+ tax = Fiscalizer::Tax.new
29
+ tax.base = rand(10000 * 100).to_f / 100.0
30
+ tax.rate = rand(100 * 100).to_f / 100.0
31
+ invoice.add_tax_other base: base, rate: rate, name: "Other tax #{i}"
32
+ end
33
+ (0..5).each do |i|
34
+ fee = Fiscalizer::Fee.new
35
+ fee.value = rand(10000 * 100).to_f / 100.0
36
+ fee.name = "My Test Fee #{i}"
37
+ invoice.add_fee fee
38
+ end
39
+ (0..5).each do |i|
40
+ fee = Fiscalizer::Fee.new
41
+ fee.value = rand(10000 * 100).to_f / 100.0
42
+ fee.name = "My Test Fee #{i}"
43
+ invoice.add_fee value: value, name: name
44
+ end
45
+ # Generate invoice
46
+ invoice_response = fiscal.fiscalize_invoice invoice
47
+
48
+ puts "The server returned the following JIR: " + invoice_response.unique_identifier if !invoice_response.errors?
@@ -0,0 +1,22 @@
1
+ fiscal = Fiscalizer.new certificate_p12_path: "/path/to/FISKAL 1.p12",
2
+ password: "12345678"
3
+
4
+ # Generate office
5
+ office_response = fiscal.office uuid: "ca996cc7-fcc3-4c50-961b-40c8b875a5e8",
6
+ time_sent: Time.now,
7
+ pin: "00123456789",
8
+ office_label: "Poslovnica1",
9
+ adress_street_name: "Somewhere",
10
+ adress_house_num: "42",
11
+ adress_house_num_addendum: "AD",
12
+ adress_post_num: "10000",
13
+ adress_settlement: "Block 25-C",
14
+ adress_township: "Vogsphere",
15
+ adress_other: nil,
16
+ office_time: "Pon-Pet: 8:00-16:00",
17
+ take_effect_date: Time.now + 3600 * 24 * 7,
18
+ closure_mark: nil,
19
+ specific_purpose: nil
20
+
21
+ puts "The server returned the following UUID: " + office_response.uuid if !office_response.errors?
22
+ puts "Office space fiscalization was successful!" if !office_response.errors?
@@ -0,0 +1,26 @@
1
+ fiscal = Fiscalizer.new certificate_p12_path: "/path/to/FISKAL 1.p12",
2
+ password: "12345678"
3
+
4
+ # Generate office
5
+ office = Fiscalizer::Office.new
6
+ office.uuid = "ca996cc7-fcc3-4c50-961b-40c8b875a5e8"
7
+ office.time_sent = Time.now
8
+ office.pin = "00123456789"
9
+ office.office_label = "Poslovnica1"
10
+ office.adress_street_name = "Somewhere"
11
+ office.adress_house_num = "42"
12
+ office.adress_house_num_addendum = "AD"
13
+ office.adress_post_num = "10000"
14
+ office.adress_settlement = "Block 25-C"
15
+ office.adress_township = "Vogsphere"
16
+ office.adress_other = nil
17
+ office.office_time = "Pon-Pet: 8:00-16:00"
18
+ office.take_effect_date = Time.now + 3600 * 24 * 7
19
+ office.closure_mark = nil
20
+ office.specific_purpose = nil
21
+
22
+ # Generate office
23
+ office_response = fiscal.fiscalize_office office
24
+
25
+ puts "The server returned the following UUID: " + office_response.uuid if !office_response.errors?
26
+ puts "Office space fiscalization was successful!" if !office_response.errors?
@@ -135,7 +135,7 @@ class Fiscalizer
135
135
  end
136
136
 
137
137
  body = soap_envelope(office_request_xml)
138
- unsigned_document = Xmldsig::SignedDocument.new(body.doc.root.to_xml)
138
+ unsigned_document = Xmldsig_fiscalizer::SignedDocument.new(body.doc.root.to_xml)
139
139
  signed_xml = unsigned_document.sign(@key_private)
140
140
  signed_xml.sub! '<?xml version="1.0"?>', ''
141
141
  signed_xml = signed_xml.gsub /^$\n/, ''
@@ -255,7 +255,7 @@ class Fiscalizer
255
255
  end
256
256
 
257
257
  body = soap_envelope(invoice_request_xml)
258
- unsigned_document = Xmldsig::SignedDocument.new(body.doc.root.to_xml)
258
+ unsigned_document = Xmldsig_fiscalizer::SignedDocument.new(body.doc.root.to_xml)
259
259
  signed_xml = unsigned_document.sign(@key_private)
260
260
  signed_xml.sub! '<?xml version="1.0"?>', ''
261
261
  signed_xml = signed_xml.gsub /^$\n/, ''
@@ -53,26 +53,26 @@ class Fiscalizer
53
53
  end # initialize
54
54
 
55
55
  # Add taxes
56
- def add_tax_vat base: 0.0, rate: 0.0, name: "", tax: nil
56
+ def add_tax_vat tax=nil, base: 0.0, rate: 0.0, name: ""
57
57
  tax = Fiscalizer::Tax.new base: base, rate: rate, name: name if tax == nil
58
58
  @tax_vat = Array.new if @tax_vat.class != Array
59
59
  @tax_vat << tax
60
60
  end # add_tax_vat
61
61
 
62
- def add_tax_spending base: 0.0, rate: 0.0, name: "", tax: nil
62
+ def add_tax_spending tax=nil, base: 0.0, rate: 0.0, name: ""
63
63
  tax = Fiscalizer::Tax.new base: base, rate: rate, name: name if tax == nil
64
64
  @tax_spending = Array.new if @tax_spending.class != Array
65
65
  @tax_spending << tax
66
66
  end # add_tax_spending
67
67
 
68
- def add_tax_other base: 0.0, rate: 0.0, name: "", tax: nil
68
+ def add_tax_other tax=nil, base: 0.0, rate: 0.0, name: ""
69
69
  tax = Fiscalizer::Tax.new base: base, rate: rate, name: name if tax == nil
70
70
  @tax_other = Array.new if @tax_other.class != Array
71
71
  @tax_other << tax
72
72
  end # add_tax_spending
73
73
 
74
74
  # Add fees
75
- def add_fee name: "", value: 0.0, fee: nil
75
+ def add_fee fee=nil, name: "", value: 0.0
76
76
  fee = Fiscalizer::Fee.new name: base, value: rate if fee == nil
77
77
  @fee << fee
78
78
  end # add_fee
@@ -1,3 +1,3 @@
1
1
  class Fiscalizer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/fiscalizer.rb CHANGED
@@ -5,4 +5,4 @@ require 'uri'
5
5
  require 'net/http'
6
6
  require 'openssl'
7
7
  require 'nokogiri'
8
- require 'xmldsig'
8
+ require 'xmldsig_fiscalizer'
data/test/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Test
2
+
3
+ ## Setup
4
+
5
+ It is important that in test enviroments both a P12 certificate (`certificate_p12_path`) and a signing certificate are passed to the Fiscalizer object (`certificate_path`). This is important because the test P12 certificates (suffixed with `.pfx`) don't contain signing certificates in them!
6
+
7
+ Don't forget to configutre all static variables in `test_fiscalizer.rb`
8
+
9
+ `EXPORTED_KEYS` specifies weather to initialize a Fiscalizer object with a P12 key or to use public and private kays instead.
10
+
11
+ __Note:__ If `EXPORTED_KEYS` is set to `true` than `KEY_PUBLIC_PATH` and `KEY_PRIVATE_PATH` have to be set.
12
+
13
+ __Note:__ On some machines the path to the certificates has to be an absolut path
@@ -5,10 +5,10 @@ require 'openssl'
5
5
 
6
6
  class FiscalizerTest < Test::Unit::TestCase
7
7
  # Configure
8
- KEY_PUBLIC_PATH = "/path/to/fiskal1.cert"
9
- KEY_PRIVATE_PATH = "/path/to/privateKey.key"
10
- CERTIFICATE_PATH = "/path/to/democacert.pem"
11
- CERTIFICATE_P12_PATH = "/path/to/fiskal1.pfx"
8
+ KEY_PUBLIC_PATH = "/test/assets/fiskal1.cert"
9
+ KEY_PRIVATE_PATH = "/test/assets/privateKey.key"
10
+ CERTIFICATE_PATH = "/test/assets/democacert.pem"
11
+ CERTIFICATE_P12_PATH = "/test/assets/fiskal1.pfx"
12
12
  URL_FISKAL = "https://cistest.apis-it.hr:8449/FiskalizacijaServiceTest"
13
13
  CER_ISSUED = "OU=DEMO,O=FINA,C=HR"
14
14
  PASSWORD = "12345678"
@@ -18,7 +18,7 @@ class FiscalizerTest < Test::Unit::TestCase
18
18
  UUID = "ca996cc7-fcc3-4c50-961b-40c8b875a5e8"
19
19
  ECHO = "This is a simple test..."
20
20
  # Personal information
21
- PIN = "00000000000"
21
+ PIN = "00123456789"
22
22
  PIN_OPERATOR = "00000000000"
23
23
 
24
24
  def test_initialization
@@ -48,22 +48,29 @@ class FiscalizerTest < Test::Unit::TestCase
48
48
  end # fiscal_ruby_test
49
49
 
50
50
  def test_echo
51
- fiscal = Fiscalizer.new url: URL_FISKAL,
52
- key_public_path: KEY_PUBLIC_PATH,
53
- key_private_path: KEY_PRIVATE_PATH,
54
- certificate_path: CERTIFICATE_PATH,
55
- certificate_issued_by: CER_ISSUED
51
+ fiscal = nil
52
+ if EXPORTED_KEYS
53
+ fiscal = Fiscalizer.new url: URL_FISKAL,
54
+ key_public_path: KEY_PUBLIC_PATH,
55
+ key_private_path: KEY_PRIVATE_PATH,
56
+ certificate_path: CERTIFICATE_PATH,
57
+ certificate_issued_by: CER_ISSUED
58
+ else
59
+ fiscal = Fiscalizer.new url: URL_FISKAL,
60
+ certificate_path: CERTIFICATE_PATH,
61
+ certificate_p12_path: CERTIFICATE_P12_PATH,
62
+ certificate_issued_by: CER_ISSUED,
63
+ password: PASSWORD
64
+ end
56
65
  echo = fiscal.echo text: ECHO
57
66
  assert_equal ECHO, echo.response, "Echo response message does not match sent message"
58
67
  assert echo.echo?, "Automatic echo check failed"
59
68
  end # test_echo
60
69
 
61
70
  def test_office
62
- # Configuration
63
- use_exported_keys = true
64
71
  # -- Here Be Dragons --
65
72
  fiscal = nil
66
- if use_exported_keys
73
+ if EXPORTED_KEYS
67
74
  fiscal = Fiscalizer.new url: URL_FISKAL,
68
75
  key_public_path: KEY_PUBLIC_PATH,
69
76
  key_private_path: KEY_PRIVATE_PATH,
@@ -99,11 +106,60 @@ class FiscalizerTest < Test::Unit::TestCase
99
106
  assert office.processed_at != nil, "'Processed at' was not returned"
100
107
  end # test_office
101
108
 
109
+ def test_office_object
110
+ # -- Here Be Dragons --
111
+ fiscal = nil
112
+ if EXPORTED_KEYS
113
+ fiscal = Fiscalizer.new url: URL_FISKAL,
114
+ key_public_path: KEY_PUBLIC_PATH,
115
+ key_private_path: KEY_PRIVATE_PATH,
116
+ certificate_path: CERTIFICATE_PATH,
117
+ certificate_issued_by: CER_ISSUED
118
+ else
119
+ fiscal = Fiscalizer.new url: URL_FISKAL,
120
+ certificate_path: CERTIFICATE_PATH,
121
+ certificate_p12_path: CERTIFICATE_P12_PATH,
122
+ certificate_issued_by: CER_ISSUED,
123
+ password: PASSWORD
124
+ end
125
+
126
+ # Generate office
127
+ office = Fiscalizer::Office.new
128
+ office.uuid = UUID
129
+ office.time_sent = Time.now
130
+ office.pin = PIN
131
+ office.office_label = "Poslovnica1"
132
+ office.adress_street_name = "Somewhere"
133
+ office.adress_house_num = "42"
134
+ office.adress_house_num_addendum = "AD"
135
+ office.adress_post_num = "10000"
136
+ office.adress_settlement = "Block 25-C"
137
+ office.adress_township = "Vogsphere"
138
+ office.adress_other = nil
139
+ office.office_time = "Pon-Pet: 8:00-16:00"
140
+ office.take_effect_date = Time.now + 3600 * 24 * 7
141
+ office.closure_mark = nil
142
+ office.specific_purpose = nil
143
+
144
+ # Generate office
145
+ office_response = fiscal.fiscalize_office office
146
+
147
+ if office_response.errors?
148
+ puts "There were some nasty errors!"
149
+ office_response.errors.each do |error_code, error_message|
150
+ puts " " + error_code + " : " + error_message
151
+ end
152
+ end
153
+
154
+ assert !office_response.errors?, "Returned an error"
155
+ assert office_response.uuid != nil, "'UUID' was not returned"
156
+ assert office_response.processed_at != nil, "'Processed at' was not returned"
157
+ end # test_office_object
158
+
102
159
  def test_invoice
103
- use_exported_keys = true
104
160
  # -- Here Be Dragons --
105
161
  fiscal = nil
106
- if use_exported_keys
162
+ if EXPORTED_KEYS
107
163
  fiscal = Fiscalizer.new url: URL_FISKAL,
108
164
  key_public_path: KEY_PUBLIC_PATH,
109
165
  key_private_path: KEY_PRIVATE_PATH,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fiscalizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanko Krtalić Rusendić
@@ -79,12 +79,16 @@ files:
79
79
  - README.md
80
80
  - Rakefile
81
81
  - doc/FiskalizacijaSchema.xsd
82
+ - doc/README.md
82
83
  - doc/Tehnicka_specifikacija_za_korisnike_1.2.pdf
83
84
  - doc/fiskalizacija_faq_v2.1_objava.pdf
85
+ - example/README.md
84
86
  - example/echo_P12.rb
85
87
  - example/echo_public_and_private_keys.rb
88
+ - example/invoice_fiscalization_passing_arguments.rb
86
89
  - example/invoice_fiscalization_passing_object.rb
87
- - example/invoice_fiscalization_with_arguments.rb
90
+ - example/office_fiscalization_passing_arguments.rb
91
+ - example/office_fiscalization_passing_object.rb
88
92
  - fiscalizer.gemspec
89
93
  - lib/README.md
90
94
  - lib/fiscalizer.rb
@@ -98,6 +102,7 @@ files:
98
102
  - lib/fiscalizer/response.rb
99
103
  - lib/fiscalizer/tax.rb
100
104
  - lib/fiscalizer/version.rb
105
+ - test/README.md
101
106
  - test/test_echo.rb
102
107
  - test/test_fee
103
108
  - test/test_fiscalizer.rb
@@ -130,6 +135,7 @@ signing_key:
130
135
  specification_version: 4
131
136
  summary: A gem that automatically handles fiscalization
132
137
  test_files:
138
+ - test/README.md
133
139
  - test/test_echo.rb
134
140
  - test/test_fee
135
141
  - test/test_fiscalizer.rb