afconwave 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- afconwave-0.1.0/LICENSE +21 -0
- afconwave-0.1.0/PKG-INFO +15 -0
- afconwave-0.1.0/README.md +206 -0
- afconwave-0.1.0/afconwave/__init__.py +159 -0
- afconwave-0.1.0/afconwave.egg-info/PKG-INFO +15 -0
- afconwave-0.1.0/afconwave.egg-info/SOURCES.txt +9 -0
- afconwave-0.1.0/afconwave.egg-info/dependency_links.txt +1 -0
- afconwave-0.1.0/afconwave.egg-info/requires.txt +1 -0
- afconwave-0.1.0/afconwave.egg-info/top_level.txt +1 -0
- afconwave-0.1.0/setup.cfg +4 -0
- afconwave-0.1.0/setup.py +17 -0
afconwave-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AfconWave
|
|
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.
|
afconwave-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: afconwave
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official AfconWave Python SDK
|
|
5
|
+
Author: AfconWave Team
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: requests>=2.25.0
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: classifier
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
Dynamic: requires-dist
|
|
15
|
+
Dynamic: summary
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# afconwave โ Official Python SDK
|
|
2
|
+
|
|
3
|
+
> The official Python client library for the AfconWave Payments API.
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/afconwave/)
|
|
6
|
+
[](https://www.python.org/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- โ
Python 3.8+ compatible
|
|
14
|
+
- ๐ Payments, Payouts, and Refunds in one library
|
|
15
|
+
- ๐ Secure API key handling
|
|
16
|
+
- ๐ Webhook signature verification helper
|
|
17
|
+
- ๐งช Sandbox-ready with test keys
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install afconwave
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from afconwave import AfconWave
|
|
33
|
+
|
|
34
|
+
afw = AfconWave(secret_key="sk_test_your_key_here")
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Usage Guide
|
|
40
|
+
|
|
41
|
+
### Create a Payment
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
payment = afw.create_payment(
|
|
45
|
+
amount=5000, # Amount in minor units (5000 = 50 XAF)
|
|
46
|
+
currency="XAF",
|
|
47
|
+
description="Order #1234",
|
|
48
|
+
callback_url="https://yoursite.com/payment/callback",
|
|
49
|
+
customer={
|
|
50
|
+
"name": "Jean Dupont",
|
|
51
|
+
"email": "jean@example.com",
|
|
52
|
+
"phone": "+237600000000",
|
|
53
|
+
},
|
|
54
|
+
metadata={"order_id": "ORD-1234"}
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
print(payment["checkout_url"]) # Redirect user here
|
|
58
|
+
print(payment["id"]) # e.g., pay_507f191e8180f
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Retrieve a Payment
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
payment = afw.retrieve_payment("pay_507f191e8180f")
|
|
65
|
+
|
|
66
|
+
print(payment["status"]) # "pending" | "success" | "failed"
|
|
67
|
+
print(payment["amount"])
|
|
68
|
+
print(payment["paid_at"])
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Create a Payout
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
payout = afw.create_payout(
|
|
75
|
+
amount=10000,
|
|
76
|
+
currency="XAF",
|
|
77
|
+
recipient={
|
|
78
|
+
"phone": "+237600000001",
|
|
79
|
+
"network": "MTN", # "MTN" | "ORANGE" | "MOOV" | "WAVE"
|
|
80
|
+
"name": "Marie Kamga",
|
|
81
|
+
},
|
|
82
|
+
reference="PAYOUT-REF-001"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
print(payout["status"]) # "pending" | "success" | "failed"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### List Payments
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
result = afw.list_payments(limit=20, status="success")
|
|
92
|
+
|
|
93
|
+
for payment in result["data"]:
|
|
94
|
+
print(payment["id"], payment["amount"], payment["status"])
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Webhook Verification
|
|
100
|
+
|
|
101
|
+
Verify that incoming webhooks are genuinely from AfconWave:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
import hashlib
|
|
105
|
+
import hmac
|
|
106
|
+
from flask import Flask, request, abort
|
|
107
|
+
|
|
108
|
+
app = Flask(__name__)
|
|
109
|
+
WEBHOOK_SECRET = "your_webhook_secret"
|
|
110
|
+
|
|
111
|
+
@app.route("/webhooks/afconwave", methods=["POST"])
|
|
112
|
+
def handle_webhook():
|
|
113
|
+
signature = request.headers.get("X-AfconWave-Signature", "")
|
|
114
|
+
payload = request.get_data(as_text=True)
|
|
115
|
+
|
|
116
|
+
expected = hmac.new(
|
|
117
|
+
WEBHOOK_SECRET.encode(),
|
|
118
|
+
payload.encode(),
|
|
119
|
+
hashlib.sha256
|
|
120
|
+
).hexdigest()
|
|
121
|
+
|
|
122
|
+
if not hmac.compare_digest(expected, signature):
|
|
123
|
+
abort(400, "Invalid signature")
|
|
124
|
+
|
|
125
|
+
event = request.get_json()
|
|
126
|
+
|
|
127
|
+
if event["event"] == "payment.success":
|
|
128
|
+
print("Payment received:", event["data"]["id"])
|
|
129
|
+
elif event["event"] == "payment.failed":
|
|
130
|
+
print("Payment failed")
|
|
131
|
+
elif event["event"] == "payout.success":
|
|
132
|
+
print("Payout delivered")
|
|
133
|
+
|
|
134
|
+
return "OK", 200
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Error Handling
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from afconwave import AfconWave, AfconWaveError
|
|
143
|
+
|
|
144
|
+
afw = AfconWave(secret_key="sk_test_...")
|
|
145
|
+
|
|
146
|
+
try:
|
|
147
|
+
payment = afw.create_payment(amount=5000, currency="XAF", callback_url="...")
|
|
148
|
+
except AfconWaveError as e:
|
|
149
|
+
print(f"API Error {e.status_code}: {e.message}")
|
|
150
|
+
except Exception as e:
|
|
151
|
+
print(f"Unexpected error: {e}")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Configuration
|
|
157
|
+
|
|
158
|
+
| Parameter | Type | Default | Description |
|
|
159
|
+
|---|---|---|---|
|
|
160
|
+
| `secret_key` | `str` | **required** | Your AfconWave secret API key |
|
|
161
|
+
| `base_url` | `str` | `https://api.afconwave.com/v1` | API base URL |
|
|
162
|
+
| `timeout` | `int` | `30` | Request timeout (seconds) |
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Sandbox / Testing
|
|
167
|
+
|
|
168
|
+
Use test keys prefixed with `sk_test_` for sandbox mode. No real transactions occur.
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
afw = AfconWave(secret_key="sk_test_...")
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Django / Flask Integration
|
|
177
|
+
|
|
178
|
+
### Django (example view)
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from django.http import JsonResponse
|
|
182
|
+
from django.views.decorators.csrf import csrf_exempt
|
|
183
|
+
from afconwave import AfconWave
|
|
184
|
+
|
|
185
|
+
afw = AfconWave(secret_key="sk_live_...")
|
|
186
|
+
|
|
187
|
+
def create_checkout(request):
|
|
188
|
+
payment = afw.create_payment(
|
|
189
|
+
amount=int(request.POST["amount"]),
|
|
190
|
+
currency="XAF",
|
|
191
|
+
callback_url="https://yoursite.com/payment/success",
|
|
192
|
+
)
|
|
193
|
+
return JsonResponse({"checkout_url": payment["checkout_url"]})
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Documentation
|
|
199
|
+
|
|
200
|
+
Full API documentation: [docs.afconwave.com](https://docs.afconwave.com)
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT ยฉ AfconWave
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import hmac
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
# โโโ Exceptions โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
8
|
+
|
|
9
|
+
class AfconWaveError(Exception):
|
|
10
|
+
def __init__(self, message, status_code=None, code=None):
|
|
11
|
+
self.message = message
|
|
12
|
+
self.status_code = status_code
|
|
13
|
+
self.code = code
|
|
14
|
+
super().__init__(self.message)
|
|
15
|
+
|
|
16
|
+
# โโโ Resources โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
17
|
+
|
|
18
|
+
class Resource:
|
|
19
|
+
def __init__(self, client):
|
|
20
|
+
self.client = client
|
|
21
|
+
|
|
22
|
+
class Payments(Resource):
|
|
23
|
+
def create(self, **kwargs):
|
|
24
|
+
return self.client.request('POST', '/payments', data=kwargs)
|
|
25
|
+
|
|
26
|
+
def retrieve(self, payment_id):
|
|
27
|
+
return self.client.request('GET', f'/payments/{payment_id}')
|
|
28
|
+
|
|
29
|
+
def list(self, **kwargs):
|
|
30
|
+
return self.client.request('GET', '/payments', params=kwargs)
|
|
31
|
+
|
|
32
|
+
class Payouts(Resource):
|
|
33
|
+
def create(self, **kwargs):
|
|
34
|
+
return self.client.request('POST', '/payouts', data=kwargs)
|
|
35
|
+
|
|
36
|
+
def retrieve(self, payout_id):
|
|
37
|
+
return self.client.request('GET', f'/payouts/{payout_id}')
|
|
38
|
+
|
|
39
|
+
class Crypto(Resource):
|
|
40
|
+
def buy(self, **kwargs):
|
|
41
|
+
return self.client.request('POST', '/crypto/buy', data=kwargs)
|
|
42
|
+
|
|
43
|
+
class Refunds(Resource):
|
|
44
|
+
def create(self, payment_id: str, amount: float, reason: str = None):
|
|
45
|
+
return self.client.request('POST', '/refunds', data={
|
|
46
|
+
'paymentId': payment_id,
|
|
47
|
+
'amount': amount,
|
|
48
|
+
'reason': reason
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
def list(self):
|
|
52
|
+
return self.client.request('GET', '/refunds')
|
|
53
|
+
|
|
54
|
+
class Disputes(Resource):
|
|
55
|
+
def open(self, transaction_id: str, reason: str, description: str):
|
|
56
|
+
return self.client.request('POST', '/disputes', data={
|
|
57
|
+
'transactionId': transaction_id,
|
|
58
|
+
'reason': reason,
|
|
59
|
+
'description': description
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
def list(self):
|
|
63
|
+
return self.client.request('GET', '/disputes')
|
|
64
|
+
|
|
65
|
+
def resolve(self, dispute_id: str, resolution: str, resolution_details: str = None):
|
|
66
|
+
return self.client.request('POST', f'/disputes/{dispute_id}/resolve', data={
|
|
67
|
+
'resolution': resolution,
|
|
68
|
+
'resolutionDetails': resolution_details
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
# โโโ Main Client โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
72
|
+
|
|
73
|
+
class AfconWave:
|
|
74
|
+
def __init__(self, secret_key: str, base_url: str = 'https://api.afconwave.com/api/v1', timeout: int = 30):
|
|
75
|
+
self.secret_key = secret_key
|
|
76
|
+
self.base_url = base_url
|
|
77
|
+
self.timeout = timeout
|
|
78
|
+
|
|
79
|
+
self.payments = Payments(self)
|
|
80
|
+
self.payouts = Payouts(self)
|
|
81
|
+
self.crypto = Crypto(self)
|
|
82
|
+
self.refunds = Refunds(self)
|
|
83
|
+
self.disputes = Disputes(self)
|
|
84
|
+
|
|
85
|
+
@staticmethod
|
|
86
|
+
def verify_webhook_signature(payload: str, signature: str, secret: str, tolerance: int = 300) -> bool:
|
|
87
|
+
"""
|
|
88
|
+
Verifies that an incoming webhook was sent by AfconWave and checks for replay attacks.
|
|
89
|
+
|
|
90
|
+
:param payload: The raw request body string.
|
|
91
|
+
:param signature: The X-Afcon-Signature header.
|
|
92
|
+
:param secret: Your webhook secret.
|
|
93
|
+
:param tolerance: Maximum allowed age in seconds (default 300).
|
|
94
|
+
"""
|
|
95
|
+
# 1. Verify Signature
|
|
96
|
+
expected = hmac.new(
|
|
97
|
+
secret.encode(),
|
|
98
|
+
payload.encode(),
|
|
99
|
+
hashlib.sha256
|
|
100
|
+
).hexdigest()
|
|
101
|
+
|
|
102
|
+
if not hmac.compare_digest(expected, signature):
|
|
103
|
+
return False
|
|
104
|
+
|
|
105
|
+
# 2. Verify Timestamp (Replay Protection)
|
|
106
|
+
try:
|
|
107
|
+
data = json.loads(payload)
|
|
108
|
+
if 'timestamp' in data:
|
|
109
|
+
current_time = time.time() # seconds
|
|
110
|
+
webhook_time = data['timestamp'] / 1000.0 # convert ms to seconds
|
|
111
|
+
age = abs(current_time - webhook_time)
|
|
112
|
+
|
|
113
|
+
if age > tolerance:
|
|
114
|
+
return False
|
|
115
|
+
except:
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
return True
|
|
119
|
+
|
|
120
|
+
def request(self, method: str, path: str, data: dict = None, params: dict = None):
|
|
121
|
+
headers = {
|
|
122
|
+
'Authorization': f'Bearer {self.secret_key}',
|
|
123
|
+
'Content-Type': 'application/json',
|
|
124
|
+
'Accept': 'application/json'
|
|
125
|
+
}
|
|
126
|
+
url = f"{self.base_url}{path}"
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
response = requests.request(
|
|
130
|
+
method, url, headers=headers, json=data, params=params, timeout=self.timeout
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
res_data = response.json()
|
|
134
|
+
|
|
135
|
+
if not response.ok:
|
|
136
|
+
raise AfconWaveError(
|
|
137
|
+
message=res_data.get('error', response.reason),
|
|
138
|
+
status_code=response.status_code,
|
|
139
|
+
code=res_data.get('code')
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
return res_data.get('data', res_data)
|
|
143
|
+
|
|
144
|
+
except requests.exceptions.RequestException as e:
|
|
145
|
+
raise AfconWaveError(message=str(e))
|
|
146
|
+
|
|
147
|
+
# โโโ Top-level Convenience Methods (Matches README) โโโโโโโโโโโโโโโโโโโโโ
|
|
148
|
+
|
|
149
|
+
def create_payment(self, **kwargs):
|
|
150
|
+
return self.payments.create(**kwargs)
|
|
151
|
+
|
|
152
|
+
def retrieve_payment(self, payment_id: str):
|
|
153
|
+
return self.payments.retrieve(payment_id)
|
|
154
|
+
|
|
155
|
+
def list_payments(self, **kwargs):
|
|
156
|
+
return self.payments.list(**kwargs)
|
|
157
|
+
|
|
158
|
+
def create_payout(self, **kwargs):
|
|
159
|
+
return self.payouts.create(**kwargs)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: afconwave
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official AfconWave Python SDK
|
|
5
|
+
Author: AfconWave Team
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: requests>=2.25.0
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: classifier
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
Dynamic: requires-dist
|
|
15
|
+
Dynamic: summary
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.25.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
afconwave
|
afconwave-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="afconwave",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
description="Official AfconWave Python SDK",
|
|
7
|
+
author="AfconWave Team",
|
|
8
|
+
packages=find_packages(),
|
|
9
|
+
install_requires=[
|
|
10
|
+
"requests>=2.25.0",
|
|
11
|
+
],
|
|
12
|
+
classifiers=[
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"License :: OSI Approved :: MIT License",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
],
|
|
17
|
+
)
|