Async API ба үндсэн объектууд
Async клиент
- class qpay_client.v2.AsyncQPayClient(settings: QPaySettings, *, client: AsyncClient | None = None, logger: Logger | None = None)[source]
Bases:
BaseClientAsynchronous client for the QPay v2 API.
Always use as an async context manager. Authentication runs on
__aenter__and the HTTP connection is closed on__aexit__:settings = QPaySettings.production( username="...", password="...", invoice_code="..." ) async with AsyncQPayClient(settings) as client: invoice = await client.invoice_create(InvoiceCreateSimpleRequest(...)) result = await client.payment_check(PaymentCheckRequest(...))
Available endpoints:
invoice_create,invoice_get,invoice_cancel,payment_get,payment_check,payment_cancel,payment_refund,payment_list,ebarimt_create,ebarimt_get,subscription_get,subscription_cancel.Concurrency-safe:
authenticate()is guarded by anasyncio.Lock, so multiple coroutines sharing one client instance will not race on token refresh.- property is_closed: bool
Returns True of connection is closed.
- async invoice_create(create_invoice_request: InvoiceCreateRequest | InvoiceCreateSimpleRequest) InvoiceCreateResponse[source]
Send invoice create request to Qpay.
- async invoice_cancel(invoice_id: str) int[source]
Send cancel invoice request to qpay. Returns status code.
- async payment_check(payment_check_request: PaymentCheckRequest) PaymentCheckResponse[source]
Check payment status, polling until a payment is found or retries exhausted.
- async payment_cancel(payment_id: str, payment_cancel_request: PaymentCancelRequest) int[source]
Send payment cancel request. Returns status code.
- async payment_refund(payment_id: str, payment_refund_request: PaymentRefundRequest) int[source]
Send refund payment request. Returns status code.
- async payment_list(payment_list_request: PaymentListRequest) PaymentListResponse[source]
Send list payment request.
- async ebarimt_create(ebarimt_create_request: EbarimtCreateRequest) EbarimtCreateResponse[source]
Send create ebarimt request.
Тохиргоо
- class qpay_client.v2.QPaySettings(username: str, password: str, invoice_code: str, base_url: str, timeout: Timeout = <factory>, limits: Limits = <factory>, log_level: int | str = 20, token_leeway: float = 60.0, client_retries: int = 5, client_delay: float = 0.5, client_jitter: float = 0.5, payment_check_retries: int = 5, payment_check_delay: float = 0.5, payment_check_jitter: float = 0.5)[source]
Bases:
objectImmutable configuration for QPay v2 clients.
Prefer the factory methods over constructing this class directly:
QPaySettings.sandbox()— connects to the QPay sandbox with shared test credentials. All parameters are optional; useful for local development.QPaySettings.production(username=..., password=..., invoice_code=...)— connects to the live QPay merchant API with your own credentials.
Retry and polling settings are independent:
client_retries/client_delay/client_jittercontrol how the HTTP transport retries network errors and 5xx responses.payment_check_retries/payment_check_delay/payment_check_jittercontrol howpayment_check()polls until a payment is confirmed.
token_leeway(default 60 s) is the window before token expiry in which the client proactively refreshes, preventing races at the boundary.- classmethod sandbox(*, username: str = 'TEST_MERCHANT', password: str = '123456', invoice_code: str = 'TEST_INVOICE', **kwargs) QPaySettings[source]
Return settings pointed at the QPay sandbox environment.
Credentials default to QPay's shared sandbox values, so calling
QPaySettings.sandbox()with no arguments is enough for basic testing. Pass explicitusername,password, orinvoice_codeto override. Any extra keyword arguments are forwarded toQPaySettings(e.g.payment_check_retries=3).
- classmethod production(*, username: str, password: str, invoice_code: str, **kwargs) QPaySettings[source]
Return settings pointed at the live QPay merchant API.
All three credential arguments are required. Any extra keyword arguments are forwarded to
QPaySettings(e.g.client_retries=3).
Алдаа
- exception qpay_client.v2.QPayError(*, status_code: int, error_key: str)[source]
Raised when the QPay API returns an error response.
- status_code
HTTP status code from the API (e.g.
400,401,422).
- error_key
Machine-readable key from QPay (e.g.
"INVOICE_NOTFOUND").
- error_detail
Human-readable description in English and Mongolian, or
"No description."if the key is not recognised.
Example:
try: invoice = client.invoice_get(invoice_id) except QPayError as e: print(e.status_code) # 422 print(e.error_key) # "INVOICE_NOTFOUND" print(e.error_detail.en) # "Invoice is not found!"