fiscalizer 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/lib/fiscalizer/communication.rb +39 -36
- data/lib/fiscalizer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf3a0286c80975a48c24f12bacbb56dd52e7bff9
|
4
|
+
data.tar.gz: 665daba6e0e75aeea89a3375a68ec7110e800e3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1527568363f50c83ea0d7fce1dce5b7581b474a44f534cde2afac59b292e2ddf44e3e96d1adf503f7cf24203bb6370230b08d281075fe915d5cbd607aab4c02
|
7
|
+
data.tar.gz: 6033347fda031491a8200df26d1dbf4d47b8fd374c5c364e2463f72d55072df6e9f77b226f325fb9e6d95f634f7320a8fbe982b53297baafe74a3b88b0a9e893
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -199,7 +199,7 @@ Direct usage of the `Fiscalizer::Communication` class is not advised!
|
|
199
199
|
|
200
200
|
# Credits
|
201
201
|
|
202
|
-
|
202
|
+
Fiscalizer is maintained and sponsored by
|
203
203
|
[Infinum](http://www.infinum.co).
|
204
204
|
|
205
205
|
![Infinum](http://www.infinum.co/system/logo.png)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class Fiscalizer
|
2
2
|
class Communication
|
3
|
-
attr_accessor :url, :tns, :schemaLocation,
|
4
|
-
:key_public, :key_private, :certificate,
|
3
|
+
attr_accessor :url, :tns, :schemaLocation,
|
4
|
+
:key_public, :key_private, :certificate,
|
5
5
|
:certificate_issued_by
|
6
6
|
|
7
|
-
def initialize( tns: "http://www.apis-it.hr/fin/2012/types/f73",
|
7
|
+
def initialize( tns: "http://www.apis-it.hr/fin/2012/types/f73",
|
8
8
|
url: "https://cis.porezna-uprava.hr:8449/FiskalizacijaService",
|
9
9
|
schemaLocation: "http://www.apis-it.hr/fin/2012/types/f73 FiskalizacijaSchema.xsd",
|
10
10
|
key_public: nil, key_private: nil, certificate: nil,
|
@@ -34,6 +34,19 @@ class Fiscalizer
|
|
34
34
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
35
35
|
|
36
36
|
# Encode object
|
37
|
+
encoded_object = encode_object object
|
38
|
+
return false if encoded_object.nil?
|
39
|
+
|
40
|
+
# Send it
|
41
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
42
|
+
request.content_type = 'application/xml'
|
43
|
+
request.body = encoded_object
|
44
|
+
response = http.request(request)
|
45
|
+
|
46
|
+
return response
|
47
|
+
end # send
|
48
|
+
|
49
|
+
def encode_object object
|
37
50
|
encoded_object = nil
|
38
51
|
if object.class == Echo
|
39
52
|
encoded_object = encode_echo object
|
@@ -41,26 +54,32 @@ class Fiscalizer
|
|
41
54
|
encoded_object = encode_office object
|
42
55
|
elsif object.class == Invoice
|
43
56
|
encoded_object = encode_invoice object
|
44
|
-
else
|
45
|
-
# Something broke so we return false,
|
46
|
-
# this enables us to check sucess in an if statement
|
47
|
-
return false
|
48
57
|
end
|
58
|
+
return encoded_object
|
59
|
+
end # encode_object
|
49
60
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
def generate_security_code invoice
|
62
|
+
# Build data set to generate security code
|
63
|
+
unsigned_code = ""
|
64
|
+
unsigned_code += invoice.pin
|
65
|
+
unsigned_code += invoice.time_sent_str " "
|
66
|
+
unsigned_code += invoice.issued_number.to_s
|
67
|
+
unsigned_code += invoice.issued_office.to_s
|
68
|
+
unsigned_code += invoice.issued_machine.to_s
|
69
|
+
unsigned_code += invoice.summed_total_str
|
70
|
+
# Sign with my private key
|
71
|
+
signed_code = OpenSSL::PKey::RSA.new(key_private).sign(OpenSSL::Digest::SHA1.new, unsigned_code)
|
72
|
+
# Create a MD5 digest from it
|
73
|
+
md5_digest = Digest::MD5.hexdigest(signed_code)
|
74
|
+
invoice.security_code = md5_digest
|
75
|
+
return md5_digest
|
76
|
+
end # generate_security_code
|
77
|
+
|
59
78
|
private
|
60
79
|
def encode_echo object
|
61
80
|
echo_xml = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
|
62
81
|
xml['tns'].EchoRequest(
|
63
|
-
'xmlns:tns' => @tns,
|
82
|
+
'xmlns:tns' => @tns,
|
64
83
|
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
65
84
|
'xsi:schemaLocation' => @schemaLocation
|
66
85
|
) {
|
@@ -75,7 +94,7 @@ class Fiscalizer
|
|
75
94
|
def encode_office object
|
76
95
|
office_request_xml = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
|
77
96
|
xml['tns'].PoslovniProstorZahtjev(
|
78
|
-
'xmlns:tns' => @tns,
|
97
|
+
'xmlns:tns' => @tns,
|
79
98
|
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
80
99
|
'xsi:schemaLocation' => schemaLocation,
|
81
100
|
'Id' => 'PoslovniProstorZahtjev'
|
@@ -149,7 +168,7 @@ class Fiscalizer
|
|
149
168
|
generate_security_code object
|
150
169
|
invoice_request_xml = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
|
151
170
|
xml['tns'].RacunZahtjev(
|
152
|
-
'xmlns:tns' => @tns,
|
171
|
+
'xmlns:tns' => @tns,
|
153
172
|
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
154
173
|
'xsi:schemaLocation' => schemaLocation,
|
155
174
|
'Id' => 'RacunZahtjev'
|
@@ -275,22 +294,6 @@ class Fiscalizer
|
|
275
294
|
end
|
276
295
|
end # soap_envelope
|
277
296
|
|
278
|
-
def generate_security_code invoice
|
279
|
-
# Build data set to generate security code
|
280
|
-
unsigned_code = ""
|
281
|
-
unsigned_code += invoice.pin
|
282
|
-
unsigned_code += invoice.time_sent_str " "
|
283
|
-
unsigned_code += invoice.issued_number.to_s
|
284
|
-
unsigned_code += invoice.issued_office.to_s
|
285
|
-
unsigned_code += invoice.issued_machine.to_s
|
286
|
-
unsigned_code += invoice.summed_total_str
|
287
|
-
# Sign with my private key
|
288
|
-
signed_code = OpenSSL::PKey::RSA.new(key_private).sign(OpenSSL::Digest::SHA1.new, unsigned_code)
|
289
|
-
# Create a MD5 digest from it
|
290
|
-
md5_digest = Digest::MD5.hexdigest(signed_code)
|
291
|
-
invoice.security_code = md5_digest
|
292
|
-
return md5_digest
|
293
|
-
end # generate_security_code
|
294
297
|
|
295
298
|
end # Communication
|
296
|
-
end # Fiscalizer
|
299
|
+
end # Fiscalizer
|
data/lib/fiscalizer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fiscalizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stanko Krtalić Rusendić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|