@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
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './modules/payments';
2
2
  export * from './modules/invoice';
3
+ export * from './modules/subscription';
4
+ export * from './modules/user';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -16,4 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./modules/payments"), exports);
18
18
  __exportStar(require("./modules/invoice"), exports);
19
+ __exportStar(require("./modules/subscription"), exports);
20
+ __exportStar(require("./modules/user"), exports);
19
21
  //# 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,qDAAmC;AACnC,oDAAkC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,oDAAkC;AAClC,yDAAuC;AACvC,iDAA+B"}
@@ -5,8 +5,8 @@ type InvoiceEntity = {
5
5
  merchantSignature: string;
6
6
  reasonCode: number;
7
7
  reason: string;
8
- createdDate: number;
9
- processingDate: number;
8
+ createdDate: string;
9
+ processingDate: string;
10
10
  currency: string;
11
11
  amount: number;
12
12
  };
@@ -0,0 +1,59 @@
1
+ import { AppNamespace } from '../app/types';
2
+ interface WayforpayResponse {
3
+ url?: string;
4
+ [key: string]: unknown;
5
+ }
6
+ /**
7
+ * Creates a payment API URL for regular purchases via Wayforpay.
8
+ * Generates a unique order reference and creates a payment URL with the provided parameters.
9
+ *
10
+ * @param params - Payment creation parameters
11
+ * @param params.userId - The unique identifier of the user making the payment
12
+ * @param params.appNamespace - The application namespace (e.g., 'app' or 'telegram')
13
+ * @param params.productName - The name of the product being purchased
14
+ * @param params.productPrice - The price of the product
15
+ * @param params.planId - The identifier of the subscription plan
16
+ * @param params.dateNext - Optional date for the next payment in the regular purchase cycle
17
+ * @param params.currency - The currency code (e.g., 'UAH', 'USD')
18
+ * @param params.regularCount - Optional number of regular payments (defaults to 3)
19
+ * @returns Promise resolving to an object containing the payment URL and order reference, or null
20
+ * @throws Error with code 'CREATE_PAYMENT_API' if the API response is invalid or missing URL
21
+ */
22
+ declare function createPaymentAPI({ userId, appNamespace, productName, productPrice, planId, dateNext, currency, regularCount, regularMode, language, }: {
23
+ userId: string;
24
+ appNamespace: AppNamespace;
25
+ productName: string;
26
+ productPrice: number;
27
+ planId: string;
28
+ dateNext?: string;
29
+ currency: string;
30
+ regularCount?: number;
31
+ regularMode?: 'daily' | 'weekly' | 'monthly' | 'yearly';
32
+ language?: string;
33
+ }): Promise<{
34
+ url: string;
35
+ orderReference: string;
36
+ } | null>;
37
+ /**
38
+ * Edits an existing regular purchase via Wayforpay.
39
+ * Updates the parameters of an existing recurring payment schedule.
40
+ *
41
+ * @param params - Parameters for editing the regular purchase
42
+ * @param params.orderReference - The unique reference of the order to edit
43
+ * @param params.amount - The new payment amount
44
+ * @param params.dateBegin - The start date for the regular purchase in DD.MM.YYYY format
45
+ * @param params.dateEnd - The end date for the regular purchase in DD.MM.YYYY format
46
+ * @param params.regularMode - The frequency mode for regular payments
47
+ * @returns Promise resolving to the Wayforpay API response
48
+ * @throws Error with code 'EDIT_REGULAR_PURCHASE_API' if the API response is invalid
49
+ */
50
+ declare function editRegularPurchaseAPI({ orderReference, amount, dateBegin, dateEnd, regularMode, currency, }: {
51
+ orderReference: string;
52
+ amount: number;
53
+ dateBegin: string;
54
+ dateEnd: string;
55
+ regularMode: 'daily' | 'weekly' | 'monthly' | 'yearly';
56
+ currency: string;
57
+ }): Promise<WayforpayResponse>;
58
+ export { createPaymentAPI, editRegularPurchaseAPI };
59
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources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C,iBAAiB,CAAC,CAmB7B;AAED,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,93 @@
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.createPaymentAPI = createPaymentAPI;
7
+ exports.editRegularPurchaseAPI = editRegularPurchaseAPI;
8
+ const moment_1 = __importDefault(require("moment"));
9
+ const wayforpay_api_1 = require("@misterhomer1992/wayforpay-api");
10
+ const utils_1 = require("../../utils");
11
+ const utils_2 = require("./utils");
12
+ /**
13
+ * Creates a payment API URL for regular purchases via Wayforpay.
14
+ * Generates a unique order reference and creates a payment URL with the provided parameters.
15
+ *
16
+ * @param params - Payment creation parameters
17
+ * @param params.userId - The unique identifier of the user making the payment
18
+ * @param params.appNamespace - The application namespace (e.g., 'app' or 'telegram')
19
+ * @param params.productName - The name of the product being purchased
20
+ * @param params.productPrice - The price of the product
21
+ * @param params.planId - The identifier of the subscription plan
22
+ * @param params.dateNext - Optional date for the next payment in the regular purchase cycle
23
+ * @param params.currency - The currency code (e.g., 'UAH', 'USD')
24
+ * @param params.regularCount - Optional number of regular payments (defaults to 3)
25
+ * @returns Promise resolving to an object containing the payment URL and order reference, or null
26
+ * @throws Error with code 'CREATE_PAYMENT_API' if the API response is invalid or missing URL
27
+ */
28
+ async function createPaymentAPI({ userId, appNamespace, productName, productPrice, planId, dateNext, currency, regularCount = 3, regularMode = 'daily', language = 'UA', }) {
29
+ const orderDate = Date.now();
30
+ const formattedUtc = moment_1.default.utc().toISOString();
31
+ const orderReference = (0, utils_2.createOrderReference)({
32
+ userId,
33
+ appNamespace,
34
+ planId,
35
+ utcDate: formattedUtc,
36
+ });
37
+ const response = (await (0, wayforpay_api_1.generateRegularPurchase)({
38
+ merchantAccount: process.env.WAYFORPAY_MERCHANT_ACCOUNT,
39
+ merchantDomainName: process.env.WAYFORPAY_MERCHANT_DOMAIN,
40
+ merchantSecretKey: process.env.WAYFORPAY_MERCHANT_SECRET_KEY,
41
+ orderDate,
42
+ orderReference,
43
+ productName: [productName],
44
+ productPrice: [productPrice],
45
+ currency: currency,
46
+ language: language,
47
+ serviceUrl: process.env.WAYFORPAY_SERVICE_URL,
48
+ regularMode,
49
+ regularCount,
50
+ dateNext,
51
+ }));
52
+ if (!(0, utils_1.isObject)(response) || (0, utils_1.isBadOrEmptyString)(response.url)) {
53
+ throw {
54
+ code: 'CREATE_PAYMENT_API',
55
+ };
56
+ }
57
+ return {
58
+ url: response.url,
59
+ orderReference,
60
+ };
61
+ }
62
+ /**
63
+ * Edits an existing regular purchase via Wayforpay.
64
+ * Updates the parameters of an existing recurring payment schedule.
65
+ *
66
+ * @param params - Parameters for editing the regular purchase
67
+ * @param params.orderReference - The unique reference of the order to edit
68
+ * @param params.amount - The new payment amount
69
+ * @param params.dateBegin - The start date for the regular purchase in DD.MM.YYYY format
70
+ * @param params.dateEnd - The end date for the regular purchase in DD.MM.YYYY format
71
+ * @param params.regularMode - The frequency mode for regular payments
72
+ * @returns Promise resolving to the Wayforpay API response
73
+ * @throws Error with code 'EDIT_REGULAR_PURCHASE_API' if the API response is invalid
74
+ */
75
+ async function editRegularPurchaseAPI({ orderReference, amount, dateBegin, dateEnd, regularMode, currency, }) {
76
+ const response = await (0, wayforpay_api_1.editRegularPurchase)({
77
+ merchantAccount: process.env.WAYFORPAY_MERCHANT_ACCOUNT,
78
+ merchantPassword: process.env.WAYFORPAY_MERCHANT_PASSWORD,
79
+ orderReference,
80
+ amount,
81
+ dateBegin,
82
+ dateEnd,
83
+ regularMode,
84
+ currency: currency,
85
+ });
86
+ if (!(0, utils_1.isObject)(response)) {
87
+ throw {
88
+ code: 'EDIT_REGULAR_PURCHASE_API',
89
+ };
90
+ }
91
+ return response;
92
+ }
93
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceR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EAAE,oBAAoB;SAC7B,CAAC;IACN,CAAC;IAED,OAAO;QACH,GAAG,EAAE,QAAQ,CAAC,GAAG;QACjB,cAAc;KACjB,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,sBAAsB,CAAC,EAClC,cAAc,EACd,MAAM,EACN,SAAS,EACT,OAAO,EACP,WAAW,EACX,QAAQ,GAQX;IACG,MAAM,QAAQ,GAAG,MAAM,IAAA,mCAAmB,EAAC;QACvC,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,0BAAoC;QACjE,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,2BAAqC;QACnE,cAAc;QACd,MAAM;QACN,SAAS;QACT,OAAO;QACP,WAAW;QACX,QAAQ,EAAE,QAAoB;KACjC,CAAC,CAAC;IAEH,IAAI,CAAC,IAAA,gBAAQ,EAAC,QAAQ,CAAC,EAAE,CAAC;QACtB,MAAM;YACF,IAAI,EAAE,2BAA2B;SACpC,CAAC;IACN,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC"}
@@ -2,4 +2,6 @@ export * from './repository';
2
2
  export * from './service';
