cetustek 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +71 -0
- data/README.md +102 -19
- data/lib/cetustek/cancel_allowance.rb +17 -39
- data/lib/cetustek/cancel_invoice.rb +38 -41
- data/lib/cetustek/configuration.rb +2 -1
- data/lib/cetustek/create_allowance.rb +24 -61
- data/lib/cetustek/create_invoice.rb +7 -21
- data/lib/cetustek/errors.rb +24 -0
- data/lib/cetustek/models/allowance_data.rb +47 -4
- data/lib/cetustek/models/invoice_data.rb +181 -10
- data/lib/cetustek/queries.rb +7 -18
- data/lib/cetustek/query_invoice_by_order_id.rb +6 -13
- data/lib/cetustek/services/invoice_xml_builder.rb +38 -61
- data/lib/cetustek/services/response_handler.rb +75 -13
- data/lib/cetustek/soap.rb +29 -0
- data/lib/cetustek/version.rb +1 -1
- data/lib/cetustek/xml.rb +43 -0
- data/lib/cetustek.rb +2 -0
- metadata +7 -6
- data/lib/cetustek/services/invoice_service.rb +0 -49
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'savon'
|
|
4
|
+
|
|
5
|
+
module Cetustek
|
|
6
|
+
# Shared SOAP plumbing: every operation hits the same WSDL and authenticates
|
|
7
|
+
# with 網站代碼+APIPassword (source) and the 租賃者統編 (rentid).
|
|
8
|
+
module Soap
|
|
9
|
+
def soap_client
|
|
10
|
+
Savon.client(wsdl: Cetustek.config.url, open_timeout: 300, read_timeout: 300)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def source
|
|
14
|
+
Cetustek.config.site_id + Cetustek.config.password
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def rentid
|
|
18
|
+
Cetustek.config.username
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def soap_call(operation, message)
|
|
22
|
+
soap_client.call(operation, message: message.merge(source: source, rentid: rentid))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def soap_return(response, operation)
|
|
26
|
+
response.body[:"#{operation}_response"][:return]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/cetustek/version.rb
CHANGED
data/lib/cetustek/xml.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'ox'
|
|
4
|
+
require 'cgi'
|
|
5
|
+
|
|
6
|
+
module Cetustek
|
|
7
|
+
# Every request document in the spec is the same shape: a UTF-8 declaration
|
|
8
|
+
# and a single <Invoice>/<Allowance> root carrying XSDVersion.
|
|
9
|
+
module Xml
|
|
10
|
+
XSD_VERSION = '2.8'
|
|
11
|
+
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
def document(root_name)
|
|
15
|
+
doc = Ox::Document.new
|
|
16
|
+
instruct = Ox::Instruct.new(:xml)
|
|
17
|
+
instruct[:version] = '1.0'
|
|
18
|
+
instruct[:encoding] = 'UTF-8'
|
|
19
|
+
doc << instruct
|
|
20
|
+
|
|
21
|
+
root = Ox::Element.new(root_name)
|
|
22
|
+
root[:XSDVersion] = XSD_VERSION
|
|
23
|
+
doc << root
|
|
24
|
+
yield root
|
|
25
|
+
|
|
26
|
+
Ox.dump(doc).force_encoding('UTF-8')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Values are HTML-escaped so that special characters (&, <, >, ", ') in any
|
|
30
|
+
# dynamic field cannot break the XML or be used for injection.
|
|
31
|
+
def tag(name, value)
|
|
32
|
+
Ox::Raw.new("<#{name}>#{CGI.escapeHTML(value.to_s)}</#{name}>")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Fields whose 備註 says "若未填,預設 X" are left out entirely when nil, so
|
|
36
|
+
# the platform applies its own default instead of parsing an empty value.
|
|
37
|
+
def append(element, name, value, skip_nil: false)
|
|
38
|
+
return if skip_nil && value.nil?
|
|
39
|
+
|
|
40
|
+
element << tag(name, value)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/cetustek.rb
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
require_relative "cetustek/version"
|
|
4
4
|
require_relative "cetustek/errors"
|
|
5
5
|
require_relative "cetustek/configuration"
|
|
6
|
+
require_relative "cetustek/xml"
|
|
7
|
+
require_relative "cetustek/soap"
|
|
6
8
|
require_relative "cetustek/models/allowance_data"
|
|
7
9
|
require_relative "cetustek/create_invoice"
|
|
8
10
|
require_relative "cetustek/cancel_invoice"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cetustek
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Zac
|
|
@@ -65,9 +65,9 @@ dependencies:
|
|
|
65
65
|
- - "~>"
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '3.12'
|
|
68
|
-
description: Cetustek is a Ruby
|
|
69
|
-
|
|
70
|
-
SOAP Web Services.
|
|
68
|
+
description: 'Cetustek is a Ruby wrapper for the 鯨躍 Cetustek e-invoice API (虛擬多通路,
|
|
69
|
+
spec AVM-26-03): issuing and cancelling 電子發票 and 折讓單, the read-only queries, and
|
|
70
|
+
手機條碼 validation, over SOAP Web Services.'
|
|
71
71
|
email:
|
|
72
72
|
- 579103+7a6163@users.noreply.github.com
|
|
73
73
|
executables: []
|
|
@@ -90,10 +90,11 @@ files:
|
|
|
90
90
|
- lib/cetustek/phone_barcode.rb
|
|
91
91
|
- lib/cetustek/queries.rb
|
|
92
92
|
- lib/cetustek/query_invoice_by_order_id.rb
|
|
93
|
-
- lib/cetustek/services/invoice_service.rb
|
|
94
93
|
- lib/cetustek/services/invoice_xml_builder.rb
|
|
95
94
|
- lib/cetustek/services/response_handler.rb
|
|
95
|
+
- lib/cetustek/soap.rb
|
|
96
96
|
- lib/cetustek/version.rb
|
|
97
|
+
- lib/cetustek/xml.rb
|
|
97
98
|
- sig/cetustek.rbs
|
|
98
99
|
homepage: https://github.com/7a6163/cetustek
|
|
99
100
|
licenses:
|
|
@@ -118,5 +119,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
118
119
|
requirements: []
|
|
119
120
|
rubygems_version: 4.0.16
|
|
120
121
|
specification_version: 4
|
|
121
|
-
summary: A Ruby
|
|
122
|
+
summary: A Ruby client for the Cetustek e-invoice API (電子發票加值中心)
|
|
122
123
|
test_files: []
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'savon'
|
|
4
|
-
require 'logger'
|
|
5
|
-
|
|
6
|
-
module Cetustek
|
|
7
|
-
module Services
|
|
8
|
-
class InvoiceService
|
|
9
|
-
def initialize(xml, order_id = nil, hastax = 1)
|
|
10
|
-
@xml = xml
|
|
11
|
-
@order_id = order_id
|
|
12
|
-
@hastax = hastax
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def create
|
|
16
|
-
client = build_soap_client
|
|
17
|
-
response = call_create_invoice(client)
|
|
18
|
-
log_response(response)
|
|
19
|
-
response
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def build_soap_client
|
|
25
|
-
Savon.client(
|
|
26
|
-
wsdl: Cetustek.config.url,
|
|
27
|
-
open_timeout: 300,
|
|
28
|
-
read_timeout: 300
|
|
29
|
-
)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def call_create_invoice(client)
|
|
33
|
-
client.call(:create_invoice_v3, message: {
|
|
34
|
-
invoicexml: @xml,
|
|
35
|
-
source: Cetustek.config.site_id + Cetustek.config.password,
|
|
36
|
-
rentid: Cetustek.config.username,
|
|
37
|
-
hastax: @hastax
|
|
38
|
-
})
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def log_response(response)
|
|
42
|
-
return unless defined?(Rails)
|
|
43
|
-
|
|
44
|
-
logger = Logger.new(Rails.root.join('log/invoice.log'))
|
|
45
|
-
logger.debug("#{@order_id} - #{response.body}") if @order_id
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|