cetustek 0.1.0__py3-none-any.whl
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.
- cetustek/__init__.py +19 -0
- cetustek/client.py +124 -0
- cetustek/models.py +57 -0
- cetustek/py.typed +0 -0
- cetustek-0.1.0.dist-info/METADATA +111 -0
- cetustek-0.1.0.dist-info/RECORD +8 -0
- cetustek-0.1.0.dist-info/WHEEL +4 -0
- cetustek-0.1.0.dist-info/licenses/LICENSE +21 -0
cetustek/__init__.py
ADDED
|
@@ -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"
|
cetustek/client.py
ADDED
|
@@ -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
|
+
"""
|
cetustek/models.py
ADDED
|
@@ -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
|
cetustek/py.typed
ADDED
|
File without changes
|
|
@@ -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
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
cetustek/__init__.py,sha256=IDmudJOsB1z-P6kdq3AXlAldzq5ycUrjiFViZmpZnYM,345
|
|
2
|
+
cetustek/client.py,sha256=dpY7SO4PudPe3O8hgHXvEk9iD5eExc260W2wrkeOxqw,3911
|
|
3
|
+
cetustek/models.py,sha256=Z0Pd9ujiF7fmkMMLHZgnxekvDZYdxE3IbxAiWjVrM3s,1565
|
|
4
|
+
cetustek/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
cetustek-0.1.0.dist-info/METADATA,sha256=5S3FSlwCAuxHiv493w1R7mJcm-ez8hdk5-fo8rG_VoU,2765
|
|
6
|
+
cetustek-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
7
|
+
cetustek-0.1.0.dist-info/licenses/LICENSE,sha256=3Zyxxlid2vbpfK2L93sfxat307kl3auQ32KXigeRGiE,1066
|
|
8
|
+
cetustek-0.1.0.dist-info/RECORD,,
|
|
@@ -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.
|