import type { RequestHandler } from "express"; import { ApiClass } from "../api"; import { SimpleJsonHttp } from "../shared/http"; import { P2pBillsApi } from "./bills.api"; import { BillRequestHandler, MiddlewareOptions } from "./p2p.middleware"; import type { P2pApiOptions } from "./p2p.options"; import { BillCurrency, BillPaySource, BillStatus } from "./p2p.types"; /** * # P2P-счета * [Документация QIWI](https://developer.qiwi.com/ru/p2p-payments/) * * @export * @class P2p */ export declare class P2p extends ApiClass { static readonly BillsApi: typeof P2pBillsApi; static readonly BillCurrency: typeof BillCurrency; static readonly BillPaySource: typeof BillPaySource; static readonly BillStatus: typeof BillStatus; static readonly Currency: typeof BillCurrency; static readonly PaySource: typeof BillPaySource; static readonly Status: typeof BillStatus; /** * * * @static * @param {string} secretKey * @return {SimpleJsonHttp} SimpleJsonHttp * @memberof P2p */ static httpClientFactory: (secretKey: string) => SimpleJsonHttp; /** * * * @static * @param {string} secretKey * @param {string} [publicKey=""] * @return {P2p} P2p * @memberof P2p */ static create(secretKey: string, publicKey?: string): P2p; /** * * * @static * @param {string} [secretKey=process.env.QIWI_SECRET_KEY] * @param {string} [publicKey=process.env.QIWI_PUBLIC_KEY] * @return {P2p} P2p * @memberof P2p */ static env(secretKey?: string, publicKey?: string): P2p; /** * Creates an instance of P2p. * @param {P2pApiOptions} [options] * @memberof P2p */ constructor({ publicKey, secretKey, http }?: Partial); readonly bills: P2pBillsApi; /** * `[Экспериментально]` Упрощает интеграцию с `express` * * ## Это middleware кидает ошибки, позаботьтесь об их обработке * * @param {Object} [options] Параметры обработки запроса * @param {boolean} [options.memo=true] Флаг для включения/отключения пропуска повторяющихся запросов, если один из них был успешно обработан * * @param {RequestHandler, any, BillStatusNotificationBody>} handler * * @return {RequestHandler} * * ##### Пример: * **В начале файла** * ```js * const p2p = new QIWI.P2P(process.env.QIWI_PRIVATE_KEY); * ``` * *`Вариант 1 - Классический`* * * ```js * app.post('/webhook/qiwi', p2p.notificationMiddleware(), (req, res) => { * req.body // Это `BillStatusNotificationBody` * }) * ``` * * *`Вариант 2 - Если нужны подсказки типов`* * * ```js * app.post('/webhook/qiwi', p2p.notificationMiddleware({}, (req, res) => { * req.body // Это `BillStatusNotificationBody` * })) * ``` * * **Обработка ошибок** * ```js * app.use((error, request, response, next) => { * console.log(error); // [Error: Notification signature mismatch] * }) * ``` */ notificationMiddleware(options?: MiddlewareOptions, handler?: BillRequestHandler): RequestHandler; }