furs_fiscal_verification 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +129 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/furs_fiscal_verification.gemspec +23 -0
- data/lib/furs_fiscal_verification.rb +270 -0
- data/lib/furs_fiscal_verification/version.rb +3 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6756121600fe215b234975a303e2ef15e9386dcb
|
4
|
+
data.tar.gz: d4c4233733cf7b30ba1ce5a4e59df0b02170120c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46a0aab60b40469c92bd9ddd4bf7c574e101810045071784446c00b7b4905a09425aacca6a96f5ea92cda69b05b5679389111e1d6a15194622b26bbe510d47b7
|
7
|
+
data.tar.gz: 36473595db94c5d4c1c28dd0d56cc184fec2a15e06830f98e3b7d0571fd3817467af5b5f49bcd2648c20ea06be400d280a89e85d31d47b31cb96eac45b10f763
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Matic Jurglic
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# Ruby library for fiscal invoice verification in Republic of Slovenia (Ruby koda za davčno potrjevanje računov)
|
2
|
+
|
3
|
+
**DISCLAIMER**: This code was not tested in production yet and I can not guarantee it's completely conformed to FURS's technical specification. Test cases described below have been tested in the FURS sandbox environment. The code is a Ruby port of [python-furs-fiscal](https://github.com/boris-savic/python-furs-fiscal), which is offering more info on the topic. See also [official documentation](http://www.datoteke.fu.gov.si/dpr/files/TehnicnaDokumentacijaVer1.6.pdf). Pull requests are most welcome.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'furs_fiscal_verification'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install furs_fiscal_verification
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
# Initialize the client
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
furs = Furs.new(cert_path: "/path/to/your-certificate.p12", cert_password: "SCREWFURS")
|
27
|
+
```
|
28
|
+
|
29
|
+
*You can pass either sandbox or production certificate*
|
30
|
+
|
31
|
+
# Register an immovable business premise
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
response = furs.register_immovable_business_premise(
|
35
|
+
tax_number: 10115609,
|
36
|
+
premise_id: 'BP105',
|
37
|
+
real_estate_cadastral_number: 112,
|
38
|
+
real_estate_building_number: 11,
|
39
|
+
real_estate_building_section_number: 1,
|
40
|
+
street: 'Trzaska cesta',
|
41
|
+
house_number: '24',
|
42
|
+
house_number_additional: 'A',
|
43
|
+
community: 'Ljubljana',
|
44
|
+
city: 'Ljubljana',
|
45
|
+
postal_code: '1000',
|
46
|
+
validity_date: Date.today,
|
47
|
+
software_supplier_tax_number: 24564444,
|
48
|
+
foreign_software_supplier_name: 'Neki')
|
49
|
+
```
|
50
|
+
|
51
|
+
If response is OK and withour errors, you should receive this response:
|
52
|
+
|
53
|
+
`#<Net::HTTPOK 200 OK readbody=true>`
|
54
|
+
|
55
|
+
In case there is data/parameters missing (or they are of wrong type - be careful about integer and string parameters), you may get this:
|
56
|
+
|
57
|
+
`#<Net::HTTPOK 200 VAT error readbody=true>`
|
58
|
+
|
59
|
+
To see the error, you need to decode the response:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
JSON.parse(Base64.urlsafe_decode64(response.body.split('.')[1]))
|
63
|
+
=> {"BusinessPremiseResponse"=>{"Header"=>{"MessageID"=>"b7b1e98f-dcae-47af-b829-3237802a2688", "DateTime"=>"2016-07-27T23:15:05"}, "Error"=>{"ErrorCode"=>"S002", "ErrorMessage"=>"Sporočilo ni v skladu s shemo JSON"}}}
|
64
|
+
```
|
65
|
+
|
66
|
+
# Invoice verification
|
67
|
+
|
68
|
+
Prepare your invoice data and calculate ZOI code:
|
69
|
+
|
70
|
+
```
|
71
|
+
zoi = furs.calculate_zoi(
|
72
|
+
tax_number: 10115609,
|
73
|
+
issued_date: Date.today,
|
74
|
+
invoice_number: '11',
|
75
|
+
business_premise_id: 'BP105',
|
76
|
+
electronic_device_id: '0001',
|
77
|
+
invoice_amount: 19.15)
|
78
|
+
|
79
|
+
=> "51a40dcabb147d1c76d843ee98f951aa"
|
80
|
+
```
|
81
|
+
|
82
|
+
Now that we got this ZOI code, we send it together with other stuff to FURS and get back the response that contains EOR (unique invoice code):
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
response = furs.report_invoice(
|
86
|
+
zoi: zoi,
|
87
|
+
tax_number: 10115609,
|
88
|
+
issued_date: Date.today,
|
89
|
+
invoice_number: '11',
|
90
|
+
business_premise_id: 'BP105',
|
91
|
+
electronic_device_id: '0001',
|
92
|
+
invoice_amount: 19.15,
|
93
|
+
low_tax_rate_base: 35.14,
|
94
|
+
low_tax_rate_amount: 3.34,
|
95
|
+
high_tax_rate_base: 23.14,
|
96
|
+
high_tax_rate_amount: 5.09)
|
97
|
+
```
|
98
|
+
|
99
|
+
If everything goes OK, we can extract the EOR code like so:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
eor = JSON.parse(Base64.decode64(response.body.split('.')[1]))["InvoiceResponse"]["UniqueInvoiceID"]
|
103
|
+
=> "dedc5383-169f-4c0e-b369-d64ec8797170"
|
104
|
+
```
|
105
|
+
|
106
|
+
Now we have ZOI and EOR code. We need to print both to our invoice. We also need to print a QR code. The code that we use to generate the QR code is generated like this:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
furs.prepare_printable(invoice_number, zoi, issued_date)
|
110
|
+
=> "108519284076690038963265761078884782506111607270000000"
|
111
|
+
```
|
112
|
+
|
113
|
+
Use the latter for input to your QR rendering library.
|
114
|
+
|
115
|
+
## Development
|
116
|
+
|
117
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
118
|
+
|
119
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
120
|
+
|
121
|
+
## Contributing
|
122
|
+
|
123
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/matixmatix/furs_fiscal_verification.
|
124
|
+
|
125
|
+
|
126
|
+
## License
|
127
|
+
|
128
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
129
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "furs_fiscal_verification"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'furs_fiscal_verification/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "furs_fiscal_verification"
|
8
|
+
spec.version = FursFiscalVerification::VERSION
|
9
|
+
spec.authors = ["Matic Jurglic"]
|
10
|
+
spec.email = ["matic@jurglic.si"]
|
11
|
+
|
12
|
+
spec.summary = "Fiscal verification of invoices (davčno potrjevanje računov)"
|
13
|
+
spec.homepage = "http://codeandtechno.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,270 @@
|
|
1
|
+
require "furs_fiscal_verification/version"
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'digest'
|
6
|
+
require 'jwt'
|
7
|
+
require 'openssl'
|
8
|
+
|
9
|
+
class Furs
|
10
|
+
FURS_TEST_ENDPOINT = 'https://blagajne-test.fu.gov.si:9002'
|
11
|
+
FURS_PRODUCTION_ENDPOINT = 'https://blagajne.fu.gov.si:9003'
|
12
|
+
|
13
|
+
REGISTER_BUSINESS_UNIT_PATH = '/v1/cash_registers/invoices/register'
|
14
|
+
INVOICE_ISSUE_PATH = '/v1/cash_registers/invoices'
|
15
|
+
|
16
|
+
LOW_TAX_RATE = 9.5
|
17
|
+
HIGH_TAX_RATE = 22
|
18
|
+
|
19
|
+
def initialize(cert_path:, cert_password:, production: false)
|
20
|
+
@cert = OpenSSL::PKCS12.new(File.read(cert_path), cert_password)
|
21
|
+
@endpoint = production ? FURS_PRODUCTION_ENDPOINT : FURS_TEST_ENDPOINT
|
22
|
+
end
|
23
|
+
|
24
|
+
def furs_accessible?(msg: 'ping')
|
25
|
+
data = { 'EchoRequest' => msg }
|
26
|
+
response = _post(data: data, path: "/v1/cash_registers/echo", sign: false)
|
27
|
+
JSON.parse(response.body)["EchoResponse"] == msg
|
28
|
+
end
|
29
|
+
|
30
|
+
def calculate_zoi(tax_number:, issued_date:, invoice_number:, business_premise_id:, electronic_device_id:,
|
31
|
+
invoice_amount:)
|
32
|
+
content = "#{tax_number}#{issued_date.strftime('%d-%m-%Y %H:%M:%S')}#{invoice_number}#{business_premise_id}
|
33
|
+
#{electronic_device_id}#{invoice_amount}"
|
34
|
+
|
35
|
+
Digest::MD5.hexdigest(_sign(content))
|
36
|
+
end
|
37
|
+
|
38
|
+
def report_invoice(zoi:,
|
39
|
+
tax_number:,
|
40
|
+
issued_date:,
|
41
|
+
invoice_number:,
|
42
|
+
business_premise_id:,
|
43
|
+
electronic_device_id:,
|
44
|
+
invoice_amount:,
|
45
|
+
low_tax_rate_base: nil,
|
46
|
+
low_tax_rate_amount: nil,
|
47
|
+
high_tax_rate_base: nil,
|
48
|
+
high_tax_rate_amount: nil,
|
49
|
+
other_taxes_amount: nil,
|
50
|
+
exempt_vat_taxable_amount: nil,
|
51
|
+
reverse_vat_taxable_amount: nil,
|
52
|
+
non_taxable_amount: nil,
|
53
|
+
special_tax_rules_amount: nil,
|
54
|
+
payment_amount: nil,
|
55
|
+
customer_vat_number: nil,
|
56
|
+
returns_amount: nil,
|
57
|
+
operator_tax_number: nil,
|
58
|
+
foreign_operator: nil,
|
59
|
+
subsequent_submit: nil,
|
60
|
+
reference_invoice_number: nil,
|
61
|
+
reference_invoice_business_premise_id: nil,
|
62
|
+
reference_invoice_electronic_device_id: nil,
|
63
|
+
reference_invoice_issued_date: nil,
|
64
|
+
numbering_structure: 'B',
|
65
|
+
special_notes: '')
|
66
|
+
|
67
|
+
data = {}
|
68
|
+
data['InvoiceRequest'] = {
|
69
|
+
"Header" => {
|
70
|
+
"MessageID" => SecureRandom.uuid,
|
71
|
+
"DateTime" => DateTime.now.strftime("%Y-%m-%dT%H:%M:%SZ")
|
72
|
+
},
|
73
|
+
'Invoice' => {
|
74
|
+
'TaxNumber' => tax_number.to_i,
|
75
|
+
'IssueDateTime' => issued_date.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
76
|
+
'NumberingStructure' => numbering_structure,
|
77
|
+
'InvoiceIdentifier' => {
|
78
|
+
'BusinessPremiseID' => business_premise_id,
|
79
|
+
'ElectronicDeviceID' => electronic_device_id,
|
80
|
+
'InvoiceNumber' => invoice_number
|
81
|
+
},
|
82
|
+
'InvoiceAmount' => invoice_amount,
|
83
|
+
'PaymentAmount' => if payment_amount then payment_amount else invoice_amount end,
|
84
|
+
'ProtectedID' => zoi,
|
85
|
+
'TaxesPerSeller' => []
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
tax_spec = {}
|
90
|
+
if low_tax_rate_base || high_tax_rate_base
|
91
|
+
tax_spec['VAT'] = _build_tax_specification(
|
92
|
+
low_tax_rate_base,
|
93
|
+
low_tax_rate_amount,
|
94
|
+
high_tax_rate_base,
|
95
|
+
high_tax_rate_amount)
|
96
|
+
end
|
97
|
+
|
98
|
+
tax_spec['NontaxableAmount'] = non_taxable_amount if non_taxable_amount
|
99
|
+
|
100
|
+
if reverse_vat_taxable_amount
|
101
|
+
tax_spec['ReverseVATTaxableAmount'] = reverse_vat_taxable_amount
|
102
|
+
end
|
103
|
+
|
104
|
+
if exempt_vat_taxable_amount
|
105
|
+
tax_spec['ExemptVATTaxableAmount'] = exempt_vat_taxable_amount
|
106
|
+
end
|
107
|
+
|
108
|
+
tax_spec['OtherTaxesAmount'] = other_taxes_amount if other_taxes_amount
|
109
|
+
|
110
|
+
data['InvoiceRequest']['Invoice']['TaxesPerSeller'] << tax_spec
|
111
|
+
|
112
|
+
if customer_vat_number
|
113
|
+
data['InvoiceRequest']['Invoice']['CustomerVATNumber'] = customer_vat_number
|
114
|
+
end
|
115
|
+
|
116
|
+
if returns_amount
|
117
|
+
data['InvoiceRequest']['Invoice']['ReturnsAmount'] = returns_amount
|
118
|
+
end
|
119
|
+
|
120
|
+
if operator_tax_number
|
121
|
+
data['InvoiceRequest']['Invoice']['OperatorTaxNumber'] = operator_tax_number
|
122
|
+
end
|
123
|
+
|
124
|
+
if foreign_operator
|
125
|
+
data['InvoiceRequest']['Invoice']['ForeignOperator'] = true
|
126
|
+
end
|
127
|
+
|
128
|
+
if subsequent_submit
|
129
|
+
data['InvoiceRequest']['Invoice']['SubsequentSubmit'] = true
|
130
|
+
end
|
131
|
+
|
132
|
+
if reference_invoice_number
|
133
|
+
reference_invoice = [{
|
134
|
+
'ReferenceInvoiceIdentifier' => {
|
135
|
+
'BusinessPremiseID' => reference_invoice_business_premise_id,
|
136
|
+
'ElectronicDeviceID' => reference_invoice_electronic_device_id,
|
137
|
+
'InvoiceNumber' => reference_invoice_number
|
138
|
+
},
|
139
|
+
'ReferenceInvoiceIssueDateTime' => reference_invoice_issued_date.strftime("%Y-%m-%dT%H:%M:%SZ")
|
140
|
+
}]
|
141
|
+
|
142
|
+
data['InvoiceRequest']['Invoice']['ReferenceInvoice'] = reference_invoice
|
143
|
+
end
|
144
|
+
|
145
|
+
_post(path: INVOICE_ISSUE_PATH, data: data)
|
146
|
+
end
|
147
|
+
|
148
|
+
def _build_tax_specification(low_tax_rate_base,
|
149
|
+
low_tax_rate_amount,
|
150
|
+
high_tax_rate_base,
|
151
|
+
high_tax_rate_amount)
|
152
|
+
low_tax_spec = {
|
153
|
+
'TaxRate' => LOW_TAX_RATE,
|
154
|
+
'TaxableAmount' => low_tax_rate_base,
|
155
|
+
'TaxAmount' => low_tax_rate_amount
|
156
|
+
}
|
157
|
+
|
158
|
+
high_tax_spec = {
|
159
|
+
'TaxRate' => HIGH_TAX_RATE,
|
160
|
+
'TaxableAmount' => high_tax_rate_base,
|
161
|
+
'TaxAmount' => high_tax_rate_amount
|
162
|
+
}
|
163
|
+
|
164
|
+
[low_tax_spec, high_tax_spec].select { |spec| !spec['TaxableAmount'].nil? }
|
165
|
+
end
|
166
|
+
|
167
|
+
def register_immovable_business_premise(tax_number:,
|
168
|
+
premise_id:,
|
169
|
+
real_estate_cadastral_number:,
|
170
|
+
real_estate_building_number:,
|
171
|
+
real_estate_building_section_number:,
|
172
|
+
street:,
|
173
|
+
house_number:,
|
174
|
+
house_number_additional:,
|
175
|
+
community:,
|
176
|
+
city:,
|
177
|
+
postal_code:,
|
178
|
+
validity_date:,
|
179
|
+
software_supplier_tax_number: nil,
|
180
|
+
foreign_software_supplier_name: nil,
|
181
|
+
special_notes: 'No notes')
|
182
|
+
|
183
|
+
data = {
|
184
|
+
"BusinessPremiseRequest" => {
|
185
|
+
"Header" => {
|
186
|
+
"MessageID" => SecureRandom.uuid,
|
187
|
+
"DateTime" => DateTime.now.strftime("%Y-%m-%dT%H:%M:%SZ")
|
188
|
+
},
|
189
|
+
"BusinessPremise" => {
|
190
|
+
"TaxNumber" => tax_number.to_i,
|
191
|
+
"BusinessPremiseID" => premise_id,
|
192
|
+
"BPIdentifier" => {
|
193
|
+
"RealEstateBP" => {
|
194
|
+
"PropertyID" => {
|
195
|
+
"CadastralNumber" => real_estate_cadastral_number.to_i,
|
196
|
+
"BuildingNumber" => real_estate_building_number.to_i,
|
197
|
+
"BuildingSectionNumber" => real_estate_building_section_number.to_i
|
198
|
+
},
|
199
|
+
"Address" => {
|
200
|
+
"Street" => street,
|
201
|
+
"HouseNumber" => house_number.to_s,
|
202
|
+
"HouseNumberAdditional" => house_number_additional,
|
203
|
+
"Community" => community,
|
204
|
+
"City" => city,
|
205
|
+
"PostalCode" => postal_code.to_s
|
206
|
+
}
|
207
|
+
}
|
208
|
+
},
|
209
|
+
"ValidityDate" => validity_date.strftime("%Y-%m-%d"),
|
210
|
+
"SoftwareSupplier" => [
|
211
|
+
{
|
212
|
+
"NameForeign" => foreign_software_supplier_name
|
213
|
+
}
|
214
|
+
],
|
215
|
+
"SpecialNotes" => special_notes
|
216
|
+
}
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
_post(path: REGISTER_BUSINESS_UNIT_PATH, data: data)
|
221
|
+
end
|
222
|
+
|
223
|
+
def prepare_printable(tax_number, zoi, issued_date)
|
224
|
+
formatted_date = issued_date.strftime('%y%m%d%H%M%S')
|
225
|
+
zoi_base_10 = zoi.hex.to_s(10).rjust(39, '0')
|
226
|
+
data = "#{zoi_base_10}#{tax_number}#{formatted_date}"
|
227
|
+
control = data.chars.map(&:to_i).inject(:+) % 10
|
228
|
+
"#{data}#{control}"
|
229
|
+
end
|
230
|
+
|
231
|
+
private
|
232
|
+
def _post(path:, data:, sign: true)
|
233
|
+
if sign
|
234
|
+
data = {
|
235
|
+
'token' => _jwt_sign(header: _jws_header, payload: data)
|
236
|
+
}
|
237
|
+
end
|
238
|
+
|
239
|
+
url = "#{@endpoint}#{path}"
|
240
|
+
uri = URI(url)
|
241
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
242
|
+
https.use_ssl = true
|
243
|
+
https.open_timeout = 60
|
244
|
+
https.read_timeout = 60
|
245
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE # should probably verify...
|
246
|
+
https.cert = @cert.certificate
|
247
|
+
https.key = @cert.key
|
248
|
+
req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json; charset=UTF-8')
|
249
|
+
https.request(req, data.to_json)
|
250
|
+
end
|
251
|
+
|
252
|
+
def _jws_header
|
253
|
+
{
|
254
|
+
'alg' => 'RS256',
|
255
|
+
'subject_name' => @cert.certificate.subject.to_a.map { |subject| "#{subject[0]}=#{subject[1]}" }.join(","),
|
256
|
+
'issuer_name' => @cert.certificate.issuer.to_a.map { |subject| "#{subject[0]}=#{subject[1]}" }.join(","),
|
257
|
+
'serial' => @cert.certificate.serial.to_i
|
258
|
+
}
|
259
|
+
end
|
260
|
+
|
261
|
+
def _jwt_sign(header:, payload:)
|
262
|
+
private_key = @cert.key
|
263
|
+
JWT.encode(payload, private_key, 'RS256', header)
|
264
|
+
end
|
265
|
+
|
266
|
+
def _sign(content)
|
267
|
+
digest = OpenSSL::Digest::SHA256.new
|
268
|
+
@cert.key.sign(digest, content)
|
269
|
+
end
|
270
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: furs_fiscal_verification
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matic Jurglic
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- matic@jurglic.si
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- furs_fiscal_verification.gemspec
|
56
|
+
- lib/furs_fiscal_verification.rb
|
57
|
+
- lib/furs_fiscal_verification/version.rb
|
58
|
+
homepage: http://codeandtechno.com
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.4.8
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Fiscal verification of invoices (davčno potrjevanje računov)
|
82
|
+
test_files: []
|
83
|
+
has_rdoc:
|