Skip to content

API reference

This page is generated from the SDK source docstrings.

Client

FawaterakClient

High-level client for Fawaterak API v3 transaction endpoints.

get_payment_methods() cached

Return all integration-enabled payment methods for this vendor.

create_transaction(*, currency, customer, cart_items, cart_total, payment_method_id=None, mobile_wallet_number=None, save_customer=False, pay_load=None, redirection_urls=None, send_email=False, send_sms=False, due_date=None, tr_number=None, redirect_option=False, auth_and_capture=None, tax_data=None, discount_data=None, list_style='h', lang='en')

Create a transaction in hosted-checkout or direct-payment mode.

get_transaction(intent_key)

Fetch one transaction by its intent key.

list_transactions(*, start_date, end_date, page=1, per_page=15, pay_load=None)

Return a paginated export of persisted transactions.

create_einvoice(*, currency, customer, cart_items, cart_total, due_date=None, invoice_number=None, pay_load=None, redirection_urls=None)

Creates an e-invoice

get_einvoice(invoice_id)

Gets a specific e-invoice based on invoice_id

list_einvoices(einvoice_filter=None)

Lists e-invoice based on filter (if found).

Returns in paginated response in pages of 10.

update_einvoice(*, invoice_id, customer, currency=None, products=None, has_history=False, due_date=None, invoice_number=None, tags=None)

Updates an existing e-invoice. When has_history is not set, currency and products are required and line items are replaced.

delete_einvoice(invoice_id)

Deletes an unpaid e-invoice.

The API refuses deletion if active payment references block it. (That's what docs say, can't replicate it) Returns True on a successful deletion response.

Can't understand how they don't soft delete, they just go full delete, like not just a status saying deleted (Soft-deletion).

get_refund_types(lang='en')

Return the refund type codes accepted by create_refund, keyed as stringified ints, mapped to their localized label.

get_refund_reasons(lang='en')

Return the valid reason strings accepted by create_refund.

create_refund(*, refund_type, refund_id, reason, refundable_amount, comment=None)

Submit a refund request for a paid invoice or transaction.

  • refund_type: which record kind refund_id points at (RefundType, its int, or its string code).
  • refund_id: invoice id or transaction id for the chosen refund_type.
  • reason: one of the strings from get_refund_reasons().
  • refundable_amount: partial or full amount; must not exceed the remaining refundable balance.
  • comment: optional internal note (only for your vendor dashboard).

list_refunds(page=1)

Return a page (10 per page, API-fixed) of this vendor's refund requests.

get_refund(refund_id)

Fetch one refund request by id.

The API answers 200 with an empty object when the id is unknown, which this method surfaces as None.

delete_refund(refund_id)

Cancel a pending refund request; approved refunds cannot be deleted.

parse_paid_webhook(payload)

Verify and parse a paid/pending webhook payload.

parse_failed_webhook(payload)

Verify and parse a failed-payment webhook payload.

parse_cancel_webhook(payload)

Verify and parse a cancel/expired webhook payload.

parse_refund_webhook(payload)

Verify and parse a refund webhook payload.

parse_webhook(payload, webhook_type)

Verify and parse a webhook payload of the given type.

Configuration

Config dataclass

Resolved configuration used to construct TokenManager/HTTPClient.

Construct this via Config.resolve(...) rather than directly for first-time — that's where env var fallback and validation happen, subsequent usage can use Config() directly since it returns the singelton object.

Attributes:

Name Type Description
client_id str

