einvoice 1.4.0 → 2.0.0.alpha2

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.coderabbit.yaml +12 -0
  3. data/.github/workflows/build.yml +7 -4
  4. data/CHANGELOG.md +55 -35
  5. data/Gemfile +3 -2
  6. data/README.md +230 -265
  7. data/README.zh-TW.md +322 -0
  8. data/Rakefile +2 -13
  9. data/bin/console +3 -6
  10. data/einvoice.gemspec +24 -21
  11. data/lib/einvoice/amego/client.rb +116 -0
  12. data/lib/einvoice/amego/errors.rb +84 -0
  13. data/lib/einvoice/amego/payload.rb +276 -0
  14. data/lib/einvoice/amego/provider.rb +267 -0
  15. data/lib/einvoice/amego.rb +27 -0
  16. data/lib/einvoice/capability.rb +79 -0
  17. data/lib/einvoice/ecpay/client.rb +183 -0
  18. data/lib/einvoice/ecpay/crypto.rb +85 -0
  19. data/lib/einvoice/ecpay/errors.rb +115 -0
  20. data/lib/einvoice/ecpay/payload.rb +241 -0
  21. data/lib/einvoice/ecpay/provider.rb +362 -0
  22. data/lib/einvoice/ecpay.rb +31 -0
  23. data/lib/einvoice/error.rb +220 -0
  24. data/lib/einvoice/ezpay/client.rb +130 -0
  25. data/lib/einvoice/ezpay/crypto.rb +85 -0
  26. data/lib/einvoice/ezpay/errors.rb +72 -0
  27. data/lib/einvoice/ezpay/payload.rb +269 -0
  28. data/lib/einvoice/ezpay/provider.rb +235 -0
  29. data/lib/einvoice/ezpay.rb +19 -0
  30. data/lib/einvoice/input.rb +494 -0
  31. data/lib/einvoice/mock_provider.rb +191 -0
  32. data/lib/einvoice/mof/donation_codes.rb +157 -0
  33. data/lib/einvoice/mof.rb +16 -0
  34. data/lib/einvoice/number.rb +51 -0
  35. data/lib/einvoice/provider.rb +57 -14
  36. data/lib/einvoice/redaction.rb +54 -0
  37. data/lib/einvoice/taipei.rb +89 -0
  38. data/lib/einvoice/tax_split.rb +124 -0
  39. data/lib/einvoice/tradevan/default_api/client.rb +175 -0
  40. data/lib/einvoice/tradevan/default_api/crypto.rb +90 -0
  41. data/lib/einvoice/tradevan/default_api/errors.rb +54 -0
  42. data/lib/einvoice/tradevan/default_api/payload.rb +259 -0
  43. data/lib/einvoice/tradevan/default_api/provider.rb +366 -0
  44. data/lib/einvoice/tradevan/default_api/rules.rb +314 -0
  45. data/lib/einvoice/tradevan.rb +25 -0
  46. data/lib/einvoice/types.rb +323 -0
  47. data/lib/einvoice/version.rb +3 -1
  48. data/lib/einvoice.rb +21 -10
  49. metadata +60 -176
  50. data/.github/workflows/cron.yml +0 -31
  51. data/docs/Tradevan E-Invoice APIs.md +0 -201
  52. data/docs/neweb.md +0 -347
  53. data/lib/einvoice/client.rb +0 -21
  54. data/lib/einvoice/configuration.rb +0 -49
  55. data/lib/einvoice/connection.rb +0 -31
  56. data/lib/einvoice/donation_unit_list.json +0 -2022
  57. data/lib/einvoice/result.rb +0 -21
  58. data/lib/einvoice/tradevan/model/base.rb +0 -34
  59. data/lib/einvoice/tradevan/model/issue_data.rb +0 -129
  60. data/lib/einvoice/tradevan/model/issue_item.rb +0 -41
  61. data/lib/einvoice/tradevan/model/void_data.rb +0 -35
  62. data/lib/einvoice/tradevan/provider.rb +0 -140
  63. data/lib/einvoice/tradevan/result.rb +0 -25
  64. data/lib/einvoice/tradevan/validator/issue_data_validator.rb +0 -80
  65. data/lib/einvoice/utils.rb +0 -13
  66. data/lib/faraday/response/decode_tradevan.rb +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2393870fedb2a46c8a29d7c903b109080499b621904e46d45b505c33e8e3147c
4
- data.tar.gz: c8ad7c8e9e6674887af0458bc00ed362e182ad39a2d30d7a4624f537e96e1c0d
3
+ metadata.gz: 8add3143532164234ebf964385784270c8888732396ad4c67d5e3bffe84f9f70
4
+ data.tar.gz: e268f679522a1721f9e247672060c075695c928fd3f1a11c11fb0b86a6413ac0
5
5
  SHA512:
