### Install YooCheckout SDK - Bash Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Command line instruction to install the @a2seven/yoo-checkout SDK using npm, the Node.js package manager. ```bash npm install @a2seven/yoo-checkout ``` -------------------------------- ### Install Dependencies (Bash) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Command to install project dependencies listed in package.json using npm. This should be run in the project's root directory. ```bash $ npm install ``` -------------------------------- ### Install Development Dependencies (Bash) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Command to install the necessary development and testing dependencies for the project. This should be run in the directory containing the package.json file. ```bash $ npm install ``` -------------------------------- ### Install Package - npm Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Command to install the @a2seven/yoo-checkout package using the npm package manager. ```bash npm install @a2seven/yoo-checkout ``` -------------------------------- ### Run Unit Tests (Bash) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Command to execute the unit tests defined in the project's package.json file. Requires that development dependencies have been installed previously. ```bash $ npm run test:unit ``` -------------------------------- ### Create a New Payment - JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Example showing how to create a new payment using the SDK, including defining the payment payload with amount, currency, payment method, and confirmation details, and handling potential errors. ```javascript import { YooCheckout, ICreatePayment } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const createPayload: ICreatePayment = { amount: { value: '2.00', currency: 'RUB' }, payment_method_data: { type: 'bank_card' }, confirmation: { type: 'redirect', return_url: 'test' } }; try { const payment = await checkout.createPayment(createPayload, idempotenceKey); console.log(payment) } catch (error) { console.error(error); } ``` -------------------------------- ### Get Shop Info using YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Illustrates initializing the YooCheckout client and asynchronously fetching the current shop's information from the Yookassa API, logging the details or any errors encountered. ```javascript import { YooCheckout, ICreateWebHook } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey', token: 'your_OAuth_token' }); try { const shop = await checkout.getShop(); console.log(shop) } catch (error) { console.error(error); } ``` -------------------------------- ### Get Webhook List using YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Demonstrates how to initialize the YooCheckout client with credentials and asynchronously retrieve the list of registered webhooks from the Yookassa API, logging the result or any errors. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey', token: 'your_OAuth_token' }); try { const webHookList = await checkout.getWebHookList(); console.log(webHookList) } catch (error) { console.error(error); } ``` -------------------------------- ### Authenticating GET Request with cURL (Bash) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Demonstrates how to make a simple GET request to the Yoo.Checkout API using cURL and HTTP Basic Authentication. The shop ID is used as the username and the secret key as the password. ```bash curl https://api.yookassa.ru/v3/payments/{payment_id} \ -u : ``` -------------------------------- ### Getting Refund List with YooKassa API (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Demonstrates how to retrieve a list of refunds using the `@a2seven/yoo-checkout` library. Similar to getting payment lists, it initializes the client, defines filtering criteria using the `IGetRefundList` interface (e.g., creation date range, limit), and calls the `getRefundList` method. The resulting list is logged or an error is handled. ```javascript import { YooCheckout, IGetRefundList } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const filters: IGetRefundList = { created_at: { value: '2021-01-27T13:58:02.977Z', mode: 'gte' }, limit: 20 }; try { const refundList = await checkout.getRefundList(filters); console.log(refundList) } catch (error) { console.error(error); } ``` -------------------------------- ### Authenticate GET Request with Basic Auth (curl) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Demonstrates how to make an authenticated GET request to the YooKassa API using curl and HTTP Basic Auth. Authentication requires providing the store ID and secret key. ```bash curl https://api.yookassa.ru/v3/payments/{payment_id} \ -u : ``` -------------------------------- ### Example SDK Error Response Object - JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Shows the structure of an error object returned by the @a2seven/yoo-checkout SDK, extending the basic API error with an 'errorCode' property. ```javascript ErrorResponse { "type": "error", "id": "ab5a11cd-13cc-4e33-af8b-75a74e18dd09", "code": "invalid_request", "description": "Idempotence key duplicated", "parameter": "Idempotence-Key" "errorCode": 401 } ``` -------------------------------- ### Example API Error Response Body Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Illustrates the structure of an error response returned directly by the YooKassa API when a request fails. ```json { "type": "error", "id": "ab5a11cd-13cc-4e33-af8b-75a74e18dd09", "code": "invalid_request", "description": "Idempotence key duplicated", "parameter": "Idempotence-Key" } ``` -------------------------------- ### Example API Error Response Body - JSON Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Illustrates the structure of an error response returned directly by the YooKassa API when a request fails, including error type, ID, code, description, and parameter. ```json { "type": "error", "id": "ab5a11cd-13cc-4e33-af8b-75a74e18dd09", "code": "invalid_request", "description": "Idempotence key duplicated", "parameter": "Idempotence-Key" } ``` -------------------------------- ### Get Shop Information using YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Illustrates how to fetch details about the configured shop using the @a2seven/yoo-checkout library. Requires an initialized client with valid credentials. The shop information object is logged to the console upon successful retrieval. ```javascript import { YooCheckout, ICreateWebHook } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey', token: 'your_OAuth_token' }); try { const shop = await checkout.getShop(); console.log(shop) } catch (error) { console.error(error); } ``` -------------------------------- ### Getting Refund List with YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Demonstrates fetching a list of refunds using the @a2seven/yoo-checkout library. It initializes the client, defines filters (like creation date and limit), and calls the `getRefundList` method, logging the result or any errors. ```javascript import { YooCheckout, IGetRefundList } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const filters: IGetRefundList = { created_at: { value: '2021-01-27T13:58:02.977Z', mode: 'gte' }, limit: 20 }; try { const refundList = await checkout.getRefundList(filters); console.log(refundList) } catch (error) { console.error(error); } ``` -------------------------------- ### Cancel a Payment - JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Example demonstrating how to cancel a payment using its ID and an idempotence key via the SDK, including error handling. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const paymentId = '21966b95-000f-50bf-b000-0d78983bb5bc'; const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; try { const payment = await checkout.cancelPayment(paymentId, idempotenceKey); console.log(payment) } catch (error) { console.error(error); } ``` -------------------------------- ### Getting Payment List with YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Demonstrates how to fetch a list of payments using the @a2seven/yoo-checkout library. It initializes the client, defines filters (like creation date and limit), and calls the `getPaymentList` method, logging the result or any errors. ```javascript import { YooCheckout, IGetPaymentList } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const filters: IGetPaymentList = { created_at: { value: '2021-01-27T13:58:02.977Z', mode: 'gte' }, limit: 20 }; try { const paymentList = await checkout.getPaymentList(filters); console.log(paymentList) } catch (error) { console.error(error); } ``` -------------------------------- ### Create Refund with Idempotency Key (curl) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Illustrates how to perform an authenticated POST request to the YooKassa API to create a refund. This example includes using Basic Auth, setting the Idempotence-Key header for idempotency, and providing the refund details in a JSON request body. ```bash curl https://api.yookassa.ru/v3/refunds \ -X POST \ -u : \ -H 'Idempotence-Key: ' \ -H 'Content-Type: application/json' \ -d '{ "amount": { "value": "2.00", "currency": "RUB" }, "payment_id": "215d8da0-000f-50be-b000-0003308c89be" }' ``` -------------------------------- ### Example SDK Error Response Object Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Shows the structure of an error object returned by the @a2seven/yoo-checkout SDK when an API call results in an error. It includes the standard API error fields plus an 'errorCode' property. ```javascript ErrorResponse { "type": "error", "id": "ab5a11cd-13cc-4e33-af8b-75a74e18dd09", "code": "invalid_request", "description": "Idempotence key duplicated", "parameter": "Idempotence-Key" "errorCode": 401 } ``` -------------------------------- ### Getting Receipt Details with YooKassa JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.ru.md Shows how to retrieve details for a specific receipt using its unique ID, utilizing the `@a2seven/yoo-checkout` library. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const receiptId = '21966b95-000f-50bf-b000-0d78983bb5bc'; try { const receipt = await checkout.getReceipt(receiptId); console.log(receipt) } catch (error) { console.error(error); } ``` -------------------------------- ### Getting Receipt List with YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Demonstrates fetching a list of receipts using the @a2seven/yoo-checkout library. It initializes the client, defines filters (like creation date and limit), and calls the `getReceiptList` method, logging the result or any errors. ```javascript import { YooCheckout, IGetReceiptList } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const filters: IGetReceiptList = { created_at: { value: '2021-01-27T13:58:02.977Z', mode: 'gte' }, limit: 20 }; try { const receiptList = await checkout.getReceiptList(filters); console.log(receiptList) } catch (error) { console.error(error); } ``` -------------------------------- ### Get Payment Details - YooCheckout JavaScript SDK Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Shows how to retrieve the details of an existing payment using its unique ID via the YooCheckout client. Includes basic error handling for the API call. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const paymentId = '21966b95-000f-50bf-b000-0d78983bb5bc'; try { const payment = await checkout.getPayment(paymentId); console.log(payment) } catch (error) { console.error(error); } ``` -------------------------------- ### Getting Refund Details with YooKassa JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.ru.md Shows how to retrieve details for a previously created refund using its unique ID. It utilizes the `@a2seven/yoo-checkout` library. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const refundId = '21966b95-000f-50bf-b000-0d78983bb5bc'; try { const refund = await checkout.getRefund(refundId); console.log(refund) } catch (error) { console.error(error); } ``` -------------------------------- ### Get Webhook List using YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Demonstrates how to retrieve a list of all registered webhooks for the configured shop using the @a2seven/yoo-checkout library. Requires an initialized client with valid credentials. The list of webhooks is printed to the console upon success. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey', token: 'your_OAuth_token' }); try { const webHookList = await checkout.getWebHookList(); console.log(webHookList) } catch (error) { console.error(error); } ``` -------------------------------- ### Getting Payment List with YooKassa API (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Demonstrates how to retrieve a list of payments using the `@a2seven/yoo-checkout` library. It initializes the client with shop credentials, defines filtering criteria using the `IGetPaymentList` interface (e.g., creation date range, limit), and calls the `getPaymentList` method. The result is logged or an error is caught. ```javascript import { YooCheckout, IGetPaymentList } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const filters: IGetPaymentList = { created_at: { value: '2021-01-27T13:58:02.977Z', mode: 'gte' }, limit: 20 }; try { const paymentList = await checkout.getPaymentList(filters); console.log(paymentList) } catch (error) { console.error(error); } ``` -------------------------------- ### Getting Refund Details with YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Illustrates how to retrieve details for a specific refund using its ID via the @a2seven/yoo-checkout library. It initializes the client and calls the `getRefund` method with the refund ID, logging the response or errors. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const refundId = '21966b95-000f-50bf-b000-0d78983bb5bc'; try { const refund = await checkout.getRefund(refundId); console.log(refund) } catch (error) { console.error(error); } ``` -------------------------------- ### Getting Refund Details with YooKassa API (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Illustrates how to fetch details for a specific refund using its unique ID via the `@a2seven/yoo-checkout` library. The code initializes the client and calls the `getRefund` method, passing the required refund identifier. The retrieved refund object is then logged. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const refundId = '21966b95-000f-50bf-b000-0d78983bb5bc'; try { const refund = await checkout.getRefund(refundId); console.log(refund) } catch (error) { console.error(error); } ``` -------------------------------- ### Getting Receipt Details with YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Illustrates how to retrieve details for a specific receipt using its ID via the @a2seven/yoo-checkout library. It initializes the client and calls the `getReceipt` method with the receipt ID, logging the response or errors. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const receiptId = '21966b95-000f-50bf-b000-0d78983bb5bc'; try { const receipt = await checkout.getReceipt(receiptId); console.log(receipt) } catch (error) { console.error(error); } ``` -------------------------------- ### Getting Receipt List with YooKassa API (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Demonstrates how to retrieve a list of fiscal receipts using the `@a2seven/yoo-checkout` library. It initializes the client, defines filtering criteria using the `IGetReceiptList` interface (e.g., creation date range, limit), and calls the `getReceiptList` method. The resulting list is logged or an error is handled. ```javascript import { YooCheckout, IGetReceiptList } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const filters: IGetReceiptList = { created_at: { value: '2021-01-27T13:58:02.977Z', mode: 'gte' }, limit: 20 }; try { const receiptList = await checkout.getReceiptList(filters); console.log(receiptList) } catch (error) { console.error(error); } ``` -------------------------------- ### Getting Receipt Details with YooKassa API (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Illustrates how to fetch details for a specific fiscal receipt using its unique ID via the `@a2seven/yoo-checkout` library. The code initializes the client and calls the `getReceipt` method, passing the required receipt identifier. The retrieved receipt object is then logged. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const receiptId = '21966b95-000f-50bf-b000-0d78983bb5bc'; try { const receipt = await checkout.getReceipt(receiptId); console.log(receipt) } catch (error) { console.error(error); } ``` -------------------------------- ### Initialize YooCheckout Client - JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Demonstrates how to import the YooCheckout class and create a new client instance using your shop ID and secret key for API interaction. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; // OR const { YooCheckout } = require('@a2seven/yoo-checkout'); const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); ``` -------------------------------- ### Initialize YooCheckout Client - JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Imports the YooCheckout class and creates a new instance of the client, configuring it with the required shop ID and secret key for authentication. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; // OR const { YooCheckout } = require('@a2seven/yoo-checkout'); const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); ``` -------------------------------- ### Run Unit Tests (Bash) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Command to execute the unit tests defined in the project's package.json scripts using npm. ```bash $ npm run test:unit ``` -------------------------------- ### Creating Refund with YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Shows how to initiate a refund for a specific payment using @a2seven/yoo-checkout. It sets up the client, defines an idempotence key and the refund payload (payment ID, amount), and calls the `createRefund` method, logging the result or errors. ```javascript import { YooCheckout, ICreateRefund } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const createRefundPayload: ICreateRefund = { payment_id: '27a3852a-000f-5000-8000-102d922df8db', amount: { value: '1.00', currency: 'RUB' } }; try { const refund = await checkout.createRefund(createRefundPayload, idempotenceKey); console.log(refund) } catch (error) { console.error(error); } ``` -------------------------------- ### Create Payment - YooCheckout JavaScript SDK Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Demonstrates how to create a new payment using the initialized YooCheckout client. It requires a payment payload object specifying details like amount and payment method, and an idempotency key to prevent duplicate requests. Includes basic error handling. ```javascript import { YooCheckout, ICreatePayment } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const createPayload: ICreatePayment = { amount: { value: '2.00', currency: 'RUB' }, payment_method_data: { type: 'bank_card' }, confirmation: { type: 'redirect', return_url: 'test' } }; try { const payment = await checkout.createPayment(createPayload, idempotenceKey); console.log(payment) } catch (error) { console.error(error); } ``` -------------------------------- ### Creating Webhook with YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Shows how to register a webhook endpoint with the YooKassa API using the @a2seven/yoo-checkout library. It initializes the client with OAuth token, defines an idempotence key and the webhook payload (event type, URL), and calls the `createWebHook` method, logging the result or errors. Note this requires an affiliate program token. ```javascript import { YooCheckout, ICreateWebHook } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey', token: 'your_OAuth_token' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const createWebHookPayload: ICreateWebHook = { event: 'payment.canceled', url: 'https://test.com/hook' }; try { const webhook = await checkout.createWebHook(createWebHookPayload, idempotenceKey); console.log(webhook) } catch (error) { console.error(error); } ``` -------------------------------- ### Creating Refund with YooKassa API (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Shows how to initiate a refund for a payment using the `@a2seven/yoo-checkout` library. It requires the payment ID, the refund amount, and an idempotence key to prevent duplicate requests. The code defines the refund payload according to the `ICreateRefund` interface and calls the `createRefund` method. ```javascript import { YooCheckout, ICreateRefund } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const createRefundPayload: ICreateRefund = { payment_id: '27a3852a-000f-5000-8000-102d922df8db', amount: { value: '1.00', currency: 'RUB' } }; try { const refund = await checkout.createRefund(createRefundPayload, idempotenceKey); console.log(refund) } catch (error) { console.error(error); } ``` -------------------------------- ### Creating Receipt with YooKassa API (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Shows how to generate a fiscal receipt, typically for a refund, using the `@a2seven/yoo-checkout` library. It requires an idempotence key and a detailed payload conforming to `ICreateReceipt`, including customer info, settlement details, refund ID, type, and item specifics. The code calls the `createReceipt` method with the payload and key. ```javascript import { YooCheckout, ICreateReceipt } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const createReceiptPayload: ICreateReceipt = { send: true, customer: { email: 'test@gmail.com' }, settlements: [ { type: 'cashless', amount: { value: '2.00', currency: 'RUB' } } ], refund_id: '27a387af-0015-5000-8000-137da144ce29', type: 'refund', items: [ { description: 'test', quantity: '2', amount: { value: '1.00', currency: 'RUB' }, vat_code: 1, } ] }; try { const receipt = await checkout.createReceipt(createReceiptPayload, idempotenceKey); console.log(receipt) } catch (error) { console.error(error); } ``` -------------------------------- ### Creating Receipt with YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Shows how to generate a fiscal receipt using the @a2seven/yoo-checkout library, often for refund operations. It sets up the client, defines an idempotence key and the receipt payload (customer, settlements, items, type), and calls the `createReceipt` method, logging the result or errors. ```javascript import { YooCheckout, ICreateReceipt } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const createReceiptPayload: ICreateReceipt = { send: true, customer: { email: 'test@gmail.com' }, settlements: [ { type: 'cashless', amount: { value: '2.00', currency: 'RUB' } } ], refund_id: '27a387af-0015-5000-8000-137da144ce29', type: 'refund', items: [ { description: 'test', quantity: '2', amount: { value: '1.00', currency: 'RUB' }, vat_code: 1, } ] }; try { const receipt = await checkout.createReceipt(createReceiptPayload, idempotenceKey); console.log(receipt) } catch (error) { console.error(error); } ``` -------------------------------- ### Making Idempotent POST Request with cURL (Bash) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Illustrates how to perform an idempotent POST request using cURL. It includes Basic Authentication, the 'Idempotence-Key' header to ensure the request is processed only once, and a JSON request body for initiating a refund. ```bash curl https://api.yookassa.ru/v3/refunds \ -X POST \ -u : \ -H 'Idempotence-Key: ' \ -H 'Content-Type: application/json' \ -d '{ "amount": { "value": "2.00", "currency": "RUB" }, "payment_id": "215d8da0-000f-50be-b000-0003308c89be" }' ``` -------------------------------- ### Retrieve Payment Details - JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Demonstrates how to fetch the details of a specific payment using its ID via the SDK client, including error handling. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const paymentId = '21966b95-000f-50bf-b000-0d78983bb5bc'; try { const payment = await checkout.getPayment(paymentId); console.log(payment) } catch (error) { console.error(error); } ``` -------------------------------- ### Creating Webhook with YooKassa API (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Shows how to register a webhook endpoint to receive notifications about specific events (like payment cancellations) using the `@a2seven/yoo-checkout` library. This functionality requires an OAuth token for initialization. The code defines the webhook payload with the event type and URL and calls the `createWebHook` method with the payload and an idempotence key. ```javascript import { YooCheckout, ICreateWebHook } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey', token: 'your_OAuth_token' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const createWebHookPayload: ICreateWebHook = { event: 'payment.canceled', url: 'https://test.com/hook' }; try { const webhook = await checkout.createWebHook(createWebHookPayload, idempotenceKey); console.log(webhook) } catch (error) { console.error(error); } ``` -------------------------------- ### Listing Refunds with YooKassa JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.ru.md Illustrates how to fetch a list of refunds, optionally applying filters like creation date and limit, using the `@a2seven/yoo-checkout` library. ```javascript import { YooCheckout, IGetRefundList } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const filters: IGetRefundList = { created_at: { value: '2021-01-27T13:58:02.977Z', mode: 'gte' }, limit: 20 }; try { const refundList = await checkout.getRefundList(filters); console.log(refundList) } catch (error) { console.error(error); } ``` -------------------------------- ### Creating Refund with YooKassa JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.ru.md Demonstrates how to initiate a refund using the `@a2seven/yoo-checkout` library. It requires a `payment_id` and the refund `amount`. An idempotence key is used to prevent duplicate requests. ```javascript import { YooCheckout, ICreateRefund } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const createRefundPayload: ICreateRefund = { payment_id: '27a3852a-000f-5000-8000-102d922df8db', amount: { value: '1.00', currency: 'RUB' } }; try { const refund = await checkout.createRefund(createRefundPayload, idempotenceKey); console.log(refund) } catch (error) { console.error(error); } ``` -------------------------------- ### Capture an Authorized Payment - JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Shows how to capture a payment that was previously authorized, providing the payment ID, an optional capture payload (e.g., partial amount), and an idempotence key, with error handling. ```javascript import { YooCheckout, ICapturePayment } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const paymentId = '21966b95-000f-50bf-b000-0d78983bb5bc'; const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const capturePayload: ICapturePayment = { amount: { value: '2.00', currency: 'RUB' } }; try { const payment = await checkout.capturePayment(paymentId, capturePayload, idempotenceKey); console.log(payment) } catch (error) { console.error(error); } ``` -------------------------------- ### Capture Payment - YooCheckout JavaScript SDK Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Illustrates how to capture a payment that was previously authorized. This method requires the payment ID, a capture payload (often specifying the amount), and an idempotency key. Includes basic error handling. ```javascript import { YooCheckout, ICapturePayment } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const paymentId = '21966b95-000f-50bf-b000-0d78983bb5bc'; const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const capturePayload: ICapturePayment = { amount: { value: '2.00', currency: 'RUB' } }; try { const payment = await checkout.capturePayment(paymentId, capturePayload, idempotenceKey); console.log(payment) } catch (error) { console.error(error); } ``` -------------------------------- ### Creating Webhook with YooKassa JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.ru.md Illustrates how to set up a webhook subscription to receive notifications about specific events (e.g., payment cancellation) using the `@a2seven/yoo-checkout` library. Requires an OAuth token for authentication. An idempotence key is used. ```javascript import { YooCheckout, ICreateWebHook } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey', token: 'your_OAuth_token' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const createWebHookPayload: ICreateWebHook = { event: 'payment.canceled', url: 'https://test.com/hook' }; try { const webhook = await checkout.createWebHook(createWebHookPayload, idempotenceKey); console.log(webhook) } catch (error) { console.error(error); } ``` -------------------------------- ### Creating Receipt with YooKassa JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.ru.md Explains how to generate a receipt, typically associated with a refund or payment, using the `@a2seven/yoo-checkout` library. It includes details like customer info, settlement type, and items. An idempotence key is used. ```javascript import { YooCheckout, ICreateReceipt } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; const createReceiptPayload: ICreateReceipt = { send: true, customer: { email: 'test@gmail.com' }, settlements: [ { type: 'cashless', amount: { value: '2.00', currency: 'RUB' } } ], refund_id: '27a387af-0015-5000-8000-137da144ce29', type: 'refund', items: [ { description: 'test', quantity: '2', amount: { value: '1.00', currency: 'RUB' }, vat_code: 1, } ] }; try { const receipt = await checkout.createReceipt(createReceiptPayload, idempotenceKey); console.log(receipt) } catch (error) { console.error(error); } ``` -------------------------------- ### Listing Receipts with YooKassa JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.ru.md Demonstrates how to fetch a list of receipts, allowing for filtering by criteria such as creation date and limit, using the `@a2seven/yoo-checkout` library. ```javascript import { YooCheckout, IGetReceiptList } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const filters: IGetReceiptList = { created_at: { value: '2021-01-27T13:58:02.977Z', mode: 'gte' }, limit: 20 }; try { const receiptList = await checkout.getReceiptList(filters); console.log(receiptList) } catch (error) { console.error(error); } ``` -------------------------------- ### Listing Webhooks with YooKassa JavaScript Source: https://github.com/a2seven/yoocheckout/blob/main/README.ru.md Shows how to retrieve a list of all registered webhooks for the account using the `@a2seven/yoo-checkout` library. Requires an OAuth token for authentication. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey', token: 'your_OAuth_token' }); try { const webHookList = await checkout.getWebHookList(); console.log(webHookList) } catch (error) { console.error(error); } ``` -------------------------------- ### Delete Webhook using YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/README.md Shows how to initialize the YooCheckout client and asynchronously delete a specific webhook from the Yookassa API using its ID, handling potential errors. ```javascript import { YooCheckout, ICreateWebHook } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey', token: 'your_OAuth_token' }); const webHookId = 'wh-edba6d49-ce3e-4d99-991b-4bb164859dc3'; try { await checkout.deleteWebHook(webHookId); } catch (error) { console.error(error); } ``` -------------------------------- ### Cancel Payment - YooCheckout JavaScript SDK Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Shows how to cancel a payment using its ID via the YooCheckout client. This operation typically requires an idempotency key to ensure the request is processed only once. Includes basic error handling. ```javascript import { YooCheckout } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey' }); const paymentId = '21966b95-000f-50bf-b000-0d78983bb5bc'; const idempotenceKey = '02347fc4-a1f0-49db-807e-f0d67c2ed5a5'; try { const payment = await checkout.cancelPayment(paymentId, idempotenceKey); console.log(payment) } catch (error) { console.error(error); } ``` -------------------------------- ### Delete Webhook using YooCheckout (JavaScript) Source: https://github.com/a2seven/yoocheckout/blob/main/npm_package/README.md Shows how to delete a specific webhook using its ID via the @a2seven/yoo-checkout library. Requires an initialized client and the ID of the webhook to be deleted. Handles potential errors during the deletion process. ```javascript import { YooCheckout, ICreateWebHook } from '@a2seven/yoo-checkout'; const checkout = new YooCheckout({ shopId: 'your_shopId', secretKey: 'your_secretKey', token: 'your_OAuth_token' }); const webHookId = 'wh-edba6d49-ce3e-4d99-991b-4bb164859dc3'; try { await checkout.deleteWebHook(webHookId); } catch (error) { console.error(error); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.