py-momo-api 1.0.2__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.
- py_momo_api-1.0.2.dist-info/METADATA +215 -0
- py_momo_api-1.0.2.dist-info/RECORD +38 -0
- py_momo_api-1.0.2.dist-info/WHEEL +4 -0
- py_momo_api-1.0.2.dist-info/entry_points.txt +2 -0
- py_momo_api-1.0.2.dist-info/licenses/LICENSE +201 -0
- pymomo/__init__.py +81 -0
- pymomo/_async/__init__.py +1 -0
- pymomo/_async/client.py +134 -0
- pymomo/_async/http.py +134 -0
- pymomo/_async/products/__init__.py +1 -0
- pymomo/_async/products/base.py +204 -0
- pymomo/_async/products/collection.py +293 -0
- pymomo/_async/products/disbursement.py +233 -0
- pymomo/_async/products/remittance.py +85 -0
- pymomo/_async/sandbox.py +145 -0
- pymomo/_cli.py +454 -0
- pymomo/airtel/__init__.py +6 -0
- pymomo/airtel/auth.py +156 -0
- pymomo/airtel/client.py +196 -0
- pymomo/airtel/config.py +53 -0
- pymomo/airtel/models.py +180 -0
- pymomo/airtel/products/collection.py +79 -0
- pymomo/airtel/products/disbursement.py +85 -0
- pymomo/auth.py +67 -0
- pymomo/client.py +141 -0
- pymomo/config.py +128 -0
- pymomo/exceptions.py +52 -0
- pymomo/http.py +169 -0
- pymomo/models.py +322 -0
- pymomo/products/__init__.py +1 -0
- pymomo/products/base.py +198 -0
- pymomo/products/collection.py +293 -0
- pymomo/products/disbursement.py +233 -0
- pymomo/products/remittance.py +85 -0
- pymomo/py.typed +0 -0
- pymomo/sandbox.py +142 -0
- pymomo/utils.py +387 -0
- pymomo/webhooks.py +144 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: py-momo-api
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: Python client for the MTN Mobile Money (MoMo) API
|
|
5
|
+
Project-URL: Homepage, https://pymomo.aiforuganda.org
|
|
6
|
+
Project-URL: Repository, https://github.com/wkambale/pymomo
|
|
7
|
+
Project-URL: Documentation, https://pymomo.aiforuganda.org
|
|
8
|
+
Project-URL: Changelog, https://github.com/wkambale/pymomo/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Wesley Kambale
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: africa,fintech,mobile money,momo,mtn,payments
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: httpx<1,>=0.28.1
|
|
24
|
+
Requires-Dist: pydantic<3,>=2.0
|
|
25
|
+
Requires-Dist: typer<1,>=0.12
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: bandit>=1.7; extra == 'dev'
|
|
28
|
+
Requires-Dist: black>=26.10.1; extra == 'dev'
|
|
29
|
+
Requires-Dist: build<2,>=1.2; extra == 'dev'
|
|
30
|
+
Requires-Dist: isort>=5; extra == 'dev'
|
|
31
|
+
Requires-Dist: mypy>=2.4.1; extra == 'dev'
|
|
32
|
+
Requires-Dist: pre-commit>=4.6.2; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest-cov>=7.1.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest-httpx>=0.30; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
37
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# PyMoMo
|
|
41
|
+
|
|
42
|
+
[](https://pypi.org/project/py-momo-api/)
|
|
43
|
+
[](https://github.com/wkambale/pymomo/actions)
|
|
44
|
+
[](https://github.com/wkambale/pymomo/blob/main/LICENSE)
|
|
45
|
+
|
|
46
|
+
PyMoMo is a fully-typed, production-grade Python client library for the MTN Mobile Money (MoMo) Open API. It provides synchronous and asynchronous clients with complete feature parity, automatic token caching, strict validation, and comprehensive product coverage.
|
|
47
|
+
|
|
48
|
+
Developed for high reliability and clean developer experience, PyMoMo adheres to the strict security standards of modern payments systems.
|
|
49
|
+
|
|
50
|
+
- **Authoritative Docs:** [https://pymomo.aiforuganda.org](https://pymomo.aiforuganda.org)
|
|
51
|
+
- **Repository:** [https://github.com/wkambale/pymomo](https://github.com/wkambale/pymomo)
|
|
52
|
+
|
|
53
|
+
## Features
|
|
54
|
+
|
|
55
|
+
- **Sync & Async Parity:** Backed by `httpx.Client` and `httpx.AsyncClient` with matching interfaces.
|
|
56
|
+
- **Pydantic v2 Models:** Fully typed request/response validation and serialization.
|
|
57
|
+
- **Automated Token Caching:** Thread-safe and async-safe in-memory token management with automated cache invalidation and retry-once logic.
|
|
58
|
+
- **Comprehensive API Coverage:** Full MTN MoMo Collection (including CIBA/OAuth2 token exchange), Disbursement, Remittance, Sandbox, and Airtel Money APIs.
|
|
59
|
+
- **Robust Security:** Strict HTTPS and input validation, constant-time webhook HMAC and source IP verification, and secret-redacting exceptions and representations.
|
|
60
|
+
- **CLI Utility:** Ships with a Typer-powered CLI to bootstrap sandbox credentials, initiate payments, and query balances or transaction status.
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
Install PyMoMo from PyPI using pip:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install py-momo-api
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
For development dependencies, install with:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install -e ".[dev]"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Quickstart
|
|
77
|
+
|
|
78
|
+
### 1. Sandbox Provisioning
|
|
79
|
+
|
|
80
|
+
To get started with the sandbox environment, bootstrap a new API User and API Key:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from pymomo import MomoClient, MomoConfig
|
|
84
|
+
|
|
85
|
+
config = MomoConfig(environment="sandbox")
|
|
86
|
+
|
|
87
|
+
with MomoClient(config) as client:
|
|
88
|
+
provisioner = client.create_sandbox_provisioner("your-sandbox-subscription-key")
|
|
89
|
+
credentials = provisioner.provision(callback_host="https://pymomo.aiforuganda.org")
|
|
90
|
+
|
|
91
|
+
print(f"API User: {credentials['api_user']}")
|
|
92
|
+
print(f"API Key: {credentials['api_key']}")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 2. Collection (Synchronous Example)
|
|
96
|
+
|
|
97
|
+
Make a payment request (Request to Pay) using the synchronous client:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from pymomo import MomoClient, MomoConfig, ProductConfig
|
|
101
|
+
|
|
102
|
+
config = MomoConfig(
|
|
103
|
+
environment="sandbox",
|
|
104
|
+
collection=ProductConfig(
|
|
105
|
+
subscription_key="your-collection-subscription-key",
|
|
106
|
+
api_user="your-api-user-uuid",
|
|
107
|
+
api_key="your-api-key",
|
|
108
|
+
callback_url="https://pymomo.aiforuganda.org/webhook",
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
with MomoClient(config) as client:
|
|
113
|
+
# Query account balance
|
|
114
|
+
balance = client.collection.get_balance()
|
|
115
|
+
print(f"Available Balance: {balance.available_balance} {balance.currency}")
|
|
116
|
+
|
|
117
|
+
# Initiate a Request to Pay
|
|
118
|
+
reference_id = client.collection.request_to_pay(
|
|
119
|
+
amount="1000.00",
|
|
120
|
+
currency="UGX",
|
|
121
|
+
payer_msisdn="256771234567",
|
|
122
|
+
external_id="ext-tx-12345",
|
|
123
|
+
payer_message="Payment for Invoice #123",
|
|
124
|
+
payee_note="Thank you for shopping with us",
|
|
125
|
+
)
|
|
126
|
+
print(f"Transaction Reference: {reference_id}")
|
|
127
|
+
|
|
128
|
+
# Check status
|
|
129
|
+
tx = client.collection.get_payment_status(reference_id)
|
|
130
|
+
print(f"Transaction Status: {tx.status}")
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 3. Disbursement (Asynchronous Example)
|
|
134
|
+
|
|
135
|
+
Send funds using the asynchronous client:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
import asyncio
|
|
139
|
+
from pymomo import AsyncMomoClient, MomoConfig, ProductConfig
|
|
140
|
+
|
|
141
|
+
config = MomoConfig(
|
|
142
|
+
environment="sandbox",
|
|
143
|
+
disbursement=ProductConfig(
|
|
144
|
+
subscription_key="your-disbursement-subscription-key",
|
|
145
|
+
api_user="your-api-user-uuid",
|
|
146
|
+
api_key="your-api-key",
|
|
147
|
+
)
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
async def main():
|
|
151
|
+
async with AsyncMomoClient(config) as client:
|
|
152
|
+
# Check active status of a mobile money user
|
|
153
|
+
is_active = await client.disbursement.is_account_holder_active("256771234567")
|
|
154
|
+
print(f"Account holder active: {is_active}")
|
|
155
|
+
|
|
156
|
+
# Initiate a transfer
|
|
157
|
+
reference_id = await client.disbursement.transfer(
|
|
158
|
+
amount="5000.00",
|
|
159
|
+
currency="UGX",
|
|
160
|
+
payee_msisdn="256771234567",
|
|
161
|
+
external_id="disb-tx-9999",
|
|
162
|
+
payer_message="Staff salary payment",
|
|
163
|
+
payee_note="Disbursement Successful",
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
# Query transaction details
|
|
167
|
+
status = await client.disbursement.get_transfer_status(reference_id)
|
|
168
|
+
print(f"Transfer status: {status.status} (ID: {status.financial_transaction_id})")
|
|
169
|
+
|
|
170
|
+
asyncio.run(main())
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## CLI Usage
|
|
174
|
+
|
|
175
|
+
PyMoMo bundles a CLI tool for common sandbox management operations:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Show installed version
|
|
179
|
+
pymomo --version
|
|
180
|
+
|
|
181
|
+
# Provision a sandbox environment
|
|
182
|
+
pymomo sandbox provision --subscription-key "your-key"
|
|
183
|
+
|
|
184
|
+
# Query the collection balance
|
|
185
|
+
pymomo collection balance --subscription-key "your-key" --api-user "550e8400-e29b-41d4-a716-446655440000" --api-key "key"
|
|
186
|
+
|
|
187
|
+
# Check the status of a Request to Pay transaction
|
|
188
|
+
pymomo collection status "550e8400-e29b-41d4-a716-446655440000" --subscription-key "your-key" --api-user "550e8400-e29b-41d4-a716-446655440000" --api-key "key"
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Use `pymomo --help` to list all available commands and flags.
|
|
192
|
+
|
|
193
|
+
## Testing
|
|
194
|
+
|
|
195
|
+
Run tests and produce coverage reports:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# Style check and format check
|
|
199
|
+
ruff check .
|
|
200
|
+
black --check .
|
|
201
|
+
isort --check .
|
|
202
|
+
|
|
203
|
+
# Static type check
|
|
204
|
+
mypy pymomo/
|
|
205
|
+
|
|
206
|
+
# Security analysis
|
|
207
|
+
bandit -r pymomo/
|
|
208
|
+
|
|
209
|
+
# Test execution with coverage
|
|
210
|
+
pytest --cov=pymomo --cov-report=term-missing
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
MIT License. See [LICENSE](LICENSE) for more details.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
pymomo/__init__.py,sha256=p0FvDU2RSHuLk69xQMDUnGovrMdVJys-rh42035xLQg,1967
|
|
2
|
+
pymomo/_cli.py,sha256=fyOMAa9S4BVxq45cLddFSJp4R0gz8_p6CMmCHe2BzC4,13194
|
|
3
|
+
pymomo/auth.py,sha256=maYGFmOxVC9_HiH7e22Q3TRBXSqN398EBtGZvHTGq1k,2240
|
|
4
|
+
pymomo/client.py,sha256=1sn2__CL3Lu9Ms1vfgwA_Zspw0pSmSaqCqHVeHNONho,4507
|
|
5
|
+
pymomo/config.py,sha256=vLjtm_7SjFiTKGNSWM9m24vQv9CVqzNiVTFbezApLJw,4208
|
|
6
|
+
pymomo/exceptions.py,sha256=HnJbHmjydoaQ_8GtRP8ctwtCW9iybL2YWu2tAVqNEPQ,1411
|
|
7
|
+
pymomo/http.py,sha256=tDedxA9RJTzAHgBJw36XFbb4WpfUc3b7W3Pu_Qfli4M,5563
|
|
8
|
+
pymomo/models.py,sha256=vH6zL2P7Ex40enRqsyWWEeju968NTeqb5KZkuZKfoEw,9601
|
|
9
|
+
pymomo/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
pymomo/sandbox.py,sha256=v8g-6DQB9y8qg-Zwf-3qk8ZqcMoqBr19gouargN4UmU,5231
|
|
11
|
+
pymomo/utils.py,sha256=RTxteGW0cGn6Nal12f89H1Fvf1H9UXoYaJxxUWol6_U,12858
|
|
12
|
+
pymomo/webhooks.py,sha256=miHidi05mQnkc9tjyMS5Vv1sOEreKwpbm1HGcLLMDcU,5217
|
|
13
|
+
pymomo/_async/__init__.py,sha256=_HtKLC8ddx6qTxNTNvHBjOV_LoIU2GIqfTohrqY6anM,26
|
|
14
|
+
pymomo/_async/client.py,sha256=GfRmAbFkswOvZWnXx1SYV3Mo9PSvMouO0PksptKy6-g,4422
|
|
15
|
+
pymomo/_async/http.py,sha256=Hkl66dD7YQcq13dxWmK6BKQsa8aYAQoUyNVvsKXGkT8,4546
|
|
16
|
+
pymomo/_async/sandbox.py,sha256=AyMJy3sH5GbRQqXi_TFMBRQuo8aDDOU0AzIbkDiPybI,5434
|
|
17
|
+
pymomo/_async/products/__init__.py,sha256=Q9fQhFXpteDpxpCKfU9RPb34ZZz1H7s2-fwGwehVfnk,24
|
|
18
|
+
pymomo/_async/products/base.py,sha256=Gh7aDsUArjNLQ2f34Aabnf_TXNSJqltXxxmUUKqi-k8,7260
|
|
19
|
+
pymomo/_async/products/collection.py,sha256=Eh-fBeVoYHYBl_r-6R1ShotXU_lYnANKfJ3eVNliPjM,10163
|
|
20
|
+
pymomo/_async/products/disbursement.py,sha256=aZlzs4noFFJxLu_ytJqk7qbDdN4A-wvF2mLqzFTX3lo,7659
|
|
21
|
+
pymomo/_async/products/remittance.py,sha256=ANHqdkdrTeRT5_YcQkBj795VTxLC_GuckXFcOmOQHKQ,2837
|
|
22
|
+
pymomo/airtel/__init__.py,sha256=nTgZVvBK62HKFK6z27W0iWehhcT9WLL7UwGS9rQP1Ac,172
|
|
23
|
+
pymomo/airtel/auth.py,sha256=O7IoCqK_OPb_67WDFccYnwqnveyILE-BLiRJxaWB0nA,5286
|
|
24
|
+
pymomo/airtel/client.py,sha256=M7ERT0-Dc5dKLO5-FLPw70wBt9U1H_SPm2JDPtVajw4,6619
|
|
25
|
+
pymomo/airtel/config.py,sha256=eSnzON5XP0ytxaAzp4S2h4yycd1TEwhQoqct4RdN31c,1818
|
|
26
|
+
pymomo/airtel/models.py,sha256=XfEIMvkS4xeYY38BbvOXTbFgX_YYvbBYPyAofVIA7MU,5004
|
|
27
|
+
pymomo/airtel/products/collection.py,sha256=OatlFRtQoOF2v-9qc5u5cANLnbL0B-Wdy4oGzmcpweQ,2359
|
|
28
|
+
pymomo/airtel/products/disbursement.py,sha256=oPULNPMNQURcJsuat0fRwBdBpRngtf7SDKFrMZt2Vcg,2493
|
|
29
|
+
pymomo/products/__init__.py,sha256=8be8ZzNaN9h9bOtSQOMmUopRmuhiygZvRd5tJozNKHs,26
|
|
30
|
+
pymomo/products/base.py,sha256=Za1OGOFkslaNcJ4B_B7GVPgRtyb8zs3yQsxWrV7sjUk,6919
|
|
31
|
+
pymomo/products/collection.py,sha256=il5Xj-Z2aXWF-K88QoNusqmG36GxFUoWw8ap8UbffOI,10013
|
|
32
|
+
pymomo/products/disbursement.py,sha256=X8ZVFVW9oqBtpp50J-BMdJeed070o4K0QleUvTlxYj8,7521
|
|
33
|
+
pymomo/products/remittance.py,sha256=cwUuEGad_L9jfOZrDypf8r4NLstk-3-GDI5pKwcSnik,2771
|
|
34
|
+
py_momo_api-1.0.2.dist-info/METADATA,sha256=LtAN8vOkdKrksuZhTwGvZZ8o2DkOriZYE6xvj33yfxw,7539
|
|
35
|
+
py_momo_api-1.0.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
36
|
+
py_momo_api-1.0.2.dist-info/entry_points.txt,sha256=3ZQovyiiVYyTDl5ClTGjsztbGuqZfgbleNi2ChoCIhI,43
|
|
37
|
+
py_momo_api-1.0.2.dist-info/licenses/LICENSE,sha256=MHyPo6m3oWUQRaTvvbBamsUNof09fi2na6qzZad6JRA,11344
|
|
38
|
+
py_momo_api-1.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Wesley Kambale
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
pymomo/__init__.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
# Async client exports
|
|
4
|
+
from pymomo._async.client import AsyncMomoClient
|
|
5
|
+
from pymomo._async.sandbox import AsyncSandboxProvisioner
|
|
6
|
+
from pymomo.airtel.client import AirtelClient
|
|
7
|
+
from pymomo.airtel.config import AirtelConfig
|
|
8
|
+
from pymomo.auth import TokenCache
|
|
9
|
+
from pymomo.client import MomoClient
|
|
10
|
+
from pymomo.config import MomoConfig, ProductConfig
|
|
11
|
+
from pymomo.exceptions import (
|
|
12
|
+
AuthenticationError,
|
|
13
|
+
BadRequestError,
|
|
14
|
+
ConflictError,
|
|
15
|
+
MissingCredentialsError,
|
|
16
|
+
MomoServerError,
|
|
17
|
+
PyMoMoError,
|
|
18
|
+
ResourceNotFoundError,
|
|
19
|
+
TransactionFailedError,
|
|
20
|
+
WebhookVerificationError,
|
|
21
|
+
)
|
|
22
|
+
from pymomo.models import (
|
|
23
|
+
AccountHolderIdType,
|
|
24
|
+
ApiKeyResult,
|
|
25
|
+
ApiUserInfo,
|
|
26
|
+
Balance,
|
|
27
|
+
BasicUserInfo,
|
|
28
|
+
BcAuthorizeRequest,
|
|
29
|
+
BcAuthorizeResponse,
|
|
30
|
+
DepositRequest,
|
|
31
|
+
OAuth2TokenResponse,
|
|
32
|
+
Party,
|
|
33
|
+
RefundRequest,
|
|
34
|
+
RequestToPayRequest,
|
|
35
|
+
RequestToWithdrawRequest,
|
|
36
|
+
TokenResponse,
|
|
37
|
+
TransactionResult,
|
|
38
|
+
TransactionStatus,
|
|
39
|
+
TransferRequest,
|
|
40
|
+
)
|
|
41
|
+
from pymomo.sandbox import SandboxProvisioner
|
|
42
|
+
from pymomo.webhooks import WebhookHandler
|
|
43
|
+
|
|
44
|
+
__all__ = [
|
|
45
|
+
"AccountHolderIdType",
|
|
46
|
+
"AirtelClient",
|
|
47
|
+
"AirtelConfig",
|
|
48
|
+
"ApiKeyResult",
|
|
49
|
+
"ApiUserInfo",
|
|
50
|
+
"AsyncMomoClient",
|
|
51
|
+
"AsyncSandboxProvisioner",
|
|
52
|
+
"AuthenticationError",
|
|
53
|
+
"BadRequestError",
|
|
54
|
+
"Balance",
|
|
55
|
+
"BasicUserInfo",
|
|
56
|
+
"BcAuthorizeRequest",
|
|
57
|
+
"BcAuthorizeResponse",
|
|
58
|
+
"ConflictError",
|
|
59
|
+
"DepositRequest",
|
|
60
|
+
"MissingCredentialsError",
|
|
61
|
+
"MomoClient",
|
|
62
|
+
"MomoConfig",
|
|
63
|
+
"MomoServerError",
|
|
64
|
+
"OAuth2TokenResponse",
|
|
65
|
+
"Party",
|
|
66
|
+
"ProductConfig",
|
|
67
|
+
"PyMoMoError",
|
|
68
|
+
"RefundRequest",
|
|
69
|
+
"RequestToPayRequest",
|
|
70
|
+
"RequestToWithdrawRequest",
|
|
71
|
+
"ResourceNotFoundError",
|
|
72
|
+
"SandboxProvisioner",
|
|
73
|
+
"TokenCache",
|
|
74
|
+
"TokenResponse",
|
|
75
|
+
"TransactionFailedError",
|
|
76
|
+
"TransactionResult",
|
|
77
|
+
"TransactionStatus",
|
|
78
|
+
"TransferRequest",
|
|
79
|
+
"WebhookHandler",
|
|
80
|
+
"WebhookVerificationError",
|
|
81
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Async client structures
|
pymomo/_async/client.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from pymomo._async.http import AsyncHttpClient
|
|
6
|
+
from pymomo._async.products.collection import Collection
|
|
7
|
+
from pymomo._async.products.disbursement import Disbursement
|
|
8
|
+
from pymomo._async.products.remittance import Remittance
|
|
9
|
+
from pymomo._async.sandbox import AsyncSandboxProvisioner
|
|
10
|
+
from pymomo.auth import TokenCache
|
|
11
|
+
from pymomo.config import MomoConfig
|
|
12
|
+
from pymomo.exceptions import MissingCredentialsError, PyMoMoError
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from typing_extensions import Self
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AsyncMomoClient:
|
|
19
|
+
"""Asynchronous MTN MoMo API client.
|
|
20
|
+
|
|
21
|
+
Instantiate with a MomoConfig and access products via attributes.
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
async with AsyncMomoClient(config) as client:
|
|
25
|
+
balance = await client.collection.get_balance()
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, config: MomoConfig) -> None:
|
|
29
|
+
self._config = config
|
|
30
|
+
self._token_cache = TokenCache()
|
|
31
|
+
if not config.base_url:
|
|
32
|
+
raise PyMoMoError("Base URL must use HTTPS")
|
|
33
|
+
self._http = AsyncHttpClient(
|
|
34
|
+
base_url=config.base_url,
|
|
35
|
+
timeout=config.timeout,
|
|
36
|
+
)
|
|
37
|
+
self._collection: Collection | None = None
|
|
38
|
+
self._disbursement: Disbursement | None = None
|
|
39
|
+
self._remittance: Remittance | None = None
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def collection(self) -> Collection:
|
|
43
|
+
"""Get Collection client instance.
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
MissingCredentialsError: If collection credentials are not configured.
|
|
47
|
+
"""
|
|
48
|
+
if self._config.collection is None:
|
|
49
|
+
raise MissingCredentialsError(
|
|
50
|
+
"Collection credentials not provided in MomoConfig"
|
|
51
|
+
)
|
|
52
|
+
if self._collection is None:
|
|
53
|
+
self._collection = Collection(
|
|
54
|
+
config=self._config,
|
|
55
|
+
product_config=self._config.collection,
|
|
56
|
+
http=self._http,
|
|
57
|
+
token_cache=self._token_cache,
|
|
58
|
+
)
|
|
59
|
+
return self._collection
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def disbursement(self) -> Disbursement:
|
|
63
|
+
"""Get Disbursement client instance.
|
|
64
|
+
|
|
65
|
+
Raises:
|
|
66
|
+
MissingCredentialsError: If disbursement credentials are not configured.
|
|
67
|
+
"""
|
|
68
|
+
if self._config.disbursement is None:
|
|
69
|
+
raise MissingCredentialsError(
|
|
70
|
+
"Disbursement credentials not provided in MomoConfig"
|
|
71
|
+
)
|
|
72
|
+
if self._disbursement is None:
|
|
73
|
+
self._disbursement = Disbursement(
|
|
74
|
+
config=self._config,
|
|
75
|
+
product_config=self._config.disbursement,
|
|
76
|
+
http=self._http,
|
|
77
|
+
token_cache=self._token_cache,
|
|
78
|
+
)
|
|
79
|
+
return self._disbursement
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def remittance(self) -> Remittance:
|
|
83
|
+
"""Get Remittance client instance.
|
|
84
|
+
|
|
85
|
+
Raises:
|
|
86
|
+
MissingCredentialsError: If remittance credentials are not configured.
|
|
87
|
+
"""
|
|
88
|
+
if self._config.remittance is None:
|
|
89
|
+
raise MissingCredentialsError(
|
|
90
|
+
"Remittance credentials not provided in MomoConfig"
|
|
91
|
+
)
|
|
92
|
+
if self._remittance is None:
|
|
93
|
+
self._remittance = Remittance(
|
|
94
|
+
config=self._config,
|
|
95
|
+
product_config=self._config.remittance,
|
|
96
|
+
http=self._http,
|
|
97
|
+
token_cache=self._token_cache,
|
|
98
|
+
)
|
|
99
|
+
return self._remittance
|
|
100
|
+
|
|
101
|
+
@property
|
|
102
|
+
def sandbox(self) -> AsyncSandboxProvisioner:
|
|
103
|
+
"""Get AsyncSandboxProvisioner client instance."""
|
|
104
|
+
return AsyncSandboxProvisioner(
|
|
105
|
+
config=self._config,
|
|
106
|
+
http=self._http,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
def create_sandbox_provisioner(
|
|
110
|
+
self, subscription_key: str
|
|
111
|
+
) -> AsyncSandboxProvisioner:
|
|
112
|
+
"""Create an AsyncSandboxProvisioner using an explicit subscription key.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
subscription_key: The sandbox Ocp-Apim-Subscription-Key.
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
A configured AsyncSandboxProvisioner sharing this client's HTTP session.
|
|
119
|
+
"""
|
|
120
|
+
return AsyncSandboxProvisioner(
|
|
121
|
+
subscription_key=subscription_key,
|
|
122
|
+
config=self._config,
|
|
123
|
+
http=self._http,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
async def close(self) -> None:
|
|
127
|
+
"""Close the underlying AsyncHttpClient session."""
|
|
128
|
+
await self._http.close()
|
|
129
|
+
|
|
130
|
+
async def __aenter__(self) -> Self:
|
|
131
|
+
return self
|
|
132
|
+
|
|
133
|
+
async def __aexit__(self, *args: object) -> None:
|
|
134
|
+
await self.close()
|