slip2sure 2.0.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.
- slip2sure-2.0.0/LICENSE +7 -0
- slip2sure-2.0.0/MANIFEST.in +8 -0
- slip2sure-2.0.0/PKG-INFO +274 -0
- slip2sure-2.0.0/README.md +239 -0
- slip2sure-2.0.0/pyproject.toml +72 -0
- slip2sure-2.0.0/setup.cfg +4 -0
- slip2sure-2.0.0/slip2sure/__init__.py +17 -0
- slip2sure-2.0.0/slip2sure/_version.py +7 -0
- slip2sure-2.0.0/slip2sure/client.py +654 -0
- slip2sure-2.0.0/slip2sure/exception.py +139 -0
- slip2sure-2.0.0/slip2sure/model/__init__.py +6 -0
- slip2sure-2.0.0/slip2sure/model/application.py +42 -0
- slip2sure-2.0.0/slip2sure/model/bankslip.py +68 -0
- slip2sure-2.0.0/slip2sure/model/base.py +20 -0
- slip2sure-2.0.0/slip2sure/model/transaction.py +96 -0
- slip2sure-2.0.0/slip2sure/model/truemoney.py +35 -0
- slip2sure-2.0.0/slip2sure/model/user.py +13 -0
- slip2sure-2.0.0/slip2sure/py.typed +0 -0
- slip2sure-2.0.0/slip2sure.egg-info/PKG-INFO +274 -0
- slip2sure-2.0.0/slip2sure.egg-info/SOURCES.txt +24 -0
- slip2sure-2.0.0/slip2sure.egg-info/dependency_links.txt +1 -0
- slip2sure-2.0.0/slip2sure.egg-info/requires.txt +6 -0
- slip2sure-2.0.0/slip2sure.egg-info/top_level.txt +1 -0
- slip2sure-2.0.0/tests/__init__.py +0 -0
- slip2sure-2.0.0/tests/test_client.py +373 -0
- slip2sure-2.0.0/tests/test_endpoints.py +449 -0
slip2sure-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 Slip2Sure
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# The wheel installs only the slip2sure package; these extras go into the
|
|
2
|
+
# sdist so the source release is complete and the tests are runnable from it.
|
|
3
|
+
include pyproject.toml
|
|
4
|
+
include README.md
|
|
5
|
+
include LICENSE
|
|
6
|
+
recursive-include tests *.py
|
|
7
|
+
global-exclude __pycache__/*
|
|
8
|
+
global-exclude *.py[cod]
|
slip2sure-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: slip2sure
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: SDK for the Slip2Sure slip verification API (Thai bank slips and TrueMoney Wallet)
|
|
5
|
+
Author-email: Slip2Sure Team <dev@slip2sure.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://slip2sure.com
|
|
8
|
+
Project-URL: Repository, https://github.com/Slip2Sure/slip2sure-py
|
|
9
|
+
Project-URL: Issues, https://github.com/Slip2Sure/slip2sure-py/issues
|
|
10
|
+
Project-URL: Documentation, https://app.slip2sure.com/user/api/docs/bankslip
|
|
11
|
+
Keywords: slip2sure,slip,slipverify,slipverification,slip-verification,promptpay,truemoney,bank-slip,thailand,api,sdk
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
22
|
+
Classifier: Framework :: AsyncIO
|
|
23
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: pydantic<3,>=2.10.6
|
|
30
|
+
Requires-Dist: aiohttp<4,>=3.11.12
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
33
|
+
Requires-Dist: twine>=5.0; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# Slip2Sure Python
|
|
37
|
+
SDK for integrating with the [Slip2Sure](https://slip2sure.com) slip verification service. (Python)
|
|
38
|
+
|
|
39
|
+
For the full API documentation, see:
|
|
40
|
+
- [API Document (Truemoney)](https://app.slip2sure.com/user/api/docs/truemoney)
|
|
41
|
+
- [API Document (Bank slip)](https://app.slip2sure.com/user/api/docs/bankslip)
|
|
42
|
+
- [Error code](https://app.slip2sure.com/user/api/docs/errorcode)
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
```sh
|
|
46
|
+
pip install slip2sure
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Requires Python 3.10 or newer; tested on 3.10 through 3.14. Ships type
|
|
50
|
+
annotations (PEP 561), so type checkers pick them up with no stubs needed.
|
|
51
|
+
|
|
52
|
+
## Example
|
|
53
|
+
### Truemoney
|
|
54
|
+
```py
|
|
55
|
+
import asyncio
|
|
56
|
+
from slip2sure import Slip2SureAPI
|
|
57
|
+
|
|
58
|
+
async def main():
|
|
59
|
+
async with Slip2SureAPI("YOUR_API_KEY") as client:
|
|
60
|
+
# You can use Flask or FastAPI to receive the body
|
|
61
|
+
with open("FILE_PATH", "rb") as f:
|
|
62
|
+
result = await client.scanTruemoneySlip(f.read())
|
|
63
|
+
|
|
64
|
+
print(result.info.amount, result.info.paid_at)
|
|
65
|
+
|
|
66
|
+
asyncio.run(main())
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Bank Slip
|
|
70
|
+
```py
|
|
71
|
+
import asyncio
|
|
72
|
+
from slip2sure import Slip2SureAPI
|
|
73
|
+
|
|
74
|
+
async def main():
|
|
75
|
+
async with Slip2SureAPI("YOUR_API_KEY") as client:
|
|
76
|
+
result = await client.scanBankSlipByPayload("YOUR_QR_CODE")
|
|
77
|
+
print(result.info.amount, result.info.sender.displayName)
|
|
78
|
+
|
|
79
|
+
asyncio.run(main())
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The client holds one `aiohttp` session across calls, so keep a single instance
|
|
83
|
+
alive rather than building one per request. Use it as an async context manager,
|
|
84
|
+
or call `await client.close()` when you are done.
|
|
85
|
+
|
|
86
|
+
## Endpoints
|
|
87
|
+
|
|
88
|
+
Every method is available in camelCase, matching earlier releases, and in
|
|
89
|
+
snake_case for PEP 8 style. `scanTruemoneySlip` and `scan_truemoney_slip` are
|
|
90
|
+
the same function.
|
|
91
|
+
|
|
92
|
+
### Slip verification — needs the Application API Key
|
|
93
|
+
|
|
94
|
+
| Method | API |
|
|
95
|
+
| --- | --- |
|
|
96
|
+
| `scanTruemoneySlip(file)` | `POST /truemoney/v2/verify` |
|
|
97
|
+
| `scanTruemoneySlipV1(file)` | `POST /truemoney/v1/verify` (deprecated) |
|
|
98
|
+
| `scanBankSlipByPayload(payload)` | `POST /bank/v0/verifyByPayload` |
|
|
99
|
+
| `scanBankSlipByFile(file)` | `POST /bank/v0/verifyByFile` |
|
|
100
|
+
| `scanBankSlipByBase64(encoded)` | `POST /bank/v0/verifyByBase64` |
|
|
101
|
+
| `scanBankSlipByImage(file)` | same, base64 encoding the image for you |
|
|
102
|
+
| `getAllTransactions(...)` | `GET /transaction/getAllTransactions` |
|
|
103
|
+
|
|
104
|
+
### Account and management — needs the User API Token
|
|
105
|
+
|
|
106
|
+
| Method | API |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| `getUserCredit()` | `GET /user/credit` |
|
|
109
|
+
| `getApplications()` | `GET /management/application` |
|
|
110
|
+
| `getApplication(app_id)` | `GET /management/application/:id` |
|
|
111
|
+
| `createApplication(name, description, whitelist_ips)` | `POST /management/application` |
|
|
112
|
+
| `updateApplication(app_id, name, description, whitelist_ips)` | `PUT /management/application/:id` |
|
|
113
|
+
| `deleteApplication(app_id)` | `DELETE /management/application/:id` |
|
|
114
|
+
| `getApplicationApiKey(app_id)` | `GET /management/application/:id/api_key` |
|
|
115
|
+
| `rotateApplicationApiKey(app_id)` | `POST /management/application/:id/api_key/rotate` |
|
|
116
|
+
|
|
117
|
+
The two credentials are different things: the Application API Key verifies
|
|
118
|
+
slips, and the User API Token manages applications and reads your credit.
|
|
119
|
+
Configure both if you use both.
|
|
120
|
+
|
|
121
|
+
```py
|
|
122
|
+
client = Slip2SureAPI("YOUR_API_KEY", user_api_token="YOUR_USER_API_TOKEN")
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Bank slip from an image
|
|
126
|
+
|
|
127
|
+
```py
|
|
128
|
+
with open("FILE_PATH", "rb") as f:
|
|
129
|
+
result = await client.scanBankSlipByFile(f.read())
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Transaction history
|
|
133
|
+
|
|
134
|
+
```py
|
|
135
|
+
from slip2sure import SlipType, TransactionStatus
|
|
136
|
+
|
|
137
|
+
page = await client.getAllTransactions(
|
|
138
|
+
page=0,
|
|
139
|
+
size=50,
|
|
140
|
+
status=TransactionStatus.COMPLETED,
|
|
141
|
+
slip_type=SlipType.BANK_SLIP_VERIFY,
|
|
142
|
+
)
|
|
143
|
+
for item in page.items:
|
|
144
|
+
print(item.id, item.amount, item.status)
|
|
145
|
+
print("last page:", page.pagination.is_end_page)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The date filter is named `from_` because `from` is a Python keyword. Page 0 is
|
|
149
|
+
a real page, so passing `page=0` still sends the filter.
|
|
150
|
+
|
|
151
|
+
### Credit and applications
|
|
152
|
+
|
|
153
|
+
```py
|
|
154
|
+
credit = await client.getUserCredit()
|
|
155
|
+
print(credit.credit) # a float, parsed from the API's string
|
|
156
|
+
|
|
157
|
+
app = await client.createApplication(
|
|
158
|
+
"My store",
|
|
159
|
+
"",
|
|
160
|
+
["203.0.113.10"], # ["*"] allows every IP
|
|
161
|
+
)
|
|
162
|
+
# app.api_key is returned in full only here, so store it now.
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Configuration
|
|
166
|
+
|
|
167
|
+
```py
|
|
168
|
+
client = Slip2SureAPI(
|
|
169
|
+
"YOUR_API_KEY",
|
|
170
|
+
base_url="https://api.slip2sure.com/api/v0",
|
|
171
|
+
timeout=30.0, # seconds for the whole call, retries included; None disables
|
|
172
|
+
max_retries=2, # 0 disables
|
|
173
|
+
retry_backoff=0.5, # base delay for exponential backoff
|
|
174
|
+
session=None, # supply your own aiohttp.ClientSession
|
|
175
|
+
user_api_token="", # needed by the credit and management endpoints
|
|
176
|
+
)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
When you pass a `session`, you keep ownership of it: `close()` leaves it open
|
|
180
|
+
for you to manage.
|
|
181
|
+
|
|
182
|
+
### Retries
|
|
183
|
+
|
|
184
|
+
Transient failures are retried with exponential backoff and full jitter, and a
|
|
185
|
+
`Retry-After` response header is honoured when present.
|
|
186
|
+
|
|
187
|
+
Only `408`, `429`, `502`, `503` and `504` are retried, along with connection
|
|
188
|
+
errors and timeouts. `500` is deliberately **not** retried: verification costs
|
|
189
|
+
credit, and a request that failed after being processed could otherwise be
|
|
190
|
+
billed twice.
|
|
191
|
+
|
|
192
|
+
`createApplication` and `rotateApplicationApiKey` are never retried at all,
|
|
193
|
+
whatever the status: a retried gateway error could create a second application
|
|
194
|
+
or rotate the key twice and discard the key the first attempt returned.
|
|
195
|
+
|
|
196
|
+
## Error handling
|
|
197
|
+
|
|
198
|
+
Every failure is a `Slip2SureError` carrying `.code`, `.message` and
|
|
199
|
+
`.status_code`. Catch a subclass to handle one family of failures:
|
|
200
|
+
|
|
201
|
+
```py
|
|
202
|
+
from slip2sure import (
|
|
203
|
+
ErrorCode,
|
|
204
|
+
Slip2SureAuthError,
|
|
205
|
+
Slip2SureCreditError,
|
|
206
|
+
Slip2SureError,
|
|
207
|
+
Slip2SureNotFoundError,
|
|
208
|
+
Slip2SureServerError,
|
|
209
|
+
Slip2SureTransportError,
|
|
210
|
+
Slip2SureValidationError,
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
try:
|
|
214
|
+
result = await client.scanBankSlipByPayload("YOUR_QR_CODE")
|
|
215
|
+
except Slip2SureCreditError:
|
|
216
|
+
... # out of credit
|
|
217
|
+
except Slip2SureNotFoundError:
|
|
218
|
+
... # not a real slip
|
|
219
|
+
except Slip2SureError as exc:
|
|
220
|
+
print(exc.code, exc.message, exc.status_code)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
| Exception | Codes |
|
|
224
|
+
| --- | --- |
|
|
225
|
+
| `Slip2SureAuthError` | `INVALID_HEADER`, `UNAUTHORIZED`, `APPLICATION_LOCKED` |
|
|
226
|
+
| `Slip2SureValidationError` | `VALIDATE_ERROR`, `FILE_REQUIRED`, `FILE_TOO_LARGE`, `FILE_NOT_SUPPORTED` |
|
|
227
|
+
| `Slip2SureCreditError` | `CREDIT_INSUFFIENCT` |
|
|
228
|
+
| `Slip2SureNotFoundError` | `SLIP_NOT_EXIST` |
|
|
229
|
+
| `Slip2SureServerError` | `SERVER_ERROR`, `SERVICE_ERROR`, `SERVICE_TIMEOUT` |
|
|
230
|
+
| `Slip2SurePendingError` | `SLIP_BBL_PENDING` |
|
|
231
|
+
| `Slip2SureTransportError` | connection failures and timeouts |
|
|
232
|
+
|
|
233
|
+
`Slip2SureAuthError` also covers `IP_NOT_ALLOWED`, and `Slip2SureNotFoundError`
|
|
234
|
+
also covers `SLIP_QRCODE_NOT_EXIST` and `TRANSACTION_NOT_EXIST`; v1 defined
|
|
235
|
+
none of those four codes.
|
|
236
|
+
|
|
237
|
+
`Slip2SurePendingError` is worth handling on its own: Bangkok Bank returns
|
|
238
|
+
`SLIP_BBL_PENDING` for a few minutes after a transfer, and the same slip
|
|
239
|
+
succeeds on a later attempt.
|
|
240
|
+
|
|
241
|
+
A code this SDK predates still raises a plain `Slip2SureError` with `.code`
|
|
242
|
+
intact, rather than being flattened or raising a `KeyError`.
|
|
243
|
+
|
|
244
|
+
## Migrating from v1
|
|
245
|
+
|
|
246
|
+
- **v1 did not import on Python 3.10 or 3.11.** `client.py` used a nested
|
|
247
|
+
same-quote f-string, which is only valid from 3.12, while the package
|
|
248
|
+
declared `python_requires=">=3.10"`. This release works on 3.10 upward.
|
|
249
|
+
- **`scanBankSlipByPayload` no longer prints the response** to stdout.
|
|
250
|
+
- **Timestamps are `datetime`, not `str`.** `info.transDateTime` and
|
|
251
|
+
`info.paid_at` are parsed, matching the Go SDK.
|
|
252
|
+
- **Optional fields now default instead of being required.** A slip whose
|
|
253
|
+
account omitted `name` used to fail validation outright; `ref1`–`ref3`,
|
|
254
|
+
`paidLocalCurrency`, `countryCode` and `toMerchantId` are likewise optional.
|
|
255
|
+
- **`scanTruemoneySlip` now calls the v2 endpoint**, which also returns
|
|
256
|
+
`info.payload`, `info.account_from_name` and `info.account_to_name`. The v1
|
|
257
|
+
endpoint is still reachable as `scanTruemoneySlipV1`.
|
|
258
|
+
- **`Slip2SureBankSlip` and `Slip2SureTruemoney` inherit `Slip2SureBase`.**
|
|
259
|
+
`credit` and `is_exist` are unchanged.
|
|
260
|
+
- **Errors gained `.code`, `.message` and `.status_code`,** plus the subclasses
|
|
261
|
+
above. The old `.errorCode` and `.errorMessage` attributes still work.
|
|
262
|
+
- **An uploaded file's MIME type is now `image/jpeg`** rather than the invalid
|
|
263
|
+
`image/jpg`.
|
|
264
|
+
- **Dependencies are ranges, not exact pins,** so installing the SDK no longer
|
|
265
|
+
forces a specific `pydantic` or `aiohttp` on your project.
|
|
266
|
+
- **There is now a 30 second default timeout.** v1 had none.
|
|
267
|
+
|
|
268
|
+
## Tests
|
|
269
|
+
```sh
|
|
270
|
+
python -m unittest discover
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## LICENSE
|
|
274
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# Slip2Sure Python
|
|
2
|
+
SDK for integrating with the [Slip2Sure](https://slip2sure.com) slip verification service. (Python)
|
|
3
|
+
|
|
4
|
+
For the full API documentation, see:
|
|
5
|
+
- [API Document (Truemoney)](https://app.slip2sure.com/user/api/docs/truemoney)
|
|
6
|
+
- [API Document (Bank slip)](https://app.slip2sure.com/user/api/docs/bankslip)
|
|
7
|
+
- [Error code](https://app.slip2sure.com/user/api/docs/errorcode)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
```sh
|
|
11
|
+
pip install slip2sure
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Requires Python 3.10 or newer; tested on 3.10 through 3.14. Ships type
|
|
15
|
+
annotations (PEP 561), so type checkers pick them up with no stubs needed.
|
|
16
|
+
|
|
17
|
+
## Example
|
|
18
|
+
### Truemoney
|
|
19
|
+
```py
|
|
20
|
+
import asyncio
|
|
21
|
+
from slip2sure import Slip2SureAPI
|
|
22
|
+
|
|
23
|
+
async def main():
|
|
24
|
+
async with Slip2SureAPI("YOUR_API_KEY") as client:
|
|
25
|
+
# You can use Flask or FastAPI to receive the body
|
|
26
|
+
with open("FILE_PATH", "rb") as f:
|
|
27
|
+
result = await client.scanTruemoneySlip(f.read())
|
|
28
|
+
|
|
29
|
+
print(result.info.amount, result.info.paid_at)
|
|
30
|
+
|
|
31
|
+
asyncio.run(main())
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Bank Slip
|
|
35
|
+
```py
|
|
36
|
+
import asyncio
|
|
37
|
+
from slip2sure import Slip2SureAPI
|
|
38
|
+
|
|
39
|
+
async def main():
|
|
40
|
+
async with Slip2SureAPI("YOUR_API_KEY") as client:
|
|
41
|
+
result = await client.scanBankSlipByPayload("YOUR_QR_CODE")
|
|
42
|
+
print(result.info.amount, result.info.sender.displayName)
|
|
43
|
+
|
|
44
|
+
asyncio.run(main())
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The client holds one `aiohttp` session across calls, so keep a single instance
|
|
48
|
+
alive rather than building one per request. Use it as an async context manager,
|
|
49
|
+
or call `await client.close()` when you are done.
|
|
50
|
+
|
|
51
|
+
## Endpoints
|
|
52
|
+
|
|
53
|
+
Every method is available in camelCase, matching earlier releases, and in
|
|
54
|
+
snake_case for PEP 8 style. `scanTruemoneySlip` and `scan_truemoney_slip` are
|
|
55
|
+
the same function.
|
|
56
|
+
|
|
57
|
+
### Slip verification — needs the Application API Key
|
|
58
|
+
|
|
59
|
+
| Method | API |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `scanTruemoneySlip(file)` | `POST /truemoney/v2/verify` |
|
|
62
|
+
| `scanTruemoneySlipV1(file)` | `POST /truemoney/v1/verify` (deprecated) |
|
|
63
|
+
| `scanBankSlipByPayload(payload)` | `POST /bank/v0/verifyByPayload` |
|
|
64
|
+
| `scanBankSlipByFile(file)` | `POST /bank/v0/verifyByFile` |
|
|
65
|
+
| `scanBankSlipByBase64(encoded)` | `POST /bank/v0/verifyByBase64` |
|
|
66
|
+
| `scanBankSlipByImage(file)` | same, base64 encoding the image for you |
|
|
67
|
+
| `getAllTransactions(...)` | `GET /transaction/getAllTransactions` |
|
|
68
|
+
|
|
69
|
+
### Account and management — needs the User API Token
|
|
70
|
+
|
|
71
|
+
| Method | API |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `getUserCredit()` | `GET /user/credit` |
|
|
74
|
+
| `getApplications()` | `GET /management/application` |
|
|
75
|
+
| `getApplication(app_id)` | `GET /management/application/:id` |
|
|
76
|
+
| `createApplication(name, description, whitelist_ips)` | `POST /management/application` |
|
|
77
|
+
| `updateApplication(app_id, name, description, whitelist_ips)` | `PUT /management/application/:id` |
|
|
78
|
+
| `deleteApplication(app_id)` | `DELETE /management/application/:id` |
|
|
79
|
+
| `getApplicationApiKey(app_id)` | `GET /management/application/:id/api_key` |
|
|
80
|
+
| `rotateApplicationApiKey(app_id)` | `POST /management/application/:id/api_key/rotate` |
|
|
81
|
+
|
|
82
|
+
The two credentials are different things: the Application API Key verifies
|
|
83
|
+
slips, and the User API Token manages applications and reads your credit.
|
|
84
|
+
Configure both if you use both.
|
|
85
|
+
|
|
86
|
+
```py
|
|
87
|
+
client = Slip2SureAPI("YOUR_API_KEY", user_api_token="YOUR_USER_API_TOKEN")
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Bank slip from an image
|
|
91
|
+
|
|
92
|
+
```py
|
|
93
|
+
with open("FILE_PATH", "rb") as f:
|
|
94
|
+
result = await client.scanBankSlipByFile(f.read())
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Transaction history
|
|
98
|
+
|
|
99
|
+
```py
|
|
100
|
+
from slip2sure import SlipType, TransactionStatus
|
|
101
|
+
|
|
102
|
+
page = await client.getAllTransactions(
|
|
103
|
+
page=0,
|
|
104
|
+
size=50,
|
|
105
|
+
status=TransactionStatus.COMPLETED,
|
|
106
|
+
slip_type=SlipType.BANK_SLIP_VERIFY,
|
|
107
|
+
)
|
|
108
|
+
for item in page.items:
|
|
109
|
+
print(item.id, item.amount, item.status)
|
|
110
|
+
print("last page:", page.pagination.is_end_page)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The date filter is named `from_` because `from` is a Python keyword. Page 0 is
|
|
114
|
+
a real page, so passing `page=0` still sends the filter.
|
|
115
|
+
|
|
116
|
+
### Credit and applications
|
|
117
|
+
|
|
118
|
+
```py
|
|
119
|
+
credit = await client.getUserCredit()
|
|
120
|
+
print(credit.credit) # a float, parsed from the API's string
|
|
121
|
+
|
|
122
|
+
app = await client.createApplication(
|
|
123
|
+
"My store",
|
|
124
|
+
"",
|
|
125
|
+
["203.0.113.10"], # ["*"] allows every IP
|
|
126
|
+
)
|
|
127
|
+
# app.api_key is returned in full only here, so store it now.
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Configuration
|
|
131
|
+
|
|
132
|
+
```py
|
|
133
|
+
client = Slip2SureAPI(
|
|
134
|
+
"YOUR_API_KEY",
|
|
135
|
+
base_url="https://api.slip2sure.com/api/v0",
|
|
136
|
+
timeout=30.0, # seconds for the whole call, retries included; None disables
|
|
137
|
+
max_retries=2, # 0 disables
|
|
138
|
+
retry_backoff=0.5, # base delay for exponential backoff
|
|
139
|
+
session=None, # supply your own aiohttp.ClientSession
|
|
140
|
+
user_api_token="", # needed by the credit and management endpoints
|
|
141
|
+
)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
When you pass a `session`, you keep ownership of it: `close()` leaves it open
|
|
145
|
+
for you to manage.
|
|
146
|
+
|
|
147
|
+
### Retries
|
|
148
|
+
|
|
149
|
+
Transient failures are retried with exponential backoff and full jitter, and a
|
|
150
|
+
`Retry-After` response header is honoured when present.
|
|
151
|
+
|
|
152
|
+
Only `408`, `429`, `502`, `503` and `504` are retried, along with connection
|
|
153
|
+
errors and timeouts. `500` is deliberately **not** retried: verification costs
|
|
154
|
+
credit, and a request that failed after being processed could otherwise be
|
|
155
|
+
billed twice.
|
|
156
|
+
|
|
157
|
+
`createApplication` and `rotateApplicationApiKey` are never retried at all,
|
|
158
|
+
whatever the status: a retried gateway error could create a second application
|
|
159
|
+
or rotate the key twice and discard the key the first attempt returned.
|
|
160
|
+
|
|
161
|
+
## Error handling
|
|
162
|
+
|
|
163
|
+
Every failure is a `Slip2SureError` carrying `.code`, `.message` and
|
|
164
|
+
`.status_code`. Catch a subclass to handle one family of failures:
|
|
165
|
+
|
|
166
|
+
```py
|
|
167
|
+
from slip2sure import (
|
|
168
|
+
ErrorCode,
|
|
169
|
+
Slip2SureAuthError,
|
|
170
|
+
Slip2SureCreditError,
|
|
171
|
+
Slip2SureError,
|
|
172
|
+
Slip2SureNotFoundError,
|
|
173
|
+
Slip2SureServerError,
|
|
174
|
+
Slip2SureTransportError,
|
|
175
|
+
Slip2SureValidationError,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
try:
|
|
179
|
+
result = await client.scanBankSlipByPayload("YOUR_QR_CODE")
|
|
180
|
+
except Slip2SureCreditError:
|
|
181
|
+
... # out of credit
|
|
182
|
+
except Slip2SureNotFoundError:
|
|
183
|
+
... # not a real slip
|
|
184
|
+
except Slip2SureError as exc:
|
|
185
|
+
print(exc.code, exc.message, exc.status_code)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
| Exception | Codes |
|
|
189
|
+
| --- | --- |
|
|
190
|
+
| `Slip2SureAuthError` | `INVALID_HEADER`, `UNAUTHORIZED`, `APPLICATION_LOCKED` |
|
|
191
|
+
| `Slip2SureValidationError` | `VALIDATE_ERROR`, `FILE_REQUIRED`, `FILE_TOO_LARGE`, `FILE_NOT_SUPPORTED` |
|
|
192
|
+
| `Slip2SureCreditError` | `CREDIT_INSUFFIENCT` |
|
|
193
|
+
| `Slip2SureNotFoundError` | `SLIP_NOT_EXIST` |
|
|
194
|
+
| `Slip2SureServerError` | `SERVER_ERROR`, `SERVICE_ERROR`, `SERVICE_TIMEOUT` |
|
|
195
|
+
| `Slip2SurePendingError` | `SLIP_BBL_PENDING` |
|
|
196
|
+
| `Slip2SureTransportError` | connection failures and timeouts |
|
|
197
|
+
|
|
198
|
+
`Slip2SureAuthError` also covers `IP_NOT_ALLOWED`, and `Slip2SureNotFoundError`
|
|
199
|
+
also covers `SLIP_QRCODE_NOT_EXIST` and `TRANSACTION_NOT_EXIST`; v1 defined
|
|
200
|
+
none of those four codes.
|
|
201
|
+
|
|
202
|
+
`Slip2SurePendingError` is worth handling on its own: Bangkok Bank returns
|
|
203
|
+
`SLIP_BBL_PENDING` for a few minutes after a transfer, and the same slip
|
|
204
|
+
succeeds on a later attempt.
|
|
205
|
+
|
|
206
|
+
A code this SDK predates still raises a plain `Slip2SureError` with `.code`
|
|
207
|
+
intact, rather than being flattened or raising a `KeyError`.
|
|
208
|
+
|
|
209
|
+
## Migrating from v1
|
|
210
|
+
|
|
211
|
+
- **v1 did not import on Python 3.10 or 3.11.** `client.py` used a nested
|
|
212
|
+
same-quote f-string, which is only valid from 3.12, while the package
|
|
213
|
+
declared `python_requires=">=3.10"`. This release works on 3.10 upward.
|
|
214
|
+
- **`scanBankSlipByPayload` no longer prints the response** to stdout.
|
|
215
|
+
- **Timestamps are `datetime`, not `str`.** `info.transDateTime` and
|
|
216
|
+
`info.paid_at` are parsed, matching the Go SDK.
|
|
217
|
+
- **Optional fields now default instead of being required.** A slip whose
|
|
218
|
+
account omitted `name` used to fail validation outright; `ref1`–`ref3`,
|
|
219
|
+
`paidLocalCurrency`, `countryCode` and `toMerchantId` are likewise optional.
|
|
220
|
+
- **`scanTruemoneySlip` now calls the v2 endpoint**, which also returns
|
|
221
|
+
`info.payload`, `info.account_from_name` and `info.account_to_name`. The v1
|
|
222
|
+
endpoint is still reachable as `scanTruemoneySlipV1`.
|
|
223
|
+
- **`Slip2SureBankSlip` and `Slip2SureTruemoney` inherit `Slip2SureBase`.**
|
|
224
|
+
`credit` and `is_exist` are unchanged.
|
|
225
|
+
- **Errors gained `.code`, `.message` and `.status_code`,** plus the subclasses
|
|
226
|
+
above. The old `.errorCode` and `.errorMessage` attributes still work.
|
|
227
|
+
- **An uploaded file's MIME type is now `image/jpeg`** rather than the invalid
|
|
228
|
+
`image/jpg`.
|
|
229
|
+
- **Dependencies are ranges, not exact pins,** so installing the SDK no longer
|
|
230
|
+
forces a specific `pydantic` or `aiohttp` on your project.
|
|
231
|
+
- **There is now a 30 second default timeout.** v1 had none.
|
|
232
|
+
|
|
233
|
+
## Tests
|
|
234
|
+
```sh
|
|
235
|
+
python -m unittest discover
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## LICENSE
|
|
239
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "slip2sure"
|
|
7
|
+
# Read from slip2sure/_version.py so the version cannot drift from the
|
|
8
|
+
# package, which it previously did (package 1.1.0 vs metadata 1.3.5).
|
|
9
|
+
dynamic = ["version"]
|
|
10
|
+
description = "SDK for the Slip2Sure slip verification API (Thai bank slips and TrueMoney Wallet)"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
authors = [{ name = "Slip2Sure Team", email = "dev@slip2sure.com" }]
|
|
16
|
+
keywords = [
|
|
17
|
+
"slip2sure",
|
|
18
|
+
"slip",
|
|
19
|
+
"slipverify",
|
|
20
|
+
"slipverification",
|
|
21
|
+
"slip-verification",
|
|
22
|
+
"promptpay",
|
|
23
|
+
"truemoney",
|
|
24
|
+
"bank-slip",
|
|
25
|
+
"thailand",
|
|
26
|
+
"api",
|
|
27
|
+
"sdk",
|
|
28
|
+
]
|
|
29
|
+
classifiers = [
|
|
30
|
+
"Development Status :: 5 - Production/Stable",
|
|
31
|
+
"Intended Audience :: Developers",
|
|
32
|
+
"Operating System :: OS Independent",
|
|
33
|
+
"Programming Language :: Python :: 3",
|
|
34
|
+
"Programming Language :: Python :: 3.10",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Programming Language :: Python :: 3.13",
|
|
38
|
+
"Programming Language :: Python :: 3.14",
|
|
39
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
40
|
+
"Framework :: AsyncIO",
|
|
41
|
+
"Topic :: Office/Business :: Financial",
|
|
42
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
43
|
+
"Typing :: Typed",
|
|
44
|
+
]
|
|
45
|
+
# Lower bounds are the versions this SDK is developed against; upper bounds
|
|
46
|
+
# stop a future major release from breaking installs.
|
|
47
|
+
dependencies = [
|
|
48
|
+
"pydantic>=2.10.6,<3",
|
|
49
|
+
"aiohttp>=3.11.12,<4",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[project.optional-dependencies]
|
|
53
|
+
dev = ["build>=1.2", "twine>=5.0"]
|
|
54
|
+
|
|
55
|
+
[project.urls]
|
|
56
|
+
Homepage = "https://slip2sure.com"
|
|
57
|
+
Repository = "https://github.com/Slip2Sure/slip2sure-py"
|
|
58
|
+
Issues = "https://github.com/Slip2Sure/slip2sure-py/issues"
|
|
59
|
+
Documentation = "https://app.slip2sure.com/user/api/docs/bankslip"
|
|
60
|
+
|
|
61
|
+
[tool.setuptools]
|
|
62
|
+
# Listed explicitly rather than auto-discovered: `tests` is a package (it has
|
|
63
|
+
# an __init__.py for its relative imports) and must not be installed as a
|
|
64
|
+
# top-level `tests` module in the user's environment.
|
|
65
|
+
packages = ["slip2sure", "slip2sure.model"]
|
|
66
|
+
|
|
67
|
+
[tool.setuptools.dynamic]
|
|
68
|
+
version = { attr = "slip2sure._version.VERSION" }
|
|
69
|
+
|
|
70
|
+
[tool.setuptools.package-data]
|
|
71
|
+
# Ships the PEP 561 marker so type checkers use the SDK's annotations.
|
|
72
|
+
slip2sure = ["py.typed"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'''
|
|
2
|
+
Copyright 2025 Slip2Sure
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
9
|
+
'''
|
|
10
|
+
|
|
11
|
+
from ._version import VERSION
|
|
12
|
+
|
|
13
|
+
AUTHOR = "Slip2Sure"
|
|
14
|
+
|
|
15
|
+
from .client import *
|
|
16
|
+
from .exception import *
|
|
17
|
+
from .model import *
|