### Install YooMoney API Python Library Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt Instructions for installing the YooMoney API Python library using pip or uv. Ensure you have Python 3.10+ installed. ```bash # Using pip pip install yoomoney --upgrade # Using uv uv add yoomoney ``` -------------------------------- ### Error Handling with YooMoney Exceptions Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt Illustrates how to handle various errors that can occur during API interactions using specific exceptions inherited from YooMoneyError. This example shows how to catch common issues like invalid tokens, invalid requests, and technical errors. ```python from yoomoney import Client from yoomoney.exceptions import ( YooMoneyError, InvalidToken, EmptyToken, InvalidRequest, UnauthorizedClient, InvalidGrant, IllegalParamType, IllegalParamStartRecord, IllegalParamRecords, IllegalParamLabel, IllegalParamFromDate, IllegalParamTillDate, IllegalParamOperationId, TechnicalError, ) client = Client("YOUR_ACCESS_TOKEN") try: user = client.account_info() except InvalidToken: print("Token is invalid or lacks required permissions") except EmptyToken: print("Response token is empty") except InvalidRequest: print("Missing or invalid query parameters") except UnauthorizedClient: print("Invalid client_id or client_secret") except InvalidGrant: print("Authorization code expired or already used") except TechnicalError: print("Temporary server error, retry later") except YooMoneyError as e: print(f"YooMoney error: {e}") finally: client.close() ``` -------------------------------- ### Get Operation Details - Python Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt This snippet demonstrates how to retrieve detailed information for a specific YooMoney operation using its unique ID. It requires an initialized YooMoney Client and an operation ID. The output includes various transaction attributes like status, amount, sender, recipient, and fees. ```python from yoomoney import Client client = Client("YOUR_ACCESS_TOKEN") details = client.operation_details(operation_id="670244335488002312") print(f"Operation ID: {details.operation_id}") print(f"Status: {details.status}") # success, refused, in_progress print(f"Pattern ID: {details.pattern_id}") # p2p, phone-topup, etc. print(f"Direction: {details.direction}") # in, out print(f"Amount: {details.amount}") # Transaction amount print(f"Amount due: {details.amount_due}") # Amount charged (with fees) print(f"Fee: {details.fee}") # Fee amount print(f"Datetime: {details.datetime}") # datetime object print(f"Title: {details.title}") # Human-readable description print(f"Sender: {details.sender}") # Sender account number print(f"Recipient: {details.recipient}") # Recipient account/phone/email print(f"Recipient type: {details.recipient_type}") # account, phone, email print(f"Message: {details.message}") # Sender's message print(f"Comment: {details.comment}") # Payment comment print(f"Code protected: {details.codepro}") # True if code-protected print(f"Protection code: {details.protection_code}") # Code to accept transfer print(f"Expires: {details.expires}") # Expiration datetime print(f"Label: {details.label}") # Custom label print(f"Type: {details.type}") # incoming-transfer, deposition, etc. print(f"Digital goods: {details.digital_goods}") # DigitalGood object if applicable client.close() ``` -------------------------------- ### Authorize - OAuth2 Access Token Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt Handles the interactive OAuth2 authorization flow to obtain an access token for the YooMoney API. Requires app registration to get client credentials. ```python from yoomoney import Authorize # Register your app at https://yoomoney.ru/myservices/new to get credentials Authorize( client_id="YOUR_CLIENT_ID", redirect_uri="YOUR_REDIRECT_URI", client_secret="YOUR_CLIENT_SECRET", scope=[ "account-info", # Read account information "operation-history", # View transaction history "operation-details", # View operation details "incoming-transfers", # Accept incoming transfers "payment-p2p", # Send P2P payments "payment-shop", # Make shop payments ], ) # Follow the printed URL to authorize, then paste the redirect URL or code # Output: Your access token: 410012345678901.ABCDEFGHIJKLMNOPQRSTUVWXYZ... ``` -------------------------------- ### Operation Details API Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Get detailed information about a single YooMoney operation using its unique operation ID. ```APIDOC ## GET /api/operation-details ### Description Get detailed information about a single YooMoney operation using its unique operation ID. ### Method GET ### Endpoint /api/operation-details ### Parameters #### Query Parameters - **access_token** (string) - Required - The OAuth access token for the user. - **operation_id** (string) - Required - The unique identifier of the operation. ### Request Example ```python from yoomoney import Client client = Client("YOUR_TOKEN") operation_detail = client.operation_details(operation_id="123456789") print(f"Operation ID: {operation_detail.operation_id}, Amount: {operation_detail.amount}") ``` ### Response #### Success Response (200) - **operation_id** (string) - Unique identifier for the operation. - **amount** (string) - The amount of the operation. - **currency** (string) - The currency of the operation. - **datetime** (string) - The date and time of the operation (ISO 8601 format). - **status** (string) - The status of the operation. - **type** (string) - The type of the operation. - **sender** (string or null) - The sender of the funds (if applicable). - **recipient** (string or null) - The recipient of the funds (if applicable). - **comment** (string or null) - A comment associated with the operation. - **details** (object) - Additional details about the operation. - **title** (string) - Title of the payment. - **recipient_account** (string) - Recipient's account number. - **message** (string or null) - Message associated with the payment. #### Response Example ```json { "operation_id": "123456789", "amount": "-50.00", "currency": "643", "datetime": "2023-10-27T10:00:00+0000", "status": "success", "type": "payment", "sender": null, "recipient": "410011234567890", "comment": "Payment for goods", "details": { "title": "Payment for Order #123", "recipient_account": "410011234567890", "message": null } } ``` ``` -------------------------------- ### AsyncClient: Make Asynchronous API Calls Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt Demonstrates how to use the AsyncClient for asynchronous API interactions, including fetching account information, operation history, and operation details. It requires an access token and should be used as an async context manager for proper resource cleanup. ```python import asyncio from yoomoney import AsyncClient async def main(): async with AsyncClient("YOUR_ACCESS_TOKEN") as client: # Get account information user = await client.account_info() print(f"Balance: {user.balance}") # Get operation history history = await client.operation_history(records=10) for op in history.operations: print(f"{op.datetime}: {op.title} - {op.amount}") # Get operation details if history.operations: details = await client.operation_details( operation_id=history.operations[0].operation_id ) print(f"Details: {details.title}") asyncio.run(main()) ``` -------------------------------- ### Quickpay - Payment Form Generation Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt Generates YooMoney payment form URLs for embedding on websites to accept payments. ```APIDOC ## POST /quickpay ### Description Generates a payment form URL that can be used to accept payments via YooMoney. Supports various payment methods and optional fields for customer information. ### Method POST ### Endpoint /quickpay ### Parameters #### Request Body - **receiver** (string) - Required - Your YooMoney wallet number. - **quickpay_form** (string) - Required - Type of form: 'shop', 'button', 'donate'. - **targets** (string) - Required - Payment purpose displayed to the payer. - **paymentType** (string) - Required - Payment method: 'PC' (wallet), 'AC' (card), 'SB' (SberPay). - **sum** (float) - Required - The amount in rubles. - **formcomment** (string) - Optional - Title of the payment form. - **short_dest** (string) - Optional - Short description of the payment. - **label** (string) - Optional - Your internal tracking label for the payment. - **comment** (string) - Optional - Default comment for the payment. - **successURL** (string) - Optional - URL to redirect the user to after successful payment. - **need_fio** (boolean) - Optional - Request the payer's full name (default: false). - **need_email** (boolean) - Optional - Request the payer's email (default: false). - **need_phone** (boolean) - Optional - Request the payer's phone number (default: false). - **need_address** (boolean) - Optional - Request the payer's address (default: false). ### Request Example ```json { "receiver": "410019014512803", "quickpay_form": "shop", "targets": "Sponsor this project", "paymentType": "SB", "sum": 150.00, "label": "donation-12345", "successURL": "https://example.com/thanks", "need_email": true } ``` ### Response #### Success Response (200) - **base_url** (string) - The base URL for the payment form. - **redirected_url** (string) - The final redirected URL after form generation (may include request ID). #### Response Example { "base_url": "https://yoomoney.ru/quickpay/confirm.xml?receiver=410019014512803&quickpay-form=shop&targets=Sponsor%20this%20project&paymentType=SB&sum=150", "redirected_url": "https://yoomoney.ru/transfer/quickpay?requestId=343532353937313933395f..." } ``` -------------------------------- ### Generate Payment Forms - Python Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt This snippet demonstrates how to use the `Quickpay` class to generate YooMoney payment form URLs. It allows customization of receiver, form type, payment amount, and optional fields for collecting payer information like name, email, and phone. It also supports setting success URLs and custom labels for tracking. ```python from yoomoney import Quickpay quickpay = Quickpay( receiver="410019014512803", # Your YooMoney wallet number quickpay_form="shop", # Form type: shop, button, donate targets="Sponsor this project", # Payment purpose (displayed to payer) paymentType="SB", # Payment type: PC (wallet), AC (card), SB (SberPay) sum=150, # Amount in rubles formcomment="Project donation", # Form title (optional) short_dest="Donation", # Short description (optional) label="donation-12345", # Your tracking label (optional) comment="Thank you!", # Default comment (optional) successURL="https://example.com/thanks", # Redirect URL after payment (optional) need_fio=True, # Request full name (optional) need_email=True, # Request email (optional) need_phone=False, # Request phone (optional) need_address=False, # Request address (optional) ) # URL to display or redirect user to print(quickpay.base_url) # https://yoomoney.ru/quickpay/confirm.xml?receiver=410019014512803&quickpay-form=shop&targets=Sponsor%20this%20project&paymentType=SB&sum=150 # Final redirected URL after form generation print(quickpay.redirected_url) # https://yoomoney.ru/transfer/quickpay?requestId=343532353937313933395f... ``` -------------------------------- ### Quickpay Forms API Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Generate a payment form that can be embedded into any website or blog, allowing users to make payments easily. ```APIDOC ## POST /quickpay/bind/card ### Description Generate a payment form that can be embedded into any website or blog, allowing users to make payments easily. ### Method POST ### Endpoint /quickpay/bind/card ### Parameters #### Request Body - **receiver** (string) - Required - The recipient's YooMoney account number. - **sum** (string) - Required - The payment amount. - **form_comment** (string) - Optional - A comment for the payment form. - **short_dest** (string) - Optional - A short destination for the payment form. - **comment_needed** (boolean) - Optional - Whether a comment is needed from the payer. - **payment_type** (string) - Optional - The type of payment (e.g., 'PC', 'AC', 'MC', 'WM', 'SB', 'MP', 'GP'). - **need_phone_number** (boolean) - Optional - Whether a phone number is needed from the payer. - **need_email** (boolean) - Optional - Whether an email is needed from the payer. - **success_url** (string) - Optional - URL to redirect to after successful payment. ### Request Example ```python from yoomoney import Client client = Client("YOUR_TOKEN") form_url = client.quickpay_form( receiver="410011234567890", sum="100.50", short_dest="Test Payment", success_url="https://example.com/success" ) print(f"Payment form URL: {form_url}") ``` ### Response #### Success Response (200) - **url** (string) - The URL of the generated payment form. #### Response Example ```json { "url": "https://yoomoney.ru/checkout/form/abcdef1234567890" } ``` ``` -------------------------------- ### Create Quickpay Form (Python) Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Generates a YooMoney Quickpay form for facilitating payments. It requires the receiver's account number, form type, target description, payment type, and amount. The output includes URLs for confirming and redirecting to the payment page. ```python from yoomoney import Quickpay quickpay = Quickpay( receiver="410019014512803", quickpay_form="shop", targets="Sponsor this project", paymentType="SB", sum=150, ) print(quickpay.base_url) print(quickpay.redirected_url) ``` -------------------------------- ### Async Account Information API Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Asynchronously retrieves information about the user's account. ```APIDOC ## GET /api/account-info (Async) ### Description Asynchronously retrieves detailed information about the user's account, including balance, currency, account status, and linked bank cards. This method is a coroutine and should be used with `await`. ### Method GET ### Endpoint /api/account-info ### Parameters #### Query Parameters - **token** (string) - Required - The API access token. ### Request Example ```python import asyncio from yoomoney import AsyncClient async def main(): async with AsyncClient("YOUR_TOKEN") as client: user = await client.account_info() print("Account number:", user.account) print("Account balance:", user.balance) ``` ### Response #### Success Response (200) - **account** (string) - The user's account number. - **balance** (string) - The current account balance. - **currency** (string) - The ISO 4217 currency code. - **account_status** (string) - The status of the account. - **account_type** (string) - The type of the account. - **balance_details** (object) - Extended balance information. - **cards_linked** (array) - A list of linked bank cards. #### Response Example ```json { "account": "410019014512803", "balance": "1000.00", "currency": "RUB", "account_status": "active", "account_type": "personal", "balance_details": { "total": "1000.00", "available": "1000.00" }, "cards_linked": [ { "pan_fragment": "****1234", "type": "MasterCard" } ] } ``` ``` -------------------------------- ### Quickpay Forms API Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Generates Quickpay forms for facilitating payments. ```APIDOC ## POST /quickpay/form ### Description Creates a Quickpay form that allows users to make payments to a specified receiver. This can be used for donations, purchases, or other payment scenarios. ### Method POST ### Endpoint /quickpay/form ### Parameters #### Request Body - **receiver** (string) - Required - The recipient's YooMoney account number. - **quickpay_form** (string) - Required - The type of Quickpay form (e.g., 'shop', 'donate'). - **targets** (string) - Required - A description of the payment purpose. - **paymentType** (string) - Required - The type of payment (e.g., 'SB' for card payment). - **sum** (number) - Required - The amount to be paid. ### Request Example ```python from yoomoney import Quickpay quickpay = Quickpay( receiver="410019014512803", quickpay_form="shop", targets="Sponsor this project", paymentType="SB", sum=150, ) print(quickpay.base_url) print(quickpay.redirected_url) ``` ### Response #### Success Response (200) - **base_url** (string) - The base URL for the Quickpay form. - **redirected_url** (string) - The URL to redirect the user to for completing the payment. #### Response Example ```text https://yoomoney.ru/quickpay/confirm.xml?receiver=410019014512803&quickpay-form=shop&targets=Sponsor%20this%20project&paymentType=SB&sum=150 https://yoomoney.ru/transfer/quickpay?requestId=343532353937313933395f66326561316639656131626539326632616434376662373665613831373636393537613336383639 ``` ``` -------------------------------- ### Fetch YooMoney Operation Details (Python) Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst This snippet shows how to asynchronously fetch detailed information for a specific YooMoney operation using the `yoomoney-api` library. It requires an API token and an operation ID. The output displays various attributes of the operation, such as title, pattern ID, direction, amount, label, and type. ```python import asyncio from yoomoney import AsyncClient async def main(): async with AsyncClient("YOUR_TOKEN") as client: details = await client.operation_details(operation_id="OPERATION_ID") for key, value in vars(details).items(): if not key.startswith("_"): print(f"{key:20s} : {str(value).replace(chr(10), ' ')}") asyncio.run(main()) ``` -------------------------------- ### Obtain YooMoney API Access Token Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Demonstrates how to obtain an OAuth access token for the YooMoney API. Requires client ID, redirect URI, and client secret from your YooMoney app registration. Various scopes can be requested. ```python from yoomoney import Authorize Authorize( client_id="YOUR_CLIENT_ID", redirect_uri="YOUR_REDIRECT_URI", client_secret="YOUR_CLIENT_SECRET", scope=[ "account-info", "operation-history", "operation-details", "incoming-transfers", "payment-p2p", "payment-shop", ], ) ``` -------------------------------- ### Fetch Account Information (Async Python) Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Asynchronously retrieves account information from YooMoney. This method requires an API token and should be used within an async context. It returns user details including account number, balance, currency, account status, and linked bank cards. ```python import asyncio from yoomoney import AsyncClient async def main(): async with AsyncClient("YOUR_TOKEN") as client: user = await client.account_info() print("Account number:", user.account) print("Account balance:", user.balance) print("Currency (ISO 4217):", user.currency) print("Account status:", user.account_status) print("Account type:", user.account_type) print("Extended balance information:") for key, value in vars(user.balance_details).items(): print(f" {key}: {value}") print("Linked bank cards:") if user.cards_linked: for card in user.cards_linked: print(f" {card.pan_fragment} — {card.type}") else: print(" No cards linked") asyncio.run(main()) ``` -------------------------------- ### Filter Transaction History with Parameters - Python Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt This snippet shows how to filter the operation history using various parameters such as type, date range, and custom labels. It demonstrates pagination using 'start_record' and 'next_record', and iterates through the returned operations to print their details. Requires a YooMoney Client object. ```python from yoomoney import Client from datetime import datetime # Assuming 'client' is an initialized YooMoney Client object # client = Client("YOUR_ACCESS_TOKEN") history = client.operation_history( type="deposition", # Filter: deposition, payment, incoming-transfer label="my-custom-label", # Filter by custom label from_date=datetime(2024, 1, 1), # Start date filter till_date=datetime(2024, 12, 31), # End date filter start_record="670278348725002105", # Pagination cursor records=30, # Max records to return (default: 30) details=True, # Include extended operation details ) print("Next page cursor:", history.next_record) # Use for pagination for op in history.operations: print(f"Operation: {op.operation_id}") print(f" Status: {op.status}") # success, refused, in_progress print(f" Datetime: {op.datetime}") # datetime object print(f" Title: {op.title}") # Human-readable description print(f" Direction: {op.direction}") # in, out print(f" Amount: {op.amount}") # float print(f" Type: {op.type}") # deposition, payment, incoming-transfer print(f" Pattern ID: {op.pattern_id}") # p2p, phone-topup, etc. print(f" Label: {op.label}") # Custom label if set client.close() ``` -------------------------------- ### Operation Details API Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt Retrieves detailed information for a specific operation using its unique identifier. ```APIDOC ## GET /operation_details ### Description Retrieves comprehensive details about a specific operation identified by its unique ID. ### Method GET ### Endpoint /operation_details ### Parameters #### Query Parameters - **operation_id** (string) - Required - The unique identifier of the operation. ### Response #### Success Response (200) - **operation_id** (string) - Unique identifier for the operation. - **status** (string) - Status of the operation ('success', 'refused', 'in_progress'). - **pattern_id** (string) - Identifier for the transaction pattern (e.g., 'p2p', 'phone-topup'). - **direction** (string) - Direction of the transaction ('in' or 'out'). - **amount** (float) - Transaction amount. - **amount_due** (float) - Total amount charged, including fees. - **fee** (float) - The fee amount for the transaction. - **datetime** (datetime) - Timestamp of the operation. - **title** (string) - Human-readable description of the operation. - **sender** (string) - Sender's account number or identifier. - **recipient** (string) - Recipient's account number, phone, or email. - **recipient_type** (string) - Type of the recipient ('account', 'phone', 'email'). - **message** (string) - Message sent by the sender. - **comment** (string) - Comment associated with the payment. - **codepro** (boolean) - Indicates if the operation was code-protected. - **protection_code** (string) - The code required to accept a protected transfer. - **expires** (datetime) - Expiration datetime for protected transfers. - **label** (string) - Custom label associated with the operation. - **type** (string) - Type of operation ('incoming-transfer', 'deposition', etc.). - **digital_goods** (object) - Information about digital goods if applicable. #### Response Example { "operation_id": "670244335488002312", "status": "success", "pattern_id": "p2p", "direction": "out", "amount": 50.00, "amount_due": 50.25, "fee": 0.25, "datetime": "2024-01-20T14:00:00Z", "title": "Payment to Friend", "sender": "41001...", "recipient": "79123456789", "recipient_type": "phone", "message": "Happy birthday!", "comment": "Gift", "codepro": false, "protection_code": null, "expires": null, "label": "birthday-gift", "type": "payment", "digital_goods": null } ``` -------------------------------- ### Account Information API Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Retrieves information about the user's account, including balance, currency, and linked cards. ```APIDOC ## GET /api/account-info ### Description Retrieves detailed information about the user's account, including balance, currency, account status, and linked bank cards. ### Method GET ### Endpoint /api/account-info ### Parameters #### Query Parameters - **token** (string) - Required - The API access token. ### Request Example ```python from yoomoney import Client client = Client("YOUR_TOKEN") user = client.account_info() print("Account number:", user.account) print("Account balance:", user.balance) ``` ### Response #### Success Response (200) - **account** (string) - The user's account number. - **balance** (string) - The current account balance. - **currency** (string) - The ISO 4217 currency code. - **account_status** (string) - The status of the account. - **account_type** (string) - The type of the account. - **balance_details** (object) - Extended balance information. - **cards_linked** (array) - A list of linked bank cards. #### Response Example ```json { "account": "410019014512803", "balance": "1000.00", "currency": "RUB", "account_status": "active", "account_type": "personal", "balance_details": { "total": "1000.00", "available": "1000.00" }, "cards_linked": [ { "pan_fragment": "****1234", "type": "MasterCard" } ] } ``` ``` -------------------------------- ### View Transaction History Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt Fetches a paginated list of wallet operations in reverse chronological order using `operation_history()`. Supports filtering by type, label, date, and pagination. ```python from datetime import datetime from yoomoney import Client client = Client("YOUR_ACCESS_TOKEN") # Get all operations history = client.operation_history() ``` -------------------------------- ### Retrieve Account Information Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt Retrieves the current status of a YooMoney wallet using the `account_info()` method. It returns details like account number, balance, currency, and status. Supports extended balance and linked card information. ```python from yoomoney import Client client = Client("YOUR_ACCESS_TOKEN") user = client.account_info() print("Account number:", user.account) # e.g., "410019014512803" print("Account balance:", user.balance) # e.g., 999999999999.99 print("Currency (ISO 4217):", user.currency) # e.g., "643" (RUB) print("Account status:", user.account_status) # e.g., "identified" print("Account type:", user.account_type) # e.g., "personal" # Extended balance details if user.balance_details: print("Total:", user.balance_details.total) print("Available:", user.balance_details.available) print("Pending deposits:", user.balance_details.deposition_pending) print("Blocked:", user.balance_details.blocked) print("Debt:", user.balance_details.debt) print("Hold:", user.balance_details.hold) # Linked bank cards if user.cards_linked: for card in user.cards_linked: print(f"Card: {card.pan_fragment} ({card.type})") # e.g., "****4487 (Visa)" else: print("No cards linked") client.close() ``` -------------------------------- ### Async Operation History API Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Asynchronously retrieves a list of past operations associated with the account. ```APIDOC ## GET /api/operation-history (Async) ### Description Asynchronously retrieves a paginated list of operations performed on the account. This method is a coroutine and should be used with `await`. Allows fetching subsequent pages using the `next_record` value from the previous response. ### Method GET ### Endpoint /api/operation-history ### Parameters #### Query Parameters - **token** (string) - Required - The API access token. - **from_record** (string) - Optional - The record to start fetching from (used for pagination). - **records** (integer) - Optional - The number of records to retrieve per page (default is 3). ### Request Example ```python import asyncio from yoomoney import AsyncClient async def main(): async with AsyncClient("YOUR_TOKEN") as client: history = await client.operation_history() print("List of operations:") print("Next page starts with:", history.next_record) for op in history.operations: print(f"Operation: {op.operation_id}") print(f" Amount: {op.amount}") ``` ### Response #### Success Response (200) - **next_record** (string) - The identifier for the next record to fetch for pagination. - **operations** (array) - A list of operation objects. - **operation_id** (string) - The unique identifier for the operation. - **status** (string) - The status of the operation (e.g., 'success'). - **datetime** (string) - The date and time of the operation. - **title** (string) - A description of the operation. - **pattern_id** (string) - The pattern ID associated with the operation. - **direction** (string) - The direction of the operation ('in' or 'out'). - **amount** (string) - The amount of the operation. - **label** (string) - A label associated with the operation. - **type** (string) - The type of the operation (e.g., 'deposition'). #### Response Example ```json { "next_record": "670244335488002313", "operations": [ { "operation_id": "670278348725002105", "status": "success", "datetime": "2021-10-10 10:10:10", "title": "Пополнение с карты ****4487", "pattern_id": null, "direction": "in", "amount": "100500.0", "label": "3784030974", "type": "deposition" } ] } ``` ``` -------------------------------- ### Fetch Operation History (Python) Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Retrieves a list of past operations from the YooMoney account. It requires an API token and returns a history object containing operations and information about the next page of results. Each operation includes details like ID, status, datetime, title, direction, amount, label, and type. ```python from yoomoney import Client client = Client("YOUR_TOKEN") history = client.operation_history() print("List of operations:") print("Next page starts with:", history.next_record) for op in history.operations: print() print(f"Operation: {op.operation_id}") print(f" Status : {op.status}") print(f" Datetime : {op.datetime}") print(f" Title : {op.title}") print(f" Pattern id : {op.pattern_id}") print(f" Direction : {op.direction}") print(f" Amount : {op.amount}") print(f" Label : {op.label}") print(f" Type : {op.type}") ``` -------------------------------- ### Fetch Operation History (Async Python) Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Asynchronously retrieves a list of past operations from the YooMoney account. Similar to the synchronous version, it requires an API token and returns operation details. This is useful for non-blocking operations in asynchronous applications. ```python import asyncio from yoomoney import AsyncClient async def main(): async with AsyncClient("YOUR_TOKEN") as client: history = await client.operation_history() print("List of operations:") print("Next page starts with:", history.next_record) for op in history.operations: print() print(f"Operation: {op.operation_id}") print(f" Status : {op.status}") print(f" Datetime : {op.datetime}") asyncio.run(main()) ``` -------------------------------- ### Operation History API Source: https://context7.com/alekseykorshuk/yoomoney-api/llms.txt Retrieves a history of operations (depositions, payments, transfers) with filtering and pagination capabilities. ```APIDOC ## GET /operation_history ### Description Retrieves a history of operations with filtering by type, date range, and custom labels. Supports pagination using a cursor. ### Method GET ### Endpoint /operation_history ### Parameters #### Query Parameters - **type** (string) - Optional - Filter operations by type: 'deposition', 'payment', 'incoming-transfer'. - **label** (string) - Optional - Filter by custom label. - **from_date** (datetime) - Optional - Start date for filtering operations. - **till_date** (datetime) - Optional - End date for filtering operations. - **start_record** (string) - Optional - Cursor for paginating results. - **records** (integer) - Optional - Maximum number of records to return (default: 30). - **details** (boolean) - Optional - Include extended operation details (default: false). ### Response #### Success Response (200) - **next_record** (string) - Cursor for the next page of results. - **operations** (array) - A list of operation objects. - **operation_id** (string) - Unique identifier for the operation. - **status** (string) - Status of the operation (e.g., 'success', 'refused', 'in_progress'). - **datetime** (datetime) - Timestamp of the operation. - **title** (string) - Human-readable description of the operation. - **direction** (string) - Direction of the transaction ('in' or 'out'). - **amount** (float) - Transaction amount. - **type** (string) - Type of operation ('deposition', 'payment', 'incoming-transfer'). - **pattern_id** (string) - Identifier for the transaction pattern (e.g., 'p2p', 'phone-topup'). - **label** (string) - Custom label associated with the operation. #### Response Example { "next_record": "670278348725002105", "operations": [ { "operation_id": "1234567890", "status": "success", "datetime": "2024-01-15T10:30:00Z", "title": "Payment Received", "direction": "in", "amount": 100.50, "type": "incoming-transfer", "pattern_id": "p2p", "label": "my-custom-label" } ] } ``` -------------------------------- ### Operation History API Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst View the full or partial history of operations associated with the user's account. Operations are returned in reverse-chronological order and can be paginated. ```APIDOC ## GET /api/operation-history ### Description View the full or partial history of operations associated with the user's account. Operations are returned in reverse-chronological order and can be paginated. ### Method GET ### Endpoint /api/operation-history ### Parameters #### Query Parameters - **access_token** (string) - Required - The OAuth access token for the user. - **from** (string) - Optional - The start date/time for filtering operations (ISO 8601 format). - **till** (string) - Optional - The end date/time for filtering operations (ISO 8601 format). - **order** (string) - Optional - The order of operations ('asc' or 'desc', default is 'desc'). - **records** (integer) - Optional - The number of records to retrieve per page. - **next_page_token** (string) - Optional - Token for retrieving the next page of results. ### Request Example ```python from yoomoney import Client client = Client("YOUR_TOKEN") history = client.operation_history(from_date="2023-01-01T00:00:00", records=10) for op in history.operations: print(f"Operation ID: {op.operation_id}, Amount: {op.amount}") ``` ### Response #### Success Response (200) - **operations** (array of objects) - A list of operation objects. - **operation_id** (string) - Unique identifier for the operation. - **amount** (string) - The amount of the operation. - **currency** (string) - The currency of the operation. - **datetime** (string) - The date and time of the operation (ISO 8601 format). - **status** (string) - The status of the operation. - **type** (string) - The type of the operation (e.g., 'incoming', 'payment'). - **sender** (string or null) - The sender of the funds (if applicable). - **recipient** (string or null) - The recipient of the funds (if applicable). - **comment** (string or null) - A comment associated with the operation. - **next_page_token** (string or null) - Token for retrieving the next page of results. #### Response Example ```json { "operations": [ { "operation_id": "123456789", "amount": "-50.00", "currency": "643", "datetime": "2023-10-27T10:00:00+0000", "status": "success", "type": "payment", "sender": null, "recipient": "410011234567890", "comment": "Payment for goods" } ], "next_page_token": "some_token_for_next_page" } ``` ``` -------------------------------- ### Access Token Authentication Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Obtain an OAuth access token required for authenticating with the YooMoney API. This involves providing your client ID, redirect URI, and optionally a client secret, along with the desired scopes. ```APIDOC ## POST /oauth/authorize ### Description Obtain an OAuth access token required for authenticating with the YooMoney API. This involves providing your client ID, redirect URI, and optionally a client secret, along with the desired scopes. ### Method POST ### Endpoint /oauth/authorize ### Parameters #### Query Parameters - **client_id** (string) - Required - Your application's client ID. - **redirect_uri** (string) - Required - The URI to redirect to after authorization. - **scope** (array of strings) - Optional - The list of permissions your application requests. - **client_secret** (string) - Optional - Your application's client secret. ### Request Example ```python from yoomoney import Authorize Authorize( client_id="YOUR_CLIENT_ID", redirect_uri="YOUR_REDIRECT_URI", client_secret="YOUR_CLIENT_SECRET", scope=[ "account-info", "operation-history", "operation-details", "incoming-transfers", "payment-p2p", "payment-shop", ], ) ``` ### Response #### Success Response (200) Upon successful authorization, the user is redirected to the specified `redirect_uri` with an authorization code. This code is then exchanged for an access token. #### Response Example (Redirection to `YOUR_REDIRECT_URI?code=AUTHORIZATION_CODE`) ``` -------------------------------- ### Fetch Operation Details (Python) Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Retrieves detailed information for a specific YooMoney operation. This function requires an API token and the unique operation ID. It returns an object containing various fields related to the operation, such as status, amount, datetime, sender, message, and more. ```python from yoomoney import Client client = Client("YOUR_TOKEN") details = client.operation_details(operation_id="OPERATION_ID") for key, value in vars(details).items(): if not key.startswith("_"): print(f"{key:20s} : {str(value).replace(chr(10), ' ')}") ``` -------------------------------- ### Operation History API Source: https://github.com/alekseykorshuk/yoomoney-api/blob/master/README.rst Retrieves a list of past operations associated with the account. ```APIDOC ## GET /api/operation-history ### Description Retrieves a paginated list of operations performed on the account. Allows fetching subsequent pages using the `next_record` value from the previous response. ### Method GET ### Endpoint /api/operation-history ### Parameters #### Query Parameters - **token** (string) - Required - The API access token. - **from_record** (string) - Optional - The record to start fetching from (used for pagination). - **records** (integer) - Optional - The number of records to retrieve per page (default is 3). ### Request Example ```python from yoomoney import Client client = Client("YOUR_TOKEN") history = client.operation_history() print("List of operations:") print("Next page starts with:", history.next_record) for op in history.operations: print(f"Operation: {op.operation_id}") print(f" Amount: {op.amount}") ``` ### Response #### Success Response (200) - **next_record** (string) - The identifier for the next record to fetch for pagination. - **operations** (array) - A list of operation objects. - **operation_id** (string) - The unique identifier for the operation. - **status** (string) - The status of the operation (e.g., 'success'). - **datetime** (string) - The date and time of the operation. - **title** (string) - A description of the operation. - **pattern_id** (string) - The pattern ID associated with the operation. - **direction** (string) - The direction of the operation ('in' or 'out'). - **amount** (string) - The amount of the operation. - **label** (string) - A label associated with the operation. - **type** (string) - The type of the operation (e.g., 'deposition'). #### Response Example ```json { "next_record": "670244335488002313", "operations": [ { "operation_id": "670278348725002105", "status": "success", "datetime": "2021-10-10 10:10:10", "title": "Пополнение с карты ****4487", "pattern_id": null, "direction": "in", "amount": "100500.0", "label": "3784030974", "type": "deposition" } ] } ``` ```