@misterhomer1992/miit-bot-payment 1.0.7 → 1.0.8
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 +1 -359
- package/dist/modules/cancellableAPI/utils.d.ts +1 -2
- package/dist/modules/cancellableAPI/utils.d.ts.map +1 -1
- package/dist/modules/cancellableAPI/utils.js.map +1 -1
- package/dist/modules/invoice/repository.d.ts +0 -25
- package/dist/modules/invoice/repository.d.ts.map +1 -1
- package/dist/modules/invoice/repository.js +0 -25
- package/dist/modules/invoice/repository.js.map +1 -1
- package/dist/modules/invoice/service.d.ts +0 -21
- package/dist/modules/invoice/service.d.ts.map +1 -1
- package/dist/modules/invoice/service.js +0 -21
- package/dist/modules/invoice/service.js.map +1 -1
- package/dist/modules/invoice/types.d.ts +0 -8
- package/dist/modules/invoice/types.d.ts.map +1 -1
- package/dist/modules/payments/api.d.ts +3 -4
- package/dist/modules/payments/api.d.ts.map +1 -1
- package/dist/modules/payments/api.js +3 -3
- package/dist/modules/payments/api.js.map +1 -1
- package/dist/modules/payments/repository.d.ts +1 -59
- package/dist/modules/payments/repository.d.ts.map +1 -1
- package/dist/modules/payments/repository.js +2 -59
- package/dist/modules/payments/repository.js.map +1 -1
- package/dist/modules/payments/service.d.ts +2 -66
- package/dist/modules/payments/service.d.ts.map +1 -1
- package/dist/modules/payments/service.js +5 -68
- package/dist/modules/payments/service.js.map +1 -1
- package/dist/modules/payments/types.d.ts +4 -11
- package/dist/modules/payments/types.d.ts.map +1 -1
- package/dist/modules/payments/utils.d.ts +3 -4
- package/dist/modules/payments/utils.d.ts.map +1 -1
- package/dist/modules/payments/utils.js +6 -6
- package/dist/modules/payments/utils.js.map +1 -1
- package/dist/modules/subscription/repository.d.ts +4 -83
- package/dist/modules/subscription/repository.d.ts.map +1 -1
- package/dist/modules/subscription/repository.js +15 -109
- package/dist/modules/subscription/repository.js.map +1 -1
- package/dist/modules/subscription/service.d.ts +5 -89
- package/dist/modules/subscription/service.d.ts.map +1 -1
- package/dist/modules/subscription/service.js +7 -83
- package/dist/modules/subscription/service.js.map +1 -1
- package/dist/modules/subscription/types.d.ts +12 -27
- package/dist/modules/subscription/types.d.ts.map +1 -1
- package/dist/modules/user/types.d.ts +7 -8
- package/dist/modules/user/types.d.ts.map +1 -1
- package/dist/modules/user/userRepository.d.ts +3 -46
- package/dist/modules/user/userRepository.d.ts.map +1 -1
- package/dist/modules/user/userRepository.js +6 -48
- package/dist/modules/user/userRepository.js.map +1 -1
- package/dist/modules/user/userService.d.ts +3 -37
- package/dist/modules/user/userService.d.ts.map +1 -1
- package/dist/modules/user/userService.js +3 -36
- package/dist/modules/user/userService.js.map +1 -1
- package/package.json +1 -1
|
@@ -15,7 +15,7 @@ const utils_2 = require("./utils");
|
|
|
15
15
|
*
|
|
16
16
|
* @param params - Payment creation parameters
|
|
17
17
|
* @param params.userId - The unique identifier of the user making the payment
|
|
18
|
-
* @param params.
|
|
18
|
+
* @param params.platform - The application namespace (e.g., 'app' or 'telegram')
|
|
19
19
|
* @param params.productName - The name of the product being purchased
|
|
20
20
|
* @param params.productPrice - The price of the product
|
|
21
21
|
* @param params.planId - The identifier of the subscription plan
|
|
@@ -25,12 +25,12 @@ const utils_2 = require("./utils");
|
|
|
25
25
|
* @returns Promise resolving to an object containing the payment URL and order reference, or null
|
|
26
26
|
* @throws Error with code 'CREATE_PAYMENT_API' if the API response is invalid or missing URL
|
|
27
27
|
*/
|
|
28
|
-
async function createPaymentAPI({ userId,
|
|
28
|
+
async function createPaymentAPI({ userId, platform, productName, productPrice, planId, dateNext, currency, regularCount = 3, regularMode = 'daily', language = 'UA', }) {
|
|
29
29
|
const orderDate = Date.now();
|
|
30
30
|
const formattedUtc = moment_1.default.utc().toISOString();
|
|
31
31
|
const orderReference = (0, utils_2.createOrderReference)({
|
|
32
32
|
userId,
|
|
33
|
-
|
|
33
|
+
platform,
|
|
34
34
|
planId,
|
|
35
35
|
utcDate: formattedUtc,
|
|
36
36
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/modules/payments/api.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/modules/payments/api.ts"],"names":[],"mappings":";;;;;AAsIS,4CAAgB;AAAE,wDAAsB;AAtIjD,oDAA4B;AAC5B,kEAAkH;AAClH,uCAA2D;AAC3D,mCAA+C;AAO/C;;;;;;;;;;;;;;;GAeG;AACH,KAAK,UAAU,gBAAgB,CAAC,EAC5B,MAAM,EACN,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,YAAY,GAAG,CAAC,EAChB,WAAW,GAAG,OAAO,EACrB,QAAQ,GAAG,IAAI,GAYlB;IACG,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,YAAY,GAAG,gBAAM,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;IAChD,MAAM,cAAc,GAAG,IAAA,4BAAoB,EAAC;QACxC,MAAM;QACN,QAAQ;QACR,MAAM;QACN,OAAO,EAAE,YAAY;KACxB,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,CAAC,MAAM,IAAA,uCAAuB,EAAC;QAC5C,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,0BAAoC;QACjE,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAmC;QACnE,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,6BAAuC;QACtE,SAAS;QACT,cAAc;QACd,WAAW,EAAE,CAAC,WAAW,CAAC;QAC1B,YAAY,EAAE,CAAC,YAAY,CAAC;QAC5B,QAAQ,EAAE,QAAoB;QAC9B,QAAQ,EAAE,QAAoB;QAC9B,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,qBAA+B;QACvD,WAAW;QACX,YAAY;QACZ,QAAQ;KACX,CAAC,CAAsB,CAAC;IAEzB,IAAI,CAAC,IAAA,gBAAQ,EAAC,QAAQ,CAAC,IAAI,IAAA,0BAAkB,EAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1D,MAAM;YACF,IAAI,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"}
|
|
@@ -1,86 +1,28 @@
|
|
|
1
1
|
import { FieldValue, Firestore } from 'firebase-admin/firestore';
|
|
2
2
|
import { PaymentEntity, PaymentFieldPath, IPaymentRepository } from './types';
|
|
3
|
-
import { AppNamespace } from '../app/types';
|
|
4
3
|
export type UpdateDBPaymentFields = [PaymentFieldPath, FieldValue | string | number | boolean | Date | [] | {}][];
|
|
5
|
-
/**
|
|
6
|
-
* PaymentRepository class handles all database operations related to payments.
|
|
7
|
-
* Implements repository pattern for payment data access.
|
|
8
|
-
*/
|
|
9
4
|
export declare class PaymentRepository implements IPaymentRepository {
|
|
10
5
|
private readonly db;
|
|
11
6
|
private readonly collectionName;
|
|
12
|
-
/**
|
|
13
|
-
* Creates an instance of PaymentRepository.
|
|
14
|
-
* @param params - Repository dependencies
|
|
15
|
-
* @param params.db - Optional Firestore instance for dependency injection (defaults to getFirestore())
|
|
16
|
-
*/
|
|
17
7
|
constructor({ db }?: {
|
|
18
8
|
db?: Firestore;
|
|
19
9
|
});
|
|
20
|
-
/**
|
|
21
|
-
* Retrieves a payment by its order reference.
|
|
22
|
-
* @param orderReference - The unique order reference identifier
|
|
23
|
-
* @returns Promise resolving to PaymentEntity or null if not found
|
|
24
|
-
*/
|
|
25
10
|
getByOrderReference(orderReference: string): Promise<PaymentEntity | null>;
|
|
26
|
-
/**
|
|
27
|
-
* Retrieves all payments for a specific user.
|
|
28
|
-
* @param params - Query parameters
|
|
29
|
-
* @param params.userId - The user's unique identifier
|
|
30
|
-
* @param params.appNamespace - The application namespace/platform
|
|
31
|
-
* @param params.status - Optional payment status filter
|
|
32
|
-
* @returns Promise resolving to array of PaymentEntity
|
|
33
|
-
*/
|
|
34
11
|
getByUserId(params: {
|
|
35
12
|
userId: string;
|
|
36
|
-
|
|
13
|
+
platform: string;
|
|
37
14
|
status?: PaymentEntity['status'];
|
|
38
15
|
}): Promise<PaymentEntity[]>;
|
|
39
|
-
/**
|
|
40
|
-
* Creates a new payment record in the database.
|
|
41
|
-
* @param paymentData - Payment data without ID (ID will be auto-generated)
|
|
42
|
-
* @returns Promise resolving to created PaymentEntity with ID
|
|
43
|
-
* @throws Error if payment creation fails
|
|
44
|
-
*/
|
|
45
16
|
create(paymentData: Omit<PaymentEntity, 'id'>): Promise<PaymentEntity>;
|
|
46
|
-
/**
|
|
47
|
-
* Updates specific fields of a payment identified by order reference.
|
|
48
|
-
* @param params - Update parameters
|
|
49
|
-
* @param params.orderReference - The order reference to identify the payment
|
|
50
|
-
* @param params.fields - Array of field paths and values to update
|
|
51
|
-
* @throws Error if payment not found or update fails
|
|
52
|
-
*/
|
|
53
17
|
updateFields(params: {
|
|
54
18
|
orderReference: string;
|
|
55
19
|
fields: UpdateDBPaymentFields;
|
|
56
20
|
}): Promise<void>;
|
|
57
|
-
/**
|
|
58
|
-
* Retrieves all pending payments that are older than specified hours.
|
|
59
|
-
* Used for cleaning up expired payment attempts.
|
|
60
|
-
* @param params - Query parameters
|
|
61
|
-
* @param params.hoursOld - Number of hours after which a pending payment is considered expired (default: 24)
|
|
62
|
-
* @returns Promise resolving to array of expired PaymentEntity
|
|
63
|
-
*/
|
|
64
21
|
getExpiredPendingPayments(params?: {
|
|
65
22
|
hoursOld?: number;
|
|
66
23
|
}): Promise<PaymentEntity[]>;
|
|
67
|
-
/**
|
|
68
|
-
* Maps a Firestore document to a PaymentEntity.
|
|
69
|
-
* @param doc - Firestore document snapshot
|
|
70
|
-
* @returns PaymentEntity with document ID
|
|
71
|
-
*/
|
|
72
24
|
private mapDocumentToEntity;
|
|
73
|
-
/**
|
|
74
|
-
* Builds an update object from field tuples.
|
|
75
|
-
* @param fields - Array of field paths and values
|
|
76
|
-
* @returns Object with field paths as keys and values to update
|
|
77
|
-
*/
|
|
78
25
|
private buildUpdateObject;
|
|
79
|
-
/**
|
|
80
|
-
* Calculates the cutoff time for expired payments.
|
|
81
|
-
* @param hoursOld - Number of hours to subtract from current time
|
|
82
|
-
* @returns Date object representing the cutoff time
|
|
83
|
-
*/
|
|
84
26
|
private calculateCutoffTime;
|
|
85
27
|
}
|
|
86
28
|
//# sourceMappingURL=repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAuC,MAAM,0BAA0B,CAAC;AACtG,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UA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
3
3
|
exports.PaymentRepository = void 0;
|
|
4
4
|
const firestore_1 = require("firebase-admin/firestore");
|
|
5
5
|
const const_1 = require("./const");
|
|
6
|
-
/**
|
|
7
|
-
* PaymentRepository class handles all database operations related to payments.
|
|
8
|
-
* Implements repository pattern for payment data access.
|
|
9
|
-
*/
|
|
10
6
|
class PaymentRepository {
|
|
11
|
-
/**
|
|
12
|
-
* Creates an instance of PaymentRepository.
|
|
13
|
-
* @param params - Repository dependencies
|
|
14
|
-
* @param params.db - Optional Firestore instance for dependency injection (defaults to getFirestore())
|
|
15
|
-
*/
|
|
16
7
|
constructor({ db } = {}) {
|
|
17
8
|
this.collectionName = 'payments';
|
|
18
9
|
this.db = db || (0, firestore_1.getFirestore)();
|
|
19
10
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Retrieves a payment by its order reference.
|
|
22
|
-
* @param orderReference - The unique order reference identifier
|
|
23
|
-
* @returns Promise resolving to PaymentEntity or null if not found
|
|
24
|
-
*/
|
|
25
11
|
async getByOrderReference(orderReference) {
|
|
26
12
|
const querySnapshot = await this.db
|
|
27
13
|
.collection(this.collectionName)
|
|
@@ -34,19 +20,11 @@ class PaymentRepository {
|
|
|
34
20
|
const doc = querySnapshot.docs[0];
|
|
35
21
|
return this.mapDocumentToEntity(doc);
|
|
36
22
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Retrieves all payments for a specific user.
|
|
39
|
-
* @param params - Query parameters
|
|
40
|
-
* @param params.userId - The user's unique identifier
|
|
41
|
-
* @param params.appNamespace - The application namespace/platform
|
|
42
|
-
* @param params.status - Optional payment status filter
|
|
43
|
-
* @returns Promise resolving to array of PaymentEntity
|
|
44
|
-
*/
|
|
45
23
|
async getByUserId(params) {
|
|
46
|
-
const { userId,
|
|
24
|
+
const { userId, platform, status } = params;
|
|
47
25
|
let query = this.db
|
|
48
26
|
.collection(this.collectionName)
|
|
49
|
-
.where('platform', '==',
|
|
27
|
+
.where('platform', '==', platform)
|
|
50
28
|
.where('userId', '==', userId);
|
|
51
29
|
if (status) {
|
|
52
30
|
query = query.where('status', '==', status);
|
|
@@ -57,12 +35,6 @@ class PaymentRepository {
|
|
|
57
35
|
}
|
|
58
36
|
return querySnapshot.docs.map((doc) => this.mapDocumentToEntity(doc));
|
|
59
37
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Creates a new payment record in the database.
|
|
62
|
-
* @param paymentData - Payment data without ID (ID will be auto-generated)
|
|
63
|
-
* @returns Promise resolving to created PaymentEntity with ID
|
|
64
|
-
* @throws Error if payment creation fails
|
|
65
|
-
*/
|
|
66
38
|
async create(paymentData) {
|
|
67
39
|
const docRef = this.db.collection(this.collectionName).doc();
|
|
68
40
|
const paymentEntity = {
|
|
@@ -73,13 +45,6 @@ class PaymentRepository {
|
|
|
73
45
|
docRef.set(paymentEntity);
|
|
74
46
|
return paymentEntity;
|
|
75
47
|
}
|
|
76
|
-
/**
|
|
77
|
-
* Updates specific fields of a payment identified by order reference.
|
|
78
|
-
* @param params - Update parameters
|
|
79
|
-
* @param params.orderReference - The order reference to identify the payment
|
|
80
|
-
* @param params.fields - Array of field paths and values to update
|
|
81
|
-
* @throws Error if payment not found or update fails
|
|
82
|
-
*/
|
|
83
48
|
async updateFields(params) {
|
|
84
49
|
const { orderReference, fields } = params;
|
|
85
50
|
const updateObject = this.buildUpdateObject(fields);
|
|
@@ -93,13 +58,6 @@ class PaymentRepository {
|
|
|
93
58
|
}
|
|
94
59
|
await querySnapshot.docs[0].ref.update(updateObject);
|
|
95
60
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Retrieves all pending payments that are older than specified hours.
|
|
98
|
-
* Used for cleaning up expired payment attempts.
|
|
99
|
-
* @param params - Query parameters
|
|
100
|
-
* @param params.hoursOld - Number of hours after which a pending payment is considered expired (default: 24)
|
|
101
|
-
* @returns Promise resolving to array of expired PaymentEntity
|
|
102
|
-
*/
|
|
103
61
|
async getExpiredPendingPayments(params = {}) {
|
|
104
62
|
const { hoursOld = 24 } = params;
|
|
105
63
|
const cutoffTime = this.calculateCutoffTime(hoursOld);
|
|
@@ -113,22 +71,12 @@ class PaymentRepository {
|
|
|
113
71
|
}
|
|
114
72
|
return querySnapshot.docs.map((doc) => this.mapDocumentToEntity(doc));
|
|
115
73
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Maps a Firestore document to a PaymentEntity.
|
|
118
|
-
* @param doc - Firestore document snapshot
|
|
119
|
-
* @returns PaymentEntity with document ID
|
|
120
|
-
*/
|
|
121
74
|
mapDocumentToEntity(doc) {
|
|
122
75
|
return {
|
|
123
76
|
id: doc.id,
|
|
124
77
|
...doc.data(),
|
|
125
78
|
};
|
|
126
79
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Builds an update object from field tuples.
|
|
129
|
-
* @param fields - Array of field paths and values
|
|
130
|
-
* @returns Object with field paths as keys and values to update
|
|
131
|
-
*/
|
|
132
80
|
buildUpdateObject(fields) {
|
|
133
81
|
const updateObject = {};
|
|
134
82
|
fields.forEach(([fieldPath, value]) => {
|
|
@@ -136,11 +84,6 @@ class PaymentRepository {
|
|
|
136
84
|
});
|
|
137
85
|
return updateObject;
|
|
138
86
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Calculates the cutoff time for expired payments.
|
|
141
|
-
* @param hoursOld - Number of hours to subtract from current time
|
|
142
|
-
* @returns Date object representing the cutoff time
|
|
143
|
-
*/
|
|
144
87
|
calculateCutoffTime(hoursOld) {
|
|
145
88
|
const cutoffTime = new Date();
|
|
146
89
|
cutoffTime.setHours(cutoffTime.getHours() - hoursOld);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/modules/payments/repository.ts"],"names":[],"mappings":";;;AAAA,wDAAsG;AAEtG,mCAAiD;
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/modules/payments/repository.ts"],"names":[],"mappings":";;;AAAA,wDAAsG;AAEtG,mCAAiD;AAIjD,MAAa,iBAAiB;IAI1B,YAAY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AAC,EAAE;aAC9B,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC;aAC/B,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAC;aAChC,KAAK,CAAC,WAAW,EAAE,GAAG,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC;aACjD,GAAG,EAAE,CAAC;QAEX,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC;YACtB,OAAO,EAAE,CAAC;QACd,CAAC;QAED,OAAO,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1E,CAAC;IAEO,mBAAmB,CAAC,GAA0B;QAClD,OAAO;YACH,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,GAAG,GAAG,CAAC,IAAI,EAAE;SACC,CAAC;IACvB,CAAC;IAEO,iBAAiB,CAAC,MAA6B;QACnD,MAAM,YAAY,GAAwB,EAAE,CAAC;QAE7C,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE;YAClC,YAAY,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,OAAO,YAAY,CAAC;IACxB,CAAC;IAEO,mBAAmB,CAAC,QAAgB;QACxC,MAAM,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;QAC9B,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC;QACtD,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AA5HD,8CA4HC"}
|
|
@@ -1,94 +1,30 @@
|
|
|
1
1
|
import { Logger } from '../logger/types';
|
|
2
2
|
import { UpdateDBPaymentFields } from './repository';
|
|
3
3
|
import { PaymentEntity, IPaymentRepository, IPaymentService } from './types';
|
|
4
|
-
import { AppNamespace } from '../app/types';
|
|
5
|
-
/**
|
|
6
|
-
* PaymentService class handles business logic related to payments.
|
|
7
|
-
* Acts as an intermediary between controllers/handlers and the repository layer.
|
|
8
|
-
*/
|
|
9
4
|
export declare class PaymentService implements IPaymentService {
|
|
10
5
|
private readonly logger;
|
|
11
6
|
private readonly repository;
|
|
12
|
-
/**
|
|
13
|
-
* Creates an instance of PaymentService.
|
|
14
|
-
* @param params - Service dependencies
|
|
15
|
-
* @param params.logger - Application logger instance for logging operations
|
|
16
|
-
* @param params.repository - Optional payment repository instance for dependency injection (defaults to new PaymentRepository())
|
|
17
|
-
*/
|
|
18
7
|
constructor({ logger, repository }: {
|
|
19
8
|
logger: Logger;
|
|
20
9
|
repository?: IPaymentRepository;
|
|
21
10
|
});
|
|
22
|
-
/**
|
|
23
|
-
* Retrieves a payment by its order reference.
|
|
24
|
-
* @param orderReference - The unique order reference identifier
|
|
25
|
-
* @returns Promise resolving to PaymentEntity or null if not found
|
|
26
|
-
*/
|
|
27
11
|
getByOrderReference(orderReference: string): Promise<PaymentEntity | null>;
|
|
28
|
-
/**
|
|
29
|
-
* Retrieves all payments for a specific user.
|
|
30
|
-
* @param params - Query parameters
|
|
31
|
-
* @param params.userId - The user's unique identifier
|
|
32
|
-
* @param params.appNamespace - The application namespace/platform
|
|
33
|
-
* @param params.status - Optional payment status filter
|
|
34
|
-
* @returns Promise resolving to array of PaymentEntity
|
|
35
|
-
*/
|
|
36
12
|
getByUserId(params: {
|
|
37
13
|
userId: string;
|
|
38
|
-
|
|
14
|
+
platform: string;
|
|
39
15
|
status?: PaymentEntity['status'];
|
|
40
16
|
}): Promise<PaymentEntity[]>;
|
|
41
|
-
/**
|
|
42
|
-
* Creates a new payment record in the database.
|
|
43
|
-
* @param paymentData - Payment data without ID (ID will be auto-generated)
|
|
44
|
-
* @returns Promise resolving to created PaymentEntity with ID
|
|
45
|
-
* @throws Error if payment creation fails
|
|
46
|
-
*/
|
|
47
17
|
create(paymentData: Omit<PaymentEntity, 'id'>): Promise<PaymentEntity>;
|
|
48
|
-
/**
|
|
49
|
-
* Updates specific fields of a payment identified by order reference.
|
|
50
|
-
* @param params - Update parameters
|
|
51
|
-
* @param params.orderReference - The order reference to identify the payment
|
|
52
|
-
* @param params.fields - Array of field paths and values to update
|
|
53
|
-
* @throws Error if payment not found or update fails
|
|
54
|
-
*/
|
|
55
18
|
updateFields(params: {
|
|
56
19
|
orderReference: string;
|
|
57
20
|
fields: UpdateDBPaymentFields;
|
|
58
21
|
}): Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Retrieves all pending payments that are older than specified hours.
|
|
61
|
-
* Used for cleaning up expired payment attempts.
|
|
62
|
-
* @param params - Query parameters
|
|
63
|
-
* @param params.hoursOld - Number of hours after which a pending payment is considered expired (default: 24)
|
|
64
|
-
* @returns Promise resolving to array of expired PaymentEntity
|
|
65
|
-
*/
|
|
66
22
|
getExpiredPendingPayments(params?: {
|
|
67
23
|
hoursOld?: number;
|
|
68
24
|
}): Promise<PaymentEntity[]>;
|
|
69
|
-
/**
|
|
70
|
-
* Creates a payment intent for a user subscription.
|
|
71
|
-
* This method orchestrates the payment creation process by:
|
|
72
|
-
* 1. Creating a payment URL via Wayforpay API
|
|
73
|
-
* 2. Storing the payment record in the database
|
|
74
|
-
* 3. Returning the complete payment entity with the payment link
|
|
75
|
-
*
|
|
76
|
-
* @param params - Payment intent parameters
|
|
77
|
-
* @param params.userId - The unique identifier of the user
|
|
78
|
-
* @param params.appNamespace - The application namespace/platform
|
|
79
|
-
* @param params.planId - The subscription plan identifier
|
|
80
|
-
* @param params.productName - The name of the product/plan being purchased
|
|
81
|
-
* @param params.productPrice - The price of the product
|
|
82
|
-
* @param params.currency - The currency code ('UAH' or 'USD')
|
|
83
|
-
* @param params.regularCount - Optional number of regular payments (defaults to 3)
|
|
84
|
-
* @param params.regularMode - Optional payment frequency ('daily', 'weekly', 'monthly', 'yearly')
|
|
85
|
-
* @param params.language - Optional language code for the payment page (defaults to 'UA')
|
|
86
|
-
* @returns Promise resolving to the created PaymentEntity with payment link
|
|
87
|
-
* @throws Error if payment URL generation or database creation fails
|
|
88
|
-
*/
|
|
89
25
|
createPaymentIntent(params: {
|
|
90
26
|
userId: string;
|
|
91
|
-
|
|
27
|
+
platform: string;
|
|
92
28
|
planId: string;
|
|
93
29
|
productName: string;
|
|
94
30
|
productPrice: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAqB,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAqB,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG7E,qBAAa,cAAe,YAAW,eAAe;IAClD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAqB;gBAEpC,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,kBAAkB,CAAA;KAAE;IAK1E,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAe1E,WAAW,CAAC,MAAM,EAAE;QAC7B,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAiBf,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAiBtE,YAAY,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,qBAAqB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB9F,yBAAyB,CAClC,MAAM,GAAE;QACJ,QAAQ,CAAC,EAAE,MAAM,CAAC;KAChB,GACP,OAAO,CAAC,aAAa,EAAE,CAAC;IAed,mBAAmB,CAAC,MAAM,EAAE;QACrC,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,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;CAuD7B"}
|
|
@@ -7,26 +7,11 @@ exports.PaymentService = void 0;
|
|
|
7
7
|
const moment_1 = __importDefault(require("moment"));
|
|
8
8
|
const repository_1 = require("./repository");
|
|
9
9
|
const api_1 = require("./api");
|
|
10
|
-
/**
|
|
11
|
-
* PaymentService class handles business logic related to payments.
|
|
12
|
-
* Acts as an intermediary between controllers/handlers and the repository layer.
|
|
13
|
-
*/
|
|
14
10
|
class PaymentService {
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of PaymentService.
|
|
17
|
-
* @param params - Service dependencies
|
|
18
|
-
* @param params.logger - Application logger instance for logging operations
|
|
19
|
-
* @param params.repository - Optional payment repository instance for dependency injection (defaults to new PaymentRepository())
|
|
20
|
-
*/
|
|
21
11
|
constructor({ logger, repository }) {
|
|
22
12
|
this.logger = logger;
|
|
23
13
|
this.repository = repository || new repository_1.PaymentRepository();
|
|
24
14
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves a payment by its order reference.
|
|
27
|
-
* @param orderReference - The unique order reference identifier
|
|
28
|
-
* @returns Promise resolving to PaymentEntity or null if not found
|
|
29
|
-
*/
|
|
30
15
|
async getByOrderReference(orderReference) {
|
|
31
16
|
try {
|
|
32
17
|
return await this.repository.getByOrderReference(orderReference);
|
|
@@ -42,14 +27,6 @@ class PaymentService {
|
|
|
42
27
|
return null;
|
|
43
28
|
}
|
|
44
29
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Retrieves all payments for a specific user.
|
|
47
|
-
* @param params - Query parameters
|
|
48
|
-
* @param params.userId - The user's unique identifier
|
|
49
|
-
* @param params.appNamespace - The application namespace/platform
|
|
50
|
-
* @param params.status - Optional payment status filter
|
|
51
|
-
* @returns Promise resolving to array of PaymentEntity
|
|
52
|
-
*/
|
|
53
30
|
async getByUserId(params) {
|
|
54
31
|
try {
|
|
55
32
|
return await this.repository.getByUserId(params);
|
|
@@ -59,7 +36,7 @@ class PaymentService {
|
|
|
59
36
|
message: 'Error in payment service getByUserId',
|
|
60
37
|
payload: {
|
|
61
38
|
userId: params.userId,
|
|
62
|
-
|
|
39
|
+
platform: params.platform,
|
|
63
40
|
status: params.status,
|
|
64
41
|
error: JSON.stringify(error),
|
|
65
42
|
},
|
|
@@ -67,12 +44,6 @@ class PaymentService {
|
|
|
67
44
|
return [];
|
|
68
45
|
}
|
|
69
46
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Creates a new payment record in the database.
|
|
72
|
-
* @param paymentData - Payment data without ID (ID will be auto-generated)
|
|
73
|
-
* @returns Promise resolving to created PaymentEntity with ID
|
|
74
|
-
* @throws Error if payment creation fails
|
|
75
|
-
*/
|
|
76
47
|
async create(paymentData) {
|
|
77
48
|
try {
|
|
78
49
|
return await this.repository.create(paymentData);
|
|
@@ -89,13 +60,6 @@ class PaymentService {
|
|
|
89
60
|
throw error;
|
|
90
61
|
}
|
|
91
62
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Updates specific fields of a payment identified by order reference.
|
|
94
|
-
* @param params - Update parameters
|
|
95
|
-
* @param params.orderReference - The order reference to identify the payment
|
|
96
|
-
* @param params.fields - Array of field paths and values to update
|
|
97
|
-
* @throws Error if payment not found or update fails
|
|
98
|
-
*/
|
|
99
63
|
async updateFields(params) {
|
|
100
64
|
try {
|
|
101
65
|
await this.repository.updateFields(params);
|
|
@@ -112,13 +76,6 @@ class PaymentService {
|
|
|
112
76
|
throw error;
|
|
113
77
|
}
|
|
114
78
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Retrieves all pending payments that are older than specified hours.
|
|
117
|
-
* Used for cleaning up expired payment attempts.
|
|
118
|
-
* @param params - Query parameters
|
|
119
|
-
* @param params.hoursOld - Number of hours after which a pending payment is considered expired (default: 24)
|
|
120
|
-
* @returns Promise resolving to array of expired PaymentEntity
|
|
121
|
-
*/
|
|
122
79
|
async getExpiredPendingPayments(params = {}) {
|
|
123
80
|
try {
|
|
124
81
|
return await this.repository.getExpiredPendingPayments(params);
|
|
@@ -134,34 +91,14 @@ class PaymentService {
|
|
|
134
91
|
return [];
|
|
135
92
|
}
|
|
136
93
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Creates a payment intent for a user subscription.
|
|
139
|
-
* This method orchestrates the payment creation process by:
|
|
140
|
-
* 1. Creating a payment URL via Wayforpay API
|
|
141
|
-
* 2. Storing the payment record in the database
|
|
142
|
-
* 3. Returning the complete payment entity with the payment link
|
|
143
|
-
*
|
|
144
|
-
* @param params - Payment intent parameters
|
|
145
|
-
* @param params.userId - The unique identifier of the user
|
|
146
|
-
* @param params.appNamespace - The application namespace/platform
|
|
147
|
-
* @param params.planId - The subscription plan identifier
|
|
148
|
-
* @param params.productName - The name of the product/plan being purchased
|
|
149
|
-
* @param params.productPrice - The price of the product
|
|
150
|
-
* @param params.currency - The currency code ('UAH' or 'USD')
|
|
151
|
-
* @param params.regularCount - Optional number of regular payments (defaults to 3)
|
|
152
|
-
* @param params.regularMode - Optional payment frequency ('daily', 'weekly', 'monthly', 'yearly')
|
|
153
|
-
* @param params.language - Optional language code for the payment page (defaults to 'UA')
|
|
154
|
-
* @returns Promise resolving to the created PaymentEntity with payment link
|
|
155
|
-
* @throws Error if payment URL generation or database creation fails
|
|
156
|
-
*/
|
|
157
94
|
async createPaymentIntent(params) {
|
|
158
|
-
const { userId,
|
|
95
|
+
const { userId, platform, planId, productName, productPrice, currency, regularCount, regularMode, language } = params;
|
|
159
96
|
try {
|
|
160
97
|
// Step 1: Create payment URL from Wayforpay API
|
|
161
98
|
// This also generates a unique order reference
|
|
162
99
|
const paymentResponse = await (0, api_1.createPaymentAPI)({
|
|
163
100
|
userId,
|
|
164
|
-
|
|
101
|
+
platform,
|
|
165
102
|
productName,
|
|
166
103
|
productPrice,
|
|
167
104
|
planId,
|
|
@@ -183,7 +120,7 @@ class PaymentService {
|
|
|
183
120
|
amount: productPrice,
|
|
184
121
|
currency,
|
|
185
122
|
createdAt: moment_1.default.utc().toISOString(),
|
|
186
|
-
platform:
|
|
123
|
+
platform: platform,
|
|
187
124
|
provider: 'wayforpay',
|
|
188
125
|
});
|
|
189
126
|
return paymentEntity;
|
|
@@ -193,7 +130,7 @@ class PaymentService {
|
|
|
193
130
|
message: 'Error in payment service createPaymentIntent',
|
|
194
131
|
payload: {
|
|
195
132
|
userId,
|
|
196
|
-
|
|
133
|
+
platform,
|
|
197
134
|
planId,
|
|
198
135
|
productName,
|
|
199
136
|
productPrice,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/modules/payments/service.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,6CAAwE;
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/modules/payments/service.ts"],"names":[],"mappings":";;;;;;AAAA,oDA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AAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YAEH,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AAnKD,wCAmKC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { NestedPathsAccess } from '../../types/utilities';
|
|
2
|
-
import { AppNamespace } from '../app/types';
|
|
3
2
|
type PaymentEntity = {
|
|
4
3
|
/** Auto-generated unique ID (document ID) */
|
|
5
4
|
id?: string;
|
|
@@ -22,7 +21,7 @@ type PaymentEntity = {
|
|
|
22
21
|
/** Optional. The ID of the corresponding document in the invoices collection, added after the webhook is processed */
|
|
23
22
|
invoiceId?: string;
|
|
24
23
|
/** Platform/app namespace */
|
|
25
|
-
platform:
|
|
24
|
+
platform: string;
|
|
26
25
|
/** Payment provider */
|
|
27
26
|
provider: 'wayforpay';
|
|
28
27
|
};
|
|
@@ -34,24 +33,18 @@ type PaymentFieldPath = NestedPathsAccess<PaymentEntity>;
|
|
|
34
33
|
interface IPaymentRepository {
|
|
35
34
|
/**
|
|
36
35
|
* Retrieves a payment by its order reference.
|
|
37
|
-
* @param orderReference - The unique order reference identifier
|
|
38
|
-
* @returns Promise resolving to PaymentEntity or null if not found
|
|
39
36
|
*/
|
|
40
37
|
getByOrderReference(orderReference: string): Promise<PaymentEntity | null>;
|
|
41
38
|
/**
|
|
42
39
|
* Retrieves all payments for a specific user.
|
|
43
|
-
* @param params - Query parameters
|
|
44
|
-
* @returns Promise resolving to array of PaymentEntity
|
|
45
40
|
*/
|
|
46
41
|
getByUserId(params: {
|
|
47
42
|
userId: string;
|
|
48
|
-
|
|
43
|
+
platform: string;
|
|
49
44
|
status?: PaymentEntity['status'];
|
|
50
45
|
}): Promise<PaymentEntity[]>;
|
|
51
46
|
/**
|
|
52
47
|
* Creates a new payment record in the database.
|
|
53
|
-
* @param paymentData - Payment data without ID (ID will be auto-generated)
|
|
54
|
-
* @returns Promise resolving to created PaymentEntity with ID
|
|
55
48
|
*/
|
|
56
49
|
create(paymentData: Omit<PaymentEntity, 'id'>): Promise<PaymentEntity>;
|
|
57
50
|
/**
|
|
@@ -89,7 +82,7 @@ interface IPaymentService {
|
|
|
89
82
|
*/
|
|
90
83
|
getByUserId(params: {
|
|
91
84
|
userId: string;
|
|
92
|
-
|
|
85
|
+
platform: string;
|
|
93
86
|
status?: PaymentEntity['status'];
|
|
94
87
|
}): Promise<PaymentEntity[]>;
|
|
95
88
|
/**
|
|
@@ -121,7 +114,7 @@ interface IPaymentService {
|
|
|
121
114
|
*/
|
|
122
115
|
createPaymentIntent(params: {
|
|
123
116
|
userId: string;
|
|
124
|
-
|
|
117
|
+
platform: string;
|
|
125
118
|
planId: string;
|
|
126
119
|
productName: string;
|
|
127
120
|
productPrice: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,KAAK,aAAa,GAAG;IACjB,6CAA6C;IAC7C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yHAAyH;IACzH,cAAc,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;IACvD,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,4CAA4C;IAC5C,SAAS,EAAE,MAA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aAAa,CAAC,QAAQ,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAE7B;;;;OAIG;IACH,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAEvE;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7E;;;;OAIG;IACH,yBAAyB,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAEpF;;;;OAIG;IACH,mBAAmB,CAAC,MAAM,EAAE;QACxB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,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,CAAC;CAC9B;AAED,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
declare function createOrderReference({ userId, appNamespace, planId, utcDate, }: {
|
|
1
|
+
declare function createOrderReference({ userId, platform, planId, utcDate, }: {
|
|
3
2
|
userId: string;
|
|
4
|
-
|
|
3
|
+
platform: string;
|
|
5
4
|
planId: string;
|
|
6
5
|
utcDate: string;
|
|
7
6
|
}): string;
|
|
8
7
|
export interface ParsedReferenceString {
|
|
9
8
|
appName: string;
|
|
10
|
-
|
|
9
|
+
platform: string;
|
|
11
10
|
serviceType: string;
|
|
12
11
|
userId: string;
|
|
13
12
|
planId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/utils.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/utils.ts"],"names":[],"mappings":"AAAA,iBAAS,oBAAoB,CAAC,EAC1B,MAAM,EACN,QAAQ,EACR,MAAM,EACN,OAAO,GACV,EAAE;IACC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB,GAAG,MAAM,CAET;AAED,MAAM,WAAW,qBAAqB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,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,CA0BlF;AAED,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,CAAC"}
|