edpay 1.6.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.
- edpay/__init__.py +32 -0
- edpay/client.py +122 -0
- edpay/contacts.py +102 -0
- edpay/exceptions.py +25 -0
- edpay/resources/customers.py +32 -0
- edpay/resources/fx.py +13 -0
- edpay/resources/invoices.py +37 -0
- edpay/resources/payments.py +63 -0
- edpay/resources/public.py +9 -0
- edpay/resources/subscriptions.py +29 -0
- edpay/resources/wallets.py +20 -0
- edpay/resources/webhooks.py +32 -0
- edpay/webhooks.py +92 -0
- edpay-1.6.2.dist-info/METADATA +192 -0
- edpay-1.6.2.dist-info/RECORD +17 -0
- edpay-1.6.2.dist-info/WHEEL +4 -0
- edpay-1.6.2.dist-info/licenses/LICENSE +21 -0
edpay/__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""EDPay Python SDK - Official payment library."""
|
|
2
|
+
|
|
3
|
+
from edpay.client import EDPayClient
|
|
4
|
+
from edpay.exceptions import EDPayException, SignatureVerificationException
|
|
5
|
+
from edpay.webhooks import verify_webhook_signature
|
|
6
|
+
from edpay.contacts import (
|
|
7
|
+
add_country_prefix,
|
|
8
|
+
format_phone_number,
|
|
9
|
+
normalize_phone_number,
|
|
10
|
+
phone_number_options_for_method,
|
|
11
|
+
remove_country_prefix,
|
|
12
|
+
validate_phone_number,
|
|
13
|
+
)
|
|
14
|
+
from edpay.webhooks import EDPayWebhookEvent, EDPayWebhookEventType, EDPayWebhookPaymentData, EDPayPaymentStatus
|
|
15
|
+
|
|
16
|
+
__version__ = "1.6.2"
|
|
17
|
+
__all__ = [
|
|
18
|
+
"EDPayClient",
|
|
19
|
+
"EDPayException",
|
|
20
|
+
"SignatureVerificationException",
|
|
21
|
+
"verify_webhook_signature",
|
|
22
|
+
"add_country_prefix",
|
|
23
|
+
"format_phone_number",
|
|
24
|
+
"normalize_phone_number",
|
|
25
|
+
"phone_number_options_for_method",
|
|
26
|
+
"remove_country_prefix",
|
|
27
|
+
"validate_phone_number",
|
|
28
|
+
"EDPayWebhookEvent",
|
|
29
|
+
"EDPayWebhookEventType",
|
|
30
|
+
"EDPayWebhookPaymentData",
|
|
31
|
+
"EDPayPaymentStatus",
|
|
32
|
+
]
|
edpay/client.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any, Dict, Optional
|
|
3
|
+
import urllib.request
|
|
4
|
+
import urllib.error
|
|
5
|
+
from urllib.parse import urlencode
|
|
6
|
+
|
|
7
|
+
from edpay.exceptions import EDPayException
|
|
8
|
+
from edpay.resources.payments import PaymentsResource
|
|
9
|
+
from edpay.resources.customers import CustomersResource
|
|
10
|
+
from edpay.resources.invoices import Invoices
|
|
11
|
+
from edpay.resources.subscriptions import Subscriptions
|
|
12
|
+
from edpay.resources.fx import FxResource
|
|
13
|
+
from edpay.resources.wallets import WalletsResource
|
|
14
|
+
from edpay.resources.webhooks import WebhooksResource
|
|
15
|
+
from edpay.resources.public import PublicResource
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class EDPayClient:
|
|
19
|
+
"""Official client for interacting with the EDPay API."""
|
|
20
|
+
|
|
21
|
+
DEFAULT_BASE_URL = "https://api-pay.edutecka.com"
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
public_key: str,
|
|
26
|
+
private_key: str,
|
|
27
|
+
base_url: Optional[str] = None,
|
|
28
|
+
timeout: float = 90.0,
|
|
29
|
+
):
|
|
30
|
+
public_key = public_key.strip() if isinstance(public_key, str) else ""
|
|
31
|
+
private_key = private_key.strip() if isinstance(private_key, str) else ""
|
|
32
|
+
public_mode = "test" if len(public_key) == 32 and public_key.startswith("pk_test_") else "live" if len(public_key) == 32 and public_key.startswith("pk_live_") else None
|
|
33
|
+
private_mode = "test" if len(private_key) == 72 and private_key.startswith("sk_test_") else "live" if len(private_key) == 72 and private_key.startswith("sk_live_") else None
|
|
34
|
+
if not public_mode or not all(char in "0123456789abcdefABCDEF" for char in public_key[8:]):
|
|
35
|
+
public_mode = None
|
|
36
|
+
if not private_mode or not all(char in "0123456789abcdefABCDEF" for char in private_key[8:]):
|
|
37
|
+
private_mode = None
|
|
38
|
+
if not public_mode or not private_mode:
|
|
39
|
+
raise ValueError("EDPayClient requires a valid public_key (pk_test_/pk_live_ plus 24 hex characters) and private_key (sk_test_/sk_live_ plus 64 hex characters).")
|
|
40
|
+
if public_mode != private_mode:
|
|
41
|
+
raise ValueError("EDPay public_key and private_key must use the same environment (test or live).")
|
|
42
|
+
|
|
43
|
+
self.public_key = public_key
|
|
44
|
+
self.private_key = private_key
|
|
45
|
+
self.timeout = timeout
|
|
46
|
+
self.base_url = base_url.rstrip("/") if base_url else self.DEFAULT_BASE_URL
|
|
47
|
+
|
|
48
|
+
# Resources
|
|
49
|
+
self.payments = PaymentsResource(self)
|
|
50
|
+
self.customers = CustomersResource(self)
|
|
51
|
+
self.invoices = Invoices(self)
|
|
52
|
+
self.subscriptions = Subscriptions(self)
|
|
53
|
+
self.fx = FxResource(self)
|
|
54
|
+
self.wallets = WalletsResource(self)
|
|
55
|
+
self.webhooks = WebhooksResource(self)
|
|
56
|
+
self.public = PublicResource(self)
|
|
57
|
+
|
|
58
|
+
def request(
|
|
59
|
+
self,
|
|
60
|
+
method: str,
|
|
61
|
+
endpoint: str,
|
|
62
|
+
json_data: Optional[Dict[str, Any]] = None,
|
|
63
|
+
headers: Optional[Dict[str, str]] = None,
|
|
64
|
+
*,
|
|
65
|
+
authenticated: bool = True,
|
|
66
|
+
data: Optional[Dict[str, Any]] = None,
|
|
67
|
+
params: Optional[Dict[str, Any]] = None,
|
|
68
|
+
idempotency_key: Optional[str] = None,
|
|
69
|
+
) -> Dict[str, Any]:
|
|
70
|
+
"""Execute an authenticated HTTP request to the EDPay API."""
|
|
71
|
+
if data is not None:
|
|
72
|
+
if json_data is not None:
|
|
73
|
+
raise ValueError("Pass either json_data or data, not both.")
|
|
74
|
+
json_data = data
|
|
75
|
+
url = f"{self.base_url}{endpoint}"
|
|
76
|
+
if params:
|
|
77
|
+
url += ("&" if "?" in url else "?") + urlencode(params, doseq=True)
|
|
78
|
+
req_headers = {
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
"Accept": "application/json",
|
|
81
|
+
"User-Agent": "EDPay-Python-SDK/1.6.2",
|
|
82
|
+
}
|
|
83
|
+
if authenticated:
|
|
84
|
+
req_headers["X-EDPay-Public-Key"] = self.public_key
|
|
85
|
+
req_headers["X-EDPay-Private-Key"] = self.private_key
|
|
86
|
+
if idempotency_key:
|
|
87
|
+
req_headers["Idempotency-Key"] = idempotency_key
|
|
88
|
+
if headers:
|
|
89
|
+
req_headers.update(headers)
|
|
90
|
+
|
|
91
|
+
body_bytes = None
|
|
92
|
+
if json_data is not None:
|
|
93
|
+
body_bytes = json.dumps(json_data).encode("utf-8")
|
|
94
|
+
|
|
95
|
+
req = urllib.request.Request(url, data=body_bytes, headers=req_headers, method=method)
|
|
96
|
+
|
|
97
|
+
try:
|
|
98
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as resp:
|
|
99
|
+
resp_bytes = resp.read()
|
|
100
|
+
if not resp_bytes:
|
|
101
|
+
return {}
|
|
102
|
+
return json.loads(resp_bytes.decode("utf-8"))
|
|
103
|
+
except urllib.error.HTTPError as exc:
|
|
104
|
+
err_body = exc.read().decode("utf-8")
|
|
105
|
+
try:
|
|
106
|
+
err_json = json.loads(err_body)
|
|
107
|
+
api_error = err_json.get("error") or {}
|
|
108
|
+
msg = api_error.get("message") if isinstance(api_error, dict) else api_error
|
|
109
|
+
msg = msg or err_json.get("message") or "Unknown EDPay error"
|
|
110
|
+
except Exception:
|
|
111
|
+
err_json = {"raw": err_body}
|
|
112
|
+
msg = f"HTTP {exc.code} error: {exc.reason}"
|
|
113
|
+
api_error = err_json.get("error") if isinstance(err_json, dict) else None
|
|
114
|
+
api_error = api_error if isinstance(api_error, dict) else {}
|
|
115
|
+
raise EDPayException(
|
|
116
|
+
msg, status_code=exc.code, response_data=err_json,
|
|
117
|
+
error_code=api_error.get("code"),
|
|
118
|
+
request_id=exc.headers.get("X-Request-Id") if exc.headers else None,
|
|
119
|
+
retry_after=exc.headers.get("Retry-After") if exc.headers else None,
|
|
120
|
+
) from exc
|
|
121
|
+
except urllib.error.URLError as exc:
|
|
122
|
+
raise EDPayException(f"Connection failed: {str(exc.reason)}", status_code=0) from exc
|
edpay/contacts.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""Phone number normalization and validation helpers."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _parse(value: str, options: Optional[Dict[str, Any]] = None) -> Tuple[str, str]:
|
|
7
|
+
config = options or {}
|
|
8
|
+
country_code = str(config.get("country_calling_code", "258"))
|
|
9
|
+
if country_code.startswith("+"):
|
|
10
|
+
country_code = country_code[1:]
|
|
11
|
+
national_length = int(config.get("national_length", 9))
|
|
12
|
+
if not country_code.isascii() or not country_code.isdigit() or not country_code or country_code.startswith("0") or len(country_code) > 3:
|
|
13
|
+
raise ValueError("country_calling_code must contain 1 to 3 digits and cannot start with 0.")
|
|
14
|
+
if national_length < 1 or len(country_code) + national_length > 15:
|
|
15
|
+
raise ValueError("national_length must fit within the E.164 limit of 15 digits.")
|
|
16
|
+
if not isinstance(value, str):
|
|
17
|
+
raise TypeError("Phone number must be a string.")
|
|
18
|
+
raw = value.strip()
|
|
19
|
+
if not raw or any(char not in "+0123456789 ().-" for char in raw):
|
|
20
|
+
raise ValueError("Phone number contains unsupported characters.")
|
|
21
|
+
if raw.count("(") != raw.count(")"):
|
|
22
|
+
raise ValueError("Phone number has unbalanced parentheses.")
|
|
23
|
+
digits = "".join(char for char in raw if char.isdigit())
|
|
24
|
+
international = raw.startswith("+")
|
|
25
|
+
if digits.startswith("00"):
|
|
26
|
+
digits, international = digits[2:], True
|
|
27
|
+
if not international and digits.startswith(country_code) and len(digits) > national_length:
|
|
28
|
+
international = True
|
|
29
|
+
if international:
|
|
30
|
+
if not digits.startswith(country_code):
|
|
31
|
+
raise ValueError("Phone number does not use the configured country calling code.")
|
|
32
|
+
digits = digits[len(country_code):]
|
|
33
|
+
if len(digits) != national_length:
|
|
34
|
+
raise ValueError("Phone number does not match the configured national length.")
|
|
35
|
+
prefixes = config.get("national_prefixes", [])
|
|
36
|
+
if not isinstance(prefixes, (list, tuple)) or any(
|
|
37
|
+
not isinstance(prefix, str) or not prefix.isascii() or not prefix.isdigit()
|
|
38
|
+
for prefix in prefixes
|
|
39
|
+
):
|
|
40
|
+
raise ValueError("national_prefixes must contain non-empty digit strings.")
|
|
41
|
+
if prefixes and not any(digits.startswith(prefix) for prefix in prefixes):
|
|
42
|
+
raise ValueError("Phone number does not match the configured national prefixes.")
|
|
43
|
+
return country_code, digits
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def normalize_phone_number(value: str, *, country_calling_code: str = "258", national_length: int = 9,
|
|
47
|
+
national_prefixes: Optional[List[str]] = None, output: str = "international") -> str:
|
|
48
|
+
country, national = _parse(value, {"country_calling_code": country_calling_code,
|
|
49
|
+
"national_length": national_length,
|
|
50
|
+
"national_prefixes": national_prefixes or []})
|
|
51
|
+
if output not in ("international", "country-code", "national"):
|
|
52
|
+
raise ValueError("output must be 'international', 'country-code', or 'national'.")
|
|
53
|
+
if output == "national":
|
|
54
|
+
return national
|
|
55
|
+
return (f"+{country}" if output == "international" else country) + national
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def phone_number_options_for_method(method: str) -> Optional[Dict[str, Any]]:
|
|
59
|
+
"""Return known phone rules; None means non-phone or unknown method."""
|
|
60
|
+
key = method.strip().lower().replace(" ", "").replace("_", "").replace("-", "")
|
|
61
|
+
if key == "emola":
|
|
62
|
+
return {"country_calling_code": "258", "national_length": 9, "national_prefixes": ["86", "87"], "output": "national"}
|
|
63
|
+
if key == "mpesa":
|
|
64
|
+
return {"country_calling_code": "258", "national_length": 9, "national_prefixes": ["84", "85"], "output": "country-code"}
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def add_country_prefix(value: str, **options: Any) -> str:
|
|
69
|
+
options["output"] = "international"
|
|
70
|
+
return normalize_phone_number(value, **options)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def remove_country_prefix(value: str, **options: Any) -> str:
|
|
74
|
+
options["output"] = "national"
|
|
75
|
+
return normalize_phone_number(value, **options)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def format_phone_number(value: str, *, country_calling_code: str = "258", national_length: int = 9,
|
|
79
|
+
national_prefixes: Optional[List[str]] = None, group_sizes: Optional[List[int]] = None) -> str:
|
|
80
|
+
country, national = _parse(value, {"country_calling_code": country_calling_code,
|
|
81
|
+
"national_length": national_length,
|
|
82
|
+
"national_prefixes": national_prefixes or []})
|
|
83
|
+
groups = group_sizes or ([2, 3, 4] if country == "258" and len(national) == 9 else [len(national)])
|
|
84
|
+
parts, offset = [], 0
|
|
85
|
+
for size in groups:
|
|
86
|
+
if not isinstance(size, int) or isinstance(size, bool) or size < 1:
|
|
87
|
+
raise ValueError("group_sizes must contain positive integers.")
|
|
88
|
+
if offset >= len(national):
|
|
89
|
+
break
|
|
90
|
+
parts.append(national[offset:offset + size])
|
|
91
|
+
offset += size
|
|
92
|
+
if offset < len(national):
|
|
93
|
+
parts.append(national[offset:])
|
|
94
|
+
return f"+{country} {' '.join(parts)}"
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def validate_phone_number(value: str, **options: Any) -> bool:
|
|
98
|
+
try:
|
|
99
|
+
_parse(value, {key: item for key, item in options.items() if key != "output" and key != "group_sizes"})
|
|
100
|
+
return options.get("output", "international") in ("international", "country-code", "national")
|
|
101
|
+
except (TypeError, ValueError):
|
|
102
|
+
return False
|
edpay/exceptions.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Exceptions for the EDPay Python SDK."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class EDPayException(Exception):
|
|
5
|
+
"""Base exception for EDPay API errors."""
|
|
6
|
+
|
|
7
|
+
def __init__(self, message: str, status_code: int = 400, response_data: dict = None,
|
|
8
|
+
error_code: str = None, request_id: str = None, retry_after: str = None):
|
|
9
|
+
super().__init__(message)
|
|
10
|
+
self.message = message
|
|
11
|
+
self.status_code = status_code
|
|
12
|
+
self.response_data = response_data or {}
|
|
13
|
+
self.error_code = error_code
|
|
14
|
+
self.request_id = request_id
|
|
15
|
+
self.retry_after = retry_after
|
|
16
|
+
|
|
17
|
+
def __str__(self):
|
|
18
|
+
return f"[EDPay Error {self.status_code}] {self.message}"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SignatureVerificationException(EDPayException):
|
|
22
|
+
"""Raised when an HMAC SHA-256 webhook signature is invalid."""
|
|
23
|
+
|
|
24
|
+
def __init__(self, message: str = "Invalid EDPay webhook signature"):
|
|
25
|
+
super().__init__(message, status_code=400)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
from urllib.parse import quote
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class CustomersResource:
|
|
6
|
+
def __init__(self, client):
|
|
7
|
+
self._client = client
|
|
8
|
+
|
|
9
|
+
def create(
|
|
10
|
+
self,
|
|
11
|
+
name: str,
|
|
12
|
+
email: Optional[str] = None,
|
|
13
|
+
*,
|
|
14
|
+
idempotency_key: str,
|
|
15
|
+
) -> Dict[str, Any]:
|
|
16
|
+
"""Create a customer in the EDPay system."""
|
|
17
|
+
payload: Dict[str, Any] = {
|
|
18
|
+
"name": name,
|
|
19
|
+
"email": email,
|
|
20
|
+
}
|
|
21
|
+
return self._client.request("POST", "/v1/customers", json_data=payload, idempotency_key=idempotency_key)
|
|
22
|
+
|
|
23
|
+
def list(self) -> Dict[str, Any]:
|
|
24
|
+
return self._client.request("GET", "/v1/customers")
|
|
25
|
+
|
|
26
|
+
def retrieve(self, customer_id: str) -> Dict[str, Any]:
|
|
27
|
+
"""Retrieve a customer by ID."""
|
|
28
|
+
return self._client.request("GET", f"/v1/customers/{quote(customer_id, safe='')}")
|
|
29
|
+
|
|
30
|
+
def update(self, customer_id: str, *, idempotency_key: str, **fields: Any) -> Dict[str, Any]:
|
|
31
|
+
"""Patch customer name/email; an idempotency key is mandatory."""
|
|
32
|
+
return self._client.request("PATCH", f"/v1/customers/{quote(customer_id, safe='')}", json_data=fields, idempotency_key=idempotency_key)
|
edpay/resources/fx.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from typing import Any, Dict
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class FxResource:
|
|
5
|
+
def __init__(self, client: Any) -> None:
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
def quote(self, from_currency: str, to_currency: str, amount_minor: int) -> Dict[str, Any]:
|
|
9
|
+
return self._client.request(
|
|
10
|
+
"GET",
|
|
11
|
+
"/v1/fx/quote",
|
|
12
|
+
params={"from_currency": from_currency, "to_currency": to_currency, "amount_minor": amount_minor},
|
|
13
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
from urllib.parse import quote
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Invoices:
|
|
6
|
+
"""Resource for creating, retrieving, and finalizing invoices."""
|
|
7
|
+
|
|
8
|
+
def __init__(self, client: Any) -> None:
|
|
9
|
+
self._client = client
|
|
10
|
+
|
|
11
|
+
def create(
|
|
12
|
+
self,
|
|
13
|
+
params: Dict[str, Any],
|
|
14
|
+
idempotency_key: str,
|
|
15
|
+
) -> Dict[str, Any]:
|
|
16
|
+
"""Create a commercial invoice with items and due dates."""
|
|
17
|
+
return self._client.request("POST", "/v1/invoices", data=params, idempotency_key=idempotency_key)
|
|
18
|
+
|
|
19
|
+
def get(self, invoice_id: str) -> Dict[str, Any]:
|
|
20
|
+
"""Retrieve invoice data by ID."""
|
|
21
|
+
return self._client.request("GET", f"/v1/invoices/{quote(invoice_id, safe='')}")
|
|
22
|
+
|
|
23
|
+
def list(self, limit: Optional[int] = None) -> Dict[str, Any]:
|
|
24
|
+
"""List invoices, optionally limiting the number returned."""
|
|
25
|
+
return self._client.request("GET", "/v1/invoices", params={"limit": limit} if limit is not None else None)
|
|
26
|
+
|
|
27
|
+
def finalize(
|
|
28
|
+
self,
|
|
29
|
+
invoice_id: str,
|
|
30
|
+
idempotency_key: Optional[str] = None,
|
|
31
|
+
) -> Dict[str, Any]:
|
|
32
|
+
"""Finalize and issue the invoice, generating the checkout URL."""
|
|
33
|
+
return self._client.request("POST", f"/v1/invoices/{quote(invoice_id, safe='')}/finalize", idempotency_key=idempotency_key)
|
|
34
|
+
|
|
35
|
+
def void(self, invoice_id: str) -> Dict[str, Any]:
|
|
36
|
+
"""Void an issued invoice."""
|
|
37
|
+
return self._client.request("POST", f"/v1/invoices/{quote(invoice_id, safe='')}/void")
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
from urllib.parse import quote
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class PaymentsResource:
|
|
6
|
+
def __init__(self, client):
|
|
7
|
+
self._client = client
|
|
8
|
+
|
|
9
|
+
def create(self, amount_minor: int, currency: str, customer_id: Optional[str] = None,
|
|
10
|
+
reference: Optional[str] = None, description: Optional[str] = None,
|
|
11
|
+
*, idempotency_key: str) -> Dict[str, Any]:
|
|
12
|
+
"""Create the payment parent. Choose a checkout mode afterwards."""
|
|
13
|
+
payload: Dict[str, Any] = {"amount_minor": amount_minor, "currency": currency}
|
|
14
|
+
if customer_id is not None: payload["customer_id"] = customer_id
|
|
15
|
+
if reference is not None: payload["reference"] = reference
|
|
16
|
+
if description is not None: payload["description"] = description
|
|
17
|
+
return self._client.request("POST", "/v1/payments", json_data=payload, idempotency_key=idempotency_key)
|
|
18
|
+
|
|
19
|
+
def private_checkout(self, payment_id: str, method: str, phone: Optional[str] = None,
|
|
20
|
+
channel: Optional[Dict[str, Any]] = None, *, idempotency_key: str) -> Dict[str, Any]:
|
|
21
|
+
payload: Dict[str, Any] = {"method": method}
|
|
22
|
+
if phone is not None: payload["phone"] = phone
|
|
23
|
+
if channel is not None: payload["channel"] = channel
|
|
24
|
+
return self._client.request("POST", f"/v1/payments/{quote(payment_id, safe='')}/private-checkout", json_data=payload, idempotency_key=idempotency_key)
|
|
25
|
+
|
|
26
|
+
def public_checkout(self, payment_id: str, embed_origin: Optional[str] = None,
|
|
27
|
+
*, idempotency_key: str) -> Dict[str, Any]:
|
|
28
|
+
payload = {"embed_origin": embed_origin} if embed_origin else {}
|
|
29
|
+
return self._client.request("POST", f"/v1/payments/{quote(payment_id, safe='')}/public-checkout", json_data=payload, idempotency_key=idempotency_key)
|
|
30
|
+
|
|
31
|
+
def link_checkout(self, payment_id: str, expires_at: Optional[str] = None,
|
|
32
|
+
*, idempotency_key: str) -> Dict[str, Any]:
|
|
33
|
+
payload = {"expires_at": expires_at} if expires_at else {}
|
|
34
|
+
return self._client.request("POST", f"/v1/payments/{quote(payment_id, safe='')}/link-checkout", json_data=payload, idempotency_key=idempotency_key)
|
|
35
|
+
|
|
36
|
+
def list_checkouts(self, payment_id: str) -> Dict[str, Any]:
|
|
37
|
+
"""List checkout executions with their mode and sessions with no submission."""
|
|
38
|
+
return self._client.request("GET", f"/v1/payments/{quote(payment_id, safe='')}/checkouts")
|
|
39
|
+
|
|
40
|
+
def get_checkout(self, token: str) -> Dict[str, Any]:
|
|
41
|
+
return self._client.request("GET", f"/v1/payments/checkouts/{quote(token, safe='')}", authenticated=False)
|
|
42
|
+
|
|
43
|
+
def submit_checkout_payment(self, token: str, method: str, phone: Optional[str] = None,
|
|
44
|
+
channel: Optional[Dict[str, Any]] = None, *, idempotency_key: str) -> Dict[str, Any]:
|
|
45
|
+
payload: Dict[str, Any] = {"method": method}
|
|
46
|
+
if phone is not None: payload["phone"] = phone
|
|
47
|
+
if channel is not None: payload["channel"] = channel
|
|
48
|
+
return self._client.request("POST", f"/v1/payments/checkouts/{quote(token, safe='')}/payment", json_data=payload, idempotency_key=idempotency_key, authenticated=False)
|
|
49
|
+
|
|
50
|
+
def retrieve_checkout_payment(self, token: str) -> Dict[str, Any]:
|
|
51
|
+
return self._client.request("GET", f"/v1/payments/checkouts/{quote(token, safe='')}/payment", authenticated=False)
|
|
52
|
+
|
|
53
|
+
def frame_policy(self, token: str) -> Dict[str, Any]:
|
|
54
|
+
return self._client.request("GET", f"/v1/payments/checkouts/{quote(token, safe='')}/frame-policy", authenticated=False)
|
|
55
|
+
|
|
56
|
+
def list(self, limit: int = 50) -> Dict[str, Any]:
|
|
57
|
+
return self._client.request("GET", "/v1/payments", params={"limit": limit})
|
|
58
|
+
|
|
59
|
+
def retrieve(self, payment_id: str) -> Dict[str, Any]:
|
|
60
|
+
return self._client.request("GET", f"/v1/payments/{quote(payment_id, safe='')}")
|
|
61
|
+
|
|
62
|
+
def events(self, payment_id: str) -> Dict[str, Any]:
|
|
63
|
+
return self._client.request("GET", f"/v1/payments/{quote(payment_id, safe='')}/events")
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from typing import Any, Dict
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class PublicResource:
|
|
5
|
+
def __init__(self, client: Any) -> None:
|
|
6
|
+
self._client = client
|
|
7
|
+
|
|
8
|
+
def list_payment_methods(self) -> Dict[str, Any]:
|
|
9
|
+
return self._client.request("GET", "/v1/public/payment-methods", authenticated=False)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
from urllib.parse import quote
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Subscriptions:
|
|
6
|
+
"""Resource for creating and managing recurring billing plans / subscriptions."""
|
|
7
|
+
|
|
8
|
+
def __init__(self, client: Any) -> None:
|
|
9
|
+
self._client = client
|
|
10
|
+
|
|
11
|
+
def create(
|
|
12
|
+
self,
|
|
13
|
+
params: Dict[str, Any],
|
|
14
|
+
idempotency_key: str,
|
|
15
|
+
) -> Dict[str, Any]:
|
|
16
|
+
"""Create a recurring subscription series (invoice series)."""
|
|
17
|
+
return self._client.request("POST", "/v1/invoices/series", data=params, idempotency_key=idempotency_key)
|
|
18
|
+
|
|
19
|
+
def list(self, limit: Optional[int] = None) -> Dict[str, Any]:
|
|
20
|
+
"""List invoice series, optionally limiting the number returned."""
|
|
21
|
+
return self._client.request("GET", "/v1/invoices/series", params={"limit": limit} if limit is not None else None)
|
|
22
|
+
|
|
23
|
+
def pause(self, series_id: str) -> Dict[str, Any]:
|
|
24
|
+
"""Pause a recurring subscription."""
|
|
25
|
+
return self._client.request("POST", f"/v1/invoices/series/{quote(series_id, safe='')}/pause")
|
|
26
|
+
|
|
27
|
+
def resume(self, series_id: str) -> Dict[str, Any]:
|
|
28
|
+
"""Resume a paused subscription."""
|
|
29
|
+
return self._client.request("POST", f"/v1/invoices/series/{quote(series_id, safe='')}/resume")
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
from urllib.parse import quote
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class WalletsResource:
|
|
6
|
+
def __init__(self, client: Any) -> None:
|
|
7
|
+
self._client = client
|
|
8
|
+
|
|
9
|
+
def list(self) -> Dict[str, Any]:
|
|
10
|
+
return self._client.request("GET", "/v1/wallets")
|
|
11
|
+
|
|
12
|
+
def retrieve(self, wallet_id: str) -> Dict[str, Any]:
|
|
13
|
+
return self._client.request("GET", f"/v1/wallets/{quote(wallet_id, safe='')}")
|
|
14
|
+
|
|
15
|
+
def balance(self, wallet_id: str) -> Dict[str, Any]:
|
|
16
|
+
return self._client.request("GET", f"/v1/wallets/{quote(wallet_id, safe='')}/balance")
|
|
17
|
+
|
|
18
|
+
def entries(self, wallet_id: str, cursor: Optional[str] = None, limit: Optional[int] = None) -> Dict[str, Any]:
|
|
19
|
+
params = {key: value for key, value in {"cursor": cursor, "limit": limit}.items() if value is not None}
|
|
20
|
+
return self._client.request("GET", f"/v1/wallets/{quote(wallet_id, safe='')}/entries", params=params)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
from urllib.parse import quote
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class WebhooksResource:
|
|
6
|
+
def __init__(self, client: Any) -> None:
|
|
7
|
+
self._client = client
|
|
8
|
+
|
|
9
|
+
def list_endpoints(self) -> Dict[str, Any]:
|
|
10
|
+
return self._client.request("GET", "/v1/webhooks/endpoints")
|
|
11
|
+
|
|
12
|
+
def create_endpoint(self, payload: Dict[str, Any], idempotency_key: str) -> Dict[str, Any]:
|
|
13
|
+
return self._client.request("POST", "/v1/webhooks/endpoints", json_data=payload, idempotency_key=idempotency_key)
|
|
14
|
+
|
|
15
|
+
def update_endpoint(self, endpoint_id: str, payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
16
|
+
return self._client.request("PATCH", f"/v1/webhooks/endpoints/{quote(endpoint_id, safe='')}", json_data=payload)
|
|
17
|
+
|
|
18
|
+
def disable_endpoint(self, endpoint_id: str) -> Dict[str, Any]:
|
|
19
|
+
return self._client.request("POST", f"/v1/webhooks/endpoints/{quote(endpoint_id, safe='')}/disable")
|
|
20
|
+
|
|
21
|
+
def delete_endpoint(self, endpoint_id: str) -> Dict[str, Any]:
|
|
22
|
+
return self._client.request("DELETE", f"/v1/webhooks/endpoints/{quote(endpoint_id, safe='')}")
|
|
23
|
+
|
|
24
|
+
def list_deliveries(self, limit: Optional[int] = None) -> Dict[str, Any]:
|
|
25
|
+
params = {"limit": limit} if limit is not None else None
|
|
26
|
+
return self._client.request("GET", "/v1/webhooks/deliveries", params=params)
|
|
27
|
+
|
|
28
|
+
def retrieve_delivery(self, delivery_id: str) -> Dict[str, Any]:
|
|
29
|
+
return self._client.request("GET", f"/v1/webhooks/deliveries/{quote(delivery_id, safe='')}")
|
|
30
|
+
|
|
31
|
+
def retry_delivery(self, delivery_id: str) -> Dict[str, Any]:
|
|
32
|
+
return self._client.request("POST", f"/v1/webhooks/deliveries/{quote(delivery_id, safe='')}/retry")
|
edpay/webhooks.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Security utilities for verifying EDPay webhook signatures."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import hmac
|
|
5
|
+
import re
|
|
6
|
+
import time
|
|
7
|
+
from typing import Literal, Optional, TypedDict
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
EDPayWebhookEventType = Literal[
|
|
11
|
+
"payment.created", "payment.updated", "payment.succeeded",
|
|
12
|
+
"payment.failed", "payment.cancelled", "payment.reconciliation_required",
|
|
13
|
+
]
|
|
14
|
+
EDPayPaymentStatus = Literal["pending", "processing", "unknown", "succeeded", "failed", "cancelled"]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class EDPayWebhookPaymentData(TypedDict, total=False):
|
|
18
|
+
"""Sanitized payment data delivered in a payment webhook event."""
|
|
19
|
+
object: Literal["payment"]
|
|
20
|
+
id: str
|
|
21
|
+
reference: str
|
|
22
|
+
payment_link_id: Optional[str]
|
|
23
|
+
trans_id: str
|
|
24
|
+
method: str
|
|
25
|
+
status: EDPayPaymentStatus
|
|
26
|
+
amount_minor: int
|
|
27
|
+
currency: Literal["MZN", "USD", "EUR"]
|
|
28
|
+
platform_fee_minor: int
|
|
29
|
+
receiver_net_minor: int
|
|
30
|
+
reconciliation_status: Literal["manual_review"]
|
|
31
|
+
reconciliation_code: str
|
|
32
|
+
created_at: str
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class EDPayWebhookEvent(TypedDict, total=False):
|
|
36
|
+
"""Verified webhook event envelope; verify signatures before parsing JSON."""
|
|
37
|
+
id: str
|
|
38
|
+
object: Literal["event"]
|
|
39
|
+
type: EDPayWebhookEventType
|
|
40
|
+
created_at: str
|
|
41
|
+
data: EDPayWebhookPaymentData
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def verify_webhook_signature(
|
|
45
|
+
payload: bytes,
|
|
46
|
+
signature_header: str,
|
|
47
|
+
secret: str,
|
|
48
|
+
*,
|
|
49
|
+
tolerance_seconds: int = 300,
|
|
50
|
+
now: Optional[int] = None,
|
|
51
|
+
) -> bool:
|
|
52
|
+
"""Verify a ``Payment-Signature`` header over the unmodified request body.
|
|
53
|
+
|
|
54
|
+
EDPay signs ``timestamp + b"." + payload`` with HMAC-SHA256. Timestamps
|
|
55
|
+
outside the default five-minute window are rejected to limit replay attacks.
|
|
56
|
+
``now`` is injectable for deterministic verification.
|
|
57
|
+
"""
|
|
58
|
+
if not payload or not signature_header or not secret or tolerance_seconds < 0:
|
|
59
|
+
return False
|
|
60
|
+
|
|
61
|
+
timestamp = None
|
|
62
|
+
signature = None
|
|
63
|
+
for field in signature_header.split(","):
|
|
64
|
+
key, separator, value = field.strip().partition("=")
|
|
65
|
+
if not separator:
|
|
66
|
+
continue
|
|
67
|
+
if key == "t":
|
|
68
|
+
if timestamp is not None:
|
|
69
|
+
return False
|
|
70
|
+
timestamp = value.strip()
|
|
71
|
+
elif key == "v1":
|
|
72
|
+
if signature is not None:
|
|
73
|
+
return False
|
|
74
|
+
signature = value.strip()
|
|
75
|
+
|
|
76
|
+
if not timestamp or not re.fullmatch(r"\d+", timestamp):
|
|
77
|
+
return False
|
|
78
|
+
if not signature or not re.fullmatch(r"[0-9a-fA-F]{64}", signature):
|
|
79
|
+
return False
|
|
80
|
+
|
|
81
|
+
signed_at = int(timestamp)
|
|
82
|
+
current_time = int(time.time()) if now is None else now
|
|
83
|
+
if abs(current_time - signed_at) > tolerance_seconds:
|
|
84
|
+
return False
|
|
85
|
+
|
|
86
|
+
signed_payload = timestamp.encode("ascii") + b"." + payload
|
|
87
|
+
expected = hmac.new(secret.encode("utf-8"), signed_payload, hashlib.sha256).digest()
|
|
88
|
+
try:
|
|
89
|
+
received = bytes.fromhex(signature)
|
|
90
|
+
except ValueError:
|
|
91
|
+
return False
|
|
92
|
+
return hmac.compare_digest(expected, received)
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: edpay
|
|
3
|
+
Version: 1.6.2
|
|
4
|
+
Summary: Official EDPay SDK for Python - multi-gateway payment orchestration platform
|
|
5
|
+
Author-email: EDPay Engineering <dev@edutecka.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Requires-Dist: httpx>=0.25.0
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest>=7.4.0; extra == 'dev'
|
|
21
|
+
Requires-Dist: respx>=0.20.0; extra == 'dev'
|
|
22
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# EDPay Python SDK
|
|
26
|
+
|
|
27
|
+
Python client for sending server-to-server requests to the EDPay API.
|
|
28
|
+
|
|
29
|
+
## Requirements
|
|
30
|
+
|
|
31
|
+
- Python 3.9 or later
|
|
32
|
+
- pip
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
Install the SDK:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
python -m pip install "edpay==1.6.2"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Create a payment
|
|
43
|
+
|
|
44
|
+
Every partner API request requires both `EDPAY_PUBLIC_KEY` (`pk_test_` or `pk_live_`) and `EDPAY_PRIVATE_KEY` (`sk_test_` or `sk_live_`) from the same environment. The SDK rejects missing, blank, or mismatched key pairs when creating the client. Public catalog requests and buyer-facing checkout requests authenticated by a checkout token do not use the partner key pair; never put the private key in browser code. The matching key prefixes select test or live access; both use the single default host, https://api-pay.edutecka.com.
|
|
45
|
+
|
|
46
|
+
Create API keys in the EDPay merchant dashboard and keep the private key on your server. The SDK authenticates partner API requests using the `X-EDPay-Public-Key` and `X-EDPay-Private-Key` headers.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
export EDPAY_PUBLIC_KEY=pk_test_...
|
|
50
|
+
export EDPAY_PRIVATE_KEY=sk_test_...
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import os
|
|
55
|
+
from edpay import EDPayClient, normalize_phone_number, phone_number_options_for_method
|
|
56
|
+
|
|
57
|
+
client = EDPayClient(
|
|
58
|
+
public_key=os.environ["EDPAY_PUBLIC_KEY"],
|
|
59
|
+
private_key=os.environ["EDPAY_PRIVATE_KEY"],
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
payment = client.payments.create(
|
|
63
|
+
amount_minor=50000, # 500.00 MZN
|
|
64
|
+
currency="MZN",
|
|
65
|
+
reference="ORDER-10492",
|
|
66
|
+
description="Example order",
|
|
67
|
+
idempotency_key="ORDER-10492-CREATE-1",
|
|
68
|
+
)
|
|
69
|
+
print(payment)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`amount_minor` is the amount in minor currency units. `payments.create` creates only the parent payment. Choose a dynamic method afterward through `private_checkout`, or let the buyer choose in hosted or link checkout. Method fields such as `phone` and `channel` belong to that child operation and depend on the selected method. Use an idempotency key when creating the parent. API errors are raised as `EDPayException` with the HTTP status and response data.
|
|
73
|
+
|
|
74
|
+
Populate a payment-method selector from the public catalog and use the active catalog codes as the buyer's available choices; the SDK does not hard-code gateway identifiers:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
catalog = client.public.list_payment_methods()
|
|
78
|
+
available_methods = [method for method in catalog["data"]["payment_methods"] if method["enabled"]]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Choose a checkout mode for one payment
|
|
82
|
+
|
|
83
|
+
`payments.create` creates the parent record only. Save its ID and reference with your order, then choose the integration with a child function. The same payment can use private API processing, hosted checkout, or a shareable link checkout. The payment ID and reference stay unchanged.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
payment = client.payments.create(
|
|
87
|
+
amount_minor=50000,
|
|
88
|
+
currency="MZN",
|
|
89
|
+
reference="ORDER-10492",
|
|
90
|
+
idempotency_key="ORDER-10492-CREATE",
|
|
91
|
+
)
|
|
92
|
+
payment_id = payment["data"]["id"]
|
|
93
|
+
|
|
94
|
+
# Choose a mode for this parent payment:
|
|
95
|
+
checkout = client.payments.public_checkout(
|
|
96
|
+
payment_id,
|
|
97
|
+
idempotency_key="ORDER-10492-PUBLIC-CHECKOUT",
|
|
98
|
+
)
|
|
99
|
+
# Or call private_checkout(payment_id, method=..., ...) or link_checkout(payment_id, ...).
|
|
100
|
+
# Pass checkout["data"]["token"] to the buyer-facing page; never expose partner keys.
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`private_checkout` submits a method from your backend. `public_checkout` returns an opaque token for hosted checkout. `link_checkout` returns a shareable token for this same payment. `list_checkouts(payment_id)` lists private executions, public/link executions, and sessions where no method was submitted; each execution keeps its originating checkout mode. `retrieve(payment_id)` fetches status from the API; use verified webhooks for asynchronous updates.
|
|
104
|
+
|
|
105
|
+
### Synchronous PIN confirmation
|
|
106
|
+
|
|
107
|
+
For a method that uses a PIN prompt (currently M-Pesa and e-Mola), the provider's 60-second PIN window starts only after the Master dispatches the charge. The API's 80-second `private-checkout` deadline starts when it receives the request, so validation, queueing, and dispatch latency already consume that time. Other gateway methods can use different authorization flows and timings. The API returns HTTP `200` with a terminal attempt or `202` if the result is still pending, processing, or unknown when the deadline expires. The SDK transport timeout defaults to 90 seconds; keep a custom timeout above 80 seconds. If the caller disconnects, durable processing continues; configured webhook endpoints receive the event when the payment result is confirmed. You can also query `GET /v1/payments/{id}` and `GET /v1/payments/{id}/checkouts`. Do not resubmit while the attempt is pending or unknown.
|
|
108
|
+
|
|
109
|
+
## Function reference
|
|
110
|
+
|
|
111
|
+
Each row tells you what the call does and when to use it. Partner calls use the API key pair; public catalog and buyer checkout calls do not. Supply a stable `Idempotency-Key` for writes where required.
|
|
112
|
+
|
|
113
|
+
| Resource | Function | Endpoint | What it does / when to use it |
|
|
114
|
+
|---|---|---|---|
|
|
115
|
+
| Payments | `payments.create` | `POST /v1/payments` | Creates the parent payment only. Save its ID and reference, then choose a checkout mode. |
|
|
116
|
+
| Payments | `payments.private_checkout` | `POST /v1/payments/{id}/private-checkout` | Submits a selected method from your server for the existing payment. Use when your backend controls the interface. |
|
|
117
|
+
| Payments | `payments.public_checkout` | `POST /v1/payments/{id}/public-checkout` | Creates an opaque token for EDPay-hosted checkout on the existing payment. |
|
|
118
|
+
| Payments | `payments.link_checkout` | `POST /v1/payments/{id}/link-checkout` | Creates a shareable buyer token for the existing payment; it does not create another payment. |
|
|
119
|
+
| Payments | `payments.list_checkouts` | `GET /v1/payments/{id}/checkouts` | Lists executions with their checkout mode and sessions where no method was submitted. |
|
|
120
|
+
| Payments | `payments.retrieve` | `GET /v1/payments/{id}` | Retrieves remote payment status. |
|
|
121
|
+
| Payments | `payments.events` | `GET /v1/payments/{id}/events` | Reads recorded payment status changes. |
|
|
122
|
+
| Payments | `payments.list` | `GET /v1/payments` | Lists account payments for reconciliation or history. |
|
|
123
|
+
| Hosted checkout | `payments.get_checkout` | `GET /v1/payments/checkouts/{token}` | Loads the buyer-facing hosted or link checkout with its opaque token. |
|
|
124
|
+
| Hosted checkout | `payments.submit_checkout_payment` | `POST /v1/payments/checkouts/{token}/payment` | Submits the buyer-selected method and required method fields with an idempotency key. |
|
|
125
|
+
| Hosted checkout | `payments.retrieve_checkout_payment` | `GET /v1/payments/checkouts/{token}/payment` | Reads the parent payment status without exposing its ID to the buyer. |
|
|
126
|
+
| Hosted checkout | `payments.frame_policy` | `GET /v1/payments/checkouts/{token}/frame-policy` | Checks whether the hosted checkout can be embedded. |
|
|
127
|
+
| Customers | `customers.create` | `POST /v1/customers` | Creates a customer record for the authenticated account. Save customer details before associating them with payments or invoices. |
|
|
128
|
+
| Customers | `customers.list` | `GET /v1/customers` | Lists customers in the current account and environment. Build a customer picker or reconcile customer records. |
|
|
129
|
+
| Customers | `customers.retrieve` | `GET /v1/customers/{id}` | Reads one customer record. Load a customer's saved details by ID. |
|
|
130
|
+
| Customers | `customers.update` | `PATCH /v1/customers/{id}` | Updates the supplied customer fields. Correct or refresh a customer's details; use a stable idempotency key where required. |
|
|
131
|
+
| Invoices | `invoices.create` | `POST /v1/invoices` | Creates a draft invoice with its customer and line items. Prepare an invoice before issuing it to the customer. |
|
|
132
|
+
| Invoices | `invoices.list` | `GET /v1/invoices` | Lists invoices, optionally limited to a page size. Show or reconcile invoices for the account. |
|
|
133
|
+
| Invoices | `invoices.get` | `GET /v1/invoices/{id}` | Reads one invoice and its current state. Load invoice details or check its lifecycle. |
|
|
134
|
+
| Invoices | `invoices.finalize` | `POST /v1/invoices/{id}/finalize` | Issues the draft invoice and makes it available for payment. The invoice is complete and ready to send to the customer. |
|
|
135
|
+
| Invoices | `invoices.void` | `POST /v1/invoices/{id}/void` | Voids an invoice that should no longer be payable. Cancel an issued invoice according to its allowed state transitions. |
|
|
136
|
+
| Invoice series | `subscriptions.create` | `POST /v1/invoices/series` | Creates a schedule that issues invoices on the configured interval. Bill a customer repeatedly using a defined start date, interval, and due period. |
|
|
137
|
+
| Invoice series | `subscriptions.list` | `GET /v1/invoices/series` | Lists invoice series; there is no series-detail endpoint in this API version. Review recurring schedules for the account. |
|
|
138
|
+
| Invoice series | `subscriptions.pause` | `POST /v1/invoices/series/{id}/pause` | Pauses future invoice generation for a series. Temporarily stop recurring billing without deleting the schedule. |
|
|
139
|
+
| Invoice series | `subscriptions.resume` | `POST /v1/invoices/series/{id}/resume` | Resumes invoice generation for a paused series. Restart recurring billing after the pause condition has ended. |
|
|
140
|
+
| FX quotes | `fx.quote` | `GET /v1/fx/quote` | Returns an indicative conversion quote for an amount and currency pair. Display a conversion estimate before creating a payment. A quote is not a settlement guarantee. |
|
|
141
|
+
| Wallets | `wallets.list` | `GET /v1/wallets` | Lists wallets available to the authenticated account and environment. Choose a wallet before reading its balance or entries. |
|
|
142
|
+
| Wallets | `wallets.retrieve` | `GET /v1/wallets/{id}` | Reads one wallet's details. Load the wallet metadata for an account view. |
|
|
143
|
+
| Wallets | `wallets.balance` | `GET /v1/wallets/{id}/balance` | Reads the wallet's current balance. Show the available or pending balance for a wallet. |
|
|
144
|
+
| Wallets | `wallets.entries` | `GET /v1/wallets/{id}/entries` | Lists ledger entries with cursor pagination. Show a transaction statement; pass the returned cursor for the next page. |
|
|
145
|
+
| Webhooks | `webhooks.list_endpoints` | `GET /v1/webhooks/endpoints` | Lists configured webhook destinations. Review which event destinations are active. |
|
|
146
|
+
| Webhooks | `webhooks.create_endpoint` | `POST /v1/webhooks/endpoints` | Registers an HTTPS receiver and selected event types. The signing secret is shown only at creation. Connect your server to receive payment lifecycle events; store the returned secret securely. |
|
|
147
|
+
| Webhooks | `webhooks.update_endpoint` | `PATCH /v1/webhooks/endpoints/{id}` | Updates a destination's URL or subscribed event types. Change a receiver without creating a second endpoint. |
|
|
148
|
+
| Webhooks | `webhooks.disable_endpoint` | `POST /v1/webhooks/endpoints/{id}/disable` | Stops future deliveries to an endpoint while retaining its record. Temporarily stop a destination while investigating or migrating it. |
|
|
149
|
+
| Webhooks | `webhooks.delete_endpoint` | `DELETE /v1/webhooks/endpoints/{id}` | Removes a webhook endpoint. Permanently remove a destination that is no longer used. |
|
|
150
|
+
| Webhooks | `webhooks.list_deliveries` | `GET /v1/webhooks/deliveries` | Lists delivery attempts and their summary states. Monitor failed, pending, or completed event deliveries. |
|
|
151
|
+
| Webhooks | `webhooks.retrieve_delivery` | `GET /v1/webhooks/deliveries/{id}` | Reads one delivery's status and attempt metadata. Inspect one delivery before deciding whether to retry it. |
|
|
152
|
+
| Webhooks | `webhooks.retry_delivery` | `POST /v1/webhooks/deliveries/{id}/retry` | Queues a retry for an eligible failed delivery. Retry after fixing the receiver; the endpoint must be active. |
|
|
153
|
+
| Public catalog and optional support chat | `public.list_payment_methods` | `GET /v1/public/payment-methods` | Returns active payment methods and their public requirements without partner keys. Build a method selector and validate the selected method's required fields. |
|
|
154
|
+
| Contact helpers | `normalize_phone_number` | `Local helper` | Removes display punctuation and returns the phone value in the configured national or international form. Prepare a phone value before validating or sending it to a method that requires one. |
|
|
155
|
+
| Contact helpers | `format_phone_number` | `Local helper` | Formats a valid phone number for display; it does not change the API payload automatically. Show a readable phone number in a form or confirmation screen. |
|
|
156
|
+
| Contact helpers | `add_country_prefix` | `Local helper` | Adds the configured country calling code to a national number. An integration needs the international form, such as 258 plus national digits. |
|
|
157
|
+
| Contact helpers | `remove_country_prefix` | `Local helper` | Removes the configured country calling code and returns national digits. A selected method expects the national number without a country code. |
|
|
158
|
+
| Contact helpers | `validate_phone_number` | `Local helper` | Checks length, allowed characters, country code, and configured prefixes; returns true or false. Reject invalid input before calling the API. It does not replace server-side validation. |
|
|
159
|
+
| Contact helpers | `phone_number_options_for_method` | `Local helper` | Returns known contact rules for the selected method, or None when no preset exists. Load rules before validating a phone; configure rules from the live catalog for other phone methods. |
|
|
160
|
+
| Webhook signature verification | `verify_webhook_signature` | `Local helper` | Checks the Payment-Signature HMAC and timestamp against the unmodified request body. Verify the signature before parsing or acting on an incoming webhook. Use the raw bytes and keep the secret server-side. |
|
|
161
|
+
| Client utilities | `client.request` | `Raw API request` | Sends a request to an API path without a dedicated resource wrapper. The authenticated argument controls whether partner key headers are sent. Use only for a supported endpoint that has no SDK method; keep private keys on the server and apply the endpoint's scope and idempotency rules. |
|
|
162
|
+
|
|
163
|
+
Responses are decoded Python dictionaries. API errors raise `EDPayException` with HTTP status and response data.
|
|
164
|
+
## Documentation
|
|
165
|
+
|
|
166
|
+
- [EDPay SDK integration guide](https://docs-pay.edutecka.com/sdks/)
|
|
167
|
+
- [Payments API reference](https://docs-pay.edutecka.com/api/payments/)
|
|
168
|
+
- [Authentication and API keys](https://docs-pay.edutecka.com/guides/authentication/)
|
|
169
|
+
- [Webhooks](https://docs-pay.edutecka.com/api/webhooks/)
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT. See [LICENSE](LICENSE).
|
|
174
|
+
|
|
175
|
+
## Official SDK repositories
|
|
176
|
+
|
|
177
|
+
- [JavaScript / TypeScript](https://github.com/edutecka/edpay-javascript-sdk)
|
|
178
|
+
- [PHP](https://github.com/edutecka/edpay-php-sdk)
|
|
179
|
+
- [Java](https://github.com/edutecka/edpay-java-sdk)
|
|
180
|
+
- [.NET](https://github.com/edutecka/edpay-dot-net-sdk)
|
|
181
|
+
- [Python](https://github.com/edutecka/edpay-python-sdk)
|
|
182
|
+
|
|
183
|
+
## Official e-commerce plugin repositories
|
|
184
|
+
|
|
185
|
+
These repositories contain integration previews; check each project README for its implementation status and limitations before use.
|
|
186
|
+
|
|
187
|
+
- [WooCommerce (WordPress)](https://github.com/edutecka/edpay-woocommerce-plugin)
|
|
188
|
+
- [Shopify](https://github.com/edutecka/edpay-shopify-app)
|
|
189
|
+
- [Magento / Adobe Commerce](https://github.com/edutecka/edpay-magento2-module)
|
|
190
|
+
- [PrestaShop](https://github.com/edutecka/edpay-prestashop-module)
|
|
191
|
+
- [OpenCart](https://github.com/edutecka/edpay-opencart-extension)
|
|
192
|
+
- [WHMCS](https://github.com/edutecka/edpay-whmcs-gateway)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
edpay/__init__.py,sha256=V9Z0sw9eaOyjLkycAmgC-wsVr9N6ZqWCLiO2Gkl9p8o,968
|
|
2
|
+
edpay/client.py,sha256=-SOOV5lxyctI3eBIEnJJHIerTlUv2Pl4up_iYUomkVg,5516
|
|
3
|
+
edpay/contacts.py,sha256=LzgQY3Ks3EcQyM3Xg8QLhIGIwgqP2O-e_rfjw1SGTUE,5342
|
|
4
|
+
edpay/exceptions.py,sha256=PyEy9i53LpJBUUknBC-XrKmKHLcaiK_TEjWOiVr42k8,912
|
|
5
|
+
edpay/webhooks.py,sha256=FI-964X651d9y6LNg7IR_tGcCMP-grn-YMPbmthVJUY,2906
|
|
6
|
+
edpay/resources/customers.py,sha256=NjfnDvdmDZPB0jbiMVcBTpBMifwuFoE_0TXx5X5wq8Y,1187
|
|
7
|
+
edpay/resources/fx.py,sha256=nSGyzEMZUXeeE3MMFPPFNaHL2Jg9x07h8y6wGWhtn7Y,426
|
|
8
|
+
edpay/resources/invoices.py,sha256=u7LomNI46ZqocJIdj13VUVw2xixt0nE1MoPwFS50etM,1492
|
|
9
|
+
edpay/resources/payments.py,sha256=RIzTgj_WRTJU8UpKka-bORqlT0lQq8BoQP4G1FOf7Rw,3969
|
|
10
|
+
edpay/resources/public.py,sha256=wwiMZeak0O67_1k18LRnslU9VN657LlNDxnRaDjmOyA,277
|
|
11
|
+
edpay/resources/subscriptions.py,sha256=FLojRSTEv792mfZFhUZLNj79oNKJ0pXhKf4veCoSkgM,1231
|
|
12
|
+
edpay/resources/wallets.py,sha256=f4HB2nh3tP0-74KeRWOFujkJRt-wWTKxUblclioupgE,905
|
|
13
|
+
edpay/resources/webhooks.py,sha256=6X2CdrR9UpFTaPtEWihQVg11nOPaL-9aJi1vdcFj8KQ,1646
|
|
14
|
+
edpay-1.6.2.dist-info/METADATA,sha256=gZMfUDeoEu6Gyw4b3LwlBNix7DLz6f85T2blBdMr4UA,16139
|
|
15
|
+
edpay-1.6.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
16
|
+
edpay-1.6.2.dist-info/licenses/LICENSE,sha256=JlTSs9MNaUkgQWDrUcZiy4nR-GKICZ1XzPgW3apyMUo,1091
|
|
17
|
+
edpay-1.6.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Edutecka Servicos Tecnologicos Lda
|
|
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.
|