Python client for the eDahab payment API
Project description
edahab (Python SDK)
Full Python SDK for the official eDahab API.
PyPI • n8n Node Docs • Status Codes
Table of Contents
- 1) Product separation
- 2) Install
- 3) Quick start
- 4) Credentials and configuration
- 5) API reference (module-level functions)
- 6) API reference (EdahabClient)
- 7) Result objects
- 8) Exceptions
- 9) Status codes
- 10) Troubleshooting
- 11) Exports
- 12) Official docs links
1) Product separation
This repository has two separate deliverables:
- Python SDK (this package):
edahab(published on PyPI) - n8n node package: see
n8n-nodes-edahab/README.md(published on npm)
They are independent in packaging and release process.
2) Install
Install from PyPI:
pip install edahab
Install from local source:
pip install .
Editable install for development:
pip install -e .
3) Quick start
from edahab import configure, pay, verify_invoice, is_invoice_paid
configure("your-api-key", "your-api-secret")
invoice = pay(
customer="65",
amount=1,
agent="5555",
currency="USD", # required
)
print(invoice.invoice_id, invoice.invoice_status)
print("paid?", is_invoice_paid(invoice.invoice_status))
if invoice.invoice_id:
status = verify_invoice(invoice_id=invoice.invoice_id)
print("verified:", status.invoice_status)
Every payment call requires
currencyand only acceptsUSDorSLSH.
4) Credentials and configuration
Environment variables
EDAHAB_API_KEYEDAHAB_API_SECRET
configure(api_key, api_secret, *, base_url=..., timeout=..., open_url=...)
Sets a shared default client used by pay, verify_invoice, and send_credit.
configure_from_env(...)
Same as configure, but reads from env vars.
get_client()
Returns configured client or raises RuntimeError if not configured.
clear_configuration()
Clears configured default client (mostly useful in tests).
5) API reference (module-level functions)
pay(api_key=None, api_secret=None, *, customer, amount, agent, currency) -> IssueInvoiceResult
Creates purchase invoice (Issueinvoice).
- If
api_keyandapi_secretare omitted, uses configured default client. - If either key is provided alone, raises
ValueError.
Example:
from edahab import pay
res = pay(
"your-api-key",
"your-api-secret",
customer="65",
amount=1,
agent="5555",
currency="USD",
)
verify_invoice(api_key=None, api_secret=None, *, invoice_id) -> CheckInvoiceStatusResult
Checks status via CheckInvoiceStatus.
send_credit(api_key=None, api_secret=None, *, to, amount, reference, currency) -> AgentPaymentResult
Sends merchant-balance credit (agentPayment).
is_invoice_paid(invoice_status) -> bool
Returns True only for "Paid".
normalize_currency(currency) -> str
Normalizes and validates currency:
- accepts case-insensitive input
- returns canonical
"USD"/"SLSH" - raises
ValueErroron invalid input
generate_request_hash(serialized_body, api_secret) -> str
Computes SHA-256 hex of serialized_body + api_secret.
serialize_body(payload: dict) -> str
Compacts JSON with stable sorting:
separators=(",", ":")sort_keys=True
describe_status_code(code) -> str | None
Human description for invoice StatusCode.
6) API reference (EdahabClient)
Constructor
EdahabClient(api_key, api_secret, *, base_url="https://edahab.net/api/api/", timeout=30.0, open_url=None)
Alternate constructor
EdahabClient.from_env(...)
Property
client.api_key
Methods
issue_invoice(edahab_number, amount, agent_code, *, currency, raise_on_api_error=True)
- endpoint:
Issueinvoice - returns:
IssueInvoiceResult
pay(*, customer, amount, agent, currency, raise_on_api_error=True)
Alias for issue_invoice.
agent_payment(phone_number, transaction_amount, transaction_id, *, currency)
- endpoint:
agentPayment - returns:
AgentPaymentResult
send_credit(*, to, amount, reference, currency)
Alias for agent_payment.
check_invoice_status(invoice_id, *, raise_on_api_error=True)
- endpoint:
CheckInvoiceStatus - returns:
CheckInvoiceStatusResult
verify(invoice_id, *, raise_on_api_error=True)
Alias for check_invoice_status.
Error behavior
- invoice endpoints can raise based on
StatusCodeifraise_on_api_error=True - credit endpoint currently returns parsed payload without status-code raising
7) Result objects
IssueInvoiceResult
invoice_statustransaction_idinvoice_idstatus_coderequest_idstatus_descriptionvalidation_errorsraw
CheckInvoiceStatusResult
Same field shape as IssueInvoiceResult.
AgentPaymentResult
transaction_statustransaction_message(handles API typoTransactionMesage)phone_numbertransaction_idcurrencyraw
8) Exceptions
EdahabError(base)EdahabHTTPError(status_code,url,body)EdahabDecodeErrorEdahabCredentialErrorEdahabValidationError(validation_errors)EdahabAPIStatusError(status_code,status_description,raw_response)
Example:
from edahab import (
EdahabClient,
EdahabCredentialError,
EdahabValidationError,
EdahabAPIStatusError,
EdahabHTTPError,
)
client = EdahabClient("your-api-key", "your-api-secret")
try:
client.issue_invoice("65", 1, "5555", currency="USD")
except EdahabCredentialError:
print("invalid key/secret/hash")
except EdahabValidationError as e:
print(e.validation_errors)
except EdahabAPIStatusError as e:
print(e.status_code, e.raw_response)
except EdahabHTTPError as e:
print(e.status_code, e.body)
9) Status codes
StatusCode enum:
SUCCESS = 0API_ERROR = 1INVALID_JSON = 2VALIDATION_ERROR = 3INVALID_API_CREDENTIALS = 4INSUFFICIENT_CUSTOMER_BALANCE = 5INVOICE_NOT_FOUND = 6INVALID = 7
Use STATUS_DESCRIPTIONS or describe_status_code() for labels.
10) Troubleshooting
-
RuntimeError: No default client configuredCallconfigure(...)orconfigure_from_env()first. -
ValueError: currency must be 'USD' or 'SLSH'Pass valid currency; usenormalize_currency(). -
HTTP 400at upload to PyPI You are likely re-uploading an existing release file; bump version. -
StatusCode=4from API Check key/secret pair and hash generation body consistency.
11) Exports
configure, configure_from_env, get_client, clear_configuration, pay, verify_invoice, send_credit, is_invoice_paid, normalize_currency, generate_request_hash, serialize_body, describe_status_code, EdahabClient, DEFAULT_BASE_URL, StatusCode, STATUS_DESCRIPTIONS, IssueInvoiceResult, CheckInvoiceStatusResult, AgentPaymentResult, EdahabError, EdahabHTTPError, EdahabDecodeError, EdahabCredentialError, EdahabValidationError, EdahabAPIStatusError.
12) Official docs links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file edahab-2.0.2.tar.gz.
File metadata
- Download URL: edahab-2.0.2.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8757b655724e7fe163ee6a46f0c636e73f4d8461ff9086d22c7cbb467a8e307d
|
|
| MD5 |
d246922e51780699eb3558a9505d0cda
|
|
| BLAKE2b-256 |
5c84a5dda5659f3c95c79fcc184b009004a62362a0bfc666e35869888a16dd45
|
File details
Details for the file edahab-2.0.2-py3-none-any.whl.
File metadata
- Download URL: edahab-2.0.2-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75d447a7213c30383f2c59515147e220cbf540e9297e958cfa512d75e4f8fa13
|
|
| MD5 |
0e5672f7b86cd0ddf07105dc37637ffc
|
|
| BLAKE2b-256 |
f3b22791f8c334b6b0b837df740866e8efa914ec015436ddaa7affd6abdc2aea
|