3
3
  export * from './types';
4
4
  export * from './const';
5
+ export * from './api';
6
+ export * from './utils';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC"}
@@ -18,4 +18,6 @@ __exportStar(require("./repository"), exports);
18
18
  __exportStar(require("./service"), exports);
19
19
  __exportStar(require("./types"), exports);
20
20
  __exportStar(require("./const"), exports);
21
+ __exportStar(require("./api"), exports);
22
+ __exportStar(require("./utils"), exports);
21
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/payments/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/payments/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,wCAAsB;AACtB,0CAAwB"}
@@ -61,5 +61,36 @@ export declare class PaymentService {
61
61
  getExpiredPendingPayments(params?: {
62
62
  hoursOld?: number;
63
63
  }): Promise<PaymentEntity[]>;
64
+ /**
65
+ * Creates a payment intent for a user subscription.
66
+ * This method orchestrates the payment creation process by:
67
+ * 1. Creating a payment URL via Wayforpay API
68
+ * 2. Storing the payment record in the database
69
+ * 3. Returning the complete payment entity with the payment link
70
+ *
71
+ * @param params - Payment intent parameters
72
+ * @param params.userId - The unique identifier of the user
73
+ * @param params.appNamespace - The application namespace/platform
74
+ * @param params.planId - The subscription plan identifier
75
+ * @param params.productName - The name of the product/plan being purchased
76
+ * @param params.productPrice - The price of the product
77
+ * @param params.currency - The currency code ('UAH' or 'USD')
78
+ * @param params.regularCount - Optional number of regular payments (defaults to 3)
79
+ * @param params.regularMode - Optional payment frequency ('daily', 'weekly', 'monthly', 'yearly')
80
+ * @param params.language - Optional language code for the payment page (defaults to 'UA')
81
+ * @returns Promise resolving to the created PaymentEntity with payment link
82
+ * @throws Error if payment URL generation or database creation fails
83
+ */
84
+ createPaymentIntent(params: {
85
+ userId: string;
86
+ appNamespace: AppNamespace;
87
+ planId: string;
88
+ productName: string;
89
+ productPrice: number;
90
+ currency: 'UAH' | 'USD';
91
+ regularCount?: number;
92
+ regularMode?: 'daily' | 'weekly' | 'monthly' | 'yearly';
93
+ language?: string;
94
+ }): Promise<PaymentEntity>;
64
95
  }
