@dieugene/tochka-api
v0.1.0
Published
Node.js client and webhook processor for Tochka Bank API
Maintainers
Readme
Tochka API client (payment links)
Installation
npm install @dieugene/tochka-apiUsage
const { TochkaApiClient, webhook_processor } = require('@dieugene/tochka-api');
const client = new TochkaApiClient({
base_url: process.env.TOCHKA_BASE_URL, // e.g. https://enter.tochka.com
access_token: process.env.TOCHKA_ACCESS_TOKEN, // permanent JWT
default_customer_code: process.env.TOCHKA_CUSTOMER_CODE
});
// Create payment link
await client.create_payment_operation({
amount: 1000,
customer_code: 'your_business_customer_code',
purpose: 'Оплата заказа #123',
payment_mode: ['card', 'sbp'],
redirect_url: 'https://merchant/success',
fail_redirect_url: 'https://merchant/fail'
});
// Refund
await client.refund_payment_operation('operationId', { amount: 1000 });Webhook processing (standalone)
Serverless-friendly helper
const { webhook_processor } = require('@dieugene/tochka-api');
// Generic handler (AWS Lambda style)
exports.handler = async (event) => {
try {
const payload = await webhook_processor.decode_webhook({
body: event.body,
isBase64Encoded: event.isBase64Encoded
});
// Idempotent business logic by payload.webhookType, payload fields
return { statusCode: 200, body: '' };
} catch {
return { statusCode: 400, body: '' };
}
};
// Yandex Cloud Functions (HTTP)
module.exports.handler = async (event, context) => {
try {
const payload = await webhook_processor.decode_webhook({
body: event.body,
isBase64Encoded: event.isBase64Encoded
});
return { statusCode: 200, body: '' };
} catch {
return { statusCode: 400, body: '' };
}
};
// Cloudflare Workers / Fetch API style
export default {
async fetch(request) {
try {
const payload = await webhook_processor.decode_webhook(request);
return new Response('', { status: 200 });
} catch {
return new Response('', { status: 400 });
}
}
}Endpoints
This client targets Tochka payment links API per docs:
- Работа с платёжными ссылками: https://developers.tochka.com/docs/tochka-api/api/rabota-s-platyozhnymi-ssylkami
- Redoc tag: https://enter.tochka.com/doc/v2/redoc/tag/Rabota-s-platyozhnymi-ssylkami
Note: Base URL is typically https://enter.tochka.com with endpoints under /uapi/acquiring/v1.0. You can override endpoints in the client options if your environment differs. Endpoints use payments (plural) per docs.
Testing
cp .env.example .env
# Fill TOCHKA_BASE_URL and TOCHKA_ACCESS_TOKEN for integration tests
npm test