@misterhomer1992/miit-bot-payment 1.0.2 → 1.0.4

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 (66) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/modules/invoice/types.d.ts +2 -2
  6. package/dist/modules/payments/api.d.ts +59 -0
  7. package/dist/modules/payments/api.d.ts.map +1 -0
  8. package/dist/modules/payments/api.js +93 -0
  9. package/dist/modules/payments/api.js.map +1 -0
  10. package/dist/modules/payments/index.d.ts +2 -0
  11. package/dist/modules/payments/index.d.ts.map +1 -1
  12. package/dist/modules/payments/index.js +2 -0
  13. package/dist/modules/payments/index.js.map +1 -1
  14. package/dist/modules/payments/service.d.ts +31 -0
  15. package/dist/modules/payments/service.d.ts.map +1 -1
  16. package/dist/modules/payments/service.js +75 -0
  17. package/dist/modules/payments/service.js.map +1 -1
  18. package/dist/modules/payments/utils.d.ts +20 -0
  19. package/dist/modules/payments/utils.d.ts.map +1 -0
  20. package/dist/modules/payments/utils.js +31 -0
  21. package/dist/modules/payments/utils.js.map +1 -0
  22. package/dist/modules/subscription/const.d.ts +4 -0
  23. package/dist/modules/subscription/const.d.ts.map +1 -0
  24. package/dist/modules/subscription/const.js +10 -0
  25. package/dist/modules/subscription/const.js.map +1 -0
  26. package/dist/modules/subscription/index.d.ts +5 -0
  27. package/dist/modules/subscription/index.d.ts.map +1 -0
  28. package/dist/modules/subscription/index.js +23 -0
  29. package/dist/modules/subscription/index.js.map +1 -0
  30. package/dist/modules/subscription/repository.d.ts +91 -0
  31. package/dist/modules/subscription/repository.d.ts.map +1 -0
  32. package/dist/modules/subscription/repository.js +146 -0
  33. package/dist/modules/subscription/repository.js.map +1 -0
  34. package/dist/modules/subscription/service.d.ts +101 -0
  35. package/dist/modules/subscription/service.d.ts.map +1 -0
  36. package/dist/modules/subscription/service.js +205 -0
  37. package/dist/modules/subscription/service.js.map +1 -0
  38. package/dist/modules/subscription/subscriptionPlan.d.ts +4 -0
  39. package/dist/modules/subscription/subscriptionPlan.d.ts.map +1 -0
  40. package/dist/modules/subscription/subscriptionPlan.js +63 -0
  41. package/dist/modules/subscription/subscriptionPlan.js.map +1 -0
  42. package/dist/modules/subscription/types.d.ts +37 -0
  43. package/dist/modules/subscription/types.d.ts.map +1 -0
  44. package/dist/modules/subscription/types.js +3 -0
  45. package/dist/modules/subscription/types.js.map +1 -0
  46. package/dist/modules/subscription/utils.d.ts +5 -0
  47. package/dist/modules/subscription/utils.d.ts.map +1 -0
  48. package/dist/modules/subscription/utils.js +16 -0
  49. package/dist/modules/subscription/utils.js.map +1 -0
  50. package/dist/modules/user/index.d.ts +4 -0
  51. package/dist/modules/user/index.d.ts.map +1 -0
  52. package/dist/modules/user/index.js +20 -0
  53. package/dist/modules/user/index.js.map +1 -0
  54. package/dist/modules/user/types.d.ts +78 -0
  55. package/dist/modules/user/types.d.ts.map +1 -0
  56. package/dist/modules/user/types.js +3 -0
  57. package/dist/modules/user/types.js.map +1 -0
  58. package/dist/modules/user/userRepository.d.ts +61 -19
  59. package/dist/modules/user/userRepository.d.ts.map +1 -1
  60. package/dist/modules/user/userRepository.js +72 -35
  61. package/dist/modules/user/userRepository.js.map +1 -1
  62. package/dist/modules/user/userService.d.ts +54 -0
  63. package/dist/modules/user/userService.d.ts.map +1 -0
  64. package/dist/modules/user/userService.js +92 -0
  65. package/dist/modules/user/userService.js.map +1 -0
  66. package/package.json +3 -2
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SubscriptionRepository = void 0;
4
+ const firestore_1 = require("firebase-admin/firestore");
5
+ const const_1 = require("./const");
6
+ /**
7
+ * SubscriptionRepository class handles all database operations related to subscriptions.
8
+ * Implements repository pattern for subscription data access.
9
+ */
10
+ class SubscriptionRepository {
11
+ /**
12
+ * Creates an instance of SubscriptionRepository.
13
+ */
14
+ constructor() {
15
+ this.collectionName = 'subscriptions';
16
+ this.db = (0, firestore_1.getFirestore)();
17
+ }
18
+ /**
19
+ * Retrieves an active subscription for a specific user.
20
+ * @param params - Query parameters
21
+ * @param params.userId - The user's unique identifier
22
+ * @param params.appNamespace - The application namespace/platform
23
+ * @returns Promise resolving to SubscriptionEntity or null if not found
24
+ */
25
+ async getByUserId(params) {
26
+ const { userId, appNamespace } = params;
27
+ const querySnapshot = await this.db
28
+ .collection(this.collectionName)
29
+ .where('platform', '==', appNamespace)
30
+ .where('userId', '==', userId)
31
+ .where('status', '==', 'active')
32
+ .limit(1)
33
+ .get();
34
+ if (querySnapshot.empty) {
35
+ return null;
36
+ }
37
+ const doc = querySnapshot.docs[0];
38
+ return this.mapDocumentToEntity(doc);
39
+ }
40
+ /**
41
+ * Creates a new subscription record in the database.
42
+ * @param params - Subscription creation parameters
43
+ * @param params.userId - The user's unique identifier
44
+ * @param params.appNamespace - The application namespace/platform
45
+ * @param params.planId - The subscription plan identifier
46
+ * @param params.expiresAt - ISO timestamp when subscription expires
47
+ * @param params.startedAt - ISO timestamp when subscription started
48
+ * @returns Promise resolving to created SubscriptionEntity with ID
49
+ * @throws Error if subscription creation fails
50
+ */
51
+ async create(params) {
52
+ const { userId, appNamespace, planId, expiresAt, startedAt } = params;
53
+ const subscriptionEntity = {
54
+ ...const_1.DEFAULT_SUBSCRIPTION_ENTITY,
55
+ userId,
56
+ platform: appNamespace,
57
+ planId,
58
+ expiresAt,
59
+ startedAt,
60
+ };
61
+ const docRef = await this.db.collection(this.collectionName).add(subscriptionEntity);
62
+ if (!docRef.id) {
63
+ throw new Error(`Failed to create subscription for userId: ${userId}`);
64
+ }
65
+ return {
66
+ id: docRef.id,
67
+ ...subscriptionEntity,
68
+ };
69
+ }
70
+ /**
71
+ * Updates specific fields of a subscription identified by userId and appNamespace.
72
+ * @param params - Update parameters
73
+ * @param params.userId - The user's unique identifier
74
+ * @param params.appNamespace - The application namespace/platform
75
+ * @param params.fields - Array of field paths and values to update
76
+ * @throws Error if subscription not found or update fails
77
+ */
78
+ async updateFieldsByUserId(params) {
79
+ const { userId, appNamespace, fields } = params;
80
+ const updateObject = this.buildUpdateObject(fields);
81
+ const querySnapshot = await this.db
82
+ .collection(this.collectionName)
83
+ .where('platform', '==', appNamespace)
84
+ .where('userId', '==', userId)
85
+ .limit(1)
86
+ .get();
87
+ if (querySnapshot.empty) {
88
+ throw new Error(`Subscription not found for userId: ${userId}`);
89
+ }
90
+ await querySnapshot.docs[0].ref.update(updateObject);
91
+ }
92
+ /**
93
+ * Retrieves all active subscriptions that have expired.
94
+ * Used for batch processing to update subscription statuses.
95
+ * @returns Promise resolving to array of expired SubscriptionEntity
96
+ */
97
+ async getExpiredActiveSubscriptions() {
98
+ const now = new Date().toISOString();
99
+ const querySnapshot = await this.db
100
+ .collection(this.collectionName)
101
+ .where('status', '==', 'active')
102
+ .where('expiresAt', '<', now)
103
+ .get();
104
+ if (querySnapshot.empty) {
105
+ return [];
106
+ }
107
+ return querySnapshot.docs.map((doc) => this.mapDocumentToEntity(doc));
108
+ }
109
+ /**
110
+ * Updates specific fields of a subscription identified by subscription ID.
111
+ * @param params - Update parameters
112
+ * @param params.subscriptionId - The subscription document ID
113
+ * @param params.fields - Array of field paths and values to update
114
+ * @throws Error if update fails
115
+ */
116
+ async updateFieldsById(params) {
117
+ const { subscriptionId, fields } = params;
118
+ const updateObject = this.buildUpdateObject(fields);
119
+ await this.db.collection(this.collectionName).doc(subscriptionId).update(updateObject);
120
+ }
121
+ /**
122
+ * Maps a Firestore document to a SubscriptionEntity.
123
+ * @param doc - Firestore document snapshot
124
+ * @returns SubscriptionEntity with document ID
125
+ */
126
+ mapDocumentToEntity(doc) {
127
+ return {
128
+ id: doc.id,
129
+ ...doc.data(),
130
+ };
131
+ }
132
+ /**
133
+ * Builds an update object from field tuples.
134
+ * @param fields - Array of field paths and values
135
+ * @returns Object with field paths as keys and values to update
136
+ */
137
+ buildUpdateObject(fields) {
138
+ const updateObject = {};
139
+ fields.forEach(([fieldPath, value]) => {
140
+ updateObject[fieldPath] = value;
141
+ });
142
+ return updateObject;
143
+ }
144
+ }
145
+ exports.SubscriptionRepository = SubscriptionRepository;
146
+ //# sourceMappingURL=repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/modules/subscription/repository.ts"],"names":[],"mappings":";;;AAAA,wDAAsG;AAEtG,mCAAsD;AAQtD;;;GAGG;AACH,MAAa,sBAAsB;IAI/B;;OAEG;IACH;QALiB,mBAAc,GAAG,eAAe,CAAC;QAM9C,IAAI,CAAC,EAAE,GAAG,IAAA,wBAAY,GAAE,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CAAC,MAAgD;QACrE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;QAExC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,EAAE;aAC9B,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC;aAC/B,KAAK,CAAC,UAAU,EAAE,IAAI,EAAE,YAAY,CAAC;aACrC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC;aAC7B,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC;aAC/B,KAAK,CAAC,CAAC,CAAC;aACR,GAAG,EAAE,CAAC;QAEX,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;;;;;OAUG;IACI,KAAK,CAAC,MAAM,CAAC,MAMnB;QACG,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAA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AAC;CACJ;AA9KD,wDA8KC"}
@@ -0,0 +1,101 @@
1
+ import { Logger } from '../logger/types';
2
+ import { UpdateDBSubscriptionFields } from './repository';
3
+ import { SubscriptionEntity } from './types';
4
+ import { AppNamespace } from '../app/types';
5
+ /**
6
+ * SubscriptionService class handles business logic related to subscriptions.
7
+ * Acts as an intermediary between controllers/handlers and the repository layer.
8
+ */
9
+ export declare class SubscriptionService {
10
+ private readonly logger;
11
+ private readonly repository;
12
+ private readonly paymentService;
13
+ /**
14
+ * Creates an instance of SubscriptionService.
15
+ * @param logger - Application logger instance for logging operations
16
+ */
17
+ constructor(logger: Logger);
18
+ /**
19
+ * Retrieves an active subscription for a specific user.
20
+ * @param params - Query parameters
21
+ * @param params.userId - The user's unique identifier
22
+ * @param params.appNamespace - The application namespace/platform
23
+ * @returns Promise resolving to SubscriptionEntity or null if not found
24
+ */
25
+ getByUserId(params: {
26
+ userId: string;
27
+ appNamespace: string;
28
+ }): Promise<SubscriptionEntity | null>;
29
+ /**
30
+ * Creates a new subscription record in the database.
31
+ * @param params - Subscription creation parameters
32
+ * @param params.userId - The user's unique identifier
33
+ * @param params.appNamespace - The application namespace/platform
34
+ * @param params.planId - The subscription plan identifier
35
+ * @param params.expiresAt - ISO timestamp when subscription expires
36
+ * @param params.startedAt - ISO timestamp when subscription started
37
+ * @returns Promise resolving to created SubscriptionEntity with ID
38
+ * @throws Error if subscription creation fails
39
+ */
40
+ create(params: {
41
+ userId: string;
42
+ appNamespace: AppNamespace;
43
+ planId: string;
44
+ expiresAt: string;
45
+ startedAt: string;
46
+ }): Promise<SubscriptionEntity>;
47
+ /**
48
+ * Updates specific fields of a subscription identified by userId and appNamespace.
49
+ * @param params - Update parameters
50
+ * @param params.userId - The user's unique identifier
51
+ * @param params.appNamespace - The application namespace/platform
52
+ * @param params.fields - Array of field paths and values to update
53
+ * @throws Error if subscription not found or update fails
54
+ */
55
+ updateFieldsByUserId(params: {
56
+ userId: string;
57
+ appNamespace: AppNamespace;
58
+ fields: UpdateDBSubscriptionFields;
59
+ }): Promise<void>;
60
+ /**
61
+ * Retrieves all active subscriptions that have expired.
62
+ * Used for batch processing to update subscription statuses.
63
+ * @returns Promise resolving to array of expired SubscriptionEntity
64
+ */
65
+ getExpiredActiveSubscriptions(): Promise<SubscriptionEntity[]>;
66
+ /**
67
+ * Updates specific fields of a subscription identified by subscription ID.
68
+ * @param params - Update parameters
69
+ * @param params.subscriptionId - The subscription document ID
70
+ * @param params.fields - Array of field paths and values to update
71
+ * @throws Error if update fails
72
+ */
73
+ updateFieldsById(params: {
74
+ subscriptionId: string;
75
+ fields: UpdateDBSubscriptionFields;
76
+ }): Promise<void>;
77
+ /**
78
+ * Gets or creates a subscription payment URL.
79
+ * Checks for recent pending payments (within 3 minutes) and reuses the payment link if found.
80
+ * Otherwise creates a new payment intent for the subscription.
81
+ * @param params - Payment URL creation parameters
82
+ * @param params.userId - The user's unique identifier
83
+ * @param params.appNamespace - The application namespace/platform
84
+ * @param params.planId - The subscription plan identifier
85
+ * @param params.languageCode - Language code for translations
86
+ * @param params.translate - Translation function
87
+ * @returns Promise resolving to the payment URL string
88
+ * @throws Error if subscription plan not found or payment creation fails
89
+ */
90
+ getOrCreateSubscriptionPaymentUrl(params: {
91
+ userId: string;
92
+ appNamespace: AppNamespace;
93
+ planId: string;
94
+ languageCode: string;
95
+ translate: (params: {
96
+ code: string;
97
+ path: string;
98
+ }) => string;
99
+ }): Promise<string>;
100
+ }
101
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAA0B,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C;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AE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,KAAK,MAAM,CAAC;KACjE,GAAG,OAAO,CAAC,MAAM,CAAC;CAwDtB"}
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SubscriptionService = void 0;
7
+ const moment_1 = __importDefault(require("moment"));
8
+ const repository_1 = require("./repository");
9
+ const utils_1 = require("./utils");
10
+ const service_1 = require("../payments/service");
11
+ /**
12
+ * SubscriptionService class handles business logic related to subscriptions.
13
+ * Acts as an intermediary between controllers/handlers and the repository layer.
14
+ */
15
+ class SubscriptionService {
16
+ /**
17
+ * Creates an instance of SubscriptionService.
18
+ * @param logger - Application logger instance for logging operations
19
+ */
20
+ constructor(logger) {
21
+ this.logger = logger;
22
+ this.repository = new repository_1.SubscriptionRepository();
23
+ this.paymentService = new service_1.PaymentService(logger);
24
+ }
25
+ /**
26
+ * Retrieves an active subscription for a specific user.
27
+ * @param params - Query parameters
28
+ * @param params.userId - The user's unique identifier
29
+ * @param params.appNamespace - The application namespace/platform
30
+ * @returns Promise resolving to SubscriptionEntity or null if not found
31
+ */
32
+ async getByUserId(params) {
33
+ try {
34
+ return await this.repository.getByUserId(params);
35
+ }
36
+ catch (error) {
37
+ this.logger.error({
38
+ message: 'Error in subscription service getByUserId',
39
+ payload: {
40
+ userId: params.userId,
41
+ appNamespace: params.appNamespace,
42
+ error: JSON.stringify(error),
43
+ },
44
+ });
45
+ return null;
46
+ }
47
+ }
48
+ /**
49
+ * Creates a new subscription record in the database.
50
+ * @param params - Subscription creation parameters
51
+ * @param params.userId - The user's unique identifier
52
+ * @param params.appNamespace - The application namespace/platform
53
+ * @param params.planId - The subscription plan identifier
54
+ * @param params.expiresAt - ISO timestamp when subscription expires
55
+ * @param params.startedAt - ISO timestamp when subscription started
56
+ * @returns Promise resolving to created SubscriptionEntity with ID
57
+ * @throws Error if subscription creation fails
58
+ */
59
+ async create(params) {
60
+ try {
61
+ return await this.repository.create(params);
62
+ }
63
+ catch (error) {
64
+ this.logger.error({
65
+ message: 'Error in subscription service create',
66
+ payload: {
67
+ userId: params.userId,
68
+ appNamespace: params.appNamespace,
69
+ planId: params.planId,
70
+ error: JSON.stringify(error),
71
+ },
72
+ });
73
+ throw error;
74
+ }
75
+ }
76
+ /**
77
+ * Updates specific fields of a subscription identified by userId and appNamespace.
78
+ * @param params - Update parameters
79
+ * @param params.userId - The user's unique identifier
80
+ * @param params.appNamespace - The application namespace/platform
81
+ * @param params.fields - Array of field paths and values to update
82
+ * @throws Error if subscription not found or update fails
83
+ */
84
+ async updateFieldsByUserId(params) {
85
+ try {
86
+ await this.repository.updateFieldsByUserId(params);
87
+ }
88
+ catch (error) {
89
+ this.logger.error({
90
+ message: 'Error in subscription service updateFieldsByUserId',
91
+ payload: {
92
+ userId: params.userId,
93
+ appNamespace: params.appNamespace,
94
+ fields: JSON.stringify(params.fields),
95
+ error: JSON.stringify(error),
96
+ },
97
+ });
98
+ throw error;
99
+ }
100
+ }
101
+ /**
102
+ * Retrieves all active subscriptions that have expired.
103
+ * Used for batch processing to update subscription statuses.
104
+ * @returns Promise resolving to array of expired SubscriptionEntity
105
+ */
106
+ async getExpiredActiveSubscriptions() {
107
+ try {
108
+ return await this.repository.getExpiredActiveSubscriptions();
109
+ }
110
+ catch (error) {
111
+ this.logger.error({
112
+ message: 'Error in subscription service getExpiredActiveSubscriptions',
113
+ payload: {
114
+ error: JSON.stringify(error),
115
+ },
116
+ });
117
+ return [];
118
+ }
119
+ }
120
+ /**
121
+ * Updates specific fields of a subscription identified by subscription ID.
122
+ * @param params - Update parameters
123
+ * @param params.subscriptionId - The subscription document ID
124
+ * @param params.fields - Array of field paths and values to update
125
+ * @throws Error if update fails
126
+ */
127
+ async updateFieldsById(params) {
128
+ try {
129
+ await this.repository.updateFieldsById(params);
130
+ }
131
+ catch (error) {
132
+ this.logger.error({
133
+ message: 'Error in subscription service updateFieldsById',
134
+ payload: {
135
+ subscriptionId: params.subscriptionId,
136
+ fields: JSON.stringify(params.fields),
137
+ error: JSON.stringify(error),
138
+ },
139
+ });
140
+ throw error;
141
+ }
142
+ }
143
+ /**
144
+ * Gets or creates a subscription payment URL.
145
+ * Checks for recent pending payments (within 3 minutes) and reuses the payment link if found.
146
+ * Otherwise creates a new payment intent for the subscription.
147
+ * @param params - Payment URL creation parameters
148
+ * @param params.userId - The user's unique identifier
149
+ * @param params.appNamespace - The application namespace/platform
150
+ * @param params.planId - The subscription plan identifier
151
+ * @param params.languageCode - Language code for translations
152
+ * @param params.translate - Translation function
153
+ * @returns Promise resolving to the payment URL string
154
+ * @throws Error if subscription plan not found or payment creation fails
155
+ */
156
+ async getOrCreateSubscriptionPaymentUrl(params) {
157
+ try {
158
+ // Check for existing pending payments for this plan
159
+ const existingPayments = await this.paymentService.getByUserId({
160
+ userId: params.userId,
161
+ appNamespace: params.appNamespace,
162
+ status: 'pending',
163
+ });
164
+ const recentPayment = existingPayments
165
+ .filter((payment) => payment.planId === params.planId)
166
+ .find((payment) => moment_1.default.utc().diff(moment_1.default.utc(payment.createdAt), 'minutes') < 10);
167
+ if (recentPayment && recentPayment.paymentLink) {
168
+ return recentPayment.paymentLink;
169
+ }
170
+ const subscriptionPlan = (0, utils_1.getSubscriptionById)(params.planId);
171
+ if (!subscriptionPlan) {
172
+ throw new Error(`Subscription plan not found: ${params.planId}`);
173
+ }
174
+ const productName = (0, utils_1.getSubscriptionTitle)(params.translate({
175
+ code: params.languageCode,
176
+ path: subscriptionPlan.titleCode,
177
+ }));
178
+ const paymentEntity = await this.paymentService.createPaymentIntent({
179
+ userId: params.userId,
180
+ appNamespace: params.appNamespace,
181
+ planId: subscriptionPlan.id,
182
+ productName,
183
+ productPrice: subscriptionPlan.amount,
184
+ currency: subscriptionPlan.currency,
185
+ language: params.languageCode,
186
+ regularMode: subscriptionPlan.regularMode,
187
+ });
188
+ return paymentEntity.paymentLink;
189
+ }
190
+ catch (error) {
191
+ this.logger.error({
192
+ message: 'Error in subscription service getOrCreateSubscriptionPaymentUrl',
193
+ payload: {
194
+ userId: params.userId,
195
+ appNamespace: params.appNamespace,
196
+ planId: params.planId,
197
+ error: JSON.stringify(error),
198
+ },
199
+ });
200
+ throw error;
201
+ }
202
+ }
203
+ }
204
+ exports.SubscriptionService = SubscriptionService;
205
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/modules/subscription/service.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,6CAAkF;AAGlF,mCAAoE;AACpE,iDAAqD;AAErD;;;GAGG;AACH,MAAa,mBAAmB;IAK5B;;;OAGG;IACH,YAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,mCAAsB,EAAE,CAAC;QAC/C,IAAI,CAAC,cAAc,GAAG,IAAI,wBAAc,CAAC,MAAM,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CAAC,MAAgD;QACrE,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,2CAA2C;gBACpD,OAAO,EAAE;oBACL,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,YAAY,EAAE,MAAM,CAAC,YAAY;oBACjC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACI,KAAK,CAAC,MAAM,CAAC,MAMnB;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AC;QAChB,CAAC;IACL,CAAC;CACJ;AAhOD,kDAgOC"}
@@ -0,0 +1,4 @@
1
+ import { SubscriptionPlan } from './types';
2
+ declare const SUBSCRIPTION_PLAN: SubscriptionPlan[];
3
+ export { SUBSCRIPTION_PLAN };
4
+ //# sourceMappingURL=subscriptionPlan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptionPlan.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/subscriptionPlan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,QAAA,MAAM,iBAAiB,EAAE,gBAAgB,EAyDxC,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SUBSCRIPTION_PLAN = void 0;
4
+ const SUBSCRIPTION_PLAN = [
5
+ {
6
+ id: 'basic',
7
+ titleCode: 'subscription.plan.1.title',
8
+ descriptionCode: 'subscription.plan.1.description',
9
+ amount: 7,
10
+ currency: 'UAH',
11
+ features: {
12
+ messages: 1000,
13
+ images: 0,
14
+ voice: 50,
15
+ study: 2,
16
+ },
17
+ regularMode: 'monthly',
18
+ },
19
+ {
20
+ id: 'pro',
21
+ titleCode: 'subscription.plan.2.title',
22
+ descriptionCode: 'subscription.plan.2.description',
23
+ amount: 10,
24
+ currency: 'UAH',
25
+ features: {
26
+ messages: 2000,
27
+ images: 20,
28
+ voice: 50,
29
+ study: 2,
30
+ },
31
+ regularMode: 'monthly',
32
+ },
33
+ {
34
+ id: 'basic-daily',
35
+ titleCode: 'subscription.plan.3.title',
36
+ descriptionCode: 'subscription.plan.1.description',
37
+ amount: 7,
38
+ currency: 'UAH',
39
+ features: {
40
+ messages: 10,
41
+ images: 0,
42
+ voice: 50,
43
+ study: 2,
44
+ },
45
+ regularMode: 'daily',
46
+ },
47
+ {
48
+ id: 'pro-daily',
49
+ titleCode: 'subscription.plan.3.title',
50
+ descriptionCode: 'subscription.plan.2.description',
51
+ amount: 10,
52
+ currency: 'UAH',
53
+ features: {
54
+ messages: 20,
55
+ images: 20,
56
+ voice: 50,
57
+ study: 2,
58
+ },
59
+ regularMode: 'daily',
60
+ },
61
+ ];
62
+ exports.SUBSCRIPTION_PLAN = SUBSCRIPTION_PLAN;
63
+ //# sourceMappingURL=subscriptionPlan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptionPlan.js","sourceRoot":"","sources":["../../../src/modules/subscription/subscriptionPlan.ts"],"names":[],"mappings":";;;AAEA,MAAM,iBAAiB,GAAuB;IAC1C;QACI,EAAE,EAAE,OAAO;QACX,SAAS,EAAE,2BAA2B;QACtC,eAAe,EAAE,iCAAiC;QAClD,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE;YACN,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,CAAC;YACT,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,CAAC;SACX;QACD,WAAW,EAAE,SAAS;KACzB;IACD;QACI,EAAE,EAAE,KAAK;QACT,SAAS,EAAE,2BAA2B;QACtC,eAAe,EAAE,iCAAiC;QAClD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE;YACN,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,CAAC;SACX;QACD,WAAW,EAAE,SAAS;KACzB;IACD;QACI,EAAE,EAAE,aAAa;QACjB,SAAS,EAAE,2BAA2B;QACtC,eAAe,EAAE,iCAAiC;QAClD,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE;YACN,QAAQ,EAAE,EAAE;YACZ,MAAM,EAAE,CAAC;YACT,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,CAAC;SACX;QACD,WAAW,EAAE,OAAO;KACvB;IACD;QACI,EAAE,EAAE,WAAW;QACf,SAAS,EAAE,2BAA2B;QACtC,eAAe,EAAE,iCAAiC;QAClD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE;YACN,QAAQ,EAAE,EAAE;YACZ,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,CAAC;SACX;QACD,WAAW,EAAE,OAAO;KACvB;CACJ,CAAC;AAEO,8CAAiB"}
@@ -0,0 +1,37 @@
1
+ import { NestedPathsAccess } from '../../types/utilities';
2
+ import { AppNamespace } from '../app/types';
3
+ type SubscriptionEntity = {
4
+ /** Auto-generated unique ID (document ID) */
5
+ id?: string;
6
+ /** The Telegram User ID this subscription belongs to. Links back to users. */
7
+ userId: string;
8
+ /** An identifier for the subscription plan (e.g., "basic-daily", "pro-monthly") */
9
+ planId: string;
10
+ /** The lifecycle state of this service period */
11
+ status: 'active' | 'expired' | 'cancelled';
12
+ /** The key field for the cron job. Timestamp when this paid-for period ends. */
13
+ expiresAt: string;
14
+ /** Timestamp when this period began */
15
+ startedAt: string;
16
+ /** Platform/app namespace */
17
+ platform: AppNamespace;
18
+ /** Payment provider */
19
+ provider: 'wayforpay';
20
+ };
21
+ type SubscriptionPlan = {
22
+ id: string;
23
+ titleCode: string;
24
+ descriptionCode: string;
25
+ amount: number;
26
+ currency: 'UAH' | 'USD';
27
+ features: {
28
+ messages: number;
29
+ images: number;
30
+ voice: number;
31
+ study: number;
32
+ };
33
+ regularMode: 'daily' | 'monthly' | 'yearly';
34
+ };
35
+ type SubscriptionFieldPath = NestedPathsAccess<SubscriptionEntity>;
36
+ export type { SubscriptionEntity, SubscriptionPlan, SubscriptionFieldPath };
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,KAAK,kBAAkB,GAAG;IACtB,6CAA6C;IAC7C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAC;IAC3C,gFAAgF;IAChF,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,QAAQ,EAAE,YAAY,CAAC;IACvB,uBAAuB;IACvB,QAAQ,EAAE,WAAW,CAAC;CACzB,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,QAAQ,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,WAAW,EAAE,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;CAC/C,CAAC;AAEF,KAAK,qBAAqB,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;AAEnE,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/modules/subscription/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ declare function getSubscriptionById(planId: string): import("./types").SubscriptionPlan;
2
+ declare function getSubscriptionTitle(planTitle: string): string;
3
+ declare function subscriptionPlanExists(planId: string): boolean;
4
+ export { getSubscriptionById, getSubscriptionTitle, subscriptionPlanExists };
5
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/utils.ts"],"names":[],"mappings":"AAEA,iBAAS,mBAAmB,CAAC,MAAM,EAAE,MAAM,sCAE1C;AAED,iBAAS,oBAAoB,CAAC,SAAS,EAAE,MAAM,UAE9C;AAED,iBAAS,sBAAsB,CAAC,MAAM,EAAE,MAAM,WAE7C;AAED,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSubscriptionById = getSubscriptionById;
4
+ exports.getSubscriptionTitle = getSubscriptionTitle;
5
+ exports.subscriptionPlanExists = subscriptionPlanExists;
6
+ const subscriptionPlan_1 = require("./subscriptionPlan");
7
+ function getSubscriptionById(planId) {
8
+ return subscriptionPlan_1.SUBSCRIPTION_PLAN.find((plan) => plan.id === planId);
9
+ }
10
+ function getSubscriptionTitle(planTitle) {
11
+ return `Miia telegram bot: ${planTitle}`;
12
+ }
13
+ function subscriptionPlanExists(planId) {
14
+ return subscriptionPlan_1.SUBSCRIPTION_PLAN.some((plan) => plan.id === planId);
15
+ }
16
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/modules/subscription/utils.ts"],"names":[],"mappings":";;AAcS,kDAAmB;AAAE,oDAAoB;AAAE,wDAAsB;AAd1E,yDAAuD;AAEvD,SAAS,mBAAmB,CAAC,MAAc;IACvC,OAAO,oCAAiB,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,oBAAoB,CAAC,SAAiB;IAC3C,OAAO,sBAAsB,SAAS,EAAE,CAAC;AAC7C,CAAC;AAED,SAAS,sBAAsB,CAAC,MAAc;IAC1C,OAAO,oCAAiB,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;AAChE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './userRepository';
2
+ export * from './userService';
3
+ export * from './types';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/user/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}