dime-python-sdk 1.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.
- dime_python_sdk-1.0.0/.gitignore +10 -0
- dime_python_sdk-1.0.0/LICENSE +21 -0
- dime_python_sdk-1.0.0/PKG-INFO +288 -0
- dime_python_sdk-1.0.0/README.md +244 -0
- dime_python_sdk-1.0.0/pyproject.toml +42 -0
- dime_python_sdk-1.0.0/src/dime_payments/__init__.py +29 -0
- dime_python_sdk-1.0.0/src/dime_payments/client.py +30 -0
- dime_python_sdk-1.0.0/src/dime_payments/config.py +32 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/__init__.py +31 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/address.py +30 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/customer.py +37 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/deposit.py +31 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/deposit_group.py +25 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/deposit_with_transactions.py +37 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/form_link.py +13 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/merchant.py +55 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/message_result.py +13 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/payment_method.py +63 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/recurring_payment.py +53 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/recurring_payment_method.py +17 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/tokenize_result.py +13 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/transaction.py +57 -0
- dime_python_sdk-1.0.0/src/dime_payments/data_objects/transaction_address.py +27 -0
- dime_python_sdk-1.0.0/src/dime_payments/exceptions/__init__.py +21 -0
- dime_python_sdk-1.0.0/src/dime_payments/exceptions/api_exception.py +5 -0
- dime_python_sdk-1.0.0/src/dime_payments/exceptions/authentication_exception.py +5 -0
- dime_python_sdk-1.0.0/src/dime_payments/exceptions/connection_exception.py +5 -0
- dime_python_sdk-1.0.0/src/dime_payments/exceptions/dime_exception.py +19 -0
- dime_python_sdk-1.0.0/src/dime_payments/exceptions/not_found_exception.py +5 -0
- dime_python_sdk-1.0.0/src/dime_payments/exceptions/permission_denied_exception.py +5 -0
- dime_python_sdk-1.0.0/src/dime_payments/exceptions/rate_limit_exception.py +18 -0
- dime_python_sdk-1.0.0/src/dime_payments/exceptions/server_exception.py +5 -0
- dime_python_sdk-1.0.0/src/dime_payments/exceptions/validation_exception.py +24 -0
- dime_python_sdk-1.0.0/src/dime_payments/http/__init__.py +0 -0
- dime_python_sdk-1.0.0/src/dime_payments/http/error_handler.py +76 -0
- dime_python_sdk-1.0.0/src/dime_payments/http/transport.py +80 -0
- dime_python_sdk-1.0.0/src/dime_payments/pagination/__init__.py +3 -0
- dime_python_sdk-1.0.0/src/dime_payments/pagination/cursor_page.py +72 -0
- dime_python_sdk-1.0.0/src/dime_payments/resources/__init__.py +0 -0
- dime_python_sdk-1.0.0/src/dime_payments/resources/abstract_resource.py +49 -0
- dime_python_sdk-1.0.0/src/dime_payments/resources/addresses.py +37 -0
- dime_python_sdk-1.0.0/src/dime_payments/resources/customers.py +32 -0
- dime_python_sdk-1.0.0/src/dime_payments/resources/deposits.py +31 -0
- dime_python_sdk-1.0.0/src/dime_payments/resources/merchants.py +31 -0
- dime_python_sdk-1.0.0/src/dime_payments/resources/payment_methods.py +37 -0
- dime_python_sdk-1.0.0/src/dime_payments/resources/recurring_payments.py +53 -0
- dime_python_sdk-1.0.0/src/dime_payments/resources/transactions.py +53 -0
- dime_python_sdk-1.0.0/src/dime_payments/support/__init__.py +0 -0
- dime_python_sdk-1.0.0/src/dime_payments/support/arr.py +60 -0
- dime_python_sdk-1.0.0/tests/__init__.py +0 -0
- dime_python_sdk-1.0.0/tests/helpers.py +29 -0
- dime_python_sdk-1.0.0/tests/unit/__init__.py +0 -0
- dime_python_sdk-1.0.0/tests/unit/test_addresses.py +65 -0
- dime_python_sdk-1.0.0/tests/unit/test_customers.py +68 -0
- dime_python_sdk-1.0.0/tests/unit/test_deposits.py +74 -0
- dime_python_sdk-1.0.0/tests/unit/test_error_handling.py +104 -0
- dime_python_sdk-1.0.0/tests/unit/test_merchants.py +51 -0
- dime_python_sdk-1.0.0/tests/unit/test_pagination.py +86 -0
- dime_python_sdk-1.0.0/tests/unit/test_payment_methods.py +61 -0
- dime_python_sdk-1.0.0/tests/unit/test_recurring_payments.py +78 -0
- dime_python_sdk-1.0.0/tests/unit/test_transactions.py +93 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dime Technology
|
|
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.
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dime-python-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python client for the Dime Payments API
|
|
5
|
+
Author: Dime Technology
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Dime Technology
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Keywords: api,dime,payments,sdk
|
|
29
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
30
|
+
Classifier: Intended Audience :: Developers
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Operating System :: OS Independent
|
|
33
|
+
Classifier: Programming Language :: Python :: 3
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
37
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
38
|
+
Requires-Python: >=3.10
|
|
39
|
+
Requires-Dist: requests>=2.28
|
|
40
|
+
Provides-Extra: dev
|
|
41
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
42
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
|
|
45
|
+
# Dime Payments Python SDK
|
|
46
|
+
|
|
47
|
+
A typed Python client for the [Dime Payments](https://dimepayments.com) API.
|
|
48
|
+
Works with Python 3.10+ on any platform.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from dime_payments import Client
|
|
52
|
+
|
|
53
|
+
dime = Client('your-api-token')
|
|
54
|
+
|
|
55
|
+
txn = dime.transactions.charge_card('000010', {
|
|
56
|
+
'amount': '49.99',
|
|
57
|
+
'token': 'tok_abc123',
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
print(txn.transaction_status) # "Success"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Requirements
|
|
64
|
+
|
|
65
|
+
- Python 3.10+
|
|
66
|
+
- A Dime API token (a Laravel Sanctum personal access token). Tokens are minted inside the
|
|
67
|
+
Dime application, not via this SDK, and carry abilities (e.g. `transaction:charge-card-token`,
|
|
68
|
+
`customer:read`) that gate which calls succeed.
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install dime-python-sdk
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Configuration
|
|
77
|
+
|
|
78
|
+
The simplest setup needs only a token:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
dime = Client('your-api-token')
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Point it at another environment, or use `Config` for full control:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from dime_payments import Client, Config
|
|
88
|
+
|
|
89
|
+
# Staging environment
|
|
90
|
+
dime = Client('your-api-token', 'https://staging.dimepayments.com')
|
|
91
|
+
|
|
92
|
+
# Full control
|
|
93
|
+
dime = Client(Config(
|
|
94
|
+
token='your-api-token',
|
|
95
|
+
base_url='https://app.dimepayments.com',
|
|
96
|
+
timeout=30.0, # seconds
|
|
97
|
+
max_retries=2, # retries 429 / 5xx / network errors with backoff
|
|
98
|
+
retry_base_delay=0.5,
|
|
99
|
+
))
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The SDK sends `Authorization: Bearer <token>` and JSON headers on every request. Transient
|
|
103
|
+
failures (HTTP 429 and 5xx, network errors) are retried with exponential backoff, honoring the
|
|
104
|
+
`Retry-After` header when present.
|
|
105
|
+
|
|
106
|
+
## Resources
|
|
107
|
+
|
|
108
|
+
Every resource hangs off the client as a property. The merchant `sid` is always passed
|
|
109
|
+
explicitly; remaining fields go in an `attributes` or `filters` dict. All amounts are
|
|
110
|
+
returned as strings to avoid float rounding.
|
|
111
|
+
|
|
112
|
+
| Property | Endpoints |
|
|
113
|
+
| ------------------------------- | --------------------------------------------------------------------- |
|
|
114
|
+
| `dime.transactions` | charge_card, charge_ach, tokenize_card, refund, void, show, list |
|
|
115
|
+
| `dime.customers` | list, show, create, update, delete |
|
|
116
|
+
| `dime.payment_methods` | list, show, create, update, delete |
|
|
117
|
+
| `dime.merchants` | list, show, create, update, get_form_link |
|
|
118
|
+
| `dime.addresses` | list, show, create, update, delete |
|
|
119
|
+
| `dime.deposits` | list, list_with_transactions, show |
|
|
120
|
+
| `dime.recurring_payments` | list, show, create, edit, pause, cancel, activate, delete |
|
|
121
|
+
|
|
122
|
+
### Transactions
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
# Charge a stored token
|
|
126
|
+
txn = dime.transactions.charge_card('000010', {
|
|
127
|
+
'amount': '100.00',
|
|
128
|
+
'token': 'tok_abc123',
|
|
129
|
+
'email': 'customer@example.com',
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
# Charge raw card details (merchant must be PCI compliant)
|
|
133
|
+
txn = dime.transactions.charge_card('000010', {
|
|
134
|
+
'amount': '100.00',
|
|
135
|
+
'cardholder_name': 'John Doe',
|
|
136
|
+
'card_number': '4111111111111111',
|
|
137
|
+
'expiration_date': '01/2027',
|
|
138
|
+
'cvv': '123',
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
# ACH
|
|
142
|
+
txn = dime.transactions.charge_ach('000010', {
|
|
143
|
+
'routing_number': '123456789',
|
|
144
|
+
'account_number': '9876543210',
|
|
145
|
+
'account_type': 'Checking',
|
|
146
|
+
'account_name': 'John Doe',
|
|
147
|
+
'amount': '75.00',
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
# Tokenize without charging
|
|
151
|
+
result = dime.transactions.tokenize_card('000010', {
|
|
152
|
+
'cardholder_name': 'John Doe',
|
|
153
|
+
'card_number': '4111111111111111',
|
|
154
|
+
'expiration_date': '01/2027',
|
|
155
|
+
})
|
|
156
|
+
print(result.token)
|
|
157
|
+
|
|
158
|
+
# Refund / void
|
|
159
|
+
dime.transactions.refund('000010', {'amount': '25.00', 'transaction_info_id': 123456})
|
|
160
|
+
dime.transactions.void('000010', 'CC', 123456)
|
|
161
|
+
|
|
162
|
+
# Read
|
|
163
|
+
txn = dime.transactions.show('000010', {'transaction_info_id': 123456})
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Customers, payment methods, addresses
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
customer = dime.customers.create('000010', {
|
|
170
|
+
'first_name': 'Jane',
|
|
171
|
+
'last_name': 'Doe',
|
|
172
|
+
'email': 'jane@example.com',
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
pm = dime.payment_methods.create('000010', {
|
|
176
|
+
'uuid': customer.uuid,
|
|
177
|
+
'type': 'cc',
|
|
178
|
+
'cc_name_on_card': 'Jane Doe',
|
|
179
|
+
'cc_number': '4111111111111111',
|
|
180
|
+
'cc_expiration_date': '01/2027',
|
|
181
|
+
'cc_brand': 'Visa',
|
|
182
|
+
'default': True,
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
address = dime.addresses.create('000010', customer.uuid, {
|
|
186
|
+
'recipient': 'Jane Doe',
|
|
187
|
+
'line_one': '123 Main St',
|
|
188
|
+
'city': 'Atlanta',
|
|
189
|
+
'state': 'GA',
|
|
190
|
+
'zip': '30301',
|
|
191
|
+
})
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Recurring payments
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
rp = dime.recurring_payments.create('000010', {
|
|
198
|
+
'name': 'Monthly donation',
|
|
199
|
+
'amount': '25.00',
|
|
200
|
+
'start_date': '2026-07-01 00:00:00',
|
|
201
|
+
'recurrence_schedule': 'Monthly',
|
|
202
|
+
'payment_method': pm.id,
|
|
203
|
+
'customer_uuid': customer.uuid,
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
dime.recurring_payments.pause('000010', rp.id, '2026-09-01 00:00:00')
|
|
207
|
+
dime.recurring_payments.activate('000010', rp.id)
|
|
208
|
+
dime.recurring_payments.cancel('000010', rp.id)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Pagination
|
|
212
|
+
|
|
213
|
+
List endpoints return a `CursorPage`. Iterate one page, walk pages manually, or stream every
|
|
214
|
+
item across all pages with `auto_paging()`:
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
page = dime.transactions.list('000010', {
|
|
218
|
+
'start_date': '2026-01-01 00:00:00',
|
|
219
|
+
'end_date': '2026-01-31 23:59:59',
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
# First page only
|
|
223
|
+
for txn in page:
|
|
224
|
+
print(txn.amount)
|
|
225
|
+
|
|
226
|
+
# Next page manually
|
|
227
|
+
if page.has_more():
|
|
228
|
+
next_page = page.next()
|
|
229
|
+
|
|
230
|
+
# Every transaction across every page (fetches lazily)
|
|
231
|
+
for txn in page.auto_paging():
|
|
232
|
+
print(txn.transaction_number)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Error handling
|
|
236
|
+
|
|
237
|
+
Every failure raises a `DimeException` subclass. Catch the base type, or a specific one:
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
from dime_payments import (
|
|
241
|
+
DimeException,
|
|
242
|
+
ValidationException,
|
|
243
|
+
RateLimitException,
|
|
244
|
+
)
|
|
245
|
+
import time
|
|
246
|
+
|
|
247
|
+
try:
|
|
248
|
+
dime.transactions.charge_card('000010', {'amount': '0'})
|
|
249
|
+
except ValidationException as e:
|
|
250
|
+
e.get_errors() # {'data.amount': ['must be greater than 0']}
|
|
251
|
+
e.first_error()
|
|
252
|
+
except RateLimitException as e:
|
|
253
|
+
wait = e.get_retry_after() or 1
|
|
254
|
+
time.sleep(wait)
|
|
255
|
+
except DimeException as e:
|
|
256
|
+
e.get_status_code() # HTTP status
|
|
257
|
+
e.get_response_body() # decoded API body
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
| Exception | When |
|
|
261
|
+
| ---------------------------- | ------------------------------------------------------------ |
|
|
262
|
+
| `ValidationException` | HTTP 400/422 with field errors |
|
|
263
|
+
| `AuthenticationException` | HTTP 401 (missing/invalid token) |
|
|
264
|
+
| `PermissionDeniedException` | HTTP 403 (belongs-to-company guard) |
|
|
265
|
+
| `NotFoundException` | HTTP 404 |
|
|
266
|
+
| `RateLimitException` | HTTP 429 (carries `Retry-After`) |
|
|
267
|
+
| `ServerException` | HTTP 5xx |
|
|
268
|
+
| `ConnectionException` | No HTTP response (DNS, timeout, network error) |
|
|
269
|
+
| `ApiException` | Any other non-2xx |
|
|
270
|
+
|
|
271
|
+
## Notes
|
|
272
|
+
|
|
273
|
+
- **GET requests carry a JSON body.** The Dime API expects read parameters in the request body
|
|
274
|
+
even for `GET` endpoints; the SDK handles this transparently.
|
|
275
|
+
- **No API versioning.** Endpoints live under `/api` with no version prefix.
|
|
276
|
+
|
|
277
|
+
## Development
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
python3.12 -m venv .venv
|
|
281
|
+
source .venv/bin/activate
|
|
282
|
+
pip install -e ".[dev]"
|
|
283
|
+
pytest # run tests
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## License
|
|
287
|
+
|
|
288
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# Dime Payments Python SDK
|
|
2
|
+
|
|
3
|
+
A typed Python client for the [Dime Payments](https://dimepayments.com) API.
|
|
4
|
+
Works with Python 3.10+ on any platform.
|
|
5
|
+
|
|
6
|
+
```python
|
|
7
|
+
from dime_payments import Client
|
|
8
|
+
|
|
9
|
+
dime = Client('your-api-token')
|
|
10
|
+
|
|
11
|
+
txn = dime.transactions.charge_card('000010', {
|
|
12
|
+
'amount': '49.99',
|
|
13
|
+
'token': 'tok_abc123',
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
print(txn.transaction_status) # "Success"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
- Python 3.10+
|
|
22
|
+
- A Dime API token (a Laravel Sanctum personal access token). Tokens are minted inside the
|
|
23
|
+
Dime application, not via this SDK, and carry abilities (e.g. `transaction:charge-card-token`,
|
|
24
|
+
`customer:read`) that gate which calls succeed.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install dime-python-sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
The simplest setup needs only a token:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
dime = Client('your-api-token')
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Point it at another environment, or use `Config` for full control:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from dime_payments import Client, Config
|
|
44
|
+
|
|
45
|
+
# Staging environment
|
|
46
|
+
dime = Client('your-api-token', 'https://staging.dimepayments.com')
|
|
47
|
+
|
|
48
|
+
# Full control
|
|
49
|
+
dime = Client(Config(
|
|
50
|
+
token='your-api-token',
|
|
51
|
+
base_url='https://app.dimepayments.com',
|
|
52
|
+
timeout=30.0, # seconds
|
|
53
|
+
max_retries=2, # retries 429 / 5xx / network errors with backoff
|
|
54
|
+
retry_base_delay=0.5,
|
|
55
|
+
))
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The SDK sends `Authorization: Bearer <token>` and JSON headers on every request. Transient
|
|
59
|
+
failures (HTTP 429 and 5xx, network errors) are retried with exponential backoff, honoring the
|
|
60
|
+
`Retry-After` header when present.
|
|
61
|
+
|
|
62
|
+
## Resources
|
|
63
|
+
|
|
64
|
+
Every resource hangs off the client as a property. The merchant `sid` is always passed
|
|
65
|
+
explicitly; remaining fields go in an `attributes` or `filters` dict. All amounts are
|
|
66
|
+
returned as strings to avoid float rounding.
|
|
67
|
+
|
|
68
|
+
| Property | Endpoints |
|
|
69
|
+
| ------------------------------- | --------------------------------------------------------------------- |
|
|
70
|
+
| `dime.transactions` | charge_card, charge_ach, tokenize_card, refund, void, show, list |
|
|
71
|
+
| `dime.customers` | list, show, create, update, delete |
|
|
72
|
+
| `dime.payment_methods` | list, show, create, update, delete |
|
|
73
|
+
| `dime.merchants` | list, show, create, update, get_form_link |
|
|
74
|
+
| `dime.addresses` | list, show, create, update, delete |
|
|
75
|
+
| `dime.deposits` | list, list_with_transactions, show |
|
|
76
|
+
| `dime.recurring_payments` | list, show, create, edit, pause, cancel, activate, delete |
|
|
77
|
+
|
|
78
|
+
### Transactions
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
# Charge a stored token
|
|
82
|
+
txn = dime.transactions.charge_card('000010', {
|
|
83
|
+
'amount': '100.00',
|
|
84
|
+
'token': 'tok_abc123',
|
|
85
|
+
'email': 'customer@example.com',
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
# Charge raw card details (merchant must be PCI compliant)
|
|
89
|
+
txn = dime.transactions.charge_card('000010', {
|
|
90
|
+
'amount': '100.00',
|
|
91
|
+
'cardholder_name': 'John Doe',
|
|
92
|
+
'card_number': '4111111111111111',
|
|
93
|
+
'expiration_date': '01/2027',
|
|
94
|
+
'cvv': '123',
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
# ACH
|
|
98
|
+
txn = dime.transactions.charge_ach('000010', {
|
|
99
|
+
'routing_number': '123456789',
|
|
100
|
+
'account_number': '9876543210',
|
|
101
|
+
'account_type': 'Checking',
|
|
102
|
+
'account_name': 'John Doe',
|
|
103
|
+
'amount': '75.00',
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
# Tokenize without charging
|
|
107
|
+
result = dime.transactions.tokenize_card('000010', {
|
|
108
|
+
'cardholder_name': 'John Doe',
|
|
109
|
+
'card_number': '4111111111111111',
|
|
110
|
+
'expiration_date': '01/2027',
|
|
111
|
+
})
|
|
112
|
+
print(result.token)
|
|
113
|
+
|
|
114
|
+
# Refund / void
|
|
115
|
+
dime.transactions.refund('000010', {'amount': '25.00', 'transaction_info_id': 123456})
|
|
116
|
+
dime.transactions.void('000010', 'CC', 123456)
|
|
117
|
+
|
|
118
|
+
# Read
|
|
119
|
+
txn = dime.transactions.show('000010', {'transaction_info_id': 123456})
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Customers, payment methods, addresses
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
customer = dime.customers.create('000010', {
|
|
126
|
+
'first_name': 'Jane',
|
|
127
|
+
'last_name': 'Doe',
|
|
128
|
+
'email': 'jane@example.com',
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
pm = dime.payment_methods.create('000010', {
|
|
132
|
+
'uuid': customer.uuid,
|
|
133
|
+
'type': 'cc',
|
|
134
|
+
'cc_name_on_card': 'Jane Doe',
|
|
135
|
+
'cc_number': '4111111111111111',
|
|
136
|
+
'cc_expiration_date': '01/2027',
|
|
137
|
+
'cc_brand': 'Visa',
|
|
138
|
+
'default': True,
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
address = dime.addresses.create('000010', customer.uuid, {
|
|
142
|
+
'recipient': 'Jane Doe',
|
|
143
|
+
'line_one': '123 Main St',
|
|
144
|
+
'city': 'Atlanta',
|
|
145
|
+
'state': 'GA',
|
|
146
|
+
'zip': '30301',
|
|
147
|
+
})
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Recurring payments
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
rp = dime.recurring_payments.create('000010', {
|
|
154
|
+
'name': 'Monthly donation',
|
|
155
|
+
'amount': '25.00',
|
|
156
|
+
'start_date': '2026-07-01 00:00:00',
|
|
157
|
+
'recurrence_schedule': 'Monthly',
|
|
158
|
+
'payment_method': pm.id,
|
|
159
|
+
'customer_uuid': customer.uuid,
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
dime.recurring_payments.pause('000010', rp.id, '2026-09-01 00:00:00')
|
|
163
|
+
dime.recurring_payments.activate('000010', rp.id)
|
|
164
|
+
dime.recurring_payments.cancel('000010', rp.id)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Pagination
|
|
168
|
+
|
|
169
|
+
List endpoints return a `CursorPage`. Iterate one page, walk pages manually, or stream every
|
|
170
|
+
item across all pages with `auto_paging()`:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
page = dime.transactions.list('000010', {
|
|
174
|
+
'start_date': '2026-01-01 00:00:00',
|
|
175
|
+
'end_date': '2026-01-31 23:59:59',
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
# First page only
|
|
179
|
+
for txn in page:
|
|
180
|
+
print(txn.amount)
|
|
181
|
+
|
|
182
|
+
# Next page manually
|
|
183
|
+
if page.has_more():
|
|
184
|
+
next_page = page.next()
|
|
185
|
+
|
|
186
|
+
# Every transaction across every page (fetches lazily)
|
|
187
|
+
for txn in page.auto_paging():
|
|
188
|
+
print(txn.transaction_number)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Error handling
|
|
192
|
+
|
|
193
|
+
Every failure raises a `DimeException` subclass. Catch the base type, or a specific one:
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from dime_payments import (
|
|
197
|
+
DimeException,
|
|
198
|
+
ValidationException,
|
|
199
|
+
RateLimitException,
|
|
200
|
+
)
|
|
201
|
+
import time
|
|
202
|
+
|
|
203
|
+
try:
|
|
204
|
+
dime.transactions.charge_card('000010', {'amount': '0'})
|
|
205
|
+
except ValidationException as e:
|
|
206
|
+
e.get_errors() # {'data.amount': ['must be greater than 0']}
|
|
207
|
+
e.first_error()
|
|
208
|
+
except RateLimitException as e:
|
|
209
|
+
wait = e.get_retry_after() or 1
|
|
210
|
+
time.sleep(wait)
|
|
211
|
+
except DimeException as e:
|
|
212
|
+
e.get_status_code() # HTTP status
|
|
213
|
+
e.get_response_body() # decoded API body
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
| Exception | When |
|
|
217
|
+
| ---------------------------- | ------------------------------------------------------------ |
|
|
218
|
+
| `ValidationException` | HTTP 400/422 with field errors |
|
|
219
|
+
| `AuthenticationException` | HTTP 401 (missing/invalid token) |
|
|
220
|
+
| `PermissionDeniedException` | HTTP 403 (belongs-to-company guard) |
|
|
221
|
+
| `NotFoundException` | HTTP 404 |
|
|
222
|
+
| `RateLimitException` | HTTP 429 (carries `Retry-After`) |
|
|
223
|
+
| `ServerException` | HTTP 5xx |
|
|
224
|
+
| `ConnectionException` | No HTTP response (DNS, timeout, network error) |
|
|
225
|
+
| `ApiException` | Any other non-2xx |
|
|
226
|
+
|
|
227
|
+
## Notes
|
|
228
|
+
|
|
229
|
+
- **GET requests carry a JSON body.** The Dime API expects read parameters in the request body
|
|
230
|
+
even for `GET` endpoints; the SDK handles this transparently.
|
|
231
|
+
- **No API versioning.** Endpoints live under `/api` with no version prefix.
|
|
232
|
+
|
|
233
|
+
## Development
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
python3.12 -m venv .venv
|
|
237
|
+
source .venv/bin/activate
|
|
238
|
+
pip install -e ".[dev]"
|
|
239
|
+
pytest # run tests
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dime-python-sdk"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Python client for the Dime Payments API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {file = "LICENSE"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Dime Technology"},
|
|
14
|
+
]
|
|
15
|
+
keywords = ["dime", "payments", "sdk", "api"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 5 - Production/Stable",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Operating System :: OS Independent",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"requests>=2.28",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = [
|
|
33
|
+
"pytest>=8.0",
|
|
34
|
+
"pytest-cov>=5.0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[tool.hatch.build.targets.wheel]
|
|
38
|
+
packages = ["src/dime_payments"]
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
testpaths = ["tests"]
|
|
42
|
+
pythonpath = ["src"]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from .client import Client
|
|
2
|
+
from .config import Config
|
|
3
|
+
from .exceptions import (
|
|
4
|
+
ApiException,
|
|
5
|
+
AuthenticationException,
|
|
6
|
+
ConnectionException,
|
|
7
|
+
DimeException,
|
|
8
|
+
NotFoundException,
|
|
9
|
+
PermissionDeniedException,
|
|
10
|
+
RateLimitException,
|
|
11
|
+
ServerException,
|
|
12
|
+
ValidationException,
|
|
13
|
+
)
|
|
14
|
+
from .pagination.cursor_page import CursorPage
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
'Client',
|
|
18
|
+
'Config',
|
|
19
|
+
'CursorPage',
|
|
20
|
+
'DimeException',
|
|
21
|
+
'ValidationException',
|
|
22
|
+
'AuthenticationException',
|
|
23
|
+
'PermissionDeniedException',
|
|
24
|
+
'NotFoundException',
|
|
25
|
+
'RateLimitException',
|
|
26
|
+
'ServerException',
|
|
27
|
+
'ApiException',
|
|
28
|
+
'ConnectionException',
|
|
29
|
+
]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from .config import Config
|
|
2
|
+
from .http.transport import Transport
|
|
3
|
+
from .resources.addresses import Addresses
|
|
4
|
+
from .resources.customers import Customers
|
|
5
|
+
from .resources.deposits import Deposits
|
|
6
|
+
from .resources.merchants import Merchants
|
|
7
|
+
from .resources.payment_methods import PaymentMethods
|
|
8
|
+
from .resources.recurring_payments import RecurringPayments
|
|
9
|
+
from .resources.transactions import Transactions
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Client:
|
|
13
|
+
def __init__(self, token: str | Config, base_url: str = Config.DEFAULT_BASE_URL) -> None:
|
|
14
|
+
if isinstance(token, Config):
|
|
15
|
+
self._config = token
|
|
16
|
+
else:
|
|
17
|
+
self._config = Config(token=token, base_url=base_url)
|
|
18
|
+
|
|
19
|
+
transport = Transport(self._config)
|
|
20
|
+
|
|
21
|
+
self.transactions = Transactions(transport)
|
|
22
|
+
self.customers = Customers(transport)
|
|
23
|
+
self.payment_methods = PaymentMethods(transport)
|
|
24
|
+
self.merchants = Merchants(transport)
|
|
25
|
+
self.addresses = Addresses(transport)
|
|
26
|
+
self.deposits = Deposits(transport)
|
|
27
|
+
self.recurring_payments = RecurringPayments(transport)
|
|
28
|
+
|
|
29
|
+
def config(self) -> Config:
|
|
30
|
+
return self._config
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Callable
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Config:
|
|
10
|
+
DEFAULT_BASE_URL = 'https://app.dimepayments.com'
|
|
11
|
+
VERSION = '1.0.0'
|
|
12
|
+
|
|
13
|
+
def __init__(
|
|
14
|
+
self,
|
|
15
|
+
token: str,
|
|
16
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
17
|
+
timeout: float = 30.0,
|
|
18
|
+
max_retries: int = 2,
|
|
19
|
+
retry_base_delay: float = 0.5,
|
|
20
|
+
session: 'requests.Session | None' = None,
|
|
21
|
+
sleep: Callable[[float], None] | None = None,
|
|
22
|
+
) -> None:
|
|
23
|
+
self.token = token
|
|
24
|
+
self.base_url = base_url
|
|
25
|
+
self.timeout = timeout
|
|
26
|
+
self.max_retries = max_retries
|
|
27
|
+
self.retry_base_delay = retry_base_delay
|
|
28
|
+
self._session = session
|
|
29
|
+
self._sleep = sleep
|
|
30
|
+
|
|
31
|
+
def base_uri(self) -> str:
|
|
32
|
+
return self.base_url.rstrip('/') + '/api/'
|