A TypeScript/JavaScript client for the Yandex Pay API that helps you easily integrate Yandex Pay into your Node.js applications.
This package is based on the official Yandex Pay API documentation.
pnpm add @lexriver/yandex-payimport { YandexPayAPI } from '@lexriver/yandex-pay';
const yandexPay = new YandexPayAPI({
apiKey: 'your-api-key',
sandbox: true // set to false for production
});const order = await yandexPay.orders.createOrder({
cart: {
items: [
{
productId: 'product-1',
title: 'Product Name',
quantity: {
count: '1'
},
total: '100.00'
}
],
total: {
amount: '100.00'
}
},
orderId: 'order-123',
currencyCode: 'RUB',
redirectUrls: {
onSuccess: 'https://your-site.com/success',
onError: 'https://your-site.com/error'
},
availablePaymentMethods: ['CARD']
});
// Redirect user to the payment URL
console.log(order.paymentUrl);const orderDetails = await yandexPay.orders.getOrder('order-123');const cancelResult = await yandexPay.orders.cancelOrder('order-123', {
reason: 'Customer canceled'
});const refundResult = await yandexPay.orders.refundOrder('order-123', {
amount: '100.00'
});const captureResult = await yandexPay.orders.captureOrder('order-123', {
cart: {
// Final cart after possible modifications
items: [
{
productId: 'product-1',
title: 'Product Name',
quantity: {
count: '1'
},
total: '100.00'
}
],
total: {
amount: '100.00'
}
}
});const operations = await yandexPay.operations.getOperations('order-123');const subscription = await yandexPay.subscriptions.createSubscription({
subscriptionPlanId: 'plan-123',
returnUrls: {
onSuccess: 'https://your-site.com/success',
onError: 'https://your-site.com/error'
}
});
// Redirect user to confirmation URL
console.log(subscription.confirmationUrl);const recurringPayment = await yandexPay.subscriptions.makeRecurringPayment({
customerSubscriptionId: 'subscription-123',
amount: '100.00',
purpose: 'Monthly payment'
});const subscriptionDetails = await yandexPay.subscriptions.getSubscription(
'subscription-123',
true // Check if the card is active
);The package provides a type-safe interface to the Yandex Pay API organized into the following services:
createOrder(data)- Create a new ordergetOrder(orderId)- Get order detailscancelOrder(orderId, data)- Cancel an orderrefundOrder(orderId, data)- Refund an orderrefundOrderV2(orderId, data)- Refund an order (V2 API)captureOrder(orderId, data)- Capture (confirm) an order paymentrollbackOrder(orderId)- Rollback (void) an order paymentsubmitOrder(orderId, data)- Submit an order for processing
getOperation(externalOperationId)- Get details about a specific operation
createSubscription(data)- Create a new subscriptionmakeRecurringPayment(data)- Make a recurring payment for a subscriptiongetSubscription(subscriptionId, checkCardActive)- Get subscription details
ISC