### Get Receipts List - Python Example Source: https://yookassa.ru/developers/api/index_lang=ru This snippet provides a Python example for fetching a list of receipts from the YooKassa API. It uses the `requests` library to make a GET request and includes basic authentication. The example shows how to set up the request URL and authentication headers. ```python import requests shop_id = '<Идентификатор магазина>' secret_key = '<Секретный ключ>' url = "https://api.yookassa.ru/v3/receipts" response = requests.get(url, auth=(shop_id, secret_key)) print(response.json()) ``` -------------------------------- ### Get Account Settings (Python) Source: https://yookassa.ru/developers/api/index_lang=ru This Python example shows how to obtain account settings via the YooKassa API. It sends a GET request to the '/me' endpoint to retrieve configuration data for stores or gateways, essential for managing payments and payouts. ```python import requests import base64 # Replace with your actual credentials account_id = 'YOUR_ACCOUNT_ID' secret_key = 'YOUR_SECRET_KEY' url = 'https://api.yookassa.ru/v3/me' credentials = f'{account_id}:{secret_key}' encoded_credentials = base64.b64encode(credentials.encode()).decode() headers = { 'Authorization': f'Basic {encoded_credentials}', 'Content-Type': 'application/json' } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes settings = response.json() print(settings) except requests.exceptions.RequestException as e: print(f'Error: {e}') ``` -------------------------------- ### Get Payout Information - PHP Source: https://yookassa.ru/developers/api/index_lang=en A PHP example demonstrating how to fetch payout information. It uses the cURL extension to make the HTTP request with authentication headers. ```php ' . ':' . '<Секретный ключ>'); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); $payoutInfo = json_decode($response, true); // Process the $payoutInfo array print_r($payoutInfo); ?> ``` -------------------------------- ### Get Receipt Information - Python Example Source: https://yookassa.ru/developers/api/index This Python script demonstrates fetching receipt information from the YooKassa API using the `requests` library. It constructs the API endpoint URL, sets up basic authentication, and sends a GET request. The response JSON is then parsed for further use. ```python import requests receipt_id = 'rt-2da5c87d-0384-50e8-a7f3-8d5646dd9e10' # Replace with actual receipt ID shop_id = '<Идентификатор магазина>' # Replace with your Shop ID secret_key = '<Секретный ключ>' # Replace with your Secret Key url = f"https://api.yookassa.ru/v3/receipts/{receipt_id}" response = requests.get(url, auth=(shop_id, secret_key)) if response.status_code == 200: receipt_data = response.json() print(receipt_data) else: print(f"Error: {response.status_code}") print(response.text) ``` -------------------------------- ### Get Receipts List with Filters (PHP) Source: https://yookassa.ru/developers/api/index_lang=en PHP example demonstrating how to make a request to the YooKassa API to get a list of receipts. It shows how to include parameters like `payment_id` and `limit` in the request body to filter the results. ```php setAuth('<Идентификатор магазина>', '<Секретный ключ>'); $params = [ 'payment_id' => '215d8da0-000f-50be-b000-0003308c89be', 'limit' => 10, 'status' => 'succeeded' ]; $result = $client->newRequest($params)->receipts()->getReceipts(); print_r($result); ?> ``` -------------------------------- ### Retrieve a List of Deals - PHP Source: https://yookassa.ru/developers/api/index This PHP code demonstrates how to retrieve a list of deals from the Yookassa API. It shows how to construct the request URL and send a GET request. Authentication is handled via basic authentication. This example is a placeholder and would require a full SDK or manual HTTP request implementation. ```php '; $secretKey = '<Секретный ключ>'; $url = 'https://api.yookassa.ru/v3/deals'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Basic ' . base64_encode($merchantId . ':' . $secretKey) )); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } else { // Process the response // echo $response; } curl_close($ch); ?> ``` -------------------------------- ### Get Receipts List - PHP Example Source: https://yookassa.ru/developers/api/index_lang=ru This snippet demonstrates how to retrieve a list of receipts using the YooKassa API with PHP. It outlines the structure of a request, including necessary headers for authentication and content type. This example is a placeholder and would need to be integrated with a specific HTTP client library. ```php ``` -------------------------------- ### Receipt Operational Details Example Source: https://yookassa.ru/developers/api/index_lang=ru Provides an example of how to include operational details for a receipt. Currently, only the `operation_id` is supported, which is a required field for this object. ```json { "receipt_operational_details": { "operation_id": 123456789 } } ``` -------------------------------- ### Get Payments List Request Parameters - Example Usage Source: https://yookassa.ru/developers/api/index_lang=ru This section outlines the parameters available for filtering payment retrieval requests. It shows how to use query parameters with ISO 8601 timestamps for date filtering, specify payment methods, and set status or limits. These parameters allow for precise querying of payment data. ```text created_at.gte=2018-07-18T10:51:18.139Z created_at.gt=2018-07-18T10:51:18.139Z created_at.lte=2018-07-18T10:51:18.139Z created_at.lt=2018-07-18T10:51:18.139Z captured_at.gte=2018-07-18T10:51:18.139Z captured_at.gt=2018-07-18T10:51:18.139Z captured_at.lte=2018-07-18T10:51:18.139Z captured_at.lt=2018-07-18T10:51:18.139Z payment_method=bank_card status=succeeded limit=10 ``` -------------------------------- ### Get Deals List with PHP Source: https://yookassa.ru/developers/api/index_lang=ru Example of retrieving a list of deals using the YooKassa API in PHP. This code snippet illustrates how to construct the API request, including authentication and specifying query parameters for filtering and pagination. It handles the response to extract deal information. ```php setAuth(\'<Идентификатор магазина>\', \'<Секретный ключ>\'); $options = [ \'limit\' => 10, \'sort\' => \'-created_at\', \'created_at.gte\' => \'2018-07-18T10:51:18.139Z\', \'status\' => \'closed\', \'full_text_search\' => \'123554642-2432FF344R\', ]; try { $response = $client->deals()->getDeals($options); // Process the response print_r($response); } catch (Exception $e) { // Handle exceptions echo $e->getMessage(); } ?> ``` -------------------------------- ### PHP Receipt Creation Example Source: https://yookassa.ru/developers/api/index Illustrates how to create a receipt using PHP with the Yookassa API. This example highlights the use of a client library or direct HTTP requests to send receipt data, including item details and customer information. ```php // PHP example would go here, demonstrating how to construct and send the request. ``` -------------------------------- ### Create Payment Request (cURL) Source: https://yookassa.ru/developers/api/index_lang=en Example of creating a payment request using cURL. This request includes amount, payment method, confirmation details, and a description. It requires Shop ID, Secret Key, and an Idempotence Key. ```bash curl https://api.yookassa.ru/v3/payments \ -X POST \ -u : \ -H 'Idempotence-Key: ' \ -H 'Content-Type: application/json' \ -d '{ "amount": { "value": "2.00", "currency": "RUB" }, "payment_method_data": { "type": "bank_card" }, "confirmation": { "type": "redirect", "return_url": "https://www.example.com/return_url" }, "description": "Order No. 72" }' ``` -------------------------------- ### Get Receipt Information - PHP Example Source: https://yookassa.ru/developers/api/index This PHP code illustrates how to fetch receipt details from the YooKassa API. It utilizes cURL to send a GET request, including the necessary authentication headers. The returned JSON response contains the receipt's status and other relevant data. ```php '; // Replace with your Shop ID $secretKey = '<Секретный ключ>'; // Replace with your Secret Key $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.yookassa.ru/v3/receipts/{$receiptId}"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Basic ' . base64_encode($shopId . ':' . $secretKey) )); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); $receiptData = json_decode($response, true); // Process the $receiptData array print_r($receiptData); ?> ``` -------------------------------- ### Refund via SBP (JSON) Source: https://yookassa.ru/developers/api/index A JSON example demonstrating the parameters required for initiating a refund using the SBP (Faster Payments System). It includes the payment type and an optional SBP operation ID for succeeded refunds. ```json { "type": "sbp", "sbp_operation_id": "1027088AE4CB48CB81287833347A8777" } ``` -------------------------------- ### Get Receipts List (cURL) Source: https://yookassa.ru/developers/api/index Example of making a request to the YooKassa API to retrieve a list of receipts using cURL. Requires shop ID and secret key for authentication. ```shell curl https://api.yookassa.ru/v3/receipts \ -u <Идентификатор магазина>:<Секретный ключ> ``` -------------------------------- ### Python Receipt Creation Example Source: https://yookassa.ru/developers/api/index Demonstrates receipt creation in Python using the Yookassa API. This snippet shows how to structure the request payload and send it to the API endpoint, including essential parameters for a receipt. ```python # Python example would go here, showing request construction and sending. ``` -------------------------------- ### Get Receipts List with Filters (Python) Source: https://yookassa.ru/developers/api/index_lang=en Python example for fetching receipts from the YooKassa API. This snippet illustrates how to construct a request with filters such as `created_at.gte`, `limit`, and `payment_id` to narrow down the search. ```python from yookassa import Configuration, Receipts Configuration.account_id = '<Идентификатор магазина>' Configuration.secret_key = '<Секретный ключ>' params = { 'payment_id': '215d8da0-000f-50be-b000-0003308c89be', 'limit': 10, 'status': 'succeeded', 'created_at.gte': '2018-07-18T10:51:18.139Z' } response = Receipts.list_receipts(params) print(response.json()) ``` -------------------------------- ### List Refunds Response Example Source: https://yookassa.ru/developers/api/index_lang=ru Example JSON response when listing refunds. It includes a list of refund items, each with details like ID, status, amount, creation timestamp, and payment ID. The 'next_cursor' is provided for pagination if more results are available. ```json { "type": "list", "items": [ { "id": "216749f7-0016-50be-b000-078d43a63ae4", "status": "succeeded", "amount": { "value": "1.00", "currency": "RUB" }, "created_at": "2017-10-04T19:27:51.407Z", "payment_id": "216749da-000f-50be-b000-096747fad91e", "metadata": {} } ], "next_cursor": "416746f8-0016-50be-b000-078d43a4578" } ``` -------------------------------- ### Get Invoice Information using PHP Source: https://yookassa.ru/developers/api/index_lang=ru This PHP code example shows how to make a GET request to the Yookassa API to fetch invoice information. It utilizes cURL to send the request with appropriate authentication headers and returns the invoice object in its current status. Ensure you replace placeholders with your actual shop ID, secret key, and invoice ID. ```php ' . ':' . '<Секретный ключ>'); $headers = array(); $headers[] = 'Content-Type: application/json'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); echo $response; ?> ``` -------------------------------- ### Get Receipts List Request Body (JSON) Source: https://yookassa.ru/developers/api/index Example of a JSON request body for the YooKassa API's 'receipts' endpoint. This includes parameters like type, payment_id, status, and details about items and settlements. ```json { "type": "list", "items": [ { "id": "rt_1da5c87d-0984-50e8-a7f3-8de646dd9ec9", "type": "payment", "payment_id": "215d8da0-000f-50be-b000-0003308c89be", "status": "succeeded", "fiscal_document_number": "3986", "fiscal_storage_number": "9288000100115785", "fiscal_attribute": "2617603921" } ], "settlements": [ { "type": "prepayment", "amount": { "value": "8000.00", "currency": "RUB" } }, { "type": "prepayment", "amount": { "value": "7000.00", "currency": "RUB" } } ], "tax_system_code": 1 } ``` -------------------------------- ### Get Receipts List Request Body with Items (JSON) Source: https://yookassa.ru/developers/api/index Example JSON request body for YooKassa API's 'receipts' endpoint, demonstrating the structure for 'items' with details like description, quantity, amount, vat_code, payment_mode, payment_subject, and country_of_origin_code. ```json { "id": "rt_1da5c87d-0984-50e8-a7f3-8de646dd9ec9", "type": "payment", "payment_id": "215d8da0-000f-50be-b000-0003308c89be", "status": "pending", "items": [ { "description": "Наименование товара 1", "quantity": 1.000, "amount": { "value": "14000.00", "currency": "RUB" }, "vat_code": 2, "payment_mode": "full_payment", "payment_subject": "commodity", "country_of_origin_code": "CN" }, { "description": "Наименование товара 2", "quantity": 1.000, "amount": { "value": "1000.00", "currency": "RUB" }, "vat_code": 2, "payment_mode": "full_payment", "payment_subject": "commodity", "country_of_origin_code": "CN" } ], "settlements": [ { "type": "prepayment", "amount": { "value": "8000.00", "currency": "RUB" } }, { "type": "prepayment", "amount": { "value": "7000.00", "currency": "RUB" } } ], "tax_system_code": 1 } ``` -------------------------------- ### Example Payout Object Source: https://yookassa.ru/developers/api/index An example of a successfully created payout object in JSON format. This object includes details like the payout ID, amount, status, destination, creation timestamp, and associated metadata. ```json { "id": "po-2855a19a-0003-5000-a000-0efa9e7f4264", "amount": { "value": "320.00", "currency": "RUB" }, "status": "succeeded", "payout_destination": { "type": "bank_card", "card": { "first6": "220220", "last4": "2537", "card_type": "Mir", "issuer_country": "RU", "issuer_name": "Sberbank Of Russia" } }, "description": "Выплата по заказу №37", "created_at": "2021-06-21T16:22:50.512Z", "succeeded_at": "2021-06-21T16:23:39.634Z", "metadata": { "order_id": "37" }, "test": false } ``` -------------------------------- ### Create Payment Method (cURL) Source: https://yookassa.ru/developers/api/index This snippet demonstrates how to create a payment method using a POST request to the /payment_methods endpoint. It requires specifying the payment method type and includes optional card details. The response contains the details of the created payment method. ```bash curl -X POST "https://api.yookassa.ru/v3/payment_methods" \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "type": "bank_card", "card": { "number": "4111111111111111", "expiry_month": "12", "expiry_year": "2025" } }' ```