65
96
  //# sourceMappingURL=service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAqB,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;GAGG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAE/C;;;OAGG;gBACS,MAAM,EAAE,MAAM;IAK1B;;;;OAIG;IACU,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAevF;;;;;;;OAOG;IACU,WAAW,CAAC,MAAM,EAAE;QAC7B,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAiB5B;;;;;OAKG;IACU,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAiBnF;;;;;;OAMG;IACU,YAAY,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,qBAAqB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB3G;;;;;;OAMG;IACU,yBAAyB,CAClC,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3B;;;;;;;;;;;;;;;;;;;OAmBG;IACU,mBAAmB,CAAC,MAAM,EAAE;QACrC,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC;QACxB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;QACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,aAAa,CAAC;CAgE7B"}
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.PaymentService = void 0;
7
+ const moment_1 = __importDefault(require("moment"));
4
8
  const repository_1 = require("./repository");
9
+ const api_1 = require("./api");
5
10
  /**
6
11
  * PaymentService class handles business logic related to payments.
7
12
  * Acts as an intermediary between controllers/handlers and the repository layer.
@@ -127,6 +132,76 @@ class PaymentService {
127
132
  return [];
128
133
  }
129
134
  }
135
+ /**
136
+ * Creates a payment intent for a user subscription.
137
+ * This method orchestrates the payment creation process by:
138
+ * 1. Creating a payment URL via Wayforpay API
139
+ * 2. Storing the payment record in the database
140
+ * 3. Returning the complete payment entity with the payment link
141
+ *
142
+ * @param params - Payment intent parameters
143
+ * @param params.userId - The unique identifier of the user
144
+ * @param params.appNamespace - The application namespace/platform
145
+ * @param params.planId - The subscription plan identifier
146
+ * @param params.productName - The name of the product/plan being purchased
147
+ * @param params.productPrice - The price of the product
148
+ * @param params.currency - The currency code ('UAH' or 'USD')
149
+ * @param params.regularCount - Optional number of regular payments (defaults to 3)
150
+ * @param params.regularMode - Optional payment frequency ('daily', 'weekly', 'monthly', 'yearly')
151
+ * @param params.language - Optional language code for the payment page (defaults to 'UA')
152
+ * @returns Promise resolving to the created PaymentEntity with payment link
153
+ * @throws Error if payment URL generation or database creation fails
154
+ */
155
+ async createPaymentIntent(params) {
156
+ const { userId, appNamespace, planId, productName, productPrice, currency, regularCount, regularMode, language, } = params;
157
+ try {
158
+ // Step 1: Create payment URL from Wayforpay API
159
+ // This also generates a unique order reference
160
+ const paymentResponse = await (0, api_1.createPaymentAPI)({
161
+ userId,
162
+ appNamespace,
163
+ productName,
164
+ productPrice,
165
+ planId,
166
+ currency,
167
+ regularCount,
168
+ regularMode,
169
+ language,
170
+ });
171
+ if (!paymentResponse?.url || !paymentResponse?.orderReference) {
172
+ throw new Error('Failed to get payment URL or order reference from Wayforpay');
173
+ }
174
+ // Step 2: Create payment record in database
175
+ const paymentEntity = await this.repository.create({
176
+ orderReference: paymentResponse.orderReference,
177
+ userId,
178
+ status: 'pending',
179
+ paymentLink: paymentResponse.url,
180
+ planId,
181
+ amount: productPrice,
182
+ currency,
183
+ createdAt: moment_1.default.utc().toISOString(),
184
+ platform: appNamespace,
185
+ provider: 'wayforpay',
186
+ });
187
+ return paymentEntity;
188
+ }
189
+ catch (error) {
190
+ this.logger.error({
191
+ message: 'Error in payment service createPaymentIntent',
192
+ payload: {
193
+ userId,
194
+ appNamespace,
195
+ planId,
196
+ productName,
197
+ productPrice,
198
+ currency,
199
+ error: JSON.stringify(error),
200
+ },
201
+ });
202
+ throw error;
203
+ }
204
+ }
130
205
  }
