@misterhomer1992/miit-bot-payment 1.0.1 → 1.0.3
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 +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -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/api.d.ts +34 -0
- package/dist/modules/payments/api.d.ts.map +1 -0
- package/dist/modules/payments/api.js +63 -0
- package/dist/modules/payments/api.js.map +1 -0
- package/dist/modules/payments/index.d.ts +6 -0
- package/dist/modules/payments/index.d.ts.map +1 -0
- package/dist/modules/payments/index.js +22 -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 +96 -0
- package/dist/modules/payments/service.d.ts.map +1 -0
- package/dist/modules/payments/service.js +207 -0
- package/dist/modules/payments/service.js.map +1 -0
- package/dist/modules/payments/utils.d.ts +9 -0
- package/dist/modules/payments/utils.d.ts.map +1 -0
- package/dist/modules/payments/utils.js +7 -0
- package/dist/modules/payments/utils.js.map +1 -0
- package/dist/modules/subscription/const.d.ts +4 -0
- package/dist/modules/subscription/const.d.ts.map +1 -0
- package/dist/modules/subscription/const.js +10 -0
- package/dist/modules/subscription/const.js.map +1 -0
- package/dist/modules/subscription/index.d.ts +5 -0
- package/dist/modules/subscription/index.d.ts.map +1 -0
- package/dist/modules/subscription/index.js +23 -0
- package/dist/modules/subscription/index.js.map +1 -0
- package/dist/modules/subscription/repository.d.ts +91 -0
- package/dist/modules/subscription/repository.d.ts.map +1 -0
- package/dist/modules/subscription/repository.js +146 -0
- package/dist/modules/subscription/repository.js.map +1 -0
- package/dist/modules/subscription/service.d.ts +101 -0
- package/dist/modules/subscription/service.d.ts.map +1 -0
- package/dist/modules/subscription/service.js +205 -0
- package/dist/modules/subscription/service.js.map +1 -0
- package/dist/modules/subscription/subscriptionPlan.d.ts +4 -0
- package/dist/modules/subscription/subscriptionPlan.d.ts.map +1 -0
- package/dist/modules/subscription/subscriptionPlan.js +63 -0
- package/dist/modules/subscription/subscriptionPlan.js.map +1 -0
- package/dist/modules/subscription/types.d.ts +37 -0
- package/dist/modules/subscription/types.d.ts.map +1 -0
- package/dist/modules/subscription/types.js +3 -0
- package/dist/modules/subscription/types.js.map +1 -0
- package/dist/modules/subscription/utils.d.ts +5 -0
- package/dist/modules/subscription/utils.d.ts.map +1 -0
- package/dist/modules/subscription/utils.js +16 -0
- package/dist/modules/subscription/utils.js.map +1 -0
- package/package.json +3 -2
|
@@ -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;;;GAGG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IACpD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAEhD;;;OAGG;gBACS,MAAM,EAAE,MAAM;IAM1B;;;;;;OAMG;IACU,WAAW,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAgB9G;;;;;;;;;;OAUG;IACU,MAAM,CAAC,MAAM,EAAE;QACxB,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAkB/B;;;;;;;OAOG;IACU,oBAAoB,CAAC,MAAM,EAAE;QACtC,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,EAAE,0BAA0B,CAAC;KACtC,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBjB;;;;OAIG;IACU,6BAA6B,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAc3E;;;;;;OAMG;IACU,gBAAgB,CAAC,MAAM,EAAE;QAClC,cAAc,EAAE,MAAM,CAAC;QACvB,MAAM,EAAE,0BAA0B,CAAC;KACtC,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBjB;;;;;;;;;;;;OAYG;IACU,iCAAiC,CAAC,MAAM,EAAE;QACnD,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,CAAC,MAAM,EAAE;YAAE,IAAI,EAAE,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":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
|
+
"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 @@
|
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@misterhomer1992/miit-bot-payment",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"moment": "2.30.1",
|
|
29
29
|
"dotenv": "17.2.2",
|
|
30
30
|
"axios": "1.12.2",
|
|
31
|
-
"firebase-admin": "^11.6.0"
|
|
31
|
+
"firebase-admin": "^11.6.0",
|
|
32
|
+
"@misterhomer1992/wayforpay-api": "2.0.1"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/node": "^20.10.0",
|