einvoice 1.5.0 → 2.0.0.beta1
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 +4 -4
- data/.coderabbit.yaml +6 -8
- data/.github/workflows/build.yml +6 -3
- data/.github/workflows/cron.yml +4 -2
- data/CHANGELOG.md +63 -44
- data/Gemfile +3 -10
- data/README.md +284 -325
- data/README.zh-TW.md +381 -0
- data/Rakefile +2 -51
- data/bin/console +3 -6
- data/einvoice.gemspec +17 -18
- data/lib/einvoice/amego/client.rb +116 -0
- data/lib/einvoice/amego/errors.rb +84 -0
- data/lib/einvoice/amego/payload.rb +270 -0
- data/lib/einvoice/amego/provider.rb +272 -0
- data/lib/einvoice/amego.rb +27 -0
- data/lib/einvoice/capability.rb +79 -0
- data/lib/einvoice/ecpay/client.rb +184 -0
- data/lib/einvoice/ecpay/crypto.rb +85 -0
- data/lib/einvoice/ecpay/errors.rb +115 -0
- data/lib/einvoice/ecpay/payload.rb +241 -0
- data/lib/einvoice/ecpay/provider.rb +371 -0
- data/lib/einvoice/ecpay.rb +31 -0
- data/lib/einvoice/error.rb +220 -0
- data/lib/einvoice/ezpay/client.rb +130 -0
- data/lib/einvoice/ezpay/crypto.rb +85 -0
- data/lib/einvoice/ezpay/errors.rb +72 -0
- data/lib/einvoice/ezpay/payload.rb +269 -0
- data/lib/einvoice/ezpay/provider.rb +253 -0
- data/lib/einvoice/ezpay.rb +19 -0
- data/lib/einvoice/input.rb +547 -0
- data/lib/einvoice/mock_provider.rb +191 -0
- data/lib/einvoice/mof/donation_codes.rb +157 -0
- data/lib/einvoice/mof.rb +16 -0
- data/lib/einvoice/number.rb +91 -0
- data/lib/einvoice/provider.rb +57 -13
- data/lib/einvoice/redaction.rb +54 -0
- data/lib/einvoice/taipei.rb +89 -0
- data/lib/einvoice/tax_split.rb +112 -0
- data/lib/einvoice/tradevan/default_api/client.rb +175 -0
- data/lib/einvoice/tradevan/default_api/crypto.rb +90 -0
- data/lib/einvoice/tradevan/default_api/errors.rb +54 -0
- data/lib/einvoice/tradevan/default_api/payload.rb +259 -0
- data/lib/einvoice/tradevan/default_api/provider.rb +353 -0
- data/lib/einvoice/tradevan/default_api/rules.rb +314 -0
- data/lib/einvoice/tradevan.rb +25 -0
- data/lib/einvoice/types.rb +365 -0
- data/lib/einvoice/version.rb +3 -1
- data/lib/einvoice.rb +21 -9
- metadata +52 -144
- data/docs/Tradevan E-Invoice APIs.md +0 -201
- data/docs/neweb.md +0 -347
- data/lib/einvoice/client.rb +0 -21
- data/lib/einvoice/configuration.rb +0 -49
- data/lib/einvoice/connection.rb +0 -31
- data/lib/einvoice/donation_unit_list.json +0 -2025
- data/lib/einvoice/result.rb +0 -21
- data/lib/einvoice/tradevan/model/base.rb +0 -34
- data/lib/einvoice/tradevan/model/issue_data.rb +0 -129
- data/lib/einvoice/tradevan/model/issue_item.rb +0 -41
- data/lib/einvoice/tradevan/model/void_data.rb +0 -35
- data/lib/einvoice/tradevan/provider.rb +0 -139
- data/lib/einvoice/tradevan/result.rb +0 -25
- data/lib/einvoice/tradevan/validator/issue_data_validator.rb +0 -80
- data/lib/faraday/response/decode_tradevan.rb +0 -37
- data/lib/faraday/response/parse_xml.rb +0 -14
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Einvoice
|
|
4
|
+
# Provider-agnostic domain model for Taiwan e-invoices (財政部 MIG 4.0).
|
|
5
|
+
#
|
|
6
|
+
# Every adapter maps these unified types to/from its own wire format; business
|
|
7
|
+
# code depends ONLY on these so switching providers never touches application
|
|
8
|
+
# logic. All value objects are immutable ({Data}) — use +#with+ to derive a
|
|
9
|
+
# changed copy, and pattern-match via +deconstruct_keys+.
|
|
10
|
+
#
|
|
11
|
+
# Money convention: the statutory amount fields are integers in New Taiwan
|
|
12
|
+
# Dollars (a MIG invariant — even cross-border invoices are filed in TWD). For
|
|
13
|
+
# a foreign-currency sale, set +currency+ (ISO 4217) + +exchange_rate+ to
|
|
14
|
+
# annotate the original transaction; the amount fields stay TWD.
|
|
15
|
+
|
|
16
|
+
# 課稅別 — maps to MIG TaxType.
|
|
17
|
+
module TaxType
|
|
18
|
+
TAXABLE = :taxable # 應稅 (5% business tax)
|
|
19
|
+
ZERO_RATED = :zero_rated # 零稅率 (exports etc.)
|
|
20
|
+
TAX_FREE = :tax_free # 免稅
|
|
21
|
+
SPECIAL = :special # 特種稅額
|
|
22
|
+
ALL = [TAXABLE, ZERO_RATED, TAX_FREE, SPECIAL].freeze
|
|
23
|
+
# Not a MIG tax type, and an issue input does not take it. It describes an
|
|
24
|
+
# existing invoice whose items have different tax types, on a reference or
|
|
25
|
+
# an allowance. Each allowance item then has to carry its own tax_type.
|
|
26
|
+
MIXED = :mixed
|
|
27
|
+
# Taxes that add tax to a line. ZERO_RATED and TAX_FREE lines have tax 0.
|
|
28
|
+
TAXED = [TAXABLE, SPECIAL].freeze
|
|
29
|
+
|
|
30
|
+
module_function
|
|
31
|
+
|
|
32
|
+
# The tax type of each item, in item order. An item without a tax_type
|
|
33
|
+
# has the invoice's. This is the only place that applies that rule.
|
|
34
|
+
def per_item(items, invoice_tax_type)
|
|
35
|
+
items.map { |item| item.tax_type || invoice_tax_type }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# The tax type of a whole invoice: the one its items share, else MIXED.
|
|
39
|
+
def of(items, invoice_tax_type)
|
|
40
|
+
kinds = per_item(items, invoice_tax_type).uniq
|
|
41
|
+
kinds.size > 1 ? MIXED : kinds.first || invoice_tax_type
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# The items of an existing invoice, read back from a provider. An item that
|
|
45
|
+
# the provider sent without a tax type has the invoice's, unless the
|
|
46
|
+
# invoice is MIXED: then each item has to say its own.
|
|
47
|
+
def fill_items(items, invoice_tax_type)
|
|
48
|
+
return items if invoice_tax_type.nil? || invoice_tax_type == MIXED
|
|
49
|
+
|
|
50
|
+
items.map { |item| item.tax_type ? item : item.with(tax_type: invoice_tax_type) }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Invoice category. Derived from whether the buyer has a 統一編號:
|
|
55
|
+
# B2B = triplicate (三聯式), B2C = duplicate (二聯式).
|
|
56
|
+
module InvoiceCategory
|
|
57
|
+
B2B = :b2b
|
|
58
|
+
B2C = :b2c
|
|
59
|
+
ALL = [B2B, B2C].freeze
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Whether item/line amounts already include the 5% business tax.
|
|
63
|
+
module PriceMode
|
|
64
|
+
TAX_INCLUSIVE = :tax_inclusive
|
|
65
|
+
TAX_EXCLUSIVE = :tax_exclusive
|
|
66
|
+
ALL = [TAX_INCLUSIVE, TAX_EXCLUSIVE].freeze
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# 載具類別.
|
|
70
|
+
module CarrierType
|
|
71
|
+
MOBILE_BARCODE = :mobile_barcode # 手機條碼 — /ABC1234 (MIG 3J0002)
|
|
72
|
+
CITIZEN_CERTIFICATE = :citizen_certificate # 自然人憑證條碼 — 16 chars (MIG CQ0001)
|
|
73
|
+
MEMBER = :member # 會員/通用載具 issued by the center
|
|
74
|
+
ALL = [MOBILE_BARCODE, CITIZEN_CERTIFICATE, MEMBER].freeze
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Lifecycle status of an invoice as reported by a provider.
|
|
78
|
+
module InvoiceStatus
|
|
79
|
+
ISSUED = :issued
|
|
80
|
+
VOIDED = :voided
|
|
81
|
+
ALLOWANCE = :allowance # has at least one active allowance (折讓)
|
|
82
|
+
ALL = [ISSUED, VOIDED, ALLOWANCE].freeze
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
module ProviderMode
|
|
86
|
+
TEST = :test
|
|
87
|
+
PRODUCTION = :production
|
|
88
|
+
ALL = [TEST, PRODUCTION].freeze
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# 買受人. A ubn (統一編號, 8 digits) implies a B2B / triplicate invoice.
|
|
92
|
+
Buyer = Data.define(:name, :ubn, :email, :address, :phone) do
|
|
93
|
+
def initialize(name: nil, ubn: nil, email: nil, address: nil, phone: nil)
|
|
94
|
+
super
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Presence of a 統一編號 implies a business (B2B) buyer.
|
|
98
|
+
def business?
|
|
99
|
+
!(ubn.nil? || ubn.to_s.empty?)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Name, email, address and phone are personal data, so inspect, to_s and pp
|
|
103
|
+
# show them as [FILTERED], here and inside every input or result. The ubn is
|
|
104
|
+
# a company's public number and stays. Read the fields directly when needed.
|
|
105
|
+
def inspect
|
|
106
|
+
fields = to_h.map do |key, value|
|
|
107
|
+
"#{key}=#{key == :ubn || value.nil? ? value.inspect : Redaction::FILTERED}"
|
|
108
|
+
end
|
|
109
|
+
"#<data #{self.class.name} #{fields.join(', ')}>"
|
|
110
|
+
end
|
|
111
|
+
alias_method :to_s, :inspect
|
|
112
|
+
|
|
113
|
+
def pretty_print(printer)
|
|
114
|
+
printer.text(inspect)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# 載具. +code+ shape depends on +type+ (mobile barcode "/"+7, citizen cert 16
|
|
119
|
+
# chars, member often omitted — provider links by email/member id).
|
|
120
|
+
Carrier = Data.define(:type, :code) do
|
|
121
|
+
def initialize(type:, code: nil)
|
|
122
|
+
super
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# 捐贈 — donating the invoice to a charity by 愛心碼.
|
|
127
|
+
Donation = Data.define(:npoban)
|
|
128
|
+
|
|
129
|
+
# 愛心碼 are 3–7 digits (MIG 捐贈碼). The single definition of that shape:
|
|
130
|
+
# {Input} enforces it on the way in, and both the adapters and
|
|
131
|
+
# {MOF::DonationCodes} refer to it rather than restating the pattern.
|
|
132
|
+
#
|
|
133
|
+
# F0401 NPOBAN also takes the recipient's 統一編號 [mig 表 15-3]. A recipient
|
|
134
|
+
# is always a 受捐贈機關或團體 that has registered on the MOF platform
|
|
135
|
+
# (電子發票實施作業要點第 2 點), not any company. At the time of sale the
|
|
136
|
+
# buyer gives a 愛心碼 (第 22 點), so the core takes that form only. ECPay and
|
|
137
|
+
# ezPay take 3 to 7 digits only too.
|
|
138
|
+
#
|
|
139
|
+
# Assigned here rather than inside a +Data.define+ block, where a constant
|
|
140
|
+
# would land in +Einvoice+ instead of on this class — the block is evaluated
|
|
141
|
+
# with the enclosing lexical scope, so +Donation::CODE_FORMAT+ would not exist.
|
|
142
|
+
Donation::CODE_FORMAT = /\A\d{3,7}\z/
|
|
143
|
+
|
|
144
|
+
# A single invoice line. +tax_type+ is required only on mixed-tax invoices.
|
|
145
|
+
# +unit_price+ and +amount+ include tax or not as the input's +price_mode+
|
|
146
|
+
# says. The core never changes them: the tax of each line is in the input's
|
|
147
|
+
# #tax_breakdown.
|
|
148
|
+
InvoiceItem = Data.define(:description, :quantity, :unit_price, :amount, :unit, :tax_type, :remark) do
|
|
149
|
+
def initialize(description:, quantity:, unit_price:, amount:, unit: nil, tax_type: nil, remark: nil)
|
|
150
|
+
super
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# Monetary summary for the whole invoice (integer TWD).
|
|
155
|
+
# total_amount = sales_amount + tax_amount.
|
|
156
|
+
AmountSummary = Data.define(:sales_amount, :tax_amount, :total_amount)
|
|
157
|
+
|
|
158
|
+
# --- Issue (開立) ---
|
|
159
|
+
|
|
160
|
+
# +customs_clearance_mark+ (+"1"+ or +"2"+) and +zero_tax_rate_reason+
|
|
161
|
+
# (+"71"+ to +"79"+) are the MIG's CustomsClearanceMark and
|
|
162
|
+
# ZeroTaxRateReason, for an invoice with a zero-rated line.
|
|
163
|
+
IssueInvoiceInput = Data.define(
|
|
164
|
+
:order_id, :buyer, :items, :amount, :tax_type, :price_mode, :tax_rate, :category,
|
|
165
|
+
:carrier, :donation, :remark, :currency, :exchange_rate, :customs_clearance_mark,
|
|
166
|
+
:zero_tax_rate_reason, :provider_options
|
|
167
|
+
) do
|
|
168
|
+
def initialize(order_id:, buyer:, items:, tax_type:, price_mode:, amount: nil, tax_rate: nil,
|
|
169
|
+
category: nil, carrier: nil, donation: nil, remark: nil, currency: nil,
|
|
170
|
+
exchange_rate: nil, customs_clearance_mark: nil, zero_tax_rate_reason: nil,
|
|
171
|
+
provider_options: nil)
|
|
172
|
+
super
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# The tax type of each item, in item order. See TaxType.per_item.
|
|
176
|
+
def item_tax_types
|
|
177
|
+
TaxType.per_item(items, tax_type)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# The tax type of the whole invoice: the one its items share, else MIXED.
|
|
181
|
+
def resolved_tax_type
|
|
182
|
+
TaxType.of(items, tax_type)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# True when a line is zero rated, by its own tax type or the invoice's.
|
|
186
|
+
def zero_rated?
|
|
187
|
+
item_tax_types.include?(TaxType::ZERO_RATED)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Explicit +category+, else derived from the buyer's 統一編號.
|
|
191
|
+
def resolved_category
|
|
192
|
+
category || (buyer&.business? ? InvoiceCategory::B2B : InvoiceCategory::B2C)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# The tax of every line and the MIG totals, computed by the core. See
|
|
196
|
+
# {TaxBreakdown}.
|
|
197
|
+
def tax_breakdown
|
|
198
|
+
TaxSplit.breakdown(items, types: item_tax_types, tax_rate: tax_rate, price_mode: price_mode)
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# --- References ---
|
|
203
|
+
|
|
204
|
+
# The facts about an existing invoice that providers ask for when they void,
|
|
205
|
+
# credit or query it. Results of issue and query return one as #reference, so
|
|
206
|
+
# a caller passes it on and does not have to know what each provider needs.
|
|
207
|
+
# Every field is optional. An adapter that needs a missing field may query the
|
|
208
|
+
# provider for it, or raises ValidationError naming the field.
|
|
209
|
+
#
|
|
210
|
+
# +invoice_datetime+ is a Time in UTC+8. +buyer_ubn+ is nil for a consumer.
|
|
211
|
+
# +tax_type+ and +tax_rate+ are the invoice's, so an allowance can take them
|
|
212
|
+
# from here. +tax_type+ is MIXED when the items differ.
|
|
213
|
+
#
|
|
214
|
+
# A reference is stored between calls, often for days. #to_h is that stored
|
|
215
|
+
# form: JSON-safe values only, with +invoice_datetime+ as an ISO 8601 string in
|
|
216
|
+
# UTC+8. Pass the Hash back as +invoice:+, as it is or after a JSON round
|
|
217
|
+
# trip, and Input reads the same reference.
|
|
218
|
+
InvoiceReference = Data.define(:number, :invoice_datetime, :random_code, :order_id, :total_amount,
|
|
219
|
+
:buyer_ubn, :tax_type, :tax_rate) do
|
|
220
|
+
def initialize(number: nil, invoice_datetime: nil, random_code: nil, order_id: nil,
|
|
221
|
+
total_amount: nil, buyer_ubn: nil, tax_type: nil, tax_rate: nil)
|
|
222
|
+
super
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def to_h
|
|
226
|
+
super.merge(invoice_datetime: invoice_datetime && Taipei.iso8601(invoice_datetime),
|
|
227
|
+
tax_type: tax_type&.to_s, tax_rate: tax_rate && Number.plain(tax_rate.to_r)).compact
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# The facts about an existing allowance. +allowance_date+ is a Date. #to_h is
|
|
232
|
+
# the stored form, as for InvoiceReference, with the date as YYYY-MM-DD.
|
|
233
|
+
AllowanceReference = Data.define(:allowance_number, :allowance_date, :invoice_number) do
|
|
234
|
+
def initialize(allowance_number:, allowance_date: nil, invoice_number: nil)
|
|
235
|
+
super
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def to_h
|
|
239
|
+
super.merge(allowance_date: allowance_date&.strftime("%Y-%m-%d")).compact
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
# --- Issue results ---
|
|
244
|
+
|
|
245
|
+
# +invoice_datetime+ is a Time in UTC+8 (MIG InvoiceDate and InvoiceTime).
|
|
246
|
+
# +buyer_ubn+ is nil for a consumer. +tax_type+ is TaxType.of the input, so
|
|
247
|
+
# MIXED for a mixed-tax invoice, and +tax_rate+ is the input's rate.
|
|
248
|
+
IssueInvoiceResult = Data.define(
|
|
249
|
+
:invoice_number, :invoice_datetime, :random_code, :order_id, :total_amount, :buyer_ubn, :tax_type,
|
|
250
|
+
:tax_rate, :status, :raw
|
|
251
|
+
) do
|
|
252
|
+
include Redaction::Raw
|
|
253
|
+
|
|
254
|
+
def reference
|
|
255
|
+
InvoiceReference.new(number: invoice_number, invoice_datetime: invoice_datetime,
|
|
256
|
+
random_code: random_code, order_id: order_id,
|
|
257
|
+
total_amount: total_amount, buyer_ubn: buyer_ubn,
|
|
258
|
+
tax_type: tax_type, tax_rate: tax_rate)
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# --- Void (作廢) ---
|
|
263
|
+
|
|
264
|
+
# +invoice+ is an InvoiceReference (Input also takes a plain number).
|
|
265
|
+
VoidInvoiceInput = Data.define(:invoice, :reason, :provider_options) do
|
|
266
|
+
def initialize(invoice:, reason:, provider_options: nil)
|
|
267
|
+
super
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# +cancel_datetime+ is a Time in UTC+8 (MIG CancelDate and CancelTime), or nil
|
|
272
|
+
# when the provider does not return it.
|
|
273
|
+
VoidInvoiceResult = Data.define(:invoice_number, :status, :cancel_datetime, :raw) do
|
|
274
|
+
include Redaction::Raw
|
|
275
|
+
|
|
276
|
+
def initialize(invoice_number:, status:, raw:, cancel_datetime: nil)
|
|
277
|
+
super
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# --- Allowance (折讓) and its cancellation (折讓作廢) ---
|
|
282
|
+
|
|
283
|
+
# +price_mode+ says if the item amounts include tax. +tax_type+ and
|
|
284
|
+
# +tax_rate+ come from the input, else from the invoice reference. With a
|
|
285
|
+
# MIXED tax type, every item carries its own tax_type.
|
|
286
|
+
#
|
|
287
|
+
# +amount+ follows G0401: +sales_amount+ excludes tax. Input checks it
|
|
288
|
+
# against #tax_breakdown, which holds the tax of each line.
|
|
289
|
+
AllowanceInput = Data.define(:invoice, :allowance_id, :items, :amount, :price_mode, :tax_type, :tax_rate,
|
|
290
|
+
:provider_options) do
|
|
291
|
+
def initialize(invoice:, allowance_id:, items:, price_mode:, tax_type:, tax_rate:, amount: nil,
|
|
292
|
+
provider_options: nil)
|
|
293
|
+
super
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
# See IssueInvoiceInput#item_tax_types.
|
|
297
|
+
def item_tax_types
|
|
298
|
+
TaxType.per_item(items, tax_type)
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
# See IssueInvoiceInput#resolved_tax_type.
|
|
302
|
+
def resolved_tax_type
|
|
303
|
+
TaxType.of(items, tax_type)
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# See IssueInvoiceInput#tax_breakdown.
|
|
307
|
+
def tax_breakdown
|
|
308
|
+
TaxSplit.breakdown(items, types: item_tax_types, tax_rate: tax_rate, price_mode: price_mode)
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
# +allowance_date+ is a Date (MIG AllowanceDate has no time).
|
|
313
|
+
AllowanceResult = Data.define(:allowance_number, :invoice_number, :allowance_date, :total_amount, :raw) do
|
|
314
|
+
include Redaction::Raw
|
|
315
|
+
|
|
316
|
+
def reference
|
|
317
|
+
AllowanceReference.new(allowance_number: allowance_number, allowance_date: allowance_date,
|
|
318
|
+
invoice_number: invoice_number)
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# +allowance+ is an AllowanceReference (Input also takes a plain number).
|
|
323
|
+
VoidAllowanceInput = Data.define(:allowance, :reason, :provider_options) do
|
|
324
|
+
def initialize(allowance:, reason: nil, provider_options: nil)
|
|
325
|
+
super
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
VoidAllowanceResult = Data.define(:allowance_number, :cancel_datetime, :raw) do
|
|
330
|
+
include Redaction::Raw
|
|
331
|
+
|
|
332
|
+
def initialize(allowance_number:, raw:, cancel_datetime: nil)
|
|
333
|
+
super
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
# --- Query (查詢) ---
|
|
338
|
+
|
|
339
|
+
# +invoice+ is an InvoiceReference with a number or an order id. A reference
|
|
340
|
+
# with only an order id (and what the provider needs with it) finds an invoice
|
|
341
|
+
# without its number. That needs QUERY_BY_ORDER_ID.
|
|
342
|
+
QueryInvoiceInput = Data.define(:invoice, :provider_options) do
|
|
343
|
+
def initialize(invoice:, provider_options: nil)
|
|
344
|
+
super
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
# +status+ is nil when the provider's status has no InvoiceStatus, for
|
|
349
|
+
# example a cancelled (註銷) invoice.
|
|
350
|
+
#
|
|
351
|
+
# +tax_type+ and +tax_rate+ are nil when the provider does not say.
|
|
352
|
+
QueryInvoiceResult = Data.define(
|
|
353
|
+
:invoice_number, :invoice_datetime, :random_code, :order_id, :status, :amount, :buyer, :items, :tax_type,
|
|
354
|
+
:tax_rate, :raw
|
|
355
|
+
) do
|
|
356
|
+
include Redaction::Raw
|
|
357
|
+
|
|
358
|
+
def reference
|
|
359
|
+
InvoiceReference.new(number: invoice_number, invoice_datetime: invoice_datetime,
|
|
360
|
+
random_code: random_code, order_id: order_id,
|
|
361
|
+
total_amount: amount&.total_amount, buyer_ubn: buyer&.ubn,
|
|
362
|
+
tax_type: tax_type, tax_rate: tax_rate)
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
end
|
data/lib/einvoice/version.rb
CHANGED
data/lib/einvoice.rb
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "einvoice/client"
|
|
4
|
-
require "einvoice/configuration"
|
|
5
|
-
require "einvoice/connection"
|
|
6
|
-
require "einvoice/provider"
|
|
7
|
-
require "einvoice/result"
|
|
8
3
|
require "einvoice/version"
|
|
4
|
+
require "einvoice/error"
|
|
5
|
+
require "einvoice/redaction"
|
|
6
|
+
require "einvoice/taipei"
|
|
7
|
+
require "einvoice/number"
|
|
8
|
+
require "einvoice/tax_split"
|
|
9
|
+
require "einvoice/capability"
|
|
10
|
+
require "einvoice/types"
|
|
11
|
+
require "einvoice/input"
|
|
12
|
+
require "einvoice/provider"
|
|
13
|
+
require "einvoice/mock_provider"
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
# Provider-agnostic Taiwan e-invoice SDK (財政部 MIG 4.1).
|
|
16
|
+
#
|
|
17
|
+
# The core models the five operations once: issue (開立), void (作廢),
|
|
18
|
+
# allowance (折讓), void-allowance (折讓作廢) and query (查詢). It has a unified
|
|
19
|
+
# value model and an {Einvoice::Provider} contract. Each value-added center is a
|
|
20
|
+
# thin adapter that maps the unified model to its wire format and back.
|
|
21
|
+
#
|
|
22
|
+
# This file loads the core only. The adapters and the MOF clients load on
|
|
23
|
+
# demand, so an app loads only what it uses: require "einvoice/ecpay",
|
|
24
|
+
# "einvoice/amego", "einvoice/ezpay", "einvoice/tradevan" or "einvoice/mof".
|
|
12
25
|
module Einvoice
|
|
13
|
-
extend Configuration
|
|
14
26
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: einvoice
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0.beta1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Yun
|
|
@@ -9,76 +9,6 @@ bindir: exe
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
-
- !ruby/object:Gem::Dependency
|
|
13
|
-
name: faraday
|
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
|
15
|
-
requirements:
|
|
16
|
-
- - "~>"
|
|
17
|
-
- !ruby/object:Gem::Version
|
|
18
|
-
version: '2.1'
|
|
19
|
-
type: :runtime
|
|
20
|
-
prerelease: false
|
|
21
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
-
requirements:
|
|
23
|
-
- - "~>"
|
|
24
|
-
- !ruby/object:Gem::Version
|
|
25
|
-
version: '2.1'
|
|
26
|
-
- !ruby/object:Gem::Dependency
|
|
27
|
-
name: multi_xml
|
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
|
29
|
-
requirements:
|
|
30
|
-
- - ">="
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0'
|
|
33
|
-
type: :runtime
|
|
34
|
-
prerelease: false
|
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
-
requirements:
|
|
37
|
-
- - ">="
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: '0'
|
|
40
|
-
- !ruby/object:Gem::Dependency
|
|
41
|
-
name: activemodel
|
|
42
|
-
requirement: !ruby/object:Gem::Requirement
|
|
43
|
-
requirements:
|
|
44
|
-
- - ">="
|
|
45
|
-
- !ruby/object:Gem::Version
|
|
46
|
-
version: '0'
|
|
47
|
-
type: :runtime
|
|
48
|
-
prerelease: false
|
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
-
requirements:
|
|
51
|
-
- - ">="
|
|
52
|
-
- !ruby/object:Gem::Version
|
|
53
|
-
version: '0'
|
|
54
|
-
- !ruby/object:Gem::Dependency
|
|
55
|
-
name: activesupport
|
|
56
|
-
requirement: !ruby/object:Gem::Requirement
|
|
57
|
-
requirements:
|
|
58
|
-
- - ">="
|
|
59
|
-
- !ruby/object:Gem::Version
|
|
60
|
-
version: '0'
|
|
61
|
-
type: :runtime
|
|
62
|
-
prerelease: false
|
|
63
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
-
requirements:
|
|
65
|
-
- - ">="
|
|
66
|
-
- !ruby/object:Gem::Version
|
|
67
|
-
version: '0'
|
|
68
|
-
- !ruby/object:Gem::Dependency
|
|
69
|
-
name: bundler
|
|
70
|
-
requirement: !ruby/object:Gem::Requirement
|
|
71
|
-
requirements:
|
|
72
|
-
- - ">"
|
|
73
|
-
- !ruby/object:Gem::Version
|
|
74
|
-
version: '1.17'
|
|
75
|
-
type: :development
|
|
76
|
-
prerelease: false
|
|
77
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
-
requirements:
|
|
79
|
-
- - ">"
|
|
80
|
-
- !ruby/object:Gem::Version
|
|
81
|
-
version: '1.17'
|
|
82
12
|
- !ruby/object:Gem::Dependency
|
|
83
13
|
name: rake
|
|
84
14
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -93,90 +23,48 @@ dependencies:
|
|
|
93
23
|
- - "~>"
|
|
94
24
|
- !ruby/object:Gem::Version
|
|
95
25
|
version: '13.0'
|
|
96
|
-
- !ruby/object:Gem::Dependency
|
|
97
|
-
name: pry
|
|
98
|
-
requirement: !ruby/object:Gem::Requirement
|
|
99
|
-
requirements:
|
|
100
|
-
- - ">="
|
|
101
|
-
- !ruby/object:Gem::Version
|
|
102
|
-
version: '0'
|
|
103
|
-
type: :development
|
|
104
|
-
prerelease: false
|
|
105
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
-
requirements:
|
|
107
|
-
- - ">="
|
|
108
|
-
- !ruby/object:Gem::Version
|
|
109
|
-
version: '0'
|
|
110
26
|
- !ruby/object:Gem::Dependency
|
|
111
27
|
name: rspec
|
|
112
28
|
requirement: !ruby/object:Gem::Requirement
|
|
113
29
|
requirements:
|
|
114
|
-
- - "
|
|
115
|
-
- !ruby/object:Gem::Version
|
|
116
|
-
version: '0'
|
|
117
|
-
type: :development
|
|
118
|
-
prerelease: false
|
|
119
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
-
requirements:
|
|
121
|
-
- - ">="
|
|
122
|
-
- !ruby/object:Gem::Version
|
|
123
|
-
version: '0'
|
|
124
|
-
- !ruby/object:Gem::Dependency
|
|
125
|
-
name: factory_bot
|
|
126
|
-
requirement: !ruby/object:Gem::Requirement
|
|
127
|
-
requirements:
|
|
128
|
-
- - ">="
|
|
129
|
-
- !ruby/object:Gem::Version
|
|
130
|
-
version: '0'
|
|
131
|
-
type: :development
|
|
132
|
-
prerelease: false
|
|
133
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
134
|
-
requirements:
|
|
135
|
-
- - ">="
|
|
136
|
-
- !ruby/object:Gem::Version
|
|
137
|
-
version: '0'
|
|
138
|
-
- !ruby/object:Gem::Dependency
|
|
139
|
-
name: shoulda-matchers
|
|
140
|
-
requirement: !ruby/object:Gem::Requirement
|
|
141
|
-
requirements:
|
|
142
|
-
- - ">="
|
|
30
|
+
- - "~>"
|
|
143
31
|
- !ruby/object:Gem::Version
|
|
144
|
-
version: '
|
|
32
|
+
version: '3.13'
|
|
145
33
|
type: :development
|
|
146
34
|
prerelease: false
|
|
147
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
148
36
|
requirements:
|
|
149
|
-
- - "
|
|
37
|
+
- - "~>"
|
|
150
38
|
- !ruby/object:Gem::Version
|
|
151
|
-
version: '
|
|
39
|
+
version: '3.13'
|
|
152
40
|
- !ruby/object:Gem::Dependency
|
|
153
41
|
name: vcr
|
|
154
42
|
requirement: !ruby/object:Gem::Requirement
|
|
155
43
|
requirements:
|
|
156
|
-
- - "
|
|
44
|
+
- - "~>"
|
|
157
45
|
- !ruby/object:Gem::Version
|
|
158
|
-
version: '
|
|
46
|
+
version: '6.3'
|
|
159
47
|
type: :development
|
|
160
48
|
prerelease: false
|
|
161
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
162
50
|
requirements:
|
|
163
|
-
- - "
|
|
51
|
+
- - "~>"
|
|
164
52
|
- !ruby/object:Gem::Version
|
|
165
|
-
version: '
|
|
53
|
+
version: '6.3'
|
|
166
54
|
- !ruby/object:Gem::Dependency
|
|
167
55
|
name: webmock
|
|
168
56
|
requirement: !ruby/object:Gem::Requirement
|
|
169
57
|
requirements:
|
|
170
|
-
- - "
|
|
58
|
+
- - "~>"
|
|
171
59
|
- !ruby/object:Gem::Version
|
|
172
|
-
version: '
|
|
60
|
+
version: '3.23'
|
|
173
61
|
type: :development
|
|
174
62
|
prerelease: false
|
|
175
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
176
64
|
requirements:
|
|
177
|
-
- - "
|
|
65
|
+
- - "~>"
|
|
178
66
|
- !ruby/object:Gem::Version
|
|
179
|
-
version: '
|
|
67
|
+
version: '3.23'
|
|
180
68
|
email:
|
|
181
69
|
- abookyun@gmail.com
|
|
182
70
|
executables: []
|
|
@@ -192,35 +80,55 @@ files:
|
|
|
192
80
|
- Gemfile
|
|
193
81
|
- LICENSE.txt
|
|
194
82
|
- README.md
|
|
83
|
+
- README.zh-TW.md
|
|
195
84
|
- Rakefile
|
|
196
85
|
- bin/console
|
|
197
86
|
- bin/setup
|
|
198
|
-
- docs/Tradevan E-Invoice APIs.md
|
|
199
|
-
- docs/neweb.md
|
|
200
87
|
- einvoice.gemspec
|
|
201
88
|
- lib/einvoice.rb
|
|
202
|
-
- lib/einvoice/
|
|
203
|
-
- lib/einvoice/
|
|
204
|
-
- lib/einvoice/
|
|
205
|
-
- lib/einvoice/
|
|
89
|
+
- lib/einvoice/amego.rb
|
|
90
|
+
- lib/einvoice/amego/client.rb
|
|
91
|
+
- lib/einvoice/amego/errors.rb
|
|
92
|
+
- lib/einvoice/amego/payload.rb
|
|
93
|
+
- lib/einvoice/amego/provider.rb
|
|
94
|
+
- lib/einvoice/capability.rb
|
|
95
|
+
- lib/einvoice/ecpay.rb
|
|
96
|
+
- lib/einvoice/ecpay/client.rb
|
|
97
|
+
- lib/einvoice/ecpay/crypto.rb
|
|
98
|
+
- lib/einvoice/ecpay/errors.rb
|
|
99
|
+
- lib/einvoice/ecpay/payload.rb
|
|
100
|
+
- lib/einvoice/ecpay/provider.rb
|
|
101
|
+
- lib/einvoice/error.rb
|
|
102
|
+
- lib/einvoice/ezpay.rb
|
|
103
|
+
- lib/einvoice/ezpay/client.rb
|
|
104
|
+
- lib/einvoice/ezpay/crypto.rb
|
|
105
|
+
- lib/einvoice/ezpay/errors.rb
|
|
106
|
+
- lib/einvoice/ezpay/payload.rb
|
|
107
|
+
- lib/einvoice/ezpay/provider.rb
|
|
108
|
+
- lib/einvoice/input.rb
|
|
109
|
+
- lib/einvoice/mock_provider.rb
|
|
110
|
+
- lib/einvoice/mof.rb
|
|
111
|
+
- lib/einvoice/mof/donation_codes.rb
|
|
112
|
+
- lib/einvoice/number.rb
|
|
206
113
|
- lib/einvoice/provider.rb
|
|
207
|
-
- lib/einvoice/
|
|
208
|
-
- lib/einvoice/
|
|
209
|
-
- lib/einvoice/
|
|
210
|
-
- lib/einvoice/tradevan
|
|
211
|
-
- lib/einvoice/tradevan/
|
|
212
|
-
- lib/einvoice/tradevan/
|
|
213
|
-
- lib/einvoice/tradevan/
|
|
214
|
-
- lib/einvoice/tradevan/
|
|
114
|
+
- lib/einvoice/redaction.rb
|
|
115
|
+
- lib/einvoice/taipei.rb
|
|
116
|
+
- lib/einvoice/tax_split.rb
|
|
117
|
+
- lib/einvoice/tradevan.rb
|
|
118
|
+
- lib/einvoice/tradevan/default_api/client.rb
|
|
119
|
+
- lib/einvoice/tradevan/default_api/crypto.rb
|
|
120
|
+
- lib/einvoice/tradevan/default_api/errors.rb
|
|
121
|
+
- lib/einvoice/tradevan/default_api/payload.rb
|
|
122
|
+
- lib/einvoice/tradevan/default_api/provider.rb
|
|
123
|
+
- lib/einvoice/tradevan/default_api/rules.rb
|
|
124
|
+
- lib/einvoice/types.rb
|
|
215
125
|
- lib/einvoice/version.rb
|
|
216
|
-
- lib/faraday/response/decode_tradevan.rb
|
|
217
|
-
- lib/faraday/response/parse_xml.rb
|
|
218
126
|
homepage: https://github.com/abookyun/einvoice
|
|
219
127
|
licenses:
|
|
220
128
|
- MIT
|
|
221
129
|
metadata:
|
|
222
130
|
source_code_uri: https://github.com/abookyun/einvoice
|
|
223
|
-
changelog_uri: https://github.com/abookyun/einvoice/blob/
|
|
131
|
+
changelog_uri: https://github.com/abookyun/einvoice/blob/v2.0.0.beta1/CHANGELOG.md
|
|
224
132
|
bug_tracker_uri: https://github.com/abookyun/einvoice/issues
|
|
225
133
|
rubygems_mfa_required: 'true'
|
|
226
134
|
rdoc_options: []
|
|
@@ -230,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
230
138
|
requirements:
|
|
231
139
|
- - ">="
|
|
232
140
|
- !ruby/object:Gem::Version
|
|
233
|
-
version: '3.
|
|
141
|
+
version: '3.3'
|
|
234
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
143
|
requirements:
|
|
236
144
|
- - ">="
|
|
@@ -239,5 +147,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
239
147
|
requirements: []
|
|
240
148
|
rubygems_version: 4.0.20
|
|
241
149
|
specification_version: 4
|
|
242
|
-
summary:
|
|
150
|
+
summary: Provider-agnostic Taiwan e-invoice SDK (unified model + per-provider adapters).
|
|
243
151
|
test_files: []
|