fiscalizer 0.0.12 → 1.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 +2 -1
- data/.rspec +2 -0
- data/Gemfile +0 -4
- data/LICENSE.txt +1 -1
- data/README.md +187 -171
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/doc/Tehnicka specifikacija za korisnike 1.4.pdf +0 -0
- data/fiscalizer.gemspec +14 -13
- data/lib/fiscalizer.rb +33 -4
- data/lib/fiscalizer/constants.rb +11 -0
- data/lib/fiscalizer/data_objects/echo.rb +10 -0
- data/lib/fiscalizer/data_objects/fee.rb +18 -0
- data/lib/fiscalizer/data_objects/invoice.rb +79 -0
- data/lib/fiscalizer/data_objects/office.rb +41 -0
- data/lib/fiscalizer/{tax.rb → data_objects/tax.rb} +3 -5
- data/lib/fiscalizer/deserializers/base.rb +58 -0
- data/lib/fiscalizer/deserializers/echo.rb +13 -0
- data/lib/fiscalizer/deserializers/invoice.rb +9 -0
- data/lib/fiscalizer/deserializers/office.rb +6 -0
- data/lib/fiscalizer/fiscalizer.rb +36 -152
- data/lib/fiscalizer/fiscalizers/base.rb +54 -0
- data/lib/fiscalizer/fiscalizers/echo.rb +13 -0
- data/lib/fiscalizer/fiscalizers/invoice.rb +24 -0
- data/lib/fiscalizer/fiscalizers/office.rb +15 -0
- data/lib/fiscalizer/serializers/base.rb +58 -0
- data/lib/fiscalizer/serializers/echo.rb +21 -0
- data/lib/fiscalizer/serializers/invoice.rb +92 -0
- data/lib/fiscalizer/serializers/office.rb +85 -0
- data/lib/fiscalizer/serializers/signature.rb +62 -0
- data/lib/fiscalizer/serializers/tax.rb +81 -0
- data/lib/fiscalizer/services/request_sender.rb +68 -0
- data/lib/fiscalizer/services/security_code_generator.rb +29 -0
- data/lib/fiscalizer/version.rb +1 -1
- data/spec/fiscalizer_spec.rb +119 -0
- data/spec/spec_helper.rb +9 -0
- metadata +67 -39
- data/doc/README.md +0 -3
- data/doc/Tehnicka_specifikacija_za_korisnike_1.2.pdf +0 -0
- data/example/README.md +0 -25
- data/example/echo_P12.rb +0 -13
- data/example/echo_public_and_private_keys.rb +0 -16
- data/example/invoice_fiscalization_passing_arguments.rb +0 -44
- data/example/invoice_fiscalization_passing_object.rb +0 -48
- data/example/office_fiscalization_passing_arguments.rb +0 -22
- data/example/office_fiscalization_passing_object.rb +0 -26
- data/lib/README.md +0 -0
- data/lib/fiscalizer/README.md +0 -9
- data/lib/fiscalizer/communication.rb +0 -305
- data/lib/fiscalizer/echo.rb +0 -11
- data/lib/fiscalizer/fee.rb +0 -20
- data/lib/fiscalizer/invoice.rb +0 -190
- data/lib/fiscalizer/office.rb +0 -66
- data/lib/fiscalizer/response.rb +0 -124
- data/test/README.md +0 -13
- data/test/test_echo.rb +0 -20
- data/test/test_fee +0 -64
- data/test/test_fiscalizer.rb +0 -222
- data/test/test_fiscalizer_communication.rb +0 -28
- data/test/test_invoice.rb +0 -11
- data/test/test_office.rb +0 -11
- data/test/test_tax.rb +0 -89
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc259947daa868463b0de723f158b9f4d5b46dc5
|
4
|
+
data.tar.gz: 1fe536eca7ea1a013f819c26c1ccfffd2aead82d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1249e0e6e1d45c5ce5115e562e0f903336eb16e0ee41a8a27b3c0617808a6b5d342ed774d04218d13ca8cb0089ce974558d31da212fdec910fb1ad7600855afc
|
7
|
+
data.tar.gz: 37fab01aaec2515768621f022356b6722af529e1aa425166557b26670fc4ae5a5898f261de1f4c9f89e6e4be45d668353e797a2844aa5eabc9e872a3f3573cc4
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,19 +2,9 @@
|
|
2
2
|
|
3
3
|
## Introduction
|
4
4
|
|
5
|
-
Fiscalization is the process of
|
5
|
+
Fiscalization is the process of transferring various document types from a business entity to the tax authorities with the goal of reducing tax fraud. In Croatia this process can be executed over the Internet and this gem is intended to automate the process.
|
6
6
|
|
7
|
-
##
|
8
|
-
|
9
|
-
Every folder has it's own README file which explanes in detail the files in it.
|
10
|
-
|
11
|
-
Examples are located in the `example` folder. Basic setup and fiscalization are demonstrated here.
|
12
|
-
|
13
|
-
Tests are located in the `test` folder. Test setup is explaned there.
|
14
|
-
|
15
|
-
All classes, in their separate files, are located in the `fiscalizer` folder.
|
16
|
-
|
17
|
-
## Instalation
|
7
|
+
## Installation
|
18
8
|
|
19
9
|
Add this line to your application's Gemfile:
|
20
10
|
|
@@ -29,181 +19,207 @@ Or install it yourself as:
|
|
29
19
|
$ gem install fiscalizer
|
30
20
|
|
31
21
|
## Usage
|
32
|
-
### Setup
|
33
|
-
To use Fiscalizer in your projects simply call `fiscalizer = Fiscalizer.new`, this will create a new fiscalizer object for you to interact with.
|
34
22
|
|
35
|
-
|
23
|
+
### Setup
|
24
|
+
To use Fiscalizer initialize a new Fiscalizer object (`fiscalizer = Fiscalizer.new`) with these arguments:
|
36
25
|
|
37
|
-
* `
|
26
|
+
* `app_cert_path` : Path to your fiscal certificate. (usually "FISCAL_1.p12" or "fiscal1.pfx")
|
38
27
|
* `password` : Password that unlocks the certificate
|
39
28
|
|
40
|
-
|
29
|
+
Optional argument is:
|
30
|
+
|
31
|
+
* `timeout` : Specifies the number of seconds to wait for Fiscalization server to respond. (defaults to 3)
|
32
|
+
|
33
|
+
Example:
|
41
34
|
|
42
|
-
|
43
|
-
|
44
|
-
|
35
|
+
```ruby
|
36
|
+
fiscalizer = Fiscalizer.new(
|
37
|
+
app_cert_path: 'path/to/FISCAL_1.p12',
|
38
|
+
password: 'password',
|
39
|
+
timeout: 4
|
40
|
+
)
|
41
|
+
```
|
42
|
+
#### Demo environment
|
45
43
|
|
46
|
-
|
44
|
+
If Fiscalizer is used in demo (test) environment, you need to set 2 additional parameters when initializing `Fiscalizer` object:
|
47
45
|
|
48
|
-
|
46
|
+
* `demo` : Specifies that Fiscalizer should send requests to FINA DEMO server. (boolean)
|
47
|
+
* `ca_cert_path` : Specifies the path to trusted CA certificates. This file should contain both FINA ROOT CA certificate and FINA DEMO CA certificate. (usually called "fina_ca.pem")
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
Example:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
fiscalizer = Fiscalizer.new(
|
53
|
+
app_cert_path: 'path/to/FISCAL_1.p12',
|
54
|
+
password: 'password',
|
55
|
+
demo: true,
|
56
|
+
ca_cert_path: 'path/to/fina_ca.pem'
|
57
|
+
)
|
58
|
+
```
|
54
59
|
|
55
60
|
### Fiscalization
|
56
61
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
* `
|
83
|
-
* `
|
84
|
-
* `
|
85
|
-
* `
|
86
|
-
* `
|
87
|
-
* `
|
88
|
-
* `
|
89
|
-
* `
|
90
|
-
* `
|
91
|
-
* `
|
92
|
-
* `
|
93
|
-
* `
|
94
|
-
* `
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
* `
|
108
|
-
* `
|
109
|
-
* `
|
110
|
-
* `
|
111
|
-
* `
|
112
|
-
* `
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
* `
|
117
|
-
* `
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
*
|
168
|
-
*
|
169
|
-
*
|
170
|
-
*
|
171
|
-
*
|
172
|
-
*
|
173
|
-
*
|
174
|
-
*
|
175
|
-
*
|
176
|
-
*
|
177
|
-
*
|
178
|
-
*
|
179
|
-
*
|
180
|
-
*
|
181
|
-
*
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
*
|
186
|
-
*
|
187
|
-
*
|
188
|
-
*
|
189
|
-
*
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
62
|
+
Ficalizer class provides 3 public methods:
|
63
|
+
|
64
|
+
* `echo(message)`
|
65
|
+
* `fiscalize_invoice(invoice)`
|
66
|
+
* `fiscalize_office(office)`
|
67
|
+
|
68
|
+
#### Echo
|
69
|
+
|
70
|
+
Echo method receives a message, sends it to the Fiscalization server and returns the echo response:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
response = fiscalizer.echo('Echo message')
|
74
|
+
response.success? # true
|
75
|
+
response.echo_response # Echo message
|
76
|
+
```
|
77
|
+
|
78
|
+
#### Invoice
|
79
|
+
|
80
|
+
To fiscalize the invoice, you first need to create a `Fiscalizer::Invoice` object and pass it to the `fiscalize_invoice` method.
|
81
|
+
|
82
|
+
Before the fiscalization process starts, a `security_code` (ZKI) will be automatically generated and assigned to invoice.
|
83
|
+
If the fiscalization process is successful, response will contain a `unique_identifier` (JIR). Else, it will contain an array with errors (each error is a hash with `code` and `message`).
|
84
|
+
|
85
|
+
`Fiscalizer::Invoice` object can be initialized with the following arguments:
|
86
|
+
|
87
|
+
* `uuid` : Universally Unique Identifier / ID poruke (String, required)
|
88
|
+
* `time_sent` : Time the invoice fiscalization request was sent / Datum i vrijeme slanja (DateTime in format dd.mm.yyyyThh:mm:ss, required)
|
89
|
+
* `pin` : The fiscal entitie's PIN number / OIB obveznika fiskalizacije (String, required)
|
90
|
+
* `in_vat_system` : Specifies if the fical entity is in the VAT system / U sustavu PDV (Boolean, required)
|
91
|
+
* `time_issued` : Time the invoice was created / Datum i vrijeme izdavanja (DateTime, required)
|
92
|
+
* `consistance_mark` : Character that specifes where the invoice was issued, "P" for _Office space_ or "N" for _Payment machine_ / Oznaka slijednosti (String, required)
|
93
|
+
* `issued_number` : Numerical invoice identifier / Brojčana oznaka računa (0-9) (String/Integer, required)
|
94
|
+
* `issued_office` : Office space identifier where the invoice was issued / Oznaka poslovnog prostora (String, required)
|
95
|
+
* `issued_machine` : Numerical payment machine identifier / Oznaka naplatnog uređaja (String/Integer, required)
|
96
|
+
* `tax_vat` : Array containing all VAT taxes / Porez na dodanu vrijednost (Array containing _Fiscalizer::Tax_ objects, optional)
|
97
|
+
* `tax_spending` : Array containing all spending taxes / Porez na potrošnju (Array containing _Fiscalizer::Tax_ objects, optional)
|
98
|
+
* `tax_other` : Array containing all other taxes / Ostali porezi (Array containing _Fiscalizer::Tax_ objects, optional)
|
99
|
+
* `value_tax_liberation` : Amount that will be submitted for tax liberation / Iznos oslobođenja (Float, optional)
|
100
|
+
* `value_tax_margin` : Amount that will be subjected to the special tax margin process / Iznos na koji se odnosi poseban postupak oporezivanja marže (Float, optional)
|
101
|
+
* `value_non_taxable` : Amount that isn't subject to any taxing / Iznos koji ne podliježe oporezivanju (Float, optional)
|
102
|
+
* `fees` : Array containing all fees / Naknade (Array containing _Fiscalizer::Fee_ objects, optional)
|
103
|
+
* `summed_total` : Summed total price of the invoice / Ukupan iznos (Float, required)
|
104
|
+
* `payment_method` : Specifies the payment method, "G" for cash, "K" for card, "C" for check, "T" for transaction, "O" for other / Način plaćanja (String, required)
|
105
|
+
* `operator_pin` : The PIN number of the person issuing the invoice / OIB operatera na naplatnom uređaju (String, required)
|
106
|
+
* `subsequent_delivery` : Subsequent delivery mark / Oznaka naknadne dostave računa (Boolean, required)
|
107
|
+
* `paragon_label` : Paragon label for the invoice that have to be fiscalized after the office space or payment machine has stopped working / Oznaka paragon računa (String, optional)
|
108
|
+
* `specific_purpose` : This is an additional label in case of further expansion of the fiscalization system / Specifična namjena (String, optional)
|
109
|
+
|
110
|
+
After the fiscalization process, response object contains these informations:
|
111
|
+
|
112
|
+
* `raw_response` : XML with the raw response from the Fiscalization server
|
113
|
+
* `uuid` : UUID of the response
|
114
|
+
* `processed_at` : DateTime when the fiscalization is processed
|
115
|
+
* `unique_identifier` : Unique fiscalization identifier of the invoice (JIR) (can be nil if there were errors)
|
116
|
+
* `errors?` : Boolean indicating if there were any errors during the process
|
117
|
+
* `errors` : Array containing errors if any - Each error is a hash with `code` and `message`
|
118
|
+
|
119
|
+
Fiscalizer invoice object contains these informations after the fiscalization:
|
120
|
+
|
121
|
+
* `security_code` : Security code of the invoice (ZKI)
|
122
|
+
* `generated_xml` : XML that was sent to the Fiscalization server
|
123
|
+
|
124
|
+
Example:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
invoice = YourApp::Invoice.find(...)
|
128
|
+
fiscalizer_invoice = Fiscalizer::Invoice.new(...) # convert your invoice to fiscalizer invoice
|
129
|
+
fiscalizer = Fiscalizer.new(
|
130
|
+
app_cert_path: 'path/to/FISCAL_1.p12',
|
131
|
+
password: 'password'
|
132
|
+
)
|
133
|
+
|
134
|
+
begin
|
135
|
+
response = fiscalizer.fiscalize_invoice(fiscalizer_invoice)
|
136
|
+
fail 'Fiscalization error' if response.errors? # or do something with the errors
|
137
|
+
|
138
|
+
invoice.update(jir: response.unique_identifier)
|
139
|
+
ensure
|
140
|
+
invoice.update(
|
141
|
+
fiscalization_response: response.raw_response,
|
142
|
+
fiscalization_request: fiscalizer_invoice.generated_xml,
|
143
|
+
zki: fiscalizer_invoice.security_code,
|
144
|
+
errors: response.errors
|
145
|
+
)
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
#### Taxes and Fees
|
150
|
+
|
151
|
+
When initializing `Fiscalizer::Invoice`, you can set multiple taxes, as indicated above. Those taxes need to be instances of `Fiscalizer::Tax` class.
|
152
|
+
|
153
|
+
`Fiscalizer::Tax` object can be initialized with the following arguments:
|
154
|
+
|
155
|
+
* `base` : Base amount / Iznos osnovice (Float, required)
|
156
|
+
* `rate` : Tax rate / Porezna stopa (Float, required)
|
157
|
+
* `name` : Tax name / Naziv poreza (String, required)
|
158
|
+
|
159
|
+
Also, you can set multiple fees for the invoice. Fee need to be instance of the `Fiscalizer::Fee` class.
|
160
|
+
|
161
|
+
`Fiscalizer::Fee` object can be initialized with the following arguments:
|
162
|
+
|
163
|
+
* `name` : Fee name / Naziv naknade (String, required)
|
164
|
+
* `value` : Fee amount / Iznos naknade (Float, required)
|
165
|
+
|
166
|
+
#### Office
|
167
|
+
|
168
|
+
To fiscalize the office space, you first need to create a `Fiscalizer::Office` object and pass it to the `fiscalize_office` method.
|
169
|
+
|
170
|
+
`Fiscalizer::Office` object can be initialized with the following arguments:
|
171
|
+
|
172
|
+
* `uuid` : Universally Unique Identifier / ID poruke (String, required)
|
173
|
+
* `time_sent` : Time the office space fiscalization request was sent / Datum i vrijeme slanja (DateTime, required)
|
174
|
+
* `pin` : The fiscal entitie's PIN number / OIB obveznika fiskalizacije (String, required)
|
175
|
+
* `office_label` : Office space identifier / Oznaka poslovnog prostora (String, required)
|
176
|
+
* `adress_street_name` : Street name of the office space / Ulica (String, required if `address_other` is not set)
|
177
|
+
* `adress_house_num` : House number of the office space / Kućni broj (String, required if `address_other` is not set)
|
178
|
+
* `adress_house_num_addendum` : Additional house number of the office space, eg.: "a" or "3/4" / Dodatak kućnom broju (String, optional)
|
179
|
+
* `adress_post_num` : Post office number of the office space / Broj pošte (String, required if `address_other` is not set)
|
180
|
+
* `adress_settlement` : Settlement name of the office space's location / Naselje (String, optional)
|
181
|
+
* `adress_township` : Township name of the office space's location / Naziv općine ili grada (String)
|
182
|
+
* `adress_other` : Field to specify non standard office spaces, eg.: "web store" / Ostali tipovi poslovnog prostora (String, optional)
|
183
|
+
* `office_time` : Specifies the working hours of the office space / Radno vrijeme (String, required)
|
184
|
+
* `take_effect_date` : Date from which the change takes effect / Datum početka primjene (Date, required)
|
185
|
+
* `closure_mark` : Mark that indicates the closure of the office space, send "Z" to close / Oznaka zatvaranja (String, optional)
|
186
|
+
* `specific_purpose` : Software manufacturer's PIN number / Specifična namjena (String, optional)
|
187
|
+
|
188
|
+
After the fiscalization process, response object contains these informations:
|
189
|
+
|
190
|
+
* `raw_response` : XML with the raw response from the Fiscalization server
|
191
|
+
* `uuid` : UUID of the response
|
192
|
+
* `processed_at` : DateTime when the fiscalization is processed
|
193
|
+
* `errors?` : Boolean indicating if there were any errors during the process
|
194
|
+
* `errors` : Array containing errors if any - Each error is a hash with `code` and `message`
|
195
|
+
|
196
|
+
Example:
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
fiscalizer_office = Fiscalizer::Office.new(...)
|
200
|
+
fiscalizer = Fiscalizer.new(
|
201
|
+
app_cert_path: 'path/to/FISCAL_1.p12',
|
202
|
+
password: 'password'
|
203
|
+
)
|
204
|
+
|
205
|
+
response = fiscalizer.fiscalize_office(fiscalizer_office)
|
206
|
+
|
207
|
+
# do something with the response
|
208
|
+
```
|
209
|
+
|
210
|
+
# Fiscalization specification
|
211
|
+
|
212
|
+
The official technical specification for the Fiscalization process can be found
|
213
|
+
[here](https://www.porezna-uprava.hr/HR_Fiskalizacija/Stranice/Tehni%C4%8Dke-specifikacije.aspx).
|
199
214
|
|
200
215
|
# Credits
|
201
216
|
|
202
217
|
Fiscalizer is maintained and sponsored by
|
203
|
-
[Infinum](
|
218
|
+
[Infinum](https://infinum.co/).
|
204
219
|
|
205
|
-
![Infinum](
|
220
|
+
![Infinum](https://camo.githubusercontent.com/ce804b9555629d79335cf51c0bd6aedc615aeb3f/68747470733a2f2f696e66696e756d2e636f2f696e66696e756d2e706e67)
|
206
221
|
|
207
222
|
# License
|
208
223
|
|
209
|
-
|
224
|
+
The gem is available as open source under the terms of the
|
225
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fiscalizer"
|
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
|