OAuth client id, used for the /api/v3/* endpoints.

client_secret str

OAuth client secret. Excluded from repr()/logs.

base_url str

Resolved from environment, or a direct override (e.g. to point at a local mock server in tests).

environment Environment | None

"staging" or "production" if a recognized one was given; None if base_url was supplied directly instead.

vendor_api_key str | None

Legacy static key, only needed for the Phase 8 tokenization endpoints and for webhook signature verification. Optional because most of the SDK's v3 surface never uses it. Excluded from repr()/logs.

timeout float

Default per-request timeout, in seconds.

resolve(*, client_id=None, client_secret=None, environment=None, base_url=None, vendor_api_key=None, timeout=DEFAULT_TIMEOUT_SECONDS) classmethod

Build a Config from explicit args, falling back to env vars.

Precedence:
    - explicit argument
    - matching env var.

Args:
    - client_id: OAuth client id. Falls back to $FAWATERAK_CLIENT_ID.
    - client_secret: OAuth client secret. Falls back to
        $FAWATERAK_CLIENT_SECRET.
    - environment: "staging" or "production". Falls back to
        $FAWATERAK_ENV. Ignored if `base_url` is also given.
    - base_url: Explicit API base URL, overriding `environment`
        entirely. Mainly for pointing at a local mock server in tests.
    - vendor_api_key: Legacy vendor key, needed only for Phase 8
        (tokenization) and webhook verification. Falls back to
        $FAWATERAK_VENDOR_API_KEY.
    - timeout: Default per-request timeout, in seconds.

Raises:
FawaterakConfigError: if client_id/client_secret are missing after
    checking both the argument and env var, or if no valid
    `environment` was resolved and no `base_url` override was
    given either.

Models

Customer dataclass

Customer details attached to a transaction or e-invoice.

maps to https://app.fawaterk.com/documentation#models/Customer

CartItem dataclass

One line item in a transaction cart.

maps to https://app.fawaterk.com/documentation#models/CartItem

RedirectionUrls dataclass

Customer redirect URLs and optional per-transaction webhook override.

maps to https://app.fawaterk.com/documentation#models/RedirectionUrls

TransactionData dataclass

Full transaction details from POST /api/v3/getTransactionData.

maps to https://app.fawaterk.com/documentation#models/TransactionDetail

FinancialBreakdown dataclass

Settlement amounts stored when a payment was settled.

converted_amount, converted_currency and exchange_rate are set only when original_currency is not EGP. settlement_amount is the net amount credited to the vendor balance.

maps to https://app.fawaterk.com/documentation#models/FinancialBreakdown

from_optional(value) classmethod

Parse a breakdown that may be absent, null, or a JSON string.

The API sends null until a balance row exists, and omits it from pending webhooks. Form-encoded webhook bodies carry it as a JSON string.

EInvoice dataclass

Full e-invoice detail returned by get/update and list items.

The documentation leaves this shape unknown ("Full e-invoice detail object"), so fields mirror what was observed on staging and parsing is defensive: missing or unexpected keys degrade to defaults instead of raising.

invoice_id maps from the payload's id key; the API identifies invoices by invoice_id in requests.

EinvoiceCreationResult dataclass

Result of successful E-Invoice creation.

maps to https://staging.fawaterk.com/documentation#models/CreateEinvoiceSuccess

EinvoiceFilter dataclass

Optional filter for listing e-invoices.

maps to https://staging.fawaterk.com/documentation#models/ListEinvoicesRequest

RefundType

Bases: str, Enum

The refund_type code the refund API expects (as a string).

  • INVOICE — e-invoice / invoice record; refund_id is the invoice id.
  • PAYMENT_LINK_TRANSACTION — payment link transaction; refund_id is the payment-request transaction id.
  • COLLECTION_LINK_TRANSACTION — collection link transaction.
  • INTEGRATION_TRANSACTION — transaction created through the API; the id is the transaction id visible via get_transaction.

RefundRequest dataclass

One refund request record, as returned by list or details.

The refunds list and the single-refund details endpoint return the same core record; only the list carries refundable_type, refundable_id and can_delete, so those degrade to None when parsed from a details response. Amounts come back as strings on the wire and are parsed to float.

RefundCreationResult dataclass

Result of a successful refund request submission.

Webhook events

PaidWebhookEvent dataclass

Paid or pending payment webhook payload.

Supports both API v3 Trx-style fields (transaction_key, transaction_id, status) and legacy invoice-style fields (invoice_key, invoice_id, invoice_status). Both field sets are optional because a given payload carries one or the other. financial_breakdown is only present on paid webhooks after settlement. Webhook body encoding (json, x-www-form-urlencoded), to force json add _json to the end of the webhook url.

Maps to https://staging.fawaterk.com/documentation#models/PaymentWebhookPayload

FailedWebhookEvent dataclass

Failed payment webhook payload.

Like PaidWebhookEvent, this normalizes both Trx-style and legacy invoice references into one flat result type. Webhook body encoding (json, x-www-form-urlencoded), to force json add _json to the end of the webhook url.

Maps to https://staging.fawaterk.com/documentation#models/FailedPaymentWebhookPayload

CancelWebhookEvent dataclass

Cancel or expired reference webhook payload.

transaction_id/transaction_key are the parent transaction identifiers when present; reference_id and payment_method are used for HMAC verification. Webhook body encoding (json)

Maps to https://staging.fawaterk.com/documentation#models/CancelReferenceWebhookPayload

RefundWebhookEvent dataclass

Refund approved webhook payload.

The signature covers transactionId, amount, and currency. Webhook body encoding (json)

Maps to https://staging.fawaterk.com/documentation#models/RefundWebhookPayload

Exceptions

exceptions

Fawaterak SDK exception module.

FawaterakException
├── FawaterakConfigException            # missing credentials / unknown environment
├── FawaterakConnectionException        # network/timeout, safe to retry
├── FawaterakWebhookException           # signature mismatch / malformed webhook body
└── FawaterakAPIException               # non-2xx with parsed {status, message} body
    ├── FawaterakAuthException          # 401 (after one failed refresh-and-retry)
    ├── FawaterakValidationException    # 400/422
    └── FawaterakTemporaryException     # 503 — safe to retry with backoff

FawaterakException

Bases: Exception

Base class for every exception the SDK raises

FawaterakAPIException

Bases: FawaterakException

Fawaterak API returned a non-2xx response

FawaterakAuthException

Bases: FawaterakAPIException

Error 401: OAuth failed even after refresh and retry (Bad Credentials)

FawaterakConfigException

Bases: FawaterakException

The SDK was misconfigured — missing credentials, an unrecognized environment.

FawaterakConnectionException

Bases: FawaterakException

Network-level exception where no response was received

FawaterakTemporaryException

Bases: FawaterakAPIException

Error 503: transient safe to retry with backoff

FawaterakValidationException

Bases: FawaterakAPIException

Error 400/422: bad request, non-retryable as-is

FawaterakWebhookException

Bases: FawaterakException

Webhook failed signature verification or parsing