6
- metadata.gz: d44581204a25dcd2f434510535ae5d5803263310ecbb6431590c5c9bc7398a10e63c0d9391c12d86417a2040cc5031c884fba915e7015c394ff32e14ed880801
7
- data.tar.gz: 4076e9ef62d58aba07a0261dfee0b989d58a6eb41ade8b582e1770fde2f1f709e7a6308260a6b3312221454b1e97651489343cfc63beba4d8e86d9189868a10e
6
+ metadata.gz: 8816c2f920cfb11396f873ae93083d511a45ed7b374eb3003ae4068d2f3ecec53a2726376de8e3132be3ee755587377a65ee83f7571dfe94b9d1711dc3063fa3
7
+ data.tar.gz: 946186503eeead81eddf7a46092476559d8a6476c9e50e441fdfea17374546be7d3cb3c8993651eb5ee74b33eeab7b0e468f74b5ff357c9333891e16145406f0
data/.coderabbit.yaml ADDED
@@ -0,0 +1,12 @@
1
+ reviews:
2
+ profile: chill
3
+ request_changes_workflow: false
4
+ auto_review:
5
+ enabled: true
6
+ drafts: false
7
+ base_branches:
8
+ - "2\\.0\\.0-alpha"
9
+ # This repository comments where code needs explaining, not on every method.
10
+ pre_merge_checks:
11
+ docstrings:
12
+ mode: "off"
@@ -2,9 +2,12 @@ name: build
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ main ]
5
+ branches: [ main, 2.0.0-alpha ]
6
6
  pull_request:
7
- branches: [ main ]
7
+ # Branch filters match the *base* of a pull request. Without 2.0.0-alpha here
8
+ # the 2.0 integration branch and everything stacked onto it would merge with
9
+ # no CI at all.
10
+ branches: [ main, 2.0.0-alpha ]
8
11
 
9
12
  permissions:
10
13
  contents: read
@@ -13,10 +16,10 @@ jobs:
13
16
  test:
14
17
  strategy:
15
18
  matrix:
16
- ruby-version: ['3.1', '3.2', '3.3', '3.4']
19
+ ruby-version: ['3.2', '3.3', '3.4', '4.0']
17
20
  runs-on: ubuntu-latest
18
21
  steps:
19
- - uses: actions/checkout@v3
22
+ - uses: actions/checkout@v4
20
23
  - name: Set up Ruby
21
24
  uses: ruby/setup-ruby@v1
22
25
  with:
