nestjs-yookassa
Version:
A NestJS library for integrating with YooKassa API
60 lines (59 loc) • 2.55 kB
TypeScript
import type { CreatePaymentMethodRequest, CreatePaymentMethodResponse, PaymentMethodDetails } from './interfaces';
import { YookassaHttpClient } from '../../core/http/yookassa.http-client';
export declare class PaymentMethodService {
private readonly http;
constructor(http: YookassaHttpClient);
/**
* Создает сохраненный способ оплаты (payment method).
*
* Используется для привязки карты клиента или другого способа оплаты.
* Требует подтверждения пользователя (redirect confirmation flow).
*
* @param {CreatePaymentMethodRequest} data — Данные для создания метода оплаты.
* @returns {Promise<CreatePaymentMethodResponse>} Детали созданного payment method.
*
* @example Создание сохраненного метода оплаты
* ```ts
* const method = await this.yookassaService.paymentMethods.create({
* type: PaymentMethodsEnum.BANK_CARD,
* confirmation: {
* type: 'redirect',
* return_url: 'https://myshop.com/yookassa-return'
* }
* });
*
* console.log(method.id, method.status, method.confirmation?.confirmation_url);
* ```
*
* @example Подключение карты с редиректом
* ```ts
* const res = await yookassa.paymentMethods.create({
* type: PaymentMethodsEnum.BANK_CARD,
* confirmation: {
* type: 'redirect',
* return_url: 'https://example.com/success'
* }
* });
*
* return { redirectUrl: res.confirmation.confirmation_url };
* ```
*
* @see https://yookassa.ru/developers/api#create_payment_method
*/
create(data: CreatePaymentMethodRequest): Promise<CreatePaymentMethodResponse>;
/**
* Получает сохраненный способ оплаты по ID.
*
* @param {string} id — Идентификатор способа оплаты.
* @returns {Promise<PaymentMethodDetails>} Объект с деталями метода оплаты.
*
* @example
* ```ts
* const paymentMethod = await this.yookassaService.paymentMethods.getById('pm_123');
* console.log(paymentMethod.status, paymentMethod.card?.last4);
* ```
*
* @see https://yookassa.ru/developers/api#get_payment_method
*/
getById(id: string): Promise<PaymentMethodDetails>;
}