cetustek 0.1.0__tar.gz
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.
Potentially problematic release.
This version of cetustek might be problematic. Click here for more details.
- cetustek-0.1.0/.claude/settings.local.json +9 -0
- cetustek-0.1.0/.gitignore +212 -0
- cetustek-0.1.0/LICENSE +21 -0
- cetustek-0.1.0/PKG-INFO +111 -0
- cetustek-0.1.0/README.md +81 -0
- cetustek-0.1.0/pyproject.toml +50 -0
- cetustek-0.1.0/src/cetustek/__init__.py +19 -0
- cetustek-0.1.0/src/cetustek/client.py +124 -0
- cetustek-0.1.0/src/cetustek/models.py +57 -0
- cetustek-0.1.0/src/cetustek/py.typed +0 -0
- cetustek-0.1.0/tests/__init__.py +0 -0
- cetustek-0.1.0/tests/test_cetustek.py +191 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
110
|
+
.pdm.toml
|
|
111
|
+
|
|
112
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
113
|
+
__pypackages__/
|
|
114
|
+
|
|
115
|
+
# Celery stuff
|
|
116
|
+
celerybeat-schedule
|
|
117
|
+
celerybeat.pid
|
|
118
|
+
|
|
119
|
+
# SageMath parsed files
|
|
120
|
+
*.sage.py
|
|
121
|
+
|
|
122
|
+
# Environments
|
|
123
|
+
.env
|
|
124
|
+
.venv
|
|
125
|
+
env/
|
|
126
|
+
venv/
|
|
127
|
+
ENV/
|
|
128
|
+
env.bak/
|
|
129
|
+
venv.bak/
|
|
130
|
+
|
|
131
|
+
# Spyder project settings
|
|
132
|
+
.spyderproject
|
|
133
|
+
.spyproject
|
|
134
|
+
|
|
135
|
+
# Rope project settings
|
|
136
|
+
.ropeproject
|
|
137
|
+
|
|
138
|
+
# mkdocs documentation
|
|
139
|
+
/site
|
|
140
|
+
|
|
141
|
+
# mypy
|
|
142
|
+
.mypy_cache/
|
|
143
|
+
.dmypy.json
|
|
144
|
+
dmypy.json
|
|
145
|
+
|
|
146
|
+
# Pyre type checker
|
|
147
|
+
.pyre/
|
|
148
|
+
|
|
149
|
+
# pytype static type analyzer
|
|
150
|
+
.pytype/
|
|
151
|
+
|
|
152
|
+
# Cython debug symbols
|
|
153
|
+
cython_debug/
|
|
154
|
+
|
|
155
|
+
# PyCharm
|
|
156
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
157
|
+
# be added to the global gitignore or merged into this project gitignore. For a PyCharm
|
|
158
|
+
# project, it is recommended to include the following files:
|
|
159
|
+
# .idea/
|
|
160
|
+
# .idea_modules/
|
|
161
|
+
# *.iml
|
|
162
|
+
# *.ipr
|
|
163
|
+
# *.iws
|
|
164
|
+
|
|
165
|
+
# VS Code
|
|
166
|
+
.vscode/
|
|
167
|
+
*.code-workspace
|
|
168
|
+
|
|
169
|
+
# macOS
|
|
170
|
+
.DS_Store
|
|
171
|
+
.AppleDouble
|
|
172
|
+
.LSOverride
|
|
173
|
+
|
|
174
|
+
# Windows
|
|
175
|
+
Thumbs.db
|
|
176
|
+
ehthumbs.db
|
|
177
|
+
Desktop.ini
|
|
178
|
+
$RECYCLE.BIN/
|
|
179
|
+
|
|
180
|
+
# Linux
|
|
181
|
+
*~
|
|
182
|
+
|
|
183
|
+
# IDEs
|
|
184
|
+
.idea/
|
|
185
|
+
*.swp
|
|
186
|
+
*.swo
|
|
187
|
+
*~
|
|
188
|
+
|
|
189
|
+
# Database files
|
|
190
|
+
*.db
|
|
191
|
+
*.sqlite
|
|
192
|
+
*.sqlite3
|
|
193
|
+
|
|
194
|
+
# Log files
|
|
195
|
+
*.log
|
|
196
|
+
logs/
|
|
197
|
+
|
|
198
|
+
# Temporary files
|
|
199
|
+
*.tmp
|
|
200
|
+
*.temp
|
|
201
|
+
tmp/
|
|
202
|
+
temp/
|
|
203
|
+
|
|
204
|
+
# Environment variables
|
|
205
|
+
.env.local
|
|
206
|
+
.env.*.local
|
|
207
|
+
.env.development
|
|
208
|
+
.env.production
|
|
209
|
+
|
|
210
|
+
# Local configuration
|
|
211
|
+
config.local.py
|
|
212
|
+
settings.local.py
|
cetustek-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vince Lee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
cetustek-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cetustek
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Cetustek Taiwan e-invoice API
|
|
5
|
+
Project-URL: Homepage, https://github.com/vincelee888/cetustek
|
|
6
|
+
Project-URL: Repository, https://github.com/vincelee888/cetustek
|
|
7
|
+
Project-URL: Issues, https://github.com/vincelee888/cetustek/issues
|
|
8
|
+
Author: Vince Lee
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: cetustek,e-invoice,einvoice,invoice,taiwan
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Requires-Dist: requests>=2.25.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# Cetustek
|
|
32
|
+
|
|
33
|
+
Python SDK for Cetustek Taiwan e-invoice API.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install cetustek
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from cetustek import Cetustek, CreateInvoiceInput, InvoiceItem
|
|
45
|
+
|
|
46
|
+
# Initialize the client
|
|
47
|
+
client = Cetustek(
|
|
48
|
+
endpoint="https://invoice.cetustek.com.tw/InvoiceMultiWeb/InvoiceAPI",
|
|
49
|
+
rent_id="YOUR_RENT_ID",
|
|
50
|
+
site_code="YOUR_SITE_CODE",
|
|
51
|
+
api_password="YOUR_API_PASSWORD",
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# Create an invoice
|
|
55
|
+
invoice_input = CreateInvoiceInput(
|
|
56
|
+
order_id="12345678",
|
|
57
|
+
order_date="2026/01/15",
|
|
58
|
+
buyer_identifier="12345678",
|
|
59
|
+
buyer_name="Company Name",
|
|
60
|
+
buyer_email="email@example.com",
|
|
61
|
+
donate_mark="0",
|
|
62
|
+
invoice_type="07",
|
|
63
|
+
tax_type="1",
|
|
64
|
+
tax_rate=0.05,
|
|
65
|
+
pay_way="1",
|
|
66
|
+
items=[
|
|
67
|
+
InvoiceItem(
|
|
68
|
+
production_code="PROD001",
|
|
69
|
+
description="Product description",
|
|
70
|
+
quantity=1,
|
|
71
|
+
unit_price=1000,
|
|
72
|
+
unit="件",
|
|
73
|
+
)
|
|
74
|
+
],
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
result = client.createInvoice(invoice_input)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Query an Invoice
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from cetustek import QueryInvoiceInput
|
|
84
|
+
|
|
85
|
+
query_input = QueryInvoiceInput(
|
|
86
|
+
invoice_number="AA12345678",
|
|
87
|
+
invoice_year="2026",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
result = client.queryInvoice(query_input)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Cancel an Invoice
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from cetustek import CancelInvoiceInput
|
|
97
|
+
|
|
98
|
+
cancel_input = CancelInvoiceInput(
|
|
99
|
+
invoice_number="AA12345678",
|
|
100
|
+
invoice_year="2026",
|
|
101
|
+
remark="Cancellation reason",
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
result = client.cancelInvoice(cancel_input)
|
|
105
|
+
# Or use no_check=True to skip validation
|
|
106
|
+
result = client.cancelInvoice(cancel_input, no_check=True)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|
cetustek-0.1.0/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Cetustek
|
|
2
|
+
|
|
3
|
+
Python SDK for Cetustek Taiwan e-invoice API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install cetustek
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from cetustek import Cetustek, CreateInvoiceInput, InvoiceItem
|
|
15
|
+
|
|
16
|
+
# Initialize the client
|
|
17
|
+
client = Cetustek(
|
|
18
|
+
endpoint="https://invoice.cetustek.com.tw/InvoiceMultiWeb/InvoiceAPI",
|
|
19
|
+
rent_id="YOUR_RENT_ID",
|
|
20
|
+
site_code="YOUR_SITE_CODE",
|
|
21
|
+
api_password="YOUR_API_PASSWORD",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Create an invoice
|
|
25
|
+
invoice_input = CreateInvoiceInput(
|
|
26
|
+
order_id="12345678",
|
|
27
|
+
order_date="2026/01/15",
|
|
28
|
+
buyer_identifier="12345678",
|
|
29
|
+
buyer_name="Company Name",
|
|
30
|
+
buyer_email="email@example.com",
|
|
31
|
+
donate_mark="0",
|
|
32
|
+
invoice_type="07",
|
|
33
|
+
tax_type="1",
|
|
34
|
+
tax_rate=0.05,
|
|
35
|
+
pay_way="1",
|
|
36
|
+
items=[
|
|
37
|
+
InvoiceItem(
|
|
38
|
+
production_code="PROD001",
|
|
39
|
+
description="Product description",
|
|
40
|
+
quantity=1,
|
|
41
|
+
unit_price=1000,
|
|
42
|
+
unit="件",
|
|
43
|
+
)
|
|
44
|
+
],
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
result = client.createInvoice(invoice_input)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Query an Invoice
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from cetustek import QueryInvoiceInput
|
|
54
|
+
|
|
55
|
+
query_input = QueryInvoiceInput(
|
|
56
|
+
invoice_number="AA12345678",
|
|
57
|
+
invoice_year="2026",
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
result = client.queryInvoice(query_input)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Cancel an Invoice
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from cetustek import CancelInvoiceInput
|
|
67
|
+
|
|
68
|
+
cancel_input = CancelInvoiceInput(
|
|
69
|
+
invoice_number="AA12345678",
|
|
70
|
+
invoice_year="2026",
|
|
71
|
+
remark="Cancellation reason",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
result = client.cancelInvoice(cancel_input)
|
|
75
|
+
# Or use no_check=True to skip validation
|
|
76
|
+
result = client.cancelInvoice(cancel_input, no_check=True)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "cetustek"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python SDK for Cetustek Taiwan e-invoice API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Vince Lee" }
|
|
13
|
+
]
|
|
14
|
+
keywords = ["taiwan", "invoice", "e-invoice", "cetustek", "einvoice"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Topic :: Office/Business :: Financial",
|
|
27
|
+
"Typing :: Typed",
|
|
28
|
+
]
|
|
29
|
+
requires-python = ">=3.9"
|
|
30
|
+
dependencies = [
|
|
31
|
+
"requests>=2.25.0",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = [
|
|
36
|
+
"pytest>=7.0.0",
|
|
37
|
+
"pytest-cov>=4.0.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/vincelee888/cetustek"
|
|
42
|
+
Repository = "https://github.com/vincelee888/cetustek"
|
|
43
|
+
Issues = "https://github.com/vincelee888/cetustek/issues"
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.wheel]
|
|
46
|
+
packages = ["src/cetustek"]
|
|
47
|
+
|
|
48
|
+
[tool.pytest.ini_options]
|
|
49
|
+
testpaths = ["tests"]
|
|
50
|
+
pythonpath = ["src"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Cetustek Taiwan e-invoice SDK."""
|
|
2
|
+
|
|
3
|
+
from cetustek.client import Cetustek
|
|
4
|
+
from cetustek.models import (
|
|
5
|
+
CancelInvoiceInput,
|
|
6
|
+
CreateInvoiceInput,
|
|
7
|
+
InvoiceItem,
|
|
8
|
+
QueryInvoiceInput,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"Cetustek",
|
|
13
|
+
"CreateInvoiceInput",
|
|
14
|
+
"CancelInvoiceInput",
|
|
15
|
+
"QueryInvoiceInput",
|
|
16
|
+
"InvoiceItem",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from xml.sax.saxutils import escape
|
|
3
|
+
|
|
4
|
+
from cetustek.models import (
|
|
5
|
+
CreateInvoiceInput,
|
|
6
|
+
CancelInvoiceInput,
|
|
7
|
+
QueryInvoiceInput,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Cetustek:
|
|
12
|
+
def __init__(self, *, endpoint: str, rent_id: str, api_password: str, site_code: str):
|
|
13
|
+
self.endpoint = endpoint
|
|
14
|
+
self.rent_id = rent_id
|
|
15
|
+
self.source = f"{site_code}{api_password}"
|
|
16
|
+
|
|
17
|
+
# -------------------------
|
|
18
|
+
# API methods
|
|
19
|
+
# -------------------------
|
|
20
|
+
|
|
21
|
+
def createInvoice(self, data: CreateInvoiceInput) -> str:
|
|
22
|
+
items_xml = ""
|
|
23
|
+
for item in data.items:
|
|
24
|
+
items_xml += f"""
|
|
25
|
+
<ProductItem>
|
|
26
|
+
<ProductionCode>{escape(item.production_code)}</ProductionCode>
|
|
27
|
+
<Description>{escape(item.description)}</Description>
|
|
28
|
+
<Quantity>{item.quantity}</Quantity>
|
|
29
|
+
{f"<Unit>{escape(item.unit)}</Unit>" if item.unit else ""}
|
|
30
|
+
<UnitPrice>{item.unit_price}</UnitPrice>
|
|
31
|
+
</ProductItem>
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
invoice_xml = f"""
|
|
35
|
+
<Invoice XSDVersion="2.8">
|
|
36
|
+
<OrderId>{escape(data.order_id)}</OrderId>
|
|
37
|
+
<OrderDate>{data.order_date}</OrderDate>
|
|
38
|
+
<BuyerIdentifier>{data.buyer_identifier or ""}</BuyerIdentifier>
|
|
39
|
+
<BuyerName>{escape(data.buyer_name or "")}</BuyerName>
|
|
40
|
+
<BuyerAddress>{escape(data.buyer_address or "")}</BuyerAddress>
|
|
41
|
+
<BuyerEmailAddress>{escape(data.buyer_email or "")}</BuyerEmailAddress>
|
|
42
|
+
<DonateMark>{data.donate_mark}</DonateMark>
|
|
43
|
+
<InvoiceType>{data.invoice_type}</InvoiceType>
|
|
44
|
+
<CarrierType>{data.carrier_type or ""}</CarrierType>
|
|
45
|
+
<CarrierId1>{data.carrier_id1 or ""}</CarrierId1>
|
|
46
|
+
<CarrierId2>{data.carrier_id2 or ""}</CarrierId2>
|
|
47
|
+
<NPOBAN>{data.npoban or ""}</NPOBAN>
|
|
48
|
+
<PayWay>{data.pay_way}</PayWay>
|
|
49
|
+
<TaxType>{data.tax_type}</TaxType>
|
|
50
|
+
<TaxRate>{data.tax_rate}</TaxRate>
|
|
51
|
+
<Remark>{escape(data.remark or "")}</Remark>
|
|
52
|
+
<Details>
|
|
53
|
+
{items_xml}
|
|
54
|
+
</Details>
|
|
55
|
+
</Invoice>
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
inner = f"""
|
|
59
|
+
<invoicexml><![CDATA[{invoice_xml}]]></invoicexml>
|
|
60
|
+
<rentid>{self.rent_id}</rentid>
|
|
61
|
+
<source>{self.source}</source>
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
return self._post_soap(self._wrap_soap("CreateInvoiceV3", inner))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def cancelInvoice(self, data: CancelInvoiceInput, no_check: bool = False) -> str:
|
|
68
|
+
invoice_xml = f"""
|
|
69
|
+
<Invoice XSDVersion="2.8">
|
|
70
|
+
<InvoiceNumber>{data.invoice_number}</InvoiceNumber>
|
|
71
|
+
<InvoiceYear>{data.invoice_year}</InvoiceYear>
|
|
72
|
+
<ReturnTaxDocumentNumber>{data.return_tax_document_number or ""}</ReturnTaxDocumentNumber>
|
|
73
|
+
<Remark>{escape(data.remark)}</Remark>
|
|
74
|
+
</Invoice>
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
inner = f"""
|
|
78
|
+
<invoicexml><![CDATA[{invoice_xml}]]></invoicexml>
|
|
79
|
+
<rentid>{self.rent_id}</rentid>
|
|
80
|
+
<source>{self.source}</source>
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
action = "CancelInvoiceNoCheck" if no_check else "CancelInvoice"
|
|
84
|
+
|
|
85
|
+
return self._post_soap(self._wrap_soap(action, inner))
|
|
86
|
+
|
|
87
|
+
def queryInvoice(self, data: QueryInvoiceInput) -> str:
|
|
88
|
+
"""
|
|
89
|
+
Query invoice by invoice number and year.
|
|
90
|
+
Returns XML string with invoice details.
|
|
91
|
+
"""
|
|
92
|
+
inner = f"""
|
|
93
|
+
<invoicenumber>{data.invoice_number}</invoicenumber>
|
|
94
|
+
<invoiceyear>{data.invoice_year}</invoiceyear>
|
|
95
|
+
<rentid>{self.rent_id}</rentid>
|
|
96
|
+
<source>{self.source}</source>
|
|
97
|
+
"""
|
|
98
|
+
return self._post_soap(self._wrap_soap("QueryInvoice", inner))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# -------------------------
|
|
102
|
+
# Internal helpers
|
|
103
|
+
# -------------------------
|
|
104
|
+
def _post_soap(self, body: str) -> str:
|
|
105
|
+
headers = {
|
|
106
|
+
"Content-Type": "text/xml; charset=utf-8",
|
|
107
|
+
"Accept": "text/xml",
|
|
108
|
+
"User-Agent": "Cetustek-Python-SDK/1.0",
|
|
109
|
+
}
|
|
110
|
+
resp = requests.post(self.endpoint, data=body.encode("utf-8"), headers=headers)
|
|
111
|
+
resp.raise_for_status()
|
|
112
|
+
return resp.text
|
|
113
|
+
|
|
114
|
+
def _wrap_soap(self, action: str, inner_xml: str) -> str:
|
|
115
|
+
return f"""<?xml version="1.0" encoding="utf-8"?>
|
|
116
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
|
|
117
|
+
xmlns:tns="http://webservice.cetustek.com/">
|
|
118
|
+
<soap:Body>
|
|
119
|
+
<tns:{action}>
|
|
120
|
+
{inner_xml}
|
|
121
|
+
</tns:{action}>
|
|
122
|
+
</soap:Body>
|
|
123
|
+
</soap:Envelope>
|
|
124
|
+
"""
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Optional, List
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@dataclass
|
|
6
|
+
class InvoiceItem:
|
|
7
|
+
production_code: str # ProductionCode
|
|
8
|
+
description: str # Description
|
|
9
|
+
quantity: float # Quantity
|
|
10
|
+
unit_price: float # UnitPrice
|
|
11
|
+
unit: Optional[str] = None # Unit
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class CreateInvoiceInput:
|
|
16
|
+
order_id: str
|
|
17
|
+
order_date: str # yyyy/MM/dd
|
|
18
|
+
donate_mark: str # 0 / 1 / 2
|
|
19
|
+
invoice_type: str # 07 / 08
|
|
20
|
+
pay_way: str # Table 4
|
|
21
|
+
tax_type: str # 1 / 2 / 3 / 4 / 5 / 9
|
|
22
|
+
|
|
23
|
+
items: List[InvoiceItem]
|
|
24
|
+
|
|
25
|
+
# Optional buyer fields
|
|
26
|
+
buyer_identifier: Optional[str] = None
|
|
27
|
+
buyer_name: Optional[str] = None
|
|
28
|
+
buyer_address: Optional[str] = None
|
|
29
|
+
buyer_email: Optional[str] = None
|
|
30
|
+
buyer_person_in_charge: Optional[str] = None
|
|
31
|
+
buyer_tel: Optional[str] = None
|
|
32
|
+
buyer_fax: Optional[str] = None
|
|
33
|
+
buyer_customer_number: Optional[str] = None
|
|
34
|
+
|
|
35
|
+
# Carrier / donation
|
|
36
|
+
carrier_type: Optional[str] = None
|
|
37
|
+
carrier_id1: Optional[str] = None
|
|
38
|
+
carrier_id2: Optional[str] = None
|
|
39
|
+
npoban: Optional[str] = None
|
|
40
|
+
|
|
41
|
+
# Tax
|
|
42
|
+
tax_rate: Optional[float] = 0.05
|
|
43
|
+
remark: Optional[str] = None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class CancelInvoiceInput:
|
|
48
|
+
invoice_number: str # AA12345678
|
|
49
|
+
invoice_year: str # yyyy
|
|
50
|
+
remark: str # 作廢原因
|
|
51
|
+
return_tax_document_number: Optional[str] = None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass
|
|
55
|
+
class QueryInvoiceInput:
|
|
56
|
+
invoice_number: str
|
|
57
|
+
invoice_year: str
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pytest tests for the Cetustek SDK.
|
|
3
|
+
|
|
4
|
+
Run:
|
|
5
|
+
pip install -e ".[dev]"
|
|
6
|
+
pytest -q
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import html
|
|
12
|
+
import random
|
|
13
|
+
import re
|
|
14
|
+
import time
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
|
|
17
|
+
import pytest
|
|
18
|
+
|
|
19
|
+
from cetustek import (
|
|
20
|
+
Cetustek,
|
|
21
|
+
CreateInvoiceInput,
|
|
22
|
+
CancelInvoiceInput,
|
|
23
|
+
QueryInvoiceInput,
|
|
24
|
+
InvoiceItem,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.fixture()
|
|
29
|
+
def sdk() -> Cetustek:
|
|
30
|
+
return Cetustek(
|
|
31
|
+
endpoint="https://invoice.cetustek.com.tw/InvoiceMultiWeb/InvoiceAPI",
|
|
32
|
+
rent_id="89011917",
|
|
33
|
+
site_code="ball888",
|
|
34
|
+
api_password="CACBFF1E1",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
@pytest.fixture()
|
|
38
|
+
def create_invoice_input() -> CreateInvoiceInput:
|
|
39
|
+
# Generate random order ID
|
|
40
|
+
order_id = str(random.randint(10000000, 99999999))
|
|
41
|
+
|
|
42
|
+
# Get current date in yyyy/MM/dd format
|
|
43
|
+
order_date = datetime.fromtimestamp(time.time()).strftime("%Y/%m/%d")
|
|
44
|
+
|
|
45
|
+
return CreateInvoiceInput(
|
|
46
|
+
order_id=order_id,
|
|
47
|
+
order_date=order_date,
|
|
48
|
+
buyer_identifier="53118823",
|
|
49
|
+
buyer_name="鯨躍科技有限公司",
|
|
50
|
+
buyer_email="test@cetustek.com.tw",
|
|
51
|
+
donate_mark="0",
|
|
52
|
+
invoice_type="07",
|
|
53
|
+
tax_type="1",
|
|
54
|
+
tax_rate=0.05,
|
|
55
|
+
pay_way="1",
|
|
56
|
+
remark="",
|
|
57
|
+
items=[
|
|
58
|
+
InvoiceItem(
|
|
59
|
+
production_code="AA783456",
|
|
60
|
+
description="DESCAA7890123456",
|
|
61
|
+
quantity=1,
|
|
62
|
+
unit="月",
|
|
63
|
+
unit_price=50000,
|
|
64
|
+
)
|
|
65
|
+
],
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@pytest.fixture()
|
|
70
|
+
def created_invoice(sdk: Cetustek, create_invoice_input: CreateInvoiceInput) -> tuple[str, str]:
|
|
71
|
+
"""Create an invoice and return (invoice_number, invoice_year)."""
|
|
72
|
+
result = sdk.createInvoice(create_invoice_input)
|
|
73
|
+
|
|
74
|
+
# Extract return value from <return> tag
|
|
75
|
+
return_match = re.search(r"<return>(.*?)</return>", result)
|
|
76
|
+
assert return_match is not None, "Response should contain <return> tag"
|
|
77
|
+
|
|
78
|
+
return_value = return_match.group(1).strip()
|
|
79
|
+
assert ";" in return_value, f"Success response should contain ';' separator, got: {return_value}"
|
|
80
|
+
|
|
81
|
+
invoice_number, _ = return_value.split(";")
|
|
82
|
+
|
|
83
|
+
# Extract year from invoice number (format: WP20260002 -> year is 2026)
|
|
84
|
+
# Invoice number format: 2 letters + 4 digits (year) + 4 digits (sequence)
|
|
85
|
+
assert len(invoice_number) == 10, f"Invoice number should be 10 characters, got: {invoice_number}"
|
|
86
|
+
invoice_year = invoice_number[2:6] # Extract year from position 2-5 (e.g., "2026")
|
|
87
|
+
|
|
88
|
+
return invoice_number, invoice_year
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_create_invoice(sdk: Cetustek, create_invoice_input: CreateInvoiceInput):
|
|
92
|
+
"""Test createInvoice makes a real API call and returns success response."""
|
|
93
|
+
result = sdk.createInvoice(create_invoice_input)
|
|
94
|
+
|
|
95
|
+
# Verify response is not empty
|
|
96
|
+
assert result is not None
|
|
97
|
+
assert len(result) > 0
|
|
98
|
+
|
|
99
|
+
# Verify SOAP envelope structure
|
|
100
|
+
assert "<S:Envelope" in result or "<soap:Envelope" in result
|
|
101
|
+
assert "<S:Body>" in result or "<soap:Body>" in result
|
|
102
|
+
assert "CreateInvoiceV3Response" in result
|
|
103
|
+
|
|
104
|
+
# Extract return value from <return> tag
|
|
105
|
+
return_match = re.search(r"<return>(.*?)</return>", result)
|
|
106
|
+
assert return_match is not None, "Response should contain <return> tag"
|
|
107
|
+
|
|
108
|
+
return_value = return_match.group(1).strip()
|
|
109
|
+
assert len(return_value) > 0, "Return value should not be empty"
|
|
110
|
+
|
|
111
|
+
# Verify success format: "INVOICE_NUMBER;RANDOM_NUMBER" (e.g., "WP20260002;6827")
|
|
112
|
+
assert ";" in return_value, f"Success response should contain ';' separator, got: {return_value}"
|
|
113
|
+
parts = return_value.split(";")
|
|
114
|
+
assert len(parts) == 2, f"Return value should have format 'INVOICE;RANDOM', got: {return_value}"
|
|
115
|
+
|
|
116
|
+
invoice_number, random_number = parts
|
|
117
|
+
assert len(invoice_number) == 10, "Invoice number should be 10 characters"
|
|
118
|
+
assert len(random_number) == 4, "Random number should be 4 characters"
|
|
119
|
+
assert invoice_number[0:2].isalpha(), f"Invoice number should start with two alphabets, got: {invoice_number}"
|
|
120
|
+
assert invoice_number[2:10].isdigit(), f"Invoice number should be 8 digits, got: {invoice_number}"
|
|
121
|
+
|
|
122
|
+
def test_query_invoice(sdk: Cetustek, created_invoice: tuple[str, str]):
|
|
123
|
+
"""Test queryInvoice makes a real API call and returns invoice details."""
|
|
124
|
+
invoice_number, invoice_year = created_invoice
|
|
125
|
+
|
|
126
|
+
query_input = QueryInvoiceInput(
|
|
127
|
+
invoice_number=invoice_number,
|
|
128
|
+
invoice_year=invoice_year,
|
|
129
|
+
)
|
|
130
|
+
result = sdk.queryInvoice(query_input)
|
|
131
|
+
|
|
132
|
+
# Verify response is not empty
|
|
133
|
+
assert result is not None
|
|
134
|
+
assert len(result) > 0
|
|
135
|
+
|
|
136
|
+
# Verify SOAP envelope structure
|
|
137
|
+
assert "<S:Envelope" in result or "<soap:Envelope" in result
|
|
138
|
+
assert "<S:Body>" in result or "<soap:Body>" in result
|
|
139
|
+
assert "QueryInvoiceResponse" in result
|
|
140
|
+
|
|
141
|
+
# Extract return value from <return> tag
|
|
142
|
+
return_match = re.search(r"<return>(.*?)</return>", result, re.DOTALL)
|
|
143
|
+
assert return_match is not None, "Response should contain <return> tag"
|
|
144
|
+
|
|
145
|
+
return_xml_escaped = return_match.group(1).strip()
|
|
146
|
+
assert len(return_xml_escaped) > 0, "Return XML should not be empty"
|
|
147
|
+
|
|
148
|
+
# Unescape HTML entities (e.g., < becomes <, > becomes >, becomes carriage return)
|
|
149
|
+
return_xml = html.unescape(return_xml_escaped)
|
|
150
|
+
|
|
151
|
+
# Verify return contains XML invoice data
|
|
152
|
+
assert return_xml.startswith("<"), "Return value should be XML after unescaping"
|
|
153
|
+
assert "<Invoice" in return_xml or "<invoice" in return_xml, "Return should contain invoice data"
|
|
154
|
+
assert invoice_number in return_xml, f"Return should contain invoice number {invoice_number}"
|
|
155
|
+
|
|
156
|
+
# Verify key invoice fields are present
|
|
157
|
+
assert "<InvoiceNumber>" in return_xml or "<invoicenumber>" in return_xml, "Return should contain InvoiceNumber"
|
|
158
|
+
assert "<OrderID>" in return_xml or "<orderid>" in return_xml, "Return should contain OrderID"
|
|
159
|
+
assert "<RandomNumber>" in return_xml or "<randomnumber>" in return_xml, "Return should contain RandomNumber"
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def test_cancel_invoice(sdk: Cetustek, created_invoice: tuple[str, str]):
|
|
163
|
+
"""Test cancelInvoice makes a real API call and returns success response."""
|
|
164
|
+
invoice_number, invoice_year = created_invoice
|
|
165
|
+
|
|
166
|
+
cancel_input = CancelInvoiceInput(
|
|
167
|
+
invoice_number=invoice_number,
|
|
168
|
+
invoice_year=invoice_year,
|
|
169
|
+
remark="測試作廢",
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
result = sdk.cancelInvoice(cancel_input, no_check=True)
|
|
173
|
+
|
|
174
|
+
# Verify response is not empty
|
|
175
|
+
assert result is not None
|
|
176
|
+
assert len(result) > 0
|
|
177
|
+
|
|
178
|
+
# Verify SOAP envelope structure
|
|
179
|
+
assert "<S:Envelope" in result or "<soap:Envelope" in result
|
|
180
|
+
assert "<S:Body>" in result or "<soap:Body>" in result
|
|
181
|
+
assert "CancelInvoiceNoCheckResponse" in result
|
|
182
|
+
|
|
183
|
+
# Extract return value from <return> tag
|
|
184
|
+
return_match = re.search(r"<return>(.*?)</return>", result)
|
|
185
|
+
assert return_match is not None, "Response should contain <return> tag"
|
|
186
|
+
|
|
187
|
+
return_value = return_match.group(1).strip()
|
|
188
|
+
assert len(return_value) > 0, "Return value should not be empty"
|
|
189
|
+
|
|
190
|
+
# Verify success code format: "C0" for success
|
|
191
|
+
assert return_value == "C0", f"Success response should be 'C0', got: {return_value}"
|