data/CHANGELOG.md CHANGED
@@ -2,52 +2,72 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/).
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [2.0.0.alpha2] - 2026-11-20
10
+
11
+ 2.0 is a rewrite. 1.x was a client for one provider, Tradevan. 2.0 has one interface for several providers, so application code does not depend on one provider. **2.0 is not backward compatible.** 1.x stays in maintenance on `1-x-stable`. Pin `~> 1.4` if you depend on it. To move to 2.0, read [Upgrading from 1.x to 2.0](docs/upgrading-to-2.0.md).
12
+
13
+ ### Added
14
+ - **One interface for every provider.** `Einvoice::Provider` has the five operations: `issue`, `void`, `allowance`, `void_allowance` and `query`. They take plain hashes or value objects, and return value types (`Data.define`).
15
+ - **Load only the provider you use.** `require "einvoice"` loads the core. Each adapter loads with its own `require`, such as `require "einvoice/ecpay"`, and so do the 財政部 lookups (`require "einvoice/mof"`). 2.0 has no runtime dependencies.
16
+ - **Checks before the call.** Input is checked locally, and a bad request raises `Einvoice::ValidationError` before anything goes over the network. The core checks the MIG rules that hold at every provider, so every provider answers them alike: for example the 統一編號, the 愛心碼 (3 to 7 digits), carrier codes, the MIG tax rates and the MIG field lengths. The README lists them.
17
+ - **The core computes tax.** For an issue and an allowance, the core computes the tax of every line and the MIG totals from the items, `price_mode`, `tax_type` and `tax_rate`, as `#tax_breakdown`. Adapters do not compute tax, so the same input gets the same tax at every provider. `amount` is optional: without it, the core fills it in. A given `amount` is checked against the breakdown, by F0401 for an invoice and G0401 for an allowance.
18
+ - **References.** Issue, query and allowance results return a `#reference` that holds what a provider asks for later. Pass it to `void`, `allowance` and `query`, and you do not need to know each provider's needs. `reference.to_h` is JSON-safe, so you can store it with your order. A time without an offset is refused when it is read back. An allowance takes its tax type and rate from the reference, with no default, so a zero rated invoice is not credited with tax. An allowance item may not be negative (MIG 4.1). An invoice item may be, as a discount line.
19
+ - **MIG names and types.** Dates are `invoice_datetime` (a `Time` in UTC+8), `allowance_date` (a `Date`) and `cancel_datetime`. A zero rated invoice takes `customs_clearance_mark` and `zero_tax_rate_reason`.
20
+ - **Errors you can act on.** Every failure is an `Einvoice::Error` with a stable `#code`. `#group` says which side failed, the invoice or the provider, and `#reason` says what to do next. For example, `:already_voided` on a void is safe to treat as done, but `:allowance_blocked_by_void` means that no credit was made. A `ValidationError` means that no provider takes the input. An `UnsupportedError` means that this provider does not take it, but another one may. A `NetworkError` can be retried. `#raw_code` and `#raw_message` keep the provider's own answer.
21
+ - **Capabilities.** Each provider declares the optional features it has, such as B2B, mixed tax, query by order id and carrier validation (`#supports?`, `#validate_carrier`). A missing feature raises `UnsupportedError`. `#query_statuses` lists the statuses that `query` can return, because some providers cannot tell every state.
22
+ - **`Einvoice::MockProvider`**, an in-memory provider for testing your application. It follows the same contract and the same invoice states as a real adapter.
23
+ - **ECPay (綠界)**, the first adapter. Its live spec runs against ECPay's public stage, and its specs replay responses recorded there.
24
+ - **Amego (光貿).** Its live spec runs against Amego's public test account.
25
+ - **ezPay (簡單行動支付), experimental.** Built from ezPay's manuals, and checked against their samples. Nobody has run it against ezPay, so test it against your own test shop first.
26
+ - **Tradevan (關貿) DEFAULTAPI, experimental.** Ported from the 1.x client. Nobody has run it against the live API, so test it against your own account first.
27
+ - **`Einvoice::MOF::DonationCodes`**, which looks up a 愛心碼 in 財政部's open data, in place of the list that 1.x shipped.
28
+ - **Data kept out of logs.** `inspect`, `to_s` and `pp` show a result's raw response, a buyer's personal data and a client's credentials as `[FILTERED]`. `base_url` must use https (localhost may use http), and must not carry a user, a password, a query or a fragment.
29
+
30
+ Each provider's note in `docs/providers/` gives its mapping, its limits and what was verified, and how sure we are of each.
31
+
32
+ ### Removed
33
+ - The 1.x Tradevan layer (`Client`, `Configuration`, `Connection`, `Result` and the Tradevan models). The unified core and the adapters replace it. Tradevan DEFAULTAPI is back as an adapter.
34
+ - `lib/einvoice/donation_unit_list.json` and the scheduled workflow that refreshed it. `Einvoice::MOF::DonationCodes` looks the codes up live.
35
+
36
+ ## [1.5.0] - 2026-09-11
37
+
38
+ ### Fixed
39
+ - Tradevan `IssueData#payload` and `VoidData#payload` now exclude `context_for_validation`. On Rails 8 this internal ivar was sent as a business field once `valid?` had run, and Tradevan rejected the whole request. Thanks @dlackty.
40
+
41
+ ### Changed
42
+ - **Ruby 3.1 or newer is now required.** CI covers 3.1 through 3.4.
43
+ - **Faraday 2 is now required** (`~> 2.1`); `faraday_middleware` is gone, replaced by a built-in `Faraday::Response::ParseXml`. If you pin `faraday` to 1.x, stay on 1.4.0.
44
+ - `Einvoice::Utils` and the `gyoku` dependency have been removed. Nothing in the gem called them.
45
+
46
+ ### Internal
47
+ - Added request-level Tradevan provider specs.
48
+ - CI runs on `1-x-stable`; the donation unit list task parses with `CSV`.
49
+ - README documents the allowance operations and 1.x maintenance mode.
7
50
 
8
51
  ## [1.4.0] - 2026-08-08
9
52
 
10
53
  ### Changed
