npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

yookassa-sdk-node

v0.7.0

Published

YooKassa TypeScript SDK

Readme

YooKassa SDK

TypeScript-клиент для API ЮKassa.

Позволяет создавать и получать платежи и счета, подтверждать двухстадийные платежи (capture) и работать с ответами API в типобезопасном виде. Под капотом — openapi-fetch и типы из локальной OpenAPI-спецификации src/openapi.yaml.

OpenAPI

  • Документация API: https://yookassa.ru/developers/api
  • Страница спецификации: https://yookassa.ru/developers/using-api/openapi-specification
  • Оригинальный YAML: https://yookassa.ru/developers/api/yookassa-openapi-specification.yaml

В репозитории лежит модифицированная версия спеки (src/openapi.yaml), а не копия оригинала один в один. Так удобнее для SDK:

  • осмысленные operationId (create-payment, capture-payment, …);
  • именованные $ref на схемы запросов/ответов вместо больших inline-объектов;
  • покрыт в первую очередь платёжный контур (платежи, счета, capture), без всего API ЮKassa целиком.

Как обновлять

  1. Сверь изменения с справочником API и оригинальным OpenAPI.
  2. Внеси правки в src/openapi.yaml (сохраняя локальные operationId и структуру $ref).
  3. Перегенерируй типы: npm run generate-openapi → обновится src/openapi.d.ts.
  4. Если появился новый эндпоинт в спеке — добавь метод в src/index.ts и пример в этот README.

Установка

npm install yookassa-sdk-node
# или
yarn add yookassa-sdk-node

Инициализация

import { YooKassaSDK } from 'yookassa-sdk-node';

const sdk = new YooKassaSDK({
  shopId: process.env.YOOKASSA_SHOP_ID!,
  secretKey: process.env.YOOKASSA_SECRET_KEY!,
});

Все методы возвращают результат openapi-fetch: { data, error, response }.

Платежи

Создание платежа

const { data: payment, error } = await sdk.createPayment({
  body: {
    amount: { value: '100.00', currency: 'RUB' },
    confirmation: {
      type: 'redirect',
      return_url: 'https://example.com/return',
    },
    capture: true,
    description: 'Заказ №72',
  },
  idempotenceKey: crypto.randomUUID(),
});

if (error) {
  throw error;
}

console.log(payment.id, payment.status, payment.confirmation);

Список платежей

const { data, error } = await sdk.getPaymentList({
  query: {
    status: 'succeeded',
    limit: 10,
  },
});

if (error) {
  throw error;
}

console.log(data.items, data.next_cursor);

Информация о платеже

const { data: payment, error } = await sdk.getPayment({
  payment_id: '2d78da6d-000f-5000-8000-1edbcc82210d',
});

if (error) {
  throw error;
}

console.log(payment.status);

Подтверждение платежа (capture)

Для двухстадийных платежей (capture: false при создании). Без body списывается полная сумма.

const { data: payment, error } = await sdk.capturePayment({
  payment_id: '2d78da6d-000f-5000-8000-1edbcc82210d',
  idempotenceKey: crypto.randomUUID(),
  // опционально — частичное списание:
  // body: { amount: { value: '50.00', currency: 'RUB' } },
});

if (error) {
  throw error;
}

console.log(payment.status); // succeeded

Счета

Создание счёта

const expiresAt = new Date(Date.now() + 60 * 60 * 1000).toISOString();

const { data: invoice, error } = await sdk.createInvoice({
  body: {
    payment_data: {
      amount: { value: '100.00', currency: 'RUB' },
    },
    cart: [
      {
        description: 'Модная шапка',
        price: { value: '100.00', currency: 'RUB' },
        quantity: 1,
      },
    ],
    expires_at: expiresAt,
  },
  idempotenceKey: crypto.randomUUID(),
});

if (error) {
  throw error;
}

console.log(invoice.status, invoice.delivery_method);

Информация о счёте

const { data: invoice, error } = await sdk.getInvoice({
  invoice_id: 'in-2d78da6d-000f-5000-8000-1edbcc82210d',
});

if (error) {
  throw error;
}

console.log(invoice.status);

Типы

Экспортируются типы тел запросов и webhook-событий:

import type {
  CreatePaymentBody,
  CapturePaymentBody,
  GetPaymentListQuery,
  CreateInvoiceBody,
  WebhookEvent,
  Schemas,
} from 'yookassa-sdk-node';