@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.
Files changed (40) hide show
  1. package/README.md +262 -146
  2. package/dist/index.d.ts +2 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/modules/invoice/const.d.ts +4 -0
  7. package/dist/modules/invoice/const.d.ts.map +1 -0
  8. package/dist/modules/invoice/const.js +8 -0
  9. package/dist/modules/invoice/const.js.map +1 -0
  10. package/dist/modules/invoice/index.d.ts +5 -0
  11. package/dist/modules/invoice/index.d.ts.map +1 -0
  12. package/dist/modules/invoice/index.js +21 -0
  13. package/dist/modules/invoice/index.js.map +1 -0
  14. package/dist/modules/invoice/repository.d.ts +34 -0
  15. package/dist/modules/invoice/repository.d.ts.map +1 -0
  16. package/dist/modules/invoice/repository.js +68 -0
  17. package/dist/modules/invoice/repository.js.map +1 -0
  18. package/dist/modules/invoice/service.d.ts +29 -0
  19. package/dist/modules/invoice/service.d.ts.map +1 -0
  20. package/dist/modules/invoice/service.js +61 -0
  21. package/dist/modules/invoice/service.js.map +1 -0
  22. package/dist/modules/invoice/types.d.ts +14 -0
  23. package/dist/modules/invoice/types.d.ts.map +1 -0
  24. package/dist/modules/invoice/types.js +3 -0
  25. package/dist/modules/invoice/types.js.map +1 -0
  26. package/dist/modules/logger/types.d.ts +4 -4
  27. package/dist/modules/logger/types.d.ts.map +1 -1
  28. package/dist/modules/payments/index.d.ts +5 -0
  29. package/dist/modules/payments/index.d.ts.map +1 -0
  30. package/dist/modules/payments/index.js +21 -0
  31. package/dist/modules/payments/index.js.map +1 -0
  32. package/dist/modules/payments/repository.d.ts +1 -4
  33. package/dist/modules/payments/repository.d.ts.map +1 -1
  34. package/dist/modules/payments/repository.js +46 -84
  35. package/dist/modules/payments/repository.js.map +1 -1
  36. package/dist/modules/payments/service.d.ts +65 -0
  37. package/dist/modules/payments/service.d.ts.map +1 -0
  38. package/dist/modules/payments/service.js +132 -0
  39. package/dist/modules/payments/service.js.map +1 -0
  40. package/package.json +1 -1
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaymentService = void 0;
4
+ const repository_1 = require("./repository");
5
+ /**
6
+ * PaymentService class handles business logic related to payments.
7
+ * Acts as an intermediary between controllers/handlers and the repository layer.
8
+ */
9
+ class PaymentService {
10
+ /**
11
+ * Creates an instance of PaymentService.
12
+ * @param logger - Application logger instance for logging operations
13
+ */
14
+ constructor(logger) {
15
+ this.logger = logger;
16
+ this.repository = new repository_1.PaymentRepository();
17
+ }
18
+ /**
19
+ * Retrieves a payment by its order reference.
20
+ * @param orderReference - The unique order reference identifier
21
+ * @returns Promise resolving to PaymentEntity or null if not found
22
+ */
23
+ async getByOrderReference(orderReference) {
24
+ try {
25
+ return await this.repository.getByOrderReference(orderReference);
26
+ }
27
+ catch (error) {
28
+ this.logger.error({
29
+ message: 'Error in payment service getByOrderReference',
30
+ payload: {
31
+ orderReference,
32
+ error: JSON.stringify(error),
33
+ },
34
+ });
35
+ return null;
36
+ }
37
+ }
38
+ /**
39
+ * Retrieves all payments for a specific user.
40
+ * @param params - Query parameters
41
+ * @param params.userId - The user's unique identifier
42
+ * @param params.appNamespace - The application namespace/platform
43
+ * @param params.status - Optional payment status filter
44
+ * @returns Promise resolving to array of PaymentEntity
45
+ */
46
+ async getByUserId(params) {
47
+ try {
48
+ return await this.repository.getByUserId(params);
49
+ }
50
+ catch (error) {
51
+ this.logger.error({
52
+ message: 'Error in payment service getByUserId',
53
+ payload: {
54
+ userId: params.userId,
55
+ appNamespace: params.appNamespace,
56
+ status: params.status,
57
+ error: JSON.stringify(error),
58
+ },
59
+ });
60
+ return [];
61
+ }
62
+ }
63
+ /**
64
+ * Creates a new payment record in the database.
65
+ * @param paymentData - Payment data without ID (ID will be auto-generated)
66
+ * @returns Promise resolving to created PaymentEntity with ID
67
+ * @throws Error if payment creation fails
68
+ */
69
+ async create(paymentData) {
70
+ try {
71
+ return await this.repository.create(paymentData);
72
+ }
73
+ catch (error) {
74
+ this.logger.error({
75
+ message: 'Error in payment service create',
76
+ payload: {
77
+ orderReference: paymentData.orderReference,
78
+ userId: paymentData.userId,
79
+ error: JSON.stringify(error),
80
+ },
81
+ });
82
+ throw error;
83
+ }
84
+ }
85
+ /**
86
+ * Updates specific fields of a payment identified by order reference.
87
+ * @param params - Update parameters
88
+ * @param params.orderReference - The order reference to identify the payment
89
+ * @param params.fields - Array of field paths and values to update
90
+ * @throws Error if payment not found or update fails
91
+ */
92
+ async updateFields(params) {
93
+ try {
94
+ await this.repository.updateFields(params);
95
+ }
96
+ catch (error) {
97
+ this.logger.error({
98
+ message: 'Error in payment service updateFields',
99
+ payload: {
100
+ orderReference: params.orderReference,
101
+ fields: JSON.stringify(params.fields),
102
+ error: JSON.stringify(error),
103
+ },
104
+ });
105
+ throw error;
106
+ }
107
+ }
108
+ /**
109
+ * Retrieves all pending payments that are older than specified hours.
110
+ * Used for cleaning up expired payment attempts.
111
+ * @param params - Query parameters
112
+ * @param params.hoursOld - Number of hours after which a pending payment is considered expired (default: 24)
113
+ * @returns Promise resolving to array of expired PaymentEntity
114
+ */
115
+ async getExpiredPendingPayments(params = {}) {
116
+ try {
117
+ return await this.repository.getExpiredPendingPayments(params);
118
+ }
119
+ catch (error) {
120
+ this.logger.error({
121
+ message: 'Error in payment service getExpiredPendingPayments',
122
+ payload: {
123
+ hoursOld: params.hoursOld,
124
+ error: JSON.stringify(error),
125
+ },
126
+ });
127
+ return [];
128
+ }
129
+ }
130
+ }
131
+ exports.PaymentService = PaymentService;
132
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/modules/payments/service.ts"],"names":[],"mappings":";;;AACA,6CAAwE;AAIxE;;;GAGG;AACH,MAAa,cAAc;IAIvB;;;O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ACL,CAAC;CACJ;AAtID,wCAsIC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@misterhomer1992/miit-bot-payment",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A TypeScript utility library for payment validation and formatting",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",