11
- - **TLS certificate verification is now enabled by default.** Previously every
12
- request was sent with `ssl: { verify: false }`, regardless of configuration.
13
- If you were relying on that behavior (e.g. against an endpoint with an
14
- incomplete certificate chain), set `config.ssl_verify = false` or pass
15
- `ssl_verify: false` to `Provider.new` to restore the old behavior.
16
- - `Client` now delegates to the provider via `public_send` instead of `send`,
17
- and implements `respond_to_missing?`. Private provider methods (e.g.
18
- `encrypt`, `connection`) are no longer reachable through `Client`.
54
+ - **TLS certificate verification is now enabled by default.** Previously every request was sent with `ssl: { verify: false }`, regardless of configuration. If you were relying on that behavior (e.g. against an endpoint with an incomplete certificate chain), set `config.ssl_verify = false` or pass `ssl_verify: false` to `Provider.new` to restore the old behavior.
55
+ - `Client` now delegates to the provider via `public_send` instead of `send`, and implements `respond_to_missing?`. Private provider methods (e.g. `encrypt`, `connection`) are no longer reachable through `Client`.
19
56
 
20
57
  ### Fixed
21
- - `TotalValidator` comparison was inverted and compared a `String` against an
22
- `Integer`, so it never actually validated anything. It now correctly fails
23
- when `total` doesn't match the sum of item totals.
24
- - `AllowanceNumberValidator` and `IssueItem#invoiceTime`'s format regexp had
25
- broken escape sequences (`\A` and `\d` collapsing to literal characters in a
26
- double-quoted string), causing them to reject all valid input.
27
- - `ItemListValidator` pushed directly onto `record.errors[:itemList]`, which
28
- is deprecated in Rails 6.1 and removed in 7.0. It now uses `errors.add` and
29
- actually registers errors again.
30
- - Tradevan response decoding used `JSON.load`, which is unsafe for untrusted
31
- input. Switched to `JSON.parse`.
32
- - `lib/einvoice/donation_unit_list.json` was stale since 2023-12 (the
33
- scheduled update workflow had been silently broken), causing
34
- `DonationUnitValidator` to reject currently valid donation codes and accept
35
- retired ones. The list has been refreshed (~340 entries changed).
58
+ - `TotalValidator` comparison was inverted and compared a `String` against an `Integer`, so it never actually validated anything. It now correctly fails when `total` doesn't match the sum of item totals.
59
+ - `AllowanceNumberValidator` and `IssueItem#invoiceTime`'s format regexp had broken escape sequences (`\A` and `\d` collapsing to literal characters in a double-quoted string), causing them to reject all valid input.
60
+ - `ItemListValidator` pushed directly onto `record.errors[:itemList]`, which is deprecated in Rails 6.1 and removed in 7.0. It now uses `errors.add` and actually registers errors again.
61
+ - Tradevan response decoding used `JSON.load`, which is unsafe for untrusted input. Switched to `JSON.parse`.
62
+ - `lib/einvoice/donation_unit_list.json` was stale since 2023-12 (the scheduled update workflow had been silently broken), causing `DonationUnitValidator` to reject currently valid donation codes and accept retired ones. The list has been refreshed (~340 entries changed).
36
63
 
37
64
  ### Added
38
- - Specs for `Client` delegation, `Configuration#ssl_verify`,
39
- `Provider#connection` SSL behavior, the validator fixes above, and the
40
- previously-untested `decode_tradevan` middleware.
65
+ - Specs for `Client` delegation, `Configuration#ssl_verify`, `Provider#connection` SSL behavior, the validator fixes above, and the previously-untested `decode_tradevan` middleware.
41
66
 
42
67
  ### Internal
43
68
  - CI coverage reporting migrated from Code Climate (discontinued) to Codecov.
44
- - The scheduled `cron.yml` workflow that refreshes the donation unit list
45
- has been repaired — it depended on two archived GitHub Actions
46
- (`actions/setup-ruby`, `mikeal/publish-to-github-action`) and hadn't run
47
- successfully since 2023-12.
69
+ - The scheduled `cron.yml` workflow that refreshes the donation unit list has been repaired — it depended on two archived GitHub Actions (`actions/setup-ruby`, `mikeal/publish-to-github-action`) and hadn't run successfully since 2023-12.
48
70
 
49
71
  ---
50
72
 
51
- Versions prior to 1.4.0 were not tracked in this file. See the
52
- [release history](https://github.com/abookyun/einvoice/releases) and
53
- [commit log](https://github.com/abookyun/einvoice/commits/main/) for earlier changes.
73
+ Versions prior to 1.4.0 were not tracked in this file. See the [release history](https://github.com/abookyun/einvoice/releases) and [commit log](https://github.com/abookyun/einvoice/commits/main/) for earlier changes.
data/Gemfile CHANGED
@@ -1,8 +1,9 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in einvoice.gemspec
4
6
  gemspec
5
7
 
6
- gem "ostruct", require: false, group: :development
7
8
  gem "simplecov", require: false, group: :test
8
9
  gem "simplecov-lcov", require: false, group: :test