afconwave 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
afconwave/__init__.py
ADDED
|
@@ -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,6 @@
|
|
|
1
|
+
afconwave/__init__.py,sha256=CtJRXCdBkiA-spfRqiXjviA37vRJ3HzTwKd_uiCwXJo,5798
|
|
2
|
+
afconwave-0.1.0.dist-info/licenses/LICENSE,sha256=hln7B5etngKFHn0S0_YJtSfxPljtsihUfN5pl3Umft8,1066
|
|
3
|
+
afconwave-0.1.0.dist-info/METADATA,sha256=qhPksOsrPpKbRHNXRyQgngDNyrXmWtw2rCVvreC8SG4,413
|
|
4
|
+
afconwave-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
+
afconwave-0.1.0.dist-info/top_level.txt,sha256=VnOg6xsD2cmJEyqgBGEcmNk5xSFgWaFPptWeyyttziM,10
|
|
6
|
+
afconwave-0.1.0.dist-info/RECORD,,
|
|
@@ -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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
afconwave
|