@misterhomer1992/miit-bot-payment 1.0.1 → 1.0.2
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/README.md +262 -146
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/modules/invoice/const.d.ts +4 -0
- package/dist/modules/invoice/const.d.ts.map +1 -0
- package/dist/modules/invoice/const.js +8 -0
- package/dist/modules/invoice/const.js.map +1 -0
- package/dist/modules/invoice/index.d.ts +5 -0
- package/dist/modules/invoice/index.d.ts.map +1 -0
- package/dist/modules/invoice/index.js +21 -0
- package/dist/modules/invoice/index.js.map +1 -0
- package/dist/modules/invoice/repository.d.ts +34 -0
- package/dist/modules/invoice/repository.d.ts.map +1 -0
- package/dist/modules/invoice/repository.js +68 -0
- package/dist/modules/invoice/repository.js.map +1 -0
- package/dist/modules/invoice/service.d.ts +29 -0
- package/dist/modules/invoice/service.d.ts.map +1 -0
- package/dist/modules/invoice/service.js +61 -0
- package/dist/modules/invoice/service.js.map +1 -0
- package/dist/modules/invoice/types.d.ts +14 -0
- package/dist/modules/invoice/types.d.ts.map +1 -0
- package/dist/modules/invoice/types.js +3 -0
- package/dist/modules/invoice/types.js.map +1 -0
- package/dist/modules/logger/types.d.ts +4 -4
- package/dist/modules/logger/types.d.ts.map +1 -1
- package/dist/modules/payments/index.d.ts +5 -0
- package/dist/modules/payments/index.d.ts.map +1 -0
- package/dist/modules/payments/index.js +21 -0
- package/dist/modules/payments/index.js.map +1 -0
- package/dist/modules/payments/repository.d.ts +1 -4
- package/dist/modules/payments/repository.d.ts.map +1 -1
- package/dist/modules/payments/repository.js +46 -84
- package/dist/modules/payments/repository.js.map +1 -1
- package/dist/modules/payments/service.d.ts +65 -0
- package/dist/modules/payments/service.d.ts.map +1 -0
- package/dist/modules/payments/service.js +132 -0
- package/dist/modules/payments/service.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# @miit-bot/payment-utils
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Personal TypeScript library for managing payments and invoices in my bot applications. Built specifically for Wayforpay integration with Firebase/Firestore backend.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Purpose
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
This is a private utility library I use across my bot projects to handle:
|
|
8
|
+
|
|
9
|
+
- Payment processing with Wayforpay
|
|
10
|
+
- Invoice management and webhook handling
|
|
11
|
+
- Payment lifecycle tracking (pending → completed/failed/expired)
|
|
12
|
+
- Multi-platform support (Telegram, web, etc.)
|
|
13
|
+
- Expired payment cleanup
|
|
14
|
+
|
|
15
|
+
Also includes some legacy payment validation and formatting utilities.
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
@@ -20,226 +20,342 @@ A TypeScript utility library for payment validation and formatting. This library
|
|
|
20
20
|
npm install @miit-bot/payment-utils
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
## Setup
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
### Firebase Initialization
|
|
26
|
+
|
|
27
|
+
Initialize Firebase Admin SDK before using payment/invoice services:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import * as admin from 'firebase-admin';
|
|
31
|
+
|
|
32
|
+
admin.initializeApp({
|
|
33
|
+
credential: admin.credential.cert({
|
|
34
|
+
projectId: 'your-project-id',
|
|
35
|
+
clientEmail: 'your-client-email',
|
|
36
|
+
privateKey: 'your-private-key',
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
27
39
|
```
|
|
28
40
|
|
|
41
|
+
### Required Firestore Collections
|
|
42
|
+
|
|
43
|
+
- `payments` - Payment records
|
|
44
|
+
- `invoices` - Invoice records from Wayforpay webhooks
|
|
45
|
+
|
|
29
46
|
## Usage
|
|
30
47
|
|
|
31
|
-
###
|
|
48
|
+
### PaymentService
|
|
49
|
+
|
|
50
|
+
Manages payment lifecycle from creation to completion.
|
|
32
51
|
|
|
33
52
|
```typescript
|
|
34
|
-
import {
|
|
53
|
+
import { PaymentService } from '@miit-bot/payment-utils';
|
|
54
|
+
|
|
55
|
+
const logger = {
|
|
56
|
+
error: (params) => console.error(params),
|
|
57
|
+
info: (params) => console.info(params),
|
|
58
|
+
warn: (params) => console.warn(params),
|
|
59
|
+
debug: (params) => console.debug(params),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const paymentService = new PaymentService(logger);
|
|
63
|
+
|
|
64
|
+
// Create payment when user initiates purchase
|
|
65
|
+
const payment = await paymentService.create({
|
|
66
|
+
orderReference: 'ORDER_123456',
|
|
67
|
+
userId: 'user_abc',
|
|
68
|
+
status: 'pending',
|
|
69
|
+
paymentLink: 'https://wayforpay.com/pay/...',
|
|
70
|
+
planId: 'premium_monthly',
|
|
71
|
+
amount: 99.99,
|
|
72
|
+
currency: 'USD',
|
|
73
|
+
createdAt: new Date().toISOString(),
|
|
74
|
+
platform: 'telegram',
|
|
75
|
+
provider: 'wayforpay',
|
|
76
|
+
});
|
|
35
77
|
|
|
36
|
-
//
|
|
37
|
-
const
|
|
38
|
-
console.log(result);
|
|
39
|
-
// {
|
|
40
|
-
// isValid: true,
|
|
41
|
-
// cardType: 'VISA',
|
|
42
|
-
// message: 'Valid card number'
|
|
43
|
-
// }
|
|
44
|
-
```
|
|
78
|
+
// Retrieve by order reference
|
|
79
|
+
const payment = await paymentService.getByOrderReference('ORDER_123456');
|
|
45
80
|
|
|
46
|
-
|
|
81
|
+
// Get user's payment history
|
|
82
|
+
const userPayments = await paymentService.getByUserId({
|
|
83
|
+
userId: 'user_abc',
|
|
84
|
+
appNamespace: 'telegram',
|
|
85
|
+
status: 'completed', // optional filter
|
|
86
|
+
});
|
|
47
87
|
|
|
48
|
-
|
|
49
|
-
|
|
88
|
+
// Update payment status (e.g., after webhook)
|
|
89
|
+
await paymentService.updateFields({
|
|
90
|
+
orderReference: 'ORDER_123456',
|
|
91
|
+
fields: [
|
|
92
|
+
['status', 'completed'],
|
|
93
|
+
['invoiceId', 'invoice_xyz'],
|
|
94
|
+
],
|
|
95
|
+
});
|
|
50
96
|
|
|
51
|
-
//
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// isValid: true,
|
|
56
|
-
// amount: 99.99,
|
|
57
|
-
// message: 'Valid amount'
|
|
58
|
-
// }
|
|
59
|
-
|
|
60
|
-
// With custom limits
|
|
61
|
-
const customResult = validateAmount(150.0, 10, 100);
|
|
62
|
-
console.log(customResult);
|
|
63
|
-
// {
|
|
64
|
-
// isValid: false,
|
|
65
|
-
// amount: 150,
|
|
66
|
-
// message: 'Amount must not exceed 100'
|
|
67
|
-
// }
|
|
97
|
+
// Find expired pending payments for cleanup
|
|
98
|
+
const expiredPayments = await paymentService.getExpiredPendingPayments({
|
|
99
|
+
hoursOld: 24, // default: 24
|
|
100
|
+
});
|
|
68
101
|
```
|
|
69
102
|
|
|
70
|
-
###
|
|
103
|
+
### InvoiceService
|
|
71
104
|
|
|
72
|
-
|
|
73
|
-
import { validateCVV, CardType } from '@miit-bot/payment-utils';
|
|
105
|
+
Stores invoice data from Wayforpay webhooks.
|
|
74
106
|
|
|
75
|
-
|
|
76
|
-
|
|
107
|
+
```typescript
|
|
108
|
+
import { InvoiceService } from '@miit-bot/payment-utils';
|
|
109
|
+
|
|
110
|
+
const invoiceService = new InvoiceService(logger);
|
|
111
|
+
|
|
112
|
+
// Create invoice from webhook data
|
|
113
|
+
const invoice = await invoiceService.create({
|
|
114
|
+
merchantAccount: 'merchant_123',
|
|
115
|
+
orderReference: 'ORDER_123456',
|
|
116
|
+
merchantSignature: 'signature_hash',
|
|
117
|
+
reasonCode: 1100,
|
|
118
|
+
reason: 'Payment successful',
|
|
119
|
+
createdDate: Date.now(),
|
|
120
|
+
processingDate: Date.now(),
|
|
121
|
+
currency: 'USD',
|
|
122
|
+
amount: 99.99,
|
|
123
|
+
});
|
|
77
124
|
|
|
78
|
-
//
|
|
79
|
-
const
|
|
125
|
+
// Retrieve invoice
|
|
126
|
+
const invoice = await invoiceService.getByOrderReference('ORDER_123456');
|
|
80
127
|
```
|
|
81
128
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
import { formatCardNumber, maskCardNumber } from '@miit-bot/payment-utils';
|
|
129
|
+
## Typical Workflow
|
|
86
130
|
|
|
87
|
-
|
|
88
|
-
const formatted = formatCardNumber('4532015112830366');
|
|
89
|
-
console.log(formatted); // '4532 0151 1283 0366'
|
|
131
|
+
### 1. User Initiates Payment
|
|
90
132
|
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
133
|
+
```typescript
|
|
134
|
+
const payment = await paymentService.create({
|
|
135
|
+
orderReference: generateOrderReference(),
|
|
136
|
+
userId: user.id,
|
|
137
|
+
status: 'pending',
|
|
138
|
+
paymentLink: wayforpayUrl,
|
|
139
|
+
planId: 'premium_monthly',
|
|
140
|
+
amount: 99.99,
|
|
141
|
+
currency: 'USD',
|
|
142
|
+
createdAt: new Date().toISOString(),
|
|
143
|
+
platform: 'telegram',
|
|
144
|
+
provider: 'wayforpay',
|
|
145
|
+
});
|
|
94
146
|
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
console.log(customMask); // 'XXXXXXXXXXXX0366'
|
|
147
|
+
// Send link to user
|
|
148
|
+
sendPaymentLink(payment.paymentLink);
|
|
98
149
|
```
|
|
99
150
|
|
|
100
|
-
###
|
|
151
|
+
### 2. Wayforpay Webhook Handler
|
|
101
152
|
|
|
102
153
|
```typescript
|
|
103
|
-
|
|
154
|
+
// Update payment status
|
|
155
|
+
await paymentService.updateFields({
|
|
156
|
+
orderReference: webhookData.orderReference,
|
|
157
|
+
fields: [['status', 'completed']],
|
|
158
|
+
});
|
|
104
159
|
|
|
105
|
-
//
|
|
106
|
-
const
|
|
107
|
-
|
|
160
|
+
// Save invoice
|
|
161
|
+
const invoice = await invoiceService.create({
|
|
162
|
+
merchantAccount: webhookData.merchantAccount,
|
|
163
|
+
orderReference: webhookData.orderReference,
|
|
164
|
+
merchantSignature: webhookData.merchantSignature,
|
|
165
|
+
reasonCode: webhookData.reasonCode,
|
|
166
|
+
reason: webhookData.reason,
|
|
167
|
+
createdDate: webhookData.createdDate,
|
|
168
|
+
processingDate: webhookData.processingDate,
|
|
169
|
+
currency: webhookData.currency,
|
|
170
|
+
amount: webhookData.amount,
|
|
171
|
+
});
|
|
108
172
|
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
173
|
+
// Link invoice to payment
|
|
174
|
+
await paymentService.updateFields({
|
|
175
|
+
orderReference: webhookData.orderReference,
|
|
176
|
+
fields: [['invoiceId', invoice.id]],
|
|
113
177
|
});
|
|
114
|
-
console.log(eur); // '1.234,56 €'
|
|
115
178
|
```
|
|
116
179
|
|
|
117
|
-
###
|
|
180
|
+
### 3. Cleanup Expired Payments (Cron Job)
|
|
118
181
|
|
|
119
182
|
```typescript
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
183
|
+
async function cleanupExpiredPayments() {
|
|
184
|
+
const expired = await paymentService.getExpiredPendingPayments({ hoursOld: 24 });
|
|
185
|
+
|
|
186
|
+
for (const payment of expired) {
|
|
187
|
+
await paymentService.updateFields({
|
|
188
|
+
orderReference: payment.orderReference,
|
|
189
|
+
fields: [['status', 'expired']],
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
125
193
|
```
|
|
126
194
|
|
|
127
195
|
## API Reference
|
|
128
196
|
|
|
197
|
+
### PaymentService
|
|
198
|
+
|
|
199
|
+
**Methods:**
|
|
200
|
+
|
|
201
|
+
- `getByOrderReference(orderReference: string): Promise<PaymentEntity | null>`
|
|
202
|
+
- `getByUserId(params: { userId: string; appNamespace: AppNamespace; status?: PaymentStatus }): Promise<PaymentEntity[]>`
|
|
203
|
+
- `create(paymentData: Omit<PaymentEntity, 'id'>): Promise<PaymentEntity>`
|
|
204
|
+
- `updateFields(params: { orderReference: string; fields: UpdateDBPaymentFields }): Promise<void>`
|
|
205
|
+
- `getExpiredPendingPayments(params?: { hoursOld?: number }): Promise<PaymentEntity[]>`
|
|
206
|
+
|
|
207
|
+
### InvoiceService
|
|
208
|
+
|
|
209
|
+
**Methods:**
|
|
210
|
+
|
|
211
|
+
- `create(invoiceData: Omit<InvoiceEntity, 'id'>): Promise<InvoiceEntity>`
|
|
212
|
+
- `getByOrderReference(orderReference: string): Promise<InvoiceEntity | null>`
|
|
213
|
+
|
|
129
214
|
### Types
|
|
130
215
|
|
|
131
|
-
####
|
|
216
|
+
#### PaymentEntity
|
|
132
217
|
|
|
133
218
|
```typescript
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
219
|
+
interface PaymentEntity {
|
|
220
|
+
id?: string;
|
|
221
|
+
orderReference: string;
|
|
222
|
+
userId: string;
|
|
223
|
+
status: 'pending' | 'completed' | 'failed' | 'expired';
|
|
224
|
+
paymentLink: string;
|
|
225
|
+
planId: string;
|
|
226
|
+
amount: number;
|
|
227
|
+
currency: 'UAH' | 'USD';
|
|
228
|
+
createdAt: string;
|
|
229
|
+
invoiceId?: string;
|
|
230
|
+
platform: AppNamespace;
|
|
231
|
+
provider: 'wayforpay';
|
|
140
232
|
}
|
|
141
233
|
```
|
|
142
234
|
|
|
143
|
-
####
|
|
235
|
+
#### InvoiceEntity
|
|
144
236
|
|
|
145
237
|
```typescript
|
|
146
|
-
interface
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
238
|
+
interface InvoiceEntity {
|
|
239
|
+
id: string;
|
|
240
|
+
merchantAccount: string;
|
|
241
|
+
orderReference: string;
|
|
242
|
+
merchantSignature: string;
|
|
243
|
+
reasonCode: number;
|
|
244
|
+
reason: string;
|
|
245
|
+
createdDate: number;
|
|
246
|
+
processingDate: number;
|
|
247
|
+
currency: string;
|
|
248
|
+
amount: number;
|
|
150
249
|
}
|
|
151
250
|
```
|
|
152
251
|
|
|
153
|
-
####
|
|
252
|
+
#### Logger Interface
|
|
154
253
|
|
|
155
254
|
```typescript
|
|
156
|
-
interface
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
255
|
+
interface Logger {
|
|
256
|
+
error(params: { message: string; payload?: any }): void;
|
|
257
|
+
info(params: { message: string; payload?: any }): void;
|
|
258
|
+
warn(params: { message: string; payload?: any }): void;
|
|
259
|
+
debug(params: { message: string; payload?: any }): void;
|
|
160
260
|
}
|
|
161
261
|
```
|
|
162
262
|
|
|
163
|
-
|
|
263
|
+
## Legacy Validation & Formatting
|
|
164
264
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
Validates a credit card number using the Luhn algorithm and detects the card type.
|
|
265
|
+
### Card Validation
|
|
168
266
|
|
|
169
|
-
|
|
267
|
+
```typescript
|
|
268
|
+
import { validateCardNumber, CardType } from '@miit-bot/payment-utils';
|
|
170
269
|
|
|
171
|
-
|
|
270
|
+
const result = validateCardNumber('4532015112830366');
|
|
271
|
+
// { isValid: true, cardType: 'VISA', message: 'Valid card number' }
|
|
272
|
+
```
|
|
172
273
|
|
|
173
|
-
|
|
274
|
+
### Amount Validation
|
|
174
275
|
|
|
175
|
-
|
|
276
|
+
```typescript
|
|
277
|
+
import { validateAmount } from '@miit-bot/payment-utils';
|
|
176
278
|
|
|
177
|
-
|
|
279
|
+
const result = validateAmount(99.99);
|
|
280
|
+
// { isValid: true, amount: 99.99, message: 'Valid amount' }
|
|
281
|
+
```
|
|
178
282
|
|
|
179
|
-
|
|
283
|
+
### CVV Validation
|
|
180
284
|
|
|
181
|
-
|
|
285
|
+
```typescript
|
|
286
|
+
import { validateCVV, CardType } from '@miit-bot/payment-utils';
|
|
182
287
|
|
|
183
|
-
|
|
288
|
+
const isValid = validateCVV('123'); // true
|
|
289
|
+
const isValidAmex = validateCVV('1234', CardType.AMEX); // true
|
|
290
|
+
```
|
|
184
291
|
|
|
185
|
-
|
|
292
|
+
### Card Formatting
|
|
186
293
|
|
|
187
|
-
|
|
294
|
+
```typescript
|
|
295
|
+
import { formatCardNumber, maskCardNumber } from '@miit-bot/payment-utils';
|
|
188
296
|
|
|
189
|
-
|
|
297
|
+
formatCardNumber('4532015112830366'); // '4532 0151 1283 0366'
|
|
298
|
+
formatCardNumber('4532015112830366', true); // '**** **** **** 0366'
|
|
299
|
+
maskCardNumber('4532015112830366', 4, 'X'); // 'XXXXXXXXXXXX0366'
|
|
300
|
+
```
|
|
190
301
|
|
|
191
|
-
|
|
302
|
+
### Currency Formatting
|
|
192
303
|
|
|
193
|
-
|
|
304
|
+
```typescript
|
|
305
|
+
import { formatCurrency } from '@miit-bot/payment-utils';
|
|
194
306
|
|
|
195
|
-
|
|
307
|
+
formatCurrency(1234.56); // '$1,234.56'
|
|
308
|
+
formatCurrency(1234.56, { locale: 'de-DE', currency: 'EUR' }); // '1.234,56 €'
|
|
309
|
+
```
|
|
196
310
|
|
|
197
|
-
###
|
|
311
|
+
### Expiry Date Formatting
|
|
198
312
|
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
npm install
|
|
313
|
+
```typescript
|
|
314
|
+
import { formatExpiryDate } from '@miit-bot/payment-utils';
|
|
202
315
|
|
|
203
|
-
|
|
204
|
-
|
|
316
|
+
formatExpiryDate(12, 2025); // '12/25'
|
|
317
|
+
```
|
|
205
318
|
|
|
206
|
-
|
|
207
|
-
npm run lint
|
|
319
|
+
## Architecture
|
|
208
320
|
|
|
209
|
-
|
|
210
|
-
npm run format
|
|
321
|
+
**Service Layer** - Business logic and error handling
|
|
211
322
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
```
|
|
323
|
+
- `PaymentService` - Payment operations
|
|
324
|
+
- `InvoiceService` - Invoice operations
|
|
215
325
|
|
|
216
|
-
|
|
326
|
+
**Repository Layer** - Database operations
|
|
217
327
|
|
|
218
|
-
|
|
328
|
+
- `PaymentRepository` - Firestore queries for payments
|
|
329
|
+
- `InvoiceRepository` - Firestore queries for invoices
|
|
219
330
|
|
|
220
|
-
|
|
221
|
-
- Type declaration files (.d.ts)
|
|
222
|
-
- Source maps
|
|
331
|
+
Benefits: Clean separation, easy testing, type-safe.
|
|
223
332
|
|
|
224
|
-
|
|
333
|
+
## Development
|
|
225
334
|
|
|
226
335
|
```bash
|
|
227
|
-
#
|
|
228
|
-
npm
|
|
229
|
-
```
|
|
336
|
+
# Install
|
|
337
|
+
npm install
|
|
230
338
|
|
|
231
|
-
|
|
339
|
+
# Build
|
|
340
|
+
npm run build
|
|
232
341
|
|
|
233
|
-
|
|
342
|
+
# Lint
|
|
343
|
+
npm run lint
|
|
234
344
|
|
|
235
|
-
|
|
345
|
+
# Format
|
|
346
|
+
npm run format
|
|
236
347
|
|
|
237
|
-
|
|
348
|
+
# Watch
|
|
349
|
+
npm run watch
|
|
350
|
+
```
|
|
238
351
|
|
|
239
|
-
|
|
352
|
+
### Dependencies
|
|
240
353
|
|
|
241
|
-
|
|
354
|
+
- **firebase-admin** - Peer dependency for Firestore
|
|
355
|
+
- **TypeScript** - Dev dependency
|
|
356
|
+
- **ESLint** - Dev dependency
|
|
357
|
+
- **Prettier** - Dev dependency
|
|
242
358
|
|
|
243
|
-
##
|
|
359
|
+
## License
|
|
244
360
|
|
|
245
|
-
|
|
361
|
+
MIT
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./modules/payments
|
|
17
|
+
__exportStar(require("./modules/payments"), exports);
|
|
18
|
+
__exportStar(require("./modules/invoice"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,oDAAkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../../src/modules/invoice/const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,QAAA,MAAM,sBAAsB,EAAE,OAAO,CAAC,aAAa,CAElD,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_INVOICE_ENTITY = void 0;
|
|
4
|
+
const DEFAULT_INVOICE_ENTITY = {
|
|
5
|
+
currency: 'UAH',
|
|
6
|
+
};
|
|
7
|
+
exports.DEFAULT_INVOICE_ENTITY = DEFAULT_INVOICE_ENTITY;
|
|
8
|
+
//# sourceMappingURL=const.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/modules/invoice/const.ts"],"names":[],"mappings":";;;AAEA,MAAM,sBAAsB,GAA2B;IACnD,QAAQ,EAAE,KAAK;CAClB,CAAC;AAEO,wDAAsB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/invoice/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./repository"), exports);
|
|
19
|
+
__exportStar(require("./service"), exports);
|
|
20
|
+
__exportStar(require("./const"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/invoice/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,+CAA6B;AAC7B,4CAA0B;AAC1B,0CAAwB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { InvoiceEntity } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* InvoiceRepository class handles all database operations related to invoices.
|
|
4
|
+
* Implements repository pattern for invoice data access.
|
|
5
|
+
*/
|
|
6
|
+
declare class InvoiceRepository {
|
|
7
|
+
private readonly db;
|
|
8
|
+
private readonly collectionName;
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of InvoiceRepository.
|
|
11
|
+
*/
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves an invoice by its order reference.
|
|
15
|
+
* @param orderReference - The unique order reference identifier
|
|
16
|
+
* @returns Promise resolving to InvoiceEntity or null if not found
|
|
17
|
+
*/
|
|
18
|
+
getByOrderReference(orderReference: string): Promise<InvoiceEntity | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new invoice record in the database.
|
|
21
|
+
* @param invoiceData - Invoice data without ID (ID will be auto-generated)
|
|
22
|
+
* @returns Promise resolving to created InvoiceEntity with ID
|
|
23
|
+
* @throws Error if invoice creation fails
|
|
24
|
+
*/
|
|
25
|
+
create(invoiceData: Omit<InvoiceEntity, 'id'>): Promise<InvoiceEntity>;
|
|
26
|
+
/**
|
|
27
|
+
* Maps a Firestore document to an InvoiceEntity.
|
|
28
|
+
* @param doc - Firestore document snapshot
|
|
29
|
+
* @returns InvoiceEntity with document ID
|
|
30
|
+
*/
|
|
31
|
+
private mapDocumentToEntity;
|
|
32
|
+
}
|
|
33
|
+
export { InvoiceRepository };
|
|
34
|
+
//# sourceMappingURL=repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../src/modules/invoice/repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC;;;GAGG;AACH,cAAM,iBAAiB;IACnB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAY;IAC/B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAc;IAE7C;;OAEG;;IAKH;;;;OAIG;IACU,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAevF;;;;;OAKG;IACU,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAkBnF;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;CAM9B;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|