nestjs-monobank 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +18 -0
- package/dist/common/enums/discount.enum.d.ts +24 -0
- package/dist/common/enums/discount.enum.js +2 -0
- package/dist/common/enums/index.d.ts +1 -0
- package/dist/common/enums/index.js +17 -0
- package/dist/common/interfaces/common.interface.d.ts +177 -0
- package/dist/common/interfaces/common.interface.js +2 -0
- package/dist/common/interfaces/index.d.ts +2 -0
- package/dist/common/interfaces/index.js +18 -0
- package/dist/common/interfaces/monobank-options.interface.d.ts +15 -0
- package/dist/common/interfaces/monobank-options.interface.js +4 -0
- package/dist/core/config/monobank.constants.d.ts +1 -0
- package/dist/core/config/monobank.constants.js +4 -0
- package/dist/core/http/monobank.error.d.ts +6 -0
- package/dist/core/http/monobank.error.js +13 -0
- package/dist/core/http/monobank.http-client.d.ts +16 -0
- package/dist/core/http/monobank.http-client.js +66 -0
- package/dist/core/http/monobank.interceptor.d.ts +2 -0
- package/dist/core/http/monobank.interceptor.js +19 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/modules/invoice/enums/cancel-status.enum.d.ts +18 -0
- package/dist/modules/invoice/enums/cancel-status.enum.js +22 -0
- package/dist/modules/invoice/enums/charge-status.enum.d.ts +14 -0
- package/dist/modules/invoice/enums/charge-status.enum.js +18 -0
- package/dist/modules/invoice/enums/index.d.ts +3 -0
- package/dist/modules/invoice/enums/index.js +19 -0
- package/dist/modules/invoice/enums/invoice-status.enum.d.ts +34 -0
- package/dist/modules/invoice/enums/invoice-status.enum.js +38 -0
- package/dist/modules/invoice/interfaces/index.d.ts +2 -0
- package/dist/modules/invoice/interfaces/index.js +18 -0
- package/dist/modules/invoice/interfaces/requests/create-cancel.request.d.ts +22 -0
- package/dist/modules/invoice/interfaces/requests/create-cancel.request.js +2 -0
- package/dist/modules/invoice/interfaces/requests/create-charge.request.d.ts +42 -0
- package/dist/modules/invoice/interfaces/requests/create-charge.request.js +2 -0
- package/dist/modules/invoice/interfaces/requests/create-finalize.request.d.ts +19 -0
- package/dist/modules/invoice/interfaces/requests/create-finalize.request.js +2 -0
- package/dist/modules/invoice/interfaces/requests/create-invoice.request.d.ts +88 -0
- package/dist/modules/invoice/interfaces/requests/create-invoice.request.js +2 -0
- package/dist/modules/invoice/interfaces/requests/index.d.ts +4 -0
- package/dist/modules/invoice/interfaces/requests/index.js +20 -0
- package/dist/modules/invoice/interfaces/responses/cancel.response.d.ts +18 -0
- package/dist/modules/invoice/interfaces/responses/cancel.response.js +2 -0
- package/dist/modules/invoice/interfaces/responses/charge.response.d.ts +35 -0
- package/dist/modules/invoice/interfaces/responses/charge.response.js +2 -0
- package/dist/modules/invoice/interfaces/responses/create-cancel.response.d.ts +7 -0
- package/dist/modules/invoice/interfaces/responses/create-cancel.response.js +2 -0
- package/dist/modules/invoice/interfaces/responses/create-charge.response.d.ts +7 -0
- package/dist/modules/invoice/interfaces/responses/create-charge.response.js +2 -0
- package/dist/modules/invoice/interfaces/responses/create-finalize.response.d.ts +7 -0
- package/dist/modules/invoice/interfaces/responses/create-finalize.response.js +2 -0
- package/dist/modules/invoice/interfaces/responses/create-invoice.response.d.ts +7 -0
- package/dist/modules/invoice/interfaces/responses/create-invoice.response.js +2 -0
- package/dist/modules/invoice/interfaces/responses/finalize.response.d.ts +9 -0
- package/dist/modules/invoice/interfaces/responses/finalize.response.js +2 -0
- package/dist/modules/invoice/interfaces/responses/fiscal-checks.response.d.ts +42 -0
- package/dist/modules/invoice/interfaces/responses/fiscal-checks.response.js +2 -0
- package/dist/modules/invoice/interfaces/responses/index.d.ts +9 -0
- package/dist/modules/invoice/interfaces/responses/index.js +25 -0
- package/dist/modules/invoice/interfaces/responses/invoice-status.response.d.ts +116 -0
- package/dist/modules/invoice/interfaces/responses/invoice-status.response.js +2 -0
- package/dist/modules/invoice/interfaces/responses/invoice.response.d.ts +13 -0
- package/dist/modules/invoice/interfaces/responses/invoice.response.js +2 -0
- package/dist/modules/invoice/interfaces/responses/receipt.response.d.ts +6 -0
- package/dist/modules/invoice/interfaces/responses/receipt.response.js +2 -0
- package/dist/modules/invoice/invoice.module.d.ts +2 -0
- package/dist/modules/invoice/invoice.module.js +20 -0
- package/dist/modules/invoice/invoice.service.d.ts +154 -0
- package/dist/modules/invoice/invoice.service.js +187 -0
- package/dist/modules/merchant/interfaces/index.d.ts +1 -0
- package/dist/modules/merchant/interfaces/index.js +17 -0
- package/dist/modules/merchant/interfaces/responses/index.d.ts +2 -0
- package/dist/modules/merchant/interfaces/responses/index.js +18 -0
- package/dist/modules/merchant/interfaces/responses/merchant.response.d.ts +17 -0
- package/dist/modules/merchant/interfaces/responses/merchant.response.js +2 -0
- package/dist/modules/merchant/interfaces/responses/pubkey.response.d.ts +10 -0
- package/dist/modules/merchant/interfaces/responses/pubkey.response.js +2 -0
- package/dist/modules/merchant/merchant.module.d.ts +2 -0
- package/dist/modules/merchant/merchant.module.js +20 -0
- package/dist/modules/merchant/merchant.service.d.ts +36 -0
- package/dist/modules/merchant/merchant.service.js +58 -0
- package/dist/modules/qr/enums/amount-type.enum.d.ts +11 -0
- package/dist/modules/qr/enums/amount-type.enum.js +15 -0
- package/dist/modules/qr/enums/index.d.ts +1 -0
- package/dist/modules/qr/enums/index.js +17 -0
- package/dist/modules/qr/interfaces/index.d.ts +0 -0
- package/dist/modules/qr/interfaces/index.js +0 -0
- package/dist/modules/qr/interfaces/responses/index.d.ts +2 -0
- package/dist/modules/qr/interfaces/responses/index.js +18 -0
- package/dist/modules/qr/interfaces/responses/list.response.d.ts +8 -0
- package/dist/modules/qr/interfaces/responses/list.response.js +2 -0
- package/dist/modules/qr/interfaces/responses/qr.response.d.ts +14 -0
- package/dist/modules/qr/interfaces/responses/qr.response.js +2 -0
- package/dist/modules/qr/qr.module.d.ts +2 -0
- package/dist/modules/qr/qr.module.js +20 -0
- package/dist/modules/qr/qr.service.d.ts +32 -0
- package/dist/modules/qr/qr.service.js +56 -0
- package/dist/modules/statement/interfaces/index.d.ts +1 -0
- package/dist/modules/statement/interfaces/index.js +17 -0
- package/dist/modules/statement/interfaces/responses/index.d.ts +1 -0
- package/dist/modules/statement/interfaces/responses/index.js +17 -0
- package/dist/modules/statement/interfaces/responses/statement.response.d.ts +99 -0
- package/dist/modules/statement/interfaces/responses/statement.response.js +2 -0
- package/dist/modules/statement/statement.module.d.ts +2 -0
- package/dist/modules/statement/statement.module.js +20 -0
- package/dist/modules/statement/statement.service.d.ts +17 -0
- package/dist/modules/statement/statement.service.js +38 -0
- package/dist/modules/subscription/enums/index.d.ts +2 -0
- package/dist/modules/subscription/enums/index.js +18 -0
- package/dist/modules/subscription/enums/subscription-status.enum.d.ts +13 -0
- package/dist/modules/subscription/enums/subscription-status.enum.js +17 -0
- package/dist/modules/subscription/enums/wallet-status.enum.d.ts +17 -0
- package/dist/modules/subscription/enums/wallet-status.enum.js +21 -0
- package/dist/modules/subscription/interfaces/index.d.ts +2 -0
- package/dist/modules/subscription/interfaces/index.js +18 -0
- package/dist/modules/subscription/interfaces/requests/client-subscriptions.request.d.ts +26 -0
- package/dist/modules/subscription/interfaces/requests/client-subscriptions.request.js +2 -0
- package/dist/modules/subscription/interfaces/requests/create-subscription.request.d.ts +32 -0
- package/dist/modules/subscription/interfaces/requests/create-subscription.request.js +2 -0
- package/dist/modules/subscription/interfaces/requests/edit-subscription.request.d.ts +18 -0
- package/dist/modules/subscription/interfaces/requests/edit-subscription.request.js +2 -0
- package/dist/modules/subscription/interfaces/requests/history.request.d.ts +15 -0
- package/dist/modules/subscription/interfaces/requests/history.request.js +2 -0
- package/dist/modules/subscription/interfaces/requests/index.d.ts +4 -0
- package/dist/modules/subscription/interfaces/requests/index.js +20 -0
- package/dist/modules/subscription/interfaces/responses/client-subscriptions.response.d.ts +27 -0
- package/dist/modules/subscription/interfaces/responses/client-subscriptions.response.js +2 -0
- package/dist/modules/subscription/interfaces/responses/create-subscription.response.d.ts +5 -0
- package/dist/modules/subscription/interfaces/responses/create-subscription.response.js +2 -0
- package/dist/modules/subscription/interfaces/responses/history.response.d.ts +9 -0
- package/dist/modules/subscription/interfaces/responses/history.response.js +2 -0
- package/dist/modules/subscription/interfaces/responses/index.d.ts +5 -0
- package/dist/modules/subscription/interfaces/responses/index.js +21 -0
- package/dist/modules/subscription/interfaces/responses/subscription-status.response.d.ts +29 -0
- package/dist/modules/subscription/interfaces/responses/subscription-status.response.js +2 -0
- package/dist/modules/subscription/interfaces/responses/subscription.response.d.ts +9 -0
- package/dist/modules/subscription/interfaces/responses/subscription.response.js +2 -0
- package/dist/modules/subscription/subscription.module.d.ts +2 -0
- package/dist/modules/subscription/subscription.module.js +20 -0
- package/dist/modules/subscription/subscription.service.d.ts +91 -0
- package/dist/modules/subscription/subscription.service.js +121 -0
- package/dist/modules/wallet/interfaces/index.d.ts +2 -0
- package/dist/modules/wallet/interfaces/index.js +18 -0
- package/dist/modules/wallet/interfaces/requests/create-card-token.request.d.ts +42 -0
- package/dist/modules/wallet/interfaces/requests/create-card-token.request.js +2 -0
- package/dist/modules/wallet/interfaces/requests/index.d.ts +1 -0
- package/dist/modules/wallet/interfaces/requests/index.js +17 -0
- package/dist/modules/wallet/interfaces/responses/card-token.response.d.ts +37 -0
- package/dist/modules/wallet/interfaces/responses/card-token.response.js +2 -0
- package/dist/modules/wallet/interfaces/responses/create-card-token.response.d.ts +7 -0
- package/dist/modules/wallet/interfaces/responses/create-card-token.response.js +2 -0
- package/dist/modules/wallet/interfaces/responses/index.d.ts +2 -0
- package/dist/modules/wallet/interfaces/responses/index.js +18 -0
- package/dist/modules/wallet/wallet.module.d.ts +2 -0
- package/dist/modules/wallet/wallet.module.js +20 -0
- package/dist/modules/wallet/wallet.service.d.ts +54 -0
- package/dist/modules/wallet/wallet.service.js +78 -0
- package/dist/modules/webhook/webhook.module.d.ts +2 -0
- package/dist/modules/webhook/webhook.module.js +24 -0
- package/dist/modules/webhook/webhook.service.d.ts +44 -0
- package/dist/modules/webhook/webhook.service.js +72 -0
- package/dist/monobank.module.d.ts +36 -0
- package/dist/monobank.module.js +117 -0
- package/dist/monobank.service.d.ts +17 -0
- package/dist/monobank.service.js +42 -0
- package/package.json +68 -0
- package/src/common/enums/discount.enum.ts +26 -0
- package/src/common/enums/index.ts +1 -0
- package/src/common/interfaces/common.interface.ts +206 -0
- package/src/common/interfaces/index.ts +2 -0
- package/src/common/interfaces/monobank-options.interface.ts +18 -0
- package/src/core/config/monobank.constants.ts +1 -0
- package/src/core/http/monobank.error.ts +10 -0
- package/src/core/http/monobank.http-client.ts +66 -0
- package/src/core/http/monobank.interceptor.ts +24 -0
- package/src/index.ts +3 -0
- package/src/modules/invoice/enums/cancel-status.enum.ts +20 -0
- package/src/modules/invoice/enums/charge-status.enum.ts +16 -0
- package/src/modules/invoice/enums/index.ts +3 -0
- package/src/modules/invoice/enums/invoice-status.enum.ts +40 -0
- package/src/modules/invoice/interfaces/index.ts +2 -0
- package/src/modules/invoice/interfaces/requests/create-cancel.request.ts +26 -0
- package/src/modules/invoice/interfaces/requests/create-charge.request.ts +52 -0
- package/src/modules/invoice/interfaces/requests/create-finalize.request.ts +22 -0
- package/src/modules/invoice/interfaces/requests/create-invoice.request.ts +103 -0
- package/src/modules/invoice/interfaces/requests/index.ts +4 -0
- package/src/modules/invoice/interfaces/responses/cancel.response.ts +21 -0
- package/src/modules/invoice/interfaces/responses/charge.response.ts +43 -0
- package/src/modules/invoice/interfaces/responses/create-cancel.response.ts +7 -0
- package/src/modules/invoice/interfaces/responses/create-charge.response.ts +7 -0
- package/src/modules/invoice/interfaces/responses/create-finalize.response.ts +7 -0
- package/src/modules/invoice/interfaces/responses/create-invoice.response.ts +7 -0
- package/src/modules/invoice/interfaces/responses/finalize.response.ts +9 -0
- package/src/modules/invoice/interfaces/responses/fiscal-checks.response.ts +49 -0
- package/src/modules/invoice/interfaces/responses/index.ts +10 -0
- package/src/modules/invoice/interfaces/responses/invoice-status.response.ts +142 -0
- package/src/modules/invoice/interfaces/responses/invoice.response.ts +14 -0
- package/src/modules/invoice/interfaces/responses/receipt.response.ts +6 -0
- package/src/modules/invoice/invoice.module.ts +8 -0
- package/src/modules/invoice/invoice.service.ts +191 -0
- package/src/modules/merchant/interfaces/index.ts +1 -0
- package/src/modules/merchant/interfaces/responses/index.ts +2 -0
- package/src/modules/merchant/interfaces/responses/merchant.response.ts +19 -0
- package/src/modules/merchant/interfaces/responses/pubkey.response.ts +10 -0
- package/src/modules/merchant/merchant.module.ts +8 -0
- package/src/modules/merchant/merchant.service.ts +46 -0
- package/src/modules/qr/enums/amount-type.enum.ts +13 -0
- package/src/modules/qr/enums/index.ts +1 -0
- package/src/modules/qr/interfaces/index.ts +0 -0
- package/src/modules/qr/interfaces/responses/index.ts +2 -0
- package/src/modules/qr/interfaces/responses/list.response.ts +11 -0
- package/src/modules/qr/interfaces/responses/qr.response.ts +18 -0
- package/src/modules/qr/qr.module.ts +8 -0
- package/src/modules/qr/qr.service.ts +43 -0
- package/src/modules/statement/interfaces/index.ts +1 -0
- package/src/modules/statement/interfaces/responses/index.ts +1 -0
- package/src/modules/statement/interfaces/responses/statement.response.ts +119 -0
- package/src/modules/statement/statement.module.ts +8 -0
- package/src/modules/statement/statement.service.ts +25 -0
- package/src/modules/subscription/enums/index.ts +2 -0
- package/src/modules/subscription/enums/subscription-status.enum.ts +14 -0
- package/src/modules/subscription/enums/wallet-status.enum.ts +19 -0
- package/src/modules/subscription/interfaces/index.ts +2 -0
- package/src/modules/subscription/interfaces/requests/client-subscriptions.request.ts +31 -0
- package/src/modules/subscription/interfaces/requests/create-subscription.request.ts +38 -0
- package/src/modules/subscription/interfaces/requests/edit-subscription.request.ts +20 -0
- package/src/modules/subscription/interfaces/requests/history.request.ts +20 -0
- package/src/modules/subscription/interfaces/requests/index.ts +4 -0
- package/src/modules/subscription/interfaces/responses/client-subscriptions.response.ts +36 -0
- package/src/modules/subscription/interfaces/responses/create-subscription.response.ts +6 -0
- package/src/modules/subscription/interfaces/responses/history.response.ts +12 -0
- package/src/modules/subscription/interfaces/responses/index.ts +5 -0
- package/src/modules/subscription/interfaces/responses/subscription-status.response.ts +40 -0
- package/src/modules/subscription/interfaces/responses/subscription.response.ts +11 -0
- package/src/modules/subscription/subscription.module.ts +8 -0
- package/src/modules/subscription/subscription.service.ts +121 -0
- package/src/modules/wallet/interfaces/index.ts +2 -0
- package/src/modules/wallet/interfaces/requests/create-card-token.request.ts +50 -0
- package/src/modules/wallet/interfaces/requests/index.ts +1 -0
- package/src/modules/wallet/interfaces/responses/card-token.response.ts +44 -0
- package/src/modules/wallet/interfaces/responses/create-card-token.response.ts +7 -0
- package/src/modules/wallet/interfaces/responses/index.ts +2 -0
- package/src/modules/wallet/wallet.module.ts +8 -0
- package/src/modules/wallet/wallet.service.ts +71 -0
- package/src/modules/webhook/webhook.module.ts +12 -0
- package/src/modules/webhook/webhook.service.ts +60 -0
- package/src/monobank.module.ts +115 -0
- package/src/monobank.service.ts +21 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './create-card-token.request'
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Результат платежу за токеном картки.
|
|
3
|
+
*/
|
|
4
|
+
export interface CardTokenResponse {
|
|
5
|
+
/**
|
|
6
|
+
* Унікальний ідентифікатор рахунку (invoice).
|
|
7
|
+
*/
|
|
8
|
+
invoiceId: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* URL для проведення 3DS підтвердження платежу.
|
|
12
|
+
*/
|
|
13
|
+
tdsUrl: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Статус платежу: "success", "failure" тощо.
|
|
17
|
+
*/
|
|
18
|
+
status: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Причина невдачі платежу (якщо статус "failure").
|
|
22
|
+
*/
|
|
23
|
+
failureReason?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Сума платежу в мінімальних одиницях (наприклад, копійки для гривні).
|
|
27
|
+
*/
|
|
28
|
+
amount: number;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* ISO 4217 код валюти.
|
|
32
|
+
*/
|
|
33
|
+
ccy: number;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Дата створення рахунку (може бути null).
|
|
37
|
+
*/
|
|
38
|
+
createdDate: string | null;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Дата останнього оновлення рахунку (може бути null).
|
|
42
|
+
*/
|
|
43
|
+
modifiedDate: string | null;
|
|
44
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Injectable } from "@nestjs/common";
|
|
2
|
+
import { MonobankHttpClient } from "../../core/http/monobank.http-client";
|
|
3
|
+
import type {
|
|
4
|
+
CardTokenResponse,
|
|
5
|
+
CreateCardTokenRequest,
|
|
6
|
+
CreateCardTokenResponse
|
|
7
|
+
} from './interfaces'
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class WalletService {
|
|
11
|
+
public constructor(
|
|
12
|
+
public readonly http: MonobankHttpClient
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Створює токен картки (Card Token) для збереження платіжної картки.
|
|
17
|
+
*
|
|
18
|
+
* Використовується для:
|
|
19
|
+
* - привʼязки картки клієнта
|
|
20
|
+
* - повторних платежів без повторного введення реквізитів
|
|
21
|
+
* - роботи з wallet-платежами Monobank
|
|
22
|
+
*
|
|
23
|
+
* @param {CreateCardTokenRequest} data - Дані для створення токена картки.
|
|
24
|
+
* @returns {Promise<CreateCardTokenResponse>} Дані створеного токена картки.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const data: CreateCardTokenRequest = {
|
|
28
|
+
* amount: 100,
|
|
29
|
+
* ccy: 980,
|
|
30
|
+
* redirectUrl: "https://example.com/success",
|
|
31
|
+
* webHookUrl: "https://example.com/webhook"
|
|
32
|
+
* };
|
|
33
|
+
*
|
|
34
|
+
* const token = await this.monobankService.wallet.create(data);
|
|
35
|
+
* console.log(token.cardToken);
|
|
36
|
+
*/
|
|
37
|
+
public async create(data: CreateCardTokenRequest): Promise<CreateCardTokenResponse> {
|
|
38
|
+
return this.http.post("/merchant/wallet/payment", data)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Отримує інформацію про wallet за його ідентифікатором.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} id - Унікальний ідентифікатор wallet.
|
|
45
|
+
* @returns {Promise<CardTokenResponse>} Дані wallet (привʼязана картка, статус тощо).
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const wallet = await this.monobankService.wallet.getById("wlt_123456");
|
|
49
|
+
* console.log(wallet);
|
|
50
|
+
*/
|
|
51
|
+
public async getById(id: string): Promise<CardTokenResponse> {
|
|
52
|
+
return this.http.get(`/merchant/wallet?walletId=${id}`)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Видаляє привʼязану картку за токеном.
|
|
57
|
+
*
|
|
58
|
+
* Після видалення:
|
|
59
|
+
* - токен стає недійсним
|
|
60
|
+
* - повторні списання по цій картці неможливі
|
|
61
|
+
*
|
|
62
|
+
* @param {string} token - Токен картки (cardToken).
|
|
63
|
+
* @returns {Promise<void>} Результат операції видалення.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* await this.monobankService.wallet.deleteByToken("card_token_abc123");
|
|
67
|
+
*/
|
|
68
|
+
public async deleteByToken(token: string): Promise<void> {
|
|
69
|
+
return this.http.delete(`/merchant/wallet/card?cardToken=${token}`)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common'
|
|
2
|
+
import { WebhookService } from './webhook.service'
|
|
3
|
+
import { MerchantModule } from "../merchant/merchant.module";
|
|
4
|
+
|
|
5
|
+
@Module({
|
|
6
|
+
imports: [
|
|
7
|
+
MerchantModule
|
|
8
|
+
],
|
|
9
|
+
providers: [WebhookService],
|
|
10
|
+
exports: [WebhookService]
|
|
11
|
+
})
|
|
12
|
+
export class WebhookModule {}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common'
|
|
2
|
+
import { MerchantService } from '../merchant/merchant.service'
|
|
3
|
+
|
|
4
|
+
import * as crypto from 'crypto'
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class WebhookService {
|
|
8
|
+
public constructor(public readonly merchant: MerchantService) {}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Верифікує підпис webhook-повідомлення від Monobank.
|
|
12
|
+
*
|
|
13
|
+
* Метод:
|
|
14
|
+
* 1. Отримує публічний ключ мерчанта через Merchant API
|
|
15
|
+
* 2. Декодує підпис з Base64
|
|
16
|
+
* 3. Перевіряє цифровий підпис за алгоритмом SHA256
|
|
17
|
+
*
|
|
18
|
+
* Використовується для гарантії, що webhook:
|
|
19
|
+
* - дійсно надісланий Monobank
|
|
20
|
+
* - не був змінений під час передачі
|
|
21
|
+
*
|
|
22
|
+
* @param {Buffer} rawBody - Сире тіло HTTP-запиту (без JSON.parse).
|
|
23
|
+
* @param {string} xSignBase64 - Значення заголовка `X-Sign` у форматі Base64.
|
|
24
|
+
*
|
|
25
|
+
* @returns {Promise<boolean>}
|
|
26
|
+
* - `true` — підпис валідний
|
|
27
|
+
* - `false` — підпис невалідний
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // controller.ts
|
|
31
|
+
* @Post('/mono-webhook')
|
|
32
|
+
* async handleWebhook(
|
|
33
|
+
* @Headers('x-sign') xSign: string,
|
|
34
|
+
* @Req() req: RawBodyRequest<Request>
|
|
35
|
+
* ) {
|
|
36
|
+
* const isValid = await this.webhookService.verifyWebhookSignature(
|
|
37
|
+
* req.rawBody,
|
|
38
|
+
* xSign
|
|
39
|
+
* );
|
|
40
|
+
*
|
|
41
|
+
* if (!isValid) {
|
|
42
|
+
* throw new UnauthorizedException('Invalid webhook signature');
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* // обробка події
|
|
46
|
+
* }
|
|
47
|
+
*/
|
|
48
|
+
public async verifyWebhookSignature(rawBody: Buffer, xSignBase64: string): Promise<boolean> {
|
|
49
|
+
const { key: publicKeyBase64 } = await this.merchant.getMerchantPubkey();
|
|
50
|
+
|
|
51
|
+
const sign = Buffer.from(xSignBase64, "base64");
|
|
52
|
+
const publicKey = Buffer.from(publicKeyBase64, "base64");
|
|
53
|
+
|
|
54
|
+
const verifier = crypto.createVerify("SHA256");
|
|
55
|
+
verifier.write(rawBody);
|
|
56
|
+
verifier.end();
|
|
57
|
+
|
|
58
|
+
return verifier.verify({ key: publicKey, format: "pem", type: "spki" }, sign);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type DynamicModule, Global, Module } from "@nestjs/common";
|
|
2
|
+
import {
|
|
3
|
+
type MonobankModuleAsyncOptions,
|
|
4
|
+
type MonobankModuleOptions,
|
|
5
|
+
MonobankOptionsSymbol
|
|
6
|
+
} from './common/interfaces'
|
|
7
|
+
|
|
8
|
+
import { MonobankService } from "./monobank.service";
|
|
9
|
+
import { InvoiceModule } from './modules/invoice/invoice.module'
|
|
10
|
+
import { MerchantModule } from './modules/merchant/merchant.module'
|
|
11
|
+
import { StatementModule } from './modules/statement/statement.module'
|
|
12
|
+
import { WalletModule } from './modules/wallet/wallet.module'
|
|
13
|
+
import { WebhookModule } from './modules/webhook/webhook.module'
|
|
14
|
+
import { MonobankHttpClient } from './core/http/monobank.http-client'
|
|
15
|
+
import { SubscriptionModule } from "./modules/subscription/subscription.module";
|
|
16
|
+
import { QrModule } from "./modules/qr/qr.module";
|
|
17
|
+
|
|
18
|
+
@Global()
|
|
19
|
+
@Module({})
|
|
20
|
+
export class MonobankModule {
|
|
21
|
+
/**
|
|
22
|
+
* Метод для реєстрації модуля з синхронними параметрами.
|
|
23
|
+
* Цей метод використовується для конфігурації модуля з наперед заданими параметрами.
|
|
24
|
+
* @param {MonobankModuleOptions} options - Налаштування для конфігурації Monobank API.
|
|
25
|
+
* @returns {DynamicModule} Повертає динамічний модуль з необхідними провайдерами та імпортами.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* MonobankModule.forRoot({
|
|
30
|
+
* apiKey: configService.getOrThrow('MONOBANK_API_KEY')
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
public static forRoot(options: MonobankModuleOptions): DynamicModule {
|
|
35
|
+
return {
|
|
36
|
+
module: MonobankModule,
|
|
37
|
+
imports: [
|
|
38
|
+
InvoiceModule,
|
|
39
|
+
MerchantModule,
|
|
40
|
+
StatementModule,
|
|
41
|
+
WalletModule,
|
|
42
|
+
QrModule,
|
|
43
|
+
SubscriptionModule,
|
|
44
|
+
WebhookModule
|
|
45
|
+
],
|
|
46
|
+
providers: [
|
|
47
|
+
{
|
|
48
|
+
provide: MonobankOptionsSymbol,
|
|
49
|
+
useValue: options,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
provide: MonobankHttpClient,
|
|
53
|
+
useFactory: (cfg: MonobankModuleOptions) => new MonobankHttpClient(cfg),
|
|
54
|
+
inject: [MonobankOptionsSymbol]
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
MonobankService,
|
|
58
|
+
],
|
|
59
|
+
exports: [MonobankService, MonobankHttpClient],
|
|
60
|
+
global: true,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Метод для реєстрації модуля з асинхронною конфігурацією.
|
|
66
|
+
* Цей метод використовується для конфігурації модуля з параметрами, які будуть передані через фабричну функцію.
|
|
67
|
+
* @param {MonobankModuleAsyncOptions} options - Асинхронні параметри для конфігурації Monobank API.
|
|
68
|
+
* @returns {DynamicModule} Повертає динамічний модуль з необхідними провайдерами та імпортами.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* MonobankModule.forRootAsync({
|
|
73
|
+
* imports: [ConfigModule],
|
|
74
|
+
* useFactory: async (configService: ConfigService) => ({
|
|
75
|
+
* apiKey: configService.getOrThrow('MONOBANK_API_KEY')
|
|
76
|
+
* }),
|
|
77
|
+
* inject: [ConfigService]
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
public static forRootAsync(options: MonobankModuleAsyncOptions): DynamicModule {
|
|
82
|
+
return {
|
|
83
|
+
module: MonobankModule,
|
|
84
|
+
imports: [
|
|
85
|
+
...(options.imports || []),
|
|
86
|
+
InvoiceModule,
|
|
87
|
+
MerchantModule,
|
|
88
|
+
StatementModule,
|
|
89
|
+
WalletModule,
|
|
90
|
+
WebhookModule,
|
|
91
|
+
QrModule,
|
|
92
|
+
SubscriptionModule,
|
|
93
|
+
InvoiceModule
|
|
94
|
+
],
|
|
95
|
+
providers: [
|
|
96
|
+
{
|
|
97
|
+
provide: MonobankOptionsSymbol,
|
|
98
|
+
useFactory: options.useFactory,
|
|
99
|
+
inject: options.inject || []
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
{
|
|
103
|
+
provide: MonobankHttpClient,
|
|
104
|
+
useFactory: (cfg: MonobankModuleOptions) =>
|
|
105
|
+
new MonobankHttpClient(cfg),
|
|
106
|
+
inject: [MonobankOptionsSymbol]
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
MonobankService
|
|
110
|
+
],
|
|
111
|
+
exports: [MonobankService, MonobankHttpClient],
|
|
112
|
+
global: true
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Injectable } from "@nestjs/common";
|
|
2
|
+
import { InvoiceService } from './modules/invoice/invoice.service'
|
|
3
|
+
import { MerchantService } from './modules/merchant/merchant.service'
|
|
4
|
+
import { StatementService } from './modules/statement/statement.service'
|
|
5
|
+
import { WalletService } from './modules/wallet/wallet.service'
|
|
6
|
+
import { SubscriptionService } from "./modules/subscription/subscription.service";
|
|
7
|
+
import { WebhookService } from "./modules/webhook/webhook.service";
|
|
8
|
+
import { QrService } from "./modules/qr/qr.service";
|
|
9
|
+
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class MonobankService {
|
|
12
|
+
public constructor(
|
|
13
|
+
public invoices: InvoiceService,
|
|
14
|
+
public merchants: MerchantService,
|
|
15
|
+
public statements: StatementService,
|
|
16
|
+
public wallets: WalletService,
|
|
17
|
+
public qr: QrService,
|
|
18
|
+
public subscriptions: SubscriptionService,
|
|
19
|
+
public webhook: WebhookService
|
|
20
|
+
) {}
|
|
21
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"noImplicitAny": false,
|
|
6
|
+
"removeComments": false,
|
|
7
|
+
"noLib": false,
|
|
8
|
+
"emitDecoratorMetadata": true,
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"target": "es2017",
|
|
11
|
+
"sourceMap": false,
|
|
12
|
+
"rootDir": "./src",
|
|
13
|
+
"outDir": "./dist",
|
|
14
|
+
"skipLibCheck": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*"],
|
|
17
|
+
"exclude": ["node_modules", "**/*.spec.ts"]
|
|
18
|
+
}
|