131
206
  exports.PaymentService = PaymentService;
132
207
  //# sourceMappingURL=service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/modules/payments/service.ts"],"names":[],"mappings":";;;AACA,6CAAwE;AAIxE;;;GAGG;AACH,MAAa,cAAc;IAIvB;;;OAGG;IACH,YAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,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AE;oBACL,MAAM;oBACN,YAAY;oBACZ,MAAM;oBACN,WAAW;oBACX,YAAY;oBACZ,QAAQ;oBACR,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YAEH,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AArOD,wCAqOC"}
@@ -0,0 +1,20 @@
1
+ import { AppNamespace } from '../app/types';
2
+ declare function createOrderReference({ userId, appNamespace, planId, utcDate, }: {
3
+ userId: string;
4
+ appNamespace: AppNamespace;
5
+ planId: string;
6
+ utcDate: string;
7
+ }): string;
8
+ export interface ParsedReferenceString {
9
+ appName: string;
10
+ appNamespace: AppNamespace;
11
+ serviceType: string;
12
+ userId: string;
13
+ planId: string;
14
+ version: string;
15
+ timestamp: string;
16
+ chargeId?: string;
17
+ }
18
+ declare function parseOrderReference(referenceString: string): ParsedReferenceString | null;
19
+ export { createOrderReference, parseOrderReference };
20
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,iBAAS,oBAAoB,CAAC,EAC1B,MAAM,EACN,YAAY,EACZ,MAAM,EACN,OAAO,GACV,EAAE;IACC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB,GAAG,MAAM,CAET;AAED,MAAM,WAAW,qBAAqB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,iBAAS,mBAAmB,CAAC,eAAe,EAAE,MAAM,GAAG,qBAAqB,GAAG,IAAI,CA2BlF;AAED,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createOrderReference = createOrderReference;
4
+ exports.parseOrderReference = parseOrderReference;
5
+ function createOrderReference({ userId, appNamespace, planId, utcDate, }) {
6
+ return `miia_${appNamespace}_bot_${userId}_${planId}_v1_${utcDate}`;
7
+ }
8
+ function parseOrderReference(referenceString) {
9
+ // `miia_${appNamespace}_bot_${userId}_${planId}_v1_${formattedUtc}`;
10
+ const [appName, appNamespace, serviceType, userId, planId, version, timestamp, chargeId] = referenceString.split('_');
11
+ if (typeof appName !== 'string' ||
12
+ typeof appNamespace !== 'string' ||
13
+ typeof serviceType !== 'string' ||
14
+ typeof userId !== 'string' ||
15
+ typeof planId !== 'string' ||
16
+ typeof version !== 'string' ||
17
+ typeof timestamp !== 'string') {
18
+ return null;
19
+ }
20
+ return {
21
+ appName,
22
+ appNamespace: appNamespace,
23
+ serviceType,
24
+ userId,
25
+ planId,
26
+ version,
27
+ timestamp,
28
+ chargeId,
29
+ };
30
+ }
31
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/modules/payments/utils.ts"],"names":[],"mappings":";;AAwDS,oDAAoB;AAAE,kDAAmB;AAtDlD,SAAS,oBAAoB,CAAC,EAC1B,MAAM,EACN,YAAY,EACZ,MAAM,EACN,OAAO,GAMV;IACG,OAAO,QAAQ,YAAY,QAAQ,MAAM,IAAI,MAAM,OAAO,OAAO,EAAE,CAAC;AACxE,CAAC;AAaD,SAAS,mBAAmB,CAAC,eAAuB;IAChD,qEAAqE;IACrE,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,GACpF,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE/B,IACI,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,YAAY,KAAK,QAAQ;QAChC,OAAO,WAAW,KAAK,QAAQ;QAC/B,OAAO,MAAM,KAAK,QAAQ;QAC1B,OAAO,MAAM,KAAK,QAAQ;QAC1B,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,SAAS,KAAK,QAAQ,EAC/B,CAAC;QACC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO;QACH,OAAO;QACP,YAAY,EAAE,YAA4B;QAC1C,WAAW;QACX,MAAM;QACN,MAAM;QACN,OAAO;QACP,SAAS;QACT,QAAQ;KACX,CAAC;AACN,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { SubscriptionEntity } from './types';
2
+ declare const DEFAULT_SUBSCRIPTION_ENTITY: Partial<SubscriptionEntity>;
3
+ export { DEFAULT_SUBSCRIPTION_ENTITY };
4
+ //# sourceMappingURL=const.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,QAAA,MAAM,2BAA2B,EAAE,OAAO,CAAC,kBAAkB,CAI5D,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SUBSCRIPTION_ENTITY = void 0;
4
+ const DEFAULT_SUBSCRIPTION_ENTITY = {
5
+ status: 'active',
6
+ platform: 'telegram',
7
+ provider: 'wayforpay',
8
+ };
9
+ exports.DEFAULT_SUBSCRIPTION_ENTITY = DEFAULT_SUBSCRIPTION_ENTITY;
10
+ //# sourceMappingURL=const.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/modules/subscription/const.ts"],"names":[],"mappings":";;;AAEA,MAAM,2BAA2B,GAAgC;IAC7D,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,WAAW;CACxB,CAAC;AAEO,kEAA2B"}
@@ -0,0 +1,5 @@
1
+ export * from './utils';
2
+ export * from './types';
3
+ export * from './service';
4
+ export { SUBSCRIPTION_PLAN } from './subscriptionPlan';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,23 @@
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
+ exports.SUBSCRIPTION_PLAN = void 0;
18
+ __exportStar(require("./utils"), exports);
19
+ __exportStar(require("./types"), exports);
20
+ __exportStar(require("./service"), exports);
21
+ var subscriptionPlan_1 = require("./subscriptionPlan");
22
+ Object.defineProperty(exports, "SUBSCRIPTION_PLAN", { enumerable: true, get: function () { return subscriptionPlan_1.SUBSCRIPTION_PLAN; } });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/subscription/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,0CAAwB;AACxB,4CAA0B;AAC1B,uDAAuD;AAA9C,qHAAA,iBAAiB,OAAA"}
@@ -0,0 +1,91 @@
1
+ import { FieldValue } from 'firebase-admin/firestore';
2
+ import { SubscriptionEntity, SubscriptionFieldPath } from './types';
3
+ import { AppNamespace } from '../app/types';
4
+ export type UpdateDBSubscriptionFields = [
5
+ SubscriptionFieldPath,
6
+ FieldValue | string | number | boolean | Date | [] | {}
7
+ ][];
8
+ /**
9
+ * SubscriptionRepository class handles all database operations related to subscriptions.
10
+ * Implements repository pattern for subscription data access.
11
+ */
12
+ export declare class SubscriptionRepository {
13
+ private readonly db;
14
+ private readonly collectionName;
15
+ /**
16
+ * Creates an instance of SubscriptionRepository.
17
+ */
18
+ constructor();
19
+ /**
20
+ * Retrieves an active subscription for a specific user.
21
+ * @param params - Query parameters
22
+ * @param params.userId - The user's unique identifier
23
+ * @param params.appNamespace - The application namespace/platform
24
+ * @returns Promise resolving to SubscriptionEntity or null if not found
25
+ */
26
+ getByUserId(params: {
27
+ userId: string;
28
+ appNamespace: string;
29
+ }): Promise<SubscriptionEntity | null>;
30
+ /**
31
+ * Creates a new subscription record in the database.
32
+ * @param params - Subscription creation parameters
33
+ * @param params.userId - The user's unique identifier
34
+ * @param params.appNamespace - The application namespace/platform
35
+ * @param params.planId - The subscription plan identifier
36
+ * @param params.expiresAt - ISO timestamp when subscription expires
37
+ * @param params.startedAt - ISO timestamp when subscription started
38
+ * @returns Promise resolving to created SubscriptionEntity with ID
39
+ * @throws Error if subscription creation fails
40
+ */
41
+ create(params: {
42
+ userId: string;
43
+ appNamespace: AppNamespace;
44
+ planId: string;
45
+ expiresAt: string;
46
+ startedAt: string;
47
+ }): Promise<SubscriptionEntity>;
48
+ /**
49
+ * Updates specific fields of a subscription identified by userId and appNamespace.
50
+ * @param params - Update parameters
51
+ * @param params.userId - The user's unique identifier
52
+ * @param params.appNamespace - The application namespace/platform
53
+ * @param params.fields - Array of field paths and values to update
54
+ * @throws Error if subscription not found or update fails
55
+ */
56
+ updateFieldsByUserId(params: {
57
+ userId: string;
58
+ appNamespace: AppNamespace;
59
+ fields: UpdateDBSubscriptionFields;
60
+ }): Promise<void>;
61
+ /**
62
+ * Retrieves all active subscriptions that have expired.
63
+ * Used for batch processing to update subscription statuses.
64
+ * @returns Promise resolving to array of expired SubscriptionEntity
65
+ */
66
+ getExpiredActiveSubscriptions(): Promise<SubscriptionEntity[]>;
67
+ /**
68
+ * Updates specific fields of a subscription identified by subscription ID.
69
+ * @param params - Update parameters
70
+ * @param params.subscriptionId - The subscription document ID
71
+ * @param params.fields - Array of field paths and values to update
72
+ * @throws Error if update fails
73
+ */
74
+ updateFieldsById(params: {
75
+ subscriptionId: string;
76
+ fields: UpdateDBSubscriptionFields;
77
+ }): Promise<void>;
78
+ /**
79
+ * Maps a Firestore document to a SubscriptionEntity.
80
+ * @param doc - Firestore document snapshot
81
+ * @returns SubscriptionEntity with document ID
82
+ */
83
+ private mapDocumentToEntity;
84
+ /**
85
+ * Builds an update object from field tuples.
86
+ * @param fields - Array of field paths and values
87
+ * @returns Object with field paths as keys and values to update
88
+ */
89
+ private buildUpdateObject;
90
+ }
91
+ //# sourceMappingURL=repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkD,MAAM,0BAA0B,CAAC;AACtG,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEpE,OAAO,EAAE,YAAY,EA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