liberic 1.4.1 → 1.5.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.
data/README.md CHANGED
@@ -1,229 +1,366 @@
1
1
  # Liberic
2
2
 
3
- Liberic is a ruby wrapper for ERiC, a C library to interact with German
4
- Tax Authority's ELSTER service.
3
+ Liberic is a Ruby wrapper for ERiC (ELSTER Rich Client), the native library
4
+ for validating, printing and submitting tax filings to Germany's tax
5
+ authorities through ELSTER.
5
6
 
6
- **WARNING:** This gem is at a very early stage and not able to do much useful stuff.
7
+ Most applications need only `Liberic::Process`, `Liberic::Certificate` and
8
+ `Liberic.config`; `Liberic::SDK::API` exposes the native functions directly.
7
9
 
8
- ## Documentation
10
+ ## Requirements
9
11
 
10
- This README can only give a brief overview. You can look up the complete
11
- [documentation on RubyDoc.info](http://www.rubydoc.info/github/mpm/liberic-ruby).
12
+ - Ruby 3.3 or newer.
13
+ - ERiC **43.5.4.0**. The SDK is not included in the gem; on Linux x86-64,
14
+ `bundle exec rake eric:install` downloads and installs it automatically.
15
+ - Your own ELSTER manufacturer ID (Hersteller-ID) for processing filings,
16
+ including the SDK's examples. The test manufacturer ID `74931` used in
17
+ older examples is blocked and no longer works.
18
+
19
+ The bundled SDK installer and SDK integration specs target **Linux x86-64**.
20
+ For macOS or other platforms, install the matching SDK manually and follow
21
+ the platform instructions in its `ERiC-Entwicklerhandbuch.pdf`. Ruby and the
22
+ native SDK must use matching architectures. macOS setup has not been
23
+ verified for this release.
24
+
25
+ See the [ELSTER developer information](https://www.elster.de/elsterweb/infoseite/entwickler)
26
+ for registration and manufacturer IDs.
12
27
 
13
28
  ## Installation
14
29
 
15
- Add this line to your application's Gemfile:
30
+ Add Liberic to your application's `Gemfile`:
16
31
 
17
32
  ```ruby
18
- gem 'liberic'
33
+ gem 'liberic', require: 'liberic/core'
19
34
  ```
20
35
 
21
- And then execute:
36
+ Then run `bundle install`. Loading `liberic/core` lets the application start
37
+ without loading ERiC; initialize it explicitly in the process that needs it
38
+ (see [Initialization](#initialization)).
39
+
40
+ ### Install the SDK on Linux x86-64
22
41
 
23
- $ bundle
42
+ The `eric:install` task downloads the SDK and documentation directly from
43
+ ELSTER's public download server. No developer login is needed for this
44
+ download; a manufacturer ID is still required to process filings.
24
45
 
25
- Or install it yourself (not possible yet) as:
46
+ To use the installer from an application, add rubyzip to its `Gemfile` and
47
+ load the task in its `Rakefile`:
26
48
 
27
- $ gem install liberic
49
+ ```ruby
50
+ # Gemfile — only needed for SDK installation, not at runtime
51
+ gem 'rubyzip', '>= 3.4', require: false
52
+
53
+ # Rakefile
54
+ require 'liberic/tasks'
55
+ ```
28
56
 
29
- The ERiC library files are not distributed with this gem. On Linux x86-64,
30
- download and install the SDK and its documentation with:
57
+ Run `bundle install`, then:
31
58
 
32
59
  ```sh
33
60
  bundle exec rake eric:install
61
+ export ERIC_HOME="$PWD/.eric/ERiC-43.5.4.0/Linux-x86_64"
34
62
  ```
35
63
 
36
- This installs ERiC `43.5.4.0` by default. To select another full release,
37
- run:
64
+ The task installs ERiC 43.5.4.0 and its documentation below `.eric/` in
65
+ the directory of the `Rakefile`. Allow at least 1.5 GB of free disk space
66
+ for the archives and extracted files. Completed downloads are cached in
67
+ `.eric/downloads/` for reuse.
68
+
69
+ The task prints the exact `export` command for the installed SDK. Run it in
70
+ the shell where Liberic will run, or configure `ERIC_HOME` in your deployment
71
+ environment; the task cannot change its parent shell's environment.
72
+
73
+ To choose another installation root, pass a task argument or set
74
+ `ERIC_INSTALL_ROOT`:
38
75
 
39
76
  ```sh
40
- ERIC_VERSION=43.5.4.0 bundle exec rake eric:install
77
+ bundle exec rake "eric:install[/opt/myapp]"
78
+ ERIC_INSTALL_ROOT=/opt/myapp bundle exec rake eric:install
41
79
  ```
42
80
 
43
- The task derives the ELSTER `eric_<major>` download directory from the version's
44
- first component. It caches completed archives in `.eric/downloads/` and extracts
45
- them below `.eric/`, producing this SDK home for the default version:
81
+ The installer can also be used without Rake:
46
82
 
47
- ```text
48
- .eric/ERiC-43.5.4.0/Linux-x86_64
83
+ ```ruby
84
+ require 'liberic/eric_installer'
85
+ Liberic::EricInstaller.new(root: '/opt/myapp').install # => SDK home
49
86
  ```
50
87
 
51
- Allow at least 1.5 GB of free disk space for roughly 680 MB of downloads and
52
- their extracted contents. Downloads use temporary `.part` files, can be reused
53
- on later runs, and are not included in the repository or packaged gem. The
54
- installer supports only the official Linux x86-64 SDK.
88
+ ### Use an existing or manually installed SDK
55
89
 
56
- After installation, set the version-independent `ERIC_HOME` variable in the
57
- shell where Liberic will run:
90
+ To install the SDK manually, download it through the
91
+ [ELSTER developer area](https://www.elster.de/elsterweb/entwickler/infoseite/eric)
92
+ (developer credentials required) and follow its installation instructions.
93
+ For a manual or existing installation, set `ERIC_HOME` to the platform
94
+ directory containing `bin/`, `include/` and `lib/`:
58
95
 
59
96
  ```sh
60
- export ERIC_HOME="$PWD/.eric/ERiC-43.5.4.0/Linux-x86_64"
97
+ export ERIC_HOME=/opt/ERiC-43.5.4.0/Linux-x86_64
61
98
  ```
62
99
 
63
- The install task prints the exact command for the selected version. A Rake
64
- process cannot permanently change the environment of its parent shell, so you
65
- must run the command yourself or add it to your shell configuration.
100
+ The older `ERIC_HOME_40` variable remains a fallback when `ERIC_HOME` is
101
+ not set.
66
102
 
67
- For a manual or shared installation, obtain ERiC from the
68
- [ELSTER Entwicklerbereich](https://www.elster.de/elsterweb/entwickler/infoseite/eric),
69
- which requires developer credentials. You can also browse the public
70
- [ELSTER developer information](https://www.elster.de/elsterweb/infoseite/entwickler).
71
- Follow the official installation instructions and extract the SDK to a location
72
- of your choice. It should contain at least these folders:
103
+ ## Initialization
73
104
 
74
- ```
75
- bin/
76
- include/
77
- lib/
78
- ```
105
+ Load the Ruby code, then boot ERiC in the process that will use it:
79
106
 
80
- Set `ERIC_HOME` to that folder or the gem will not find the library files.
81
- For compatibility with existing applications, `ERIC_HOME_40` remains a
82
- fallback when `ERIC_HOME` is not set.
107
+ ```ruby
108
+ require 'liberic/core'
83
109
 
84
- For example:
110
+ Liberic.boot! # uses ERIC_HOME
111
+ ```
85
112
 
86
- ```sh
87
- export ERIC_HOME=/opt/ERiC-43.5.4.0/Linux-x86_64
113
+ You can alternatively pass the SDK location, log directory and plugin
114
+ directory explicitly:
115
+
116
+ ```ruby
117
+ Liberic.boot!(
118
+ eric_home: '/opt/ERiC-43.5.4.0/Linux-x86_64',
119
+ log_path: 'log/eric', # existing directory for eric.log; default: system temp directory
120
+ plugin_path: nil # default: ERiC's lib directory
121
+ )
88
122
  ```
89
123
 
90
- The gem will raise a `Liberic::InitializationError` if neither environment
91
- variable is set.
92
- In a Rails project this can interfere with running rake (for example
93
- when building the app in Docker). In this case, use `gem 'liberic', require: false` in your `Gemfile`.
94
- And require the gem later in your Rails code (for example a model) by
95
- calling `require 'liberic'`.
124
+ ERiC stops writing `eric.log` as soon as `Liberic.config` is used, including
125
+ reading or changing a setting, unless you set `Liberic.config.log_file = true`;
126
+ see [Configuration and logging](#configuration-and-logging).
96
127
 
97
- ### Additional steps on OS X
128
+ ERiC can be initialized only once per process; a second `Liberic.boot!`
129
+ raises `Liberic::InitializationError`. `Liberic.booted?`
130
+ reports whether initialization succeeded. ERiC's single-threading API is
131
+ not thread safe; serialize calls within each process.
98
132
 
99
- The following OS X specific information dates back to the first version of this
100
- library (from 2016). Might be outdated or incorrect by now.
133
+ For compatibility, `require 'liberic'` still loads and initializes ERiC
134
+ immediately, unless already booted. It raises `Liberic::InitializationError`
135
+ if `ERIC_HOME` is not set. Use `liberic/core` to avoid
136
+ initialization in web processes or build tasks that do not need ERiC.
101
137
 
102
- On *Mac OS X* you need to process the libraries to fix the interal paths
103
- (credits to @deviantbits):
138
+ If `boot!` fails because the library cannot be loaded, you can retry with
139
+ another `eric_home`. If it fails later, during initialization, you can only
140
+ retry with the same `eric_home`; switching to a different SDK needs a new
141
+ process.
104
142
 
105
- ```
106
- libs=`ls $ERIC_HOME/lib/*.dylib`
107
- plugins=`ls $ERIC_HOME/lib/plugins2/*.dylib`
143
+ ## Usage
108
144
 
109
- for target in $libs
110
- do
111
- for lib in $libs
112
- do
113
- install_name_tool -change "@rpath/"`basename $lib` "$ERIC_HOME/lib/"`basename $lib` $target
114
- done
145
+ ### Validate a filing
115
146
 
116
- for plugin in $plugins
117
- do
118
- install_name_tool -change "@rpath/plugins2/"`basename $plugin` "$ERIC_HOME/lib/plugins2/"`basename $plugin` $target
119
- done
120
- done
147
+ This example uses the **2020 test filing** shipped with the SDK to
148
+ demonstrate the API. Set `ERIC_HOME` and `ERIC_HERSTELLER_ID` before running
149
+ it. For real filings, supply the XML and matching data type for the relevant
150
+ tax year.
121
151
 
122
- for target in $plugins
123
- do
124
- for lib in $libs
125
- do
126
- install_name_tool -change "@rpath/"`basename $lib` "$ERIC_HOME/lib/"`basename $lib` $target
127
- done
128
- done
152
+ ```ruby
153
+ require 'liberic/core'
154
+ Liberic.boot!
155
+
156
+ tax_filing = File.read(
157
+ File.join(Liberic.eric_home, 'Beispiel/ericdemo-java/ESt_2020.xml'),
158
+ encoding: 'UTF-8'
159
+ )
160
+ tax_filing = tax_filing.sub(
161
+ %r{<HerstellerID>\d+},
162
+ "<HerstellerID>#{ENV.fetch('ERIC_HERSTELLER_ID')}"
163
+ )
164
+
165
+ submission = Liberic::Process.new(tax_filing, 'ESt_2020')
166
+ result = submission.execute # local validation; does not send the filing
167
+
168
+ if result.ok?
169
+ puts 'The tax filing is valid.'
170
+ else
171
+ puts "#{result.error} (#{result.code})"
172
+ puts result[:result]
173
+ end
129
174
  ```
130
175
 
131
- Check your settings by running:
176
+ `execute` returns a `Liberic::Process::Result`, a Hash with `:result`
177
+ (ERiC's result XML) and `:server_result` (the server response when sending),
178
+ plus `code`, `error` and `ok?`. **An empty `:result` does not mean success**:
179
+ always check `ok?`.
132
180
 
133
- ```sh
134
- $ ls $ERIC_HOME/lib/libericapi.*
135
- ```
136
- This should list you one file with an operating system dependend suffix.
181
+ Use `execute!` to raise `Liberic::Process::ProcessingError` on failure;
182
+ the exception exposes `code`, `error` and `result`.
137
183
 
138
- ## Usage
184
+ For a separate XML schema check, call `submission.check`. It raises
185
+ `Liberic::Helpers::Invocation::Error` on failure, with ERiC's schema error
186
+ text in `buffer`. This check is optional; `execute` also checks the XML.
139
187
 
140
- The gem exposes an interface to ERiC's native functions inside the
141
- `Liberic::SDK::API` namespace.
188
+ ### Actions and hints
142
189
 
143
- Function names have been converted from camel case and stripped of the
144
- 'Eric' prefix, otherwise the original (German) names have been kept.
190
+ Pass `action:` to `execute` or `execute!`:
145
191
 
146
- For example:
192
+ | Action | Behavior |
193
+ | --- | --- |
194
+ | `:validate` (default) | Validate locally. |
195
+ | `:validate_with_hints` | Validate locally and include hints. |
196
+ | `:print` | Create a preview PDF locally. |
197
+ | `:submit` | Send the filing to ELSTER. |
198
+ | `:print_and_submit` | Send the filing and create the PDF of the sent filing. |
147
199
 
148
- ```c
149
- EricSystemCheck();
150
- ```
151
- is in Ruby:
200
+ Whether a submission is authenticated depends on `encryption:`, not on the
201
+ action. `:print_and_submit_auth` is a deprecated alias of `:print_and_submit`.
202
+
203
+ When validation finds hints but no errors, ERiC returns
204
+ `ERIC_GLOBAL_HINWEISE`, which counts as success. `hints?` identifies this
205
+ return code; the `<Hinweis>` elements are in `:result`:
152
206
 
153
207
  ```ruby
154
- Liberic::SDK::API.system_check
208
+ result = submission.execute(action: :validate_with_hints)
209
+ puts result[:result] if result.hints?
155
210
  ```
156
211
 
157
- A more Ruby friendly encapsulation of the ERiC functionality is in the
158
- making (check out `Liberic::Process`).
159
-
160
- ## Examples
212
+ ### Create PDFs
161
213
 
162
- The following script will load an example tax filing (from the SDK) to
163
- validate it with ERiC.
214
+ An action that prints needs a file name or `pdf: :memory`; ERiC has no
215
+ default output directory. Relative file names use the working directory.
164
216
 
165
217
  ```ruby
166
- require 'liberic'
218
+ submission.execute!(action: :print, filename: '/tmp/est_2020.pdf')
167
219
 
168
- # Use a convenience wrapper that deals with creating a buffer for the
169
- # native function's results. This will also raise a Ruby exception if
170
- # the native function returns anything else then 0 (= OK).
171
- version_info = Liberic::Helpers::Invocation.with_result_buffer do |handle|
220
+ result = submission.execute!(action: :print, pdf: :memory)
221
+ result.pdfs # => {"<Nutzdatenticket>" => "%PDF-1.4..."}
222
+ ```
172
223
 
173
- # Call ERiC function EricVersion()
174
- Liberic::SDK::API::version(handle)
175
- end
224
+ `Result#pdfs` maps ERiC's PDF names (the data block's Nutzdatenticket, or
225
+ `Uebertragungsprotokoll`) to binary strings. Pass either `filename:` or
226
+ `pdf: :memory`. Printing also accepts `footer:`, `duplex:` and `draft:`.
227
+ For `:print`, `draft` defaults to `true` (a preview marked `*** ENTWURF ***`);
228
+ ERiC 43 prints locally only as a preview. For `:print_and_submit` it
229
+ defaults to `false`: ERiC rejects `draft: true` there with
230
+ `ERIC_GLOBAL_UNGUELTIGER_PARAMETER`, before sending. A missing file name or
231
+ `pdf: :memory` is also rejected before sending.
232
+
233
+ A runnable example that validates and prints the SDK filing is included in
234
+ [examples/est_2020.rb](examples/est_2020.rb):
235
+
236
+ ```sh
237
+ # With ERIC_HOME and ERIC_HERSTELLER_ID set:
238
+ bundle exec ruby examples/est_2020.rb /tmp/est_2020.pdf
239
+ ```
176
240
 
177
- # version info contains XML with all ERiC libraries and their versions.
178
- puts version_info
241
+ ### Certificates and authenticated submission
179
242
 
180
- # Read example file that declares income tax for 2011. Assumes you have extraced
181
- # the 'Beispiel' folder that comes with the ERiC libraries.
182
- tax_filing = File.read(File.expand_path('Beispiel/ericdemo-java/steuersatz.xml', Liberic.eric_home))
243
+ Open a certificate from a file, or use
244
+ `Liberic::Certificate.from_bytes(pkcs12_bytes, pin)` for a password-protected
245
+ PKCS#12 container in memory:
183
246
 
184
- # Liberic::Process is a high level wrapper around ERiC's EricBearbeiteVorgang() function.
185
- submission = Liberic::Process.new(tax_filing, 'ESt_2011')
247
+ ```ruby
248
+ certificate = Liberic::Certificate.new('cert.pfx', pin)
249
+ begin
250
+ certificate.encryption_params do |params|
251
+ submission.execute!(action: :submit, encryption: params)
252
+ end
253
+ ensure
254
+ certificate.release_handle!
255
+ end
256
+ ```
186
257
 
187
- # Check for validity of the XML schema
188
- submission.check
258
+ When given a block, `encryption_params` wipes the native copy of the PIN
259
+ after the block returns; `from_bytes` wipes its temporary native copies of
260
+ the container and PIN.
261
+ The original Ruby strings cannot be wiped reliably.
189
262
 
190
- # Submit tax filing for a dry run (validity of the fields will be checked).
191
- result = submission.execute
263
+ ### Datenabholung
192
264
 
193
- # Will be empty if everything was ok. Otherwise, result contains XML with a list of offending fields.
194
- # Try editing the example file to see this in action- for example change the year of birth to a future year, etc.
195
- puts result
265
+ A Datenabholung's request, retrieval and acknowledgement calls share an
266
+ `EricTransferHandle`. Create one `Liberic::Process::TransferHandle` per
267
+ Datenabholung and pass it to each call with `transfer_handle:`:
268
+
269
+ ```ruby
270
+ handle = Liberic::Process::TransferHandle.new
271
+ Liberic::Process.new(request_xml, type)
272
+ .execute!(action: :submit, encryption: params, transfer_handle: handle)
273
+ Liberic::Process.new(retrieval_xml, type)
274
+ .execute!(action: :submit, encryption: params, transfer_handle: handle)
196
275
  ```
197
276
 
198
- ## Features
277
+ Leave `transfer_handle:` out for all other calls.
199
278
 
200
- This gem is rather early stage. It does not implement all ERiC features
201
- yet. It does support submitting various tax filings via
202
- `Liberic::Process` which should be sufficient for the majority of use
203
- cases. Dealing with certificates (necessary for retrieving the tax
204
- assessment or cryptographically signing a tax filing) is possible, but
205
- no Ruby style wrapper exists yet.
279
+ ## Configuration and logging
206
280
 
207
- Please refer to `Liberic::SDK::API` and the official docs for this.
281
+ `Liberic.config` reads and writes ERiC settings by German name or English
282
+ accessor, after initialization:
208
283
 
209
- ## Bugs
284
+ ```ruby
285
+ require 'logger'
210
286
 
211
- This library is used in production for submitting tax filings. Not all
212
- of the methods implemented in `Liberic::SDK::API` have been tested
213
- though, so the data types defined there might be wrong.
287
+ Liberic.config.validation_error_limit = 30
288
+ Liberic.config['validieren.fehler_max'] # => 30
289
+ Liberic.config.logger = Logger.new($stdout)
290
+ ```
214
291
 
215
- Please consider this if you encounter problems and are looking for bugs
216
- in your code.
292
+ The first use of `Liberic.config`, including reading or changing a setting,
293
+ registers a Ruby log callback. From then on ERiC no longer writes `eric.log`
294
+ (to the `log_path` passed to `Liberic.boot!`) for the rest of the process.
295
+ Its log messages go only to `Liberic.config.logger`, and are discarded while
296
+ no logger is assigned. If your application uses `Liberic.config`, assign a
297
+ logger or keep the log file right after `Liberic.boot!`, so that no messages
298
+ are lost:
217
299
 
218
- Pull requests, improvements and examples are welcome, we are all in this
219
- together :)
300
+ ```ruby
301
+ Liberic.boot!(log_path: 'log/eric')
302
+ Liberic.config.log_file = true # keep writing eric.log, also with a logger
303
+ ```
220
304
 
221
- ## Development
305
+ The accessors are `allow_test_id`, `detailed_logs`, `connect_timeout`,
306
+ `response_timeout`, `validation_error_limit`, `validation_hint_limit`,
307
+ `network` (`transfer.netz`), `test_date`, and `proxy_host`, `proxy_port`,
308
+ `proxy_username`, `proxy_password`, `proxy_auth`.
309
+
310
+ ERiC 43 removed the settings behind these older accessors; they raise
311
+ `Liberic::Config::UnsupportedSettingError`:
312
+
313
+ | Removed accessor | Replacement |
314
+ | --- | --- |
315
+ | `Liberic.config.eric_home` | `Liberic.eric_home` |
316
+ | `Liberic.config.log_path` | `Liberic.boot!(log_path: ...)`; read with `Liberic.log_path` |
317
+ | `Liberic.config.data_path` | `filename:` on `Process#execute` |
318
+ | `Liberic.config.online` | `Liberic.config.network` (`'ndb'` for the Netz des Bundes) |
319
+
320
+ ## ERiC 43 behavior and limitations
321
+
322
+ Observed with ERiC 43.5.4.0:
323
+
324
+ - The native `ERIC_PRUEFE_HINWEISE` flag alone skips validation. Liberic's
325
+ `:validate_with_hints` combines it with `ERIC_VALIDIERE` to return both
326
+ errors and hints.
327
+ - `execute` reports invalid values and unknown elements as
328
+ `<FehlerRegelpruefung>` with a field and text (rule `formalePruefung`).
329
+ `check` (`EricCheckXML`) reports schema errors with line and column, one
330
+ `EC(<code>): ...` line per error, in `Invocation::Error#buffer`.
331
+ - Characters outside Unicode's Basic Multilingual Plane, such as emoji,
332
+ cause `ERIC_IO_UNGUELTIGE_UTF8_SEQUENZ` even when the XML is valid UTF-8.
333
+ Neither `execute` nor `check` identifies the field.
334
+ - PDF footers have a maximum of 30 characters
335
+ (`ERIC_PRINT_FUSSTEXT_ZU_LANG` otherwise). German umlauts, ß and € work;
336
+ characters such as Chinese characters or emoji cause
337
+ `ERIC_IO_UNGUELTIGE_ZEICHEN_IN_PARAMETER`. Liberic passes footers in UTF-8.
338
+
339
+ Liberic does not bind every native function, including ERiC's
340
+ multithreading API (`EricMt*`), and does not parse all response XML into Ruby
341
+ objects. For other use cases, check `Liberic::SDK::API` and the official
342
+ SDK documentation. Integration coverage is concentrated on the common
343
+ wrappers; not every native binding has been exercised.
344
+
345
+ Native function names use snake case without the `Eric` prefix; German
346
+ names are otherwise retained. For example, `EricSystemCheck()` is exposed
347
+ as `Liberic::SDK::API.system_check`. Functions returning buffers can use
348
+ the invocation helper, which releases the buffer and raises on ERiC errors:
222
349
 
223
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
350
+ ```ruby
351
+ version_xml = Liberic::Helpers::Invocation.with_result_buffer do |handle|
352
+ Liberic::SDK::API.version(handle)
353
+ end
354
+ ```
224
355
 
225
- 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).
356
+ ## Documentation and contributing
226
357
 
227
- ## Contributing
358
+ - [Changelog](CHANGELOG.md) for release notes and upgrade information.
359
+ - [Ruby API documentation](https://www.rubydoc.info/github/mpm/liberic-ruby).
360
+ - The SDK's `Dokumentation/ERiC-Entwicklerhandbuch.pdf` and
361
+ `Dokumentation/API-Referenz/HTML/` for ERiC setup, settings and native APIs.
362
+ - [GitHub issues](https://github.com/mpm/liberic-ruby/issues) for bug reports.
363
+ - [CONTRIBUTING.md](CONTRIBUTING.md) for running the specs, upgrading the SDK
364
+ and releasing.
228
365
 
229
- Bug reports and pull requests are welcome on GitHub at https://github.com/mpm/liberic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
366
+ Liberic is available under the [MIT license](LICENSE).
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Validates the income tax example that comes with the ERiC SDK and creates
4
+ # its preview PDF. Run it with the SDK in ERIC_HOME and your ELSTER
5
+ # manufacturer ID (ERiC 43 blocks the SDK's test ID 74931):
6
+ #
7
+ # ERIC_HOME=... ERIC_HERSTELLER_ID=... bundle exec ruby examples/est_2020.rb [output.pdf]
8
+
9
+ require "bundler/setup"
10
+ require "liberic"
11
+
12
+ tax_filing = File.read(File.expand_path("Beispiel/ericdemo-java/ESt_2020.xml", Liberic.eric_home), encoding: "UTF-8")
13
+ tax_filing = tax_filing.sub(%r{<HerstellerID>\d+}, "<HerstellerID>#{ENV.fetch('ERIC_HERSTELLER_ID')}")
14
+
15
+ submission = Liberic::Process.new(tax_filing, "ESt_2020")
16
+
17
+ # Schema check: raises Liberic::Helpers::Invocation::Error, with ERiC's
18
+ # error text in #buffer.
19
+ submission.check
20
+
21
+ # Validation with errors and hints in one call.
22
+ result = submission.execute(action: :validate_with_hints)
23
+ puts "validate: #{result.ok? ? 'ok' : "#{result.error} (#{result.code})"}#{' with hints' if result.hints?}"
24
+ puts result[:result] unless result[:result].empty?
25
+ exit 1 unless result.ok?
26
+
27
+ # Preview PDF ("*** ENTWURF ***"), kept in memory and written here.
28
+ result = submission.execute!(action: :print, pdf: :memory, footer: "Liberic example")
29
+ filename = ARGV.fetch(0, "est_2020.pdf")
30
+ File.binwrite(filename, result.pdfs.values.first)
31
+ puts "PDF written to #{filename}"
32
+
33
+ # To send the filing to ELSTER, use action: :submit (or :print_and_submit with
34
+ # :filename or pdf: :memory) and, for authenticated submission, encryption
35
+ # params from a Liberic::Certificate:
36
+ #
37
+ # certificate = Liberic::Certificate.new("cert.pfx", pin)
38
+ # certificate.encryption_params do |params|
39
+ # submission.execute!(action: :submit, encryption: params)
40
+ # end