YooMoney API

class glQiwiApi.yoo_money.client.YooMoneyAPI(api_access_token: str, cache_time: Union[float, int] = 0, session_holder: Optional[glQiwiApi.core.session.holder.AbstractSessionHolder[Any]] = None)[source]

Bases: glQiwiApi.core.abc.wrapper.Wrapper, glQiwiApi.core.mixins.DataMixin, glQiwiApi.core.mixins.ContextInstanceMixin[YooMoneyAPI]

That class implements processing requests to YooMoney It is convenient in that it does not just give json such objects, and all this converts into pydantic models. To work with this class, you need to register a token, using the guide on the official github of the project

__init__(api_access_token: str, cache_time: Union[float, int] = 0, session_holder: Optional[glQiwiApi.core.session.holder.AbstractSessionHolder[Any]] = None) None[source]
The constructor accepts a token obtained from the method class get_access_token

and the special attribute without_context

Parameters
  • api_access_token – api token for requests

  • cache_time – Time to cache requests in seconds, default 0, respectively the request will not use the cache by default

  • session_holder – obtains session and helps to manage session lifecycle. You can pass your own session holder, for example using httpx lib and use it

api_access_token
get_request_service() glQiwiApi.core.request_service.RequestService[source]
async classmethod build_url_for_auth(scope: List[str], client_id: str, redirect_uri: str = 'https://example.com') Optional[str][source]

Method to get the link for further authorization and obtaining a token

Parameters
  • scope – OAuth2 authorization of the application by the user, the rights are transferred by the list.

  • client_id – application id, type string

  • redirect_uri – a funnel where the temporary code that you need will go to to get the main token

Returns

the link to follow and make authorization via login / password

async classmethod get_access_token(code: str, client_id: str, redirect_uri: str = 'https://example.com', client_secret: Optional[str] = None) str[source]

Method for obtaining a token for requests to the YooMoney API

Parameters
  • code – the temporary code that was obtained in the base_authorize method

  • client_id – application id, type string

  • redirect_uri – the funnel where the temporary code will go, which is needed to get the main token

  • client_secret – The secret word for authenticating the application. Specified if the service is registered with authentication.

Returns

YooMoney API TOKEN

async revoke_api_token() Optional[Dict[str, bool]][source]

Method for revoking the rights of a token, while all its rights also disappear Documentation: https://yoomoney.ru/docs/wallet/using-api/authorization/revoke-access-token

property account_info: glQiwiApi.types.yoomoney.types.AccountInfo
classmethod create_pay_form(receiver: str, quick_pay_form: str, targets: str, payment_type: str, amount: Union[int, float], form_comment: Optional[str] = None, short_dest: Optional[str] = None, label: Optional[str] = None, comment: Optional[str] = None, success_url: Optional[str] = None, need_fio: Optional[bool] = None, need_email: Optional[bool] = None, need_phone: Optional[bool] = None, need_address: Optional[bool] = None) str[source]

The YooMoney form is a set of fields with information about a transfer. You can embed payment form into your interface (for instance, a website or blog). When the sender pushes the button, the details from the form are sent to YooMoney and an order for a transfer to your wallet is initiated.

Detail docs: https://yoomoney.ru/docs/payment-buttons/using-api/forms?lang=en

Possible values for quick_pay_form:
  • shop - for a multi purpose form;

  • small - for a button;

  • donate - for a charity form.

@param receiver: Number of the YooMoney wallet which money from senders is credited to. @param quick_pay_form: @param targets: Payment purpose. @param payment_type: Payment method. Possible values: PC, AC, MC @param amount: Transfer amount (the amount debited from the sender). @param form_comment: Name of the transfer in sender’s history

(for transfers from a wallet or linked bank card). Displayed in sender’s wallet. The simplest way to create it is to combine the names of the store and product. For instance: My Store: white valenki boots

@param short_dest: Name of the transfer on the confirmation page.

We recommend using the same name as formcomment

@param label: The label that a site or app assigns to a certain transfer.

For instance, a code or order identifier may be used for this label.

@param comment: The field in which you can send sender’s comments. @param success_url: URL where the user is redirected after the transfer. @param need_fio: Sender’s full name required. @param need_email: Sender’s email address required. @param need_phone: Sender’s phone number required. @param need_address: Sender’s address required. @return: link to payment form

async retrieve_account_info() glQiwiApi.types.yoomoney.types.AccountInfo[source]

Method for getting information about user account Detailed documentation: https://yoomoney.ru/docs/wallet/user-account/account-info

Returns

объект AccountInfo

async transactions(operation_types: Optional[Union[List[glQiwiApi.types.yoomoney.types.OperationType], Tuple[glQiwiApi.types.yoomoney.types.OperationType, ...]]] = None, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None, start_record: Optional[int] = None, records: int = 30, label: Optional[Union[str, int]] = None) List[glQiwiApi.types.yoomoney.types.Operation][source]

More details: https://yoomoney.ru/docs/wallet/user-account/operation-history

The method allows you to view the history of transactions (in whole or in part) in page mode. History records are displayed in reverse chronological order from most recent to earlier.

Possible values:

DEPOSITION — refill ;

PAYMENT — consumption;

INCOMING(incoming-transfers-unaccepted) — unaccepted incoming P2P transfers of any type.

Parameters
  • operation_types – Operation type

  • label – string. Selection of payments by tag value. Selects payments that have a specified parameter value label of the request-payment call.

  • start_date – Show operations from the moment in time (operations equal to start_date or later) If the parameter is absent, all operations are displayed.

  • end_date – Output operations up to the point in time (operations older than end_date). If the parameter is absent, all operations are displayed.

  • start_record

    If the parameter is present, then operations will be displayed starting

    from start_record number.

    Operations are numbered from 0. More about paginated list output

  • records – The number of transaction history records requested. Valid values are from 1 to 100, the default is 30.

async transaction_info(operation_id: str) glQiwiApi.types.yoomoney.types.OperationDetails[source]

Allows you to get detailed information about the operation from the history. Required token rights: operation-details. More detailed documentation: https://yoomoney.ru/docs/wallet/user-account/operation-details

Parameters

operation_id – Operation ID

async send(to_account: str, amount: Union[int, float], money_source: str = 'wallet', pattern_id: str = 'p2p', cvv2_code: str = '', card_type: Optional[str] = None, protect: bool = False, comment_for_history: Optional[str] = None, comment: Optional[str] = None, expire_period: int = 1) glQiwiApi.types.yoomoney.types.Payment[source]

A method for sending money to another person’s account or card. This function makes 2 requests at once, because of this you may feel a slight loss in performance,

you can use the method

_pre_process_payment and get the PreProcessPaymentResponse object, which contains information about a still unconfirmed payment

More detailed documentation: https://yoomoney.ru/docs/wallet/process-payments/process-payment

Parameters
  • pattern_id – Payment pattern ID

  • to_account – string ID of the transfer recipient (account number, phone number or email).

  • amount – Amount to be received (the invoice will be sent to the recipient’s account after payment). MINIMUM AMOUNT 2.

  • money_source – The requested payment method. wallet - from the user’s account, if you want to use a card, then you will need to pass card_type to search for a card in the list of your bank cards, and also optionally cvv2 code for making a payment

  • comment_for_history – Comment to the translation, displayed in the sender’s history.

  • card_type – Bank card type, you need to fill in, only if you want to debit funds from your card

  • cvv2_code – optional, may not be passed, however if payment by card is required, the parameter should be passed

  • comment – Comment on the transfer, displayed to the recipient.

  • protect – The value of the parameter is true - a sign that that the transfer is protected by a protection code. By default, there is no parameter (normal translation).

  • expire_period – Number of days during which: the recipient of the transfer can enter the protection code and receive a transfer to your account, the recipient of the transfer on demand can receive the transfer. The parameter value must be in the range from 1 to 365. Optional parameter. The default is 1.

async get_balance() float[source]
async accept_incoming_transaction(operation_id: str, protection_code: str) glQiwiApi.types.yoomoney.types.IncomingTransaction[source]

Acceptance of incoming transfers protected by a protection code, if you passed the protect parameter to the send method Number of reception attempts incoming transfer with a protection code is limited. When the number of attempts is exhausted, the transfer is automatically rejected (the transfer is returned to the sender). More detailed documentation: https://yoomoney.ru/docs/wallet/process-payments/incoming-transfer-accept

Parameters
  • operation_id – Operation identifier, the value of the operation_id parameter of the history () method response

  • protection_code – Protection code. A string of 4 decimal digits. Indicated for an incoming transfer protected by a protection code. Not available for on-demand transfers.

async reject_transaction(operation_id: str) Dict[str, str][source]
Cancellation of incoming transfers protected by a protection code if you transferred

in the send method the protect parameter,

and transfers on demand.

If the transfer is canceled, it is returned to the sender.

Required token rights: incoming-transfers Docs: https://yoomoney.ru/docs/wallet/process-payments/incoming-transfer-reject

Parameters

operation_id – Operation identifier, parameter value operation_id of history () method response.

async check_transaction(amount: Union[int, float], operation_type: str = 'in', comment: Optional[str] = None, rows: int = 100, recipient: Optional[str] = None) bool[source]

Method for verifying a transaction. This method uses self.transactions (rows = rows) to receive payments. For a little optimization, you can decrease rows by setting it, however, this does not guarantee the correct result

Parameters
  • amount – payment amount

  • operation_type – payment type

  • recipient – recipient number

  • rows – number of payments to be checked

  • comment – comment by which the transaction will be verified

Returns

bool, is there such a transaction in the payment history