@misterhomer1992/miit-bot-payment 1.1.6 → 2.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.
- package/dist/config/ConfigurationManager.d.ts +64 -0
- package/dist/config/ConfigurationManager.d.ts.map +1 -0
- package/dist/config/ConfigurationManager.js +144 -0
- package/dist/config/ConfigurationManager.js.map +1 -0
- package/dist/config/defaults.d.ts +18 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +26 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/environment.d.ts +38 -0
- package/dist/config/environment.d.ts.map +1 -0
- package/dist/config/environment.js +91 -0
- package/dist/config/environment.js.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +18 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +53 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +3 -0
- package/dist/config/types.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -1
- package/dist/modules/cache/InMemoryCache.d.ts +17 -0
- package/dist/modules/cache/InMemoryCache.d.ts.map +1 -0
- package/dist/modules/cache/InMemoryCache.js +77 -0
- package/dist/modules/cache/InMemoryCache.js.map +1 -0
- package/dist/modules/cache/index.d.ts +3 -0
- package/dist/modules/cache/index.d.ts.map +1 -0
- package/dist/modules/cache/index.js +19 -0
- package/dist/modules/cache/index.js.map +1 -0
- package/dist/modules/cache/types.d.ts +52 -0
- package/dist/modules/cache/types.d.ts.map +1 -0
- package/dist/modules/cache/types.js +3 -0
- package/dist/modules/cache/types.js.map +1 -0
- package/dist/modules/errors/index.d.ts +2 -0
- package/dist/modules/errors/index.d.ts.map +1 -0
- package/dist/modules/errors/index.js +19 -0
- package/dist/modules/errors/index.js.map +1 -0
- package/dist/modules/errors/types.d.ts +112 -0
- package/dist/modules/errors/types.d.ts.map +1 -0
- package/dist/modules/errors/types.js +174 -0
- package/dist/modules/errors/types.js.map +1 -0
- package/dist/modules/payments/api.d.ts +63 -1
- package/dist/modules/payments/api.d.ts.map +1 -1
- package/dist/modules/payments/api.js +103 -1
- package/dist/modules/payments/api.js.map +1 -1
- package/dist/modules/payments/const.d.ts.map +1 -1
- package/dist/modules/payments/const.js +1 -0
- package/dist/modules/payments/const.js.map +1 -1
- package/dist/modules/payments/index.d.ts +8 -0
- package/dist/modules/payments/index.d.ts.map +1 -1
- package/dist/modules/payments/index.js +8 -0
- package/dist/modules/payments/index.js.map +1 -1
- package/dist/modules/payments/service.d.ts +42 -2
- package/dist/modules/payments/service.d.ts.map +1 -1
- package/dist/modules/payments/service.js +132 -3
- package/dist/modules/payments/service.js.map +1 -1
- package/dist/modules/payments/subscription-check-webhook.handler.d.ts +85 -0
- package/dist/modules/payments/subscription-check-webhook.handler.d.ts.map +1 -0
- package/dist/modules/payments/subscription-check-webhook.handler.js +155 -0
- package/dist/modules/payments/subscription-check-webhook.handler.js.map +1 -0
- package/dist/modules/payments/subscription-check-webhook.service.d.ts +59 -0
- package/dist/modules/payments/subscription-check-webhook.service.d.ts.map +1 -0
- package/dist/modules/payments/subscription-check-webhook.service.js +330 -0
- package/dist/modules/payments/subscription-check-webhook.service.js.map +1 -0
- package/dist/modules/payments/subscription-check-webhook.types.d.ts +25 -0
- package/dist/modules/payments/subscription-check-webhook.types.d.ts.map +1 -0
- package/dist/modules/payments/subscription-check-webhook.types.js +3 -0
- package/dist/modules/payments/subscription-check-webhook.types.js.map +1 -0
- package/dist/modules/payments/types.d.ts +69 -2
- package/dist/modules/payments/types.d.ts.map +1 -1
- package/dist/modules/payments/utils.d.ts +151 -5
- package/dist/modules/payments/utils.d.ts.map +1 -1
- package/dist/modules/payments/utils.js +253 -9
- package/dist/modules/payments/utils.js.map +1 -1
- package/dist/modules/payments/wayforpay.service.d.ts +39 -0
- package/dist/modules/payments/wayforpay.service.d.ts.map +1 -0
- package/dist/modules/payments/wayforpay.service.js +217 -0
- package/dist/modules/payments/wayforpay.service.js.map +1 -0
- package/dist/modules/payments/wayforpay.types.d.ts +115 -0
- package/dist/modules/payments/wayforpay.types.d.ts.map +1 -0
- package/dist/modules/payments/wayforpay.types.js +3 -0
- package/dist/modules/payments/wayforpay.types.js.map +1 -0
- package/dist/modules/payments/webhook.handler.d.ts +98 -0
- package/dist/modules/payments/webhook.handler.d.ts.map +1 -0
- package/dist/modules/payments/webhook.handler.js +153 -0
- package/dist/modules/payments/webhook.handler.js.map +1 -0
- package/dist/modules/payments/webhook.service.d.ts +99 -0
- package/dist/modules/payments/webhook.service.d.ts.map +1 -0
- package/dist/modules/payments/webhook.service.js +672 -0
- package/dist/modules/payments/webhook.service.js.map +1 -0
- package/dist/modules/payments/webhook.types.d.ts +35 -0
- package/dist/modules/payments/webhook.types.d.ts.map +1 -0
- package/dist/modules/payments/webhook.types.js +3 -0
- package/dist/modules/payments/webhook.types.js.map +1 -0
- package/dist/modules/subscription/change.service.d.ts +80 -0
- package/dist/modules/subscription/change.service.d.ts.map +1 -0
- package/dist/modules/subscription/change.service.js +226 -0
- package/dist/modules/subscription/change.service.js.map +1 -0
- package/dist/modules/subscription/index.d.ts +2 -0
- package/dist/modules/subscription/index.d.ts.map +1 -1
- package/dist/modules/subscription/index.js +2 -0
- package/dist/modules/subscription/index.js.map +1 -1
- package/dist/modules/subscription/service.d.ts +8 -1
- package/dist/modules/subscription/service.d.ts.map +1 -1
- package/dist/modules/subscription/service.js +59 -2
- package/dist/modules/subscription/service.js.map +1 -1
- package/dist/modules/subscription/status-check.handler.d.ts +117 -0
- package/dist/modules/subscription/status-check.handler.d.ts.map +1 -0
- package/dist/modules/subscription/status-check.handler.js +164 -0
- package/dist/modules/subscription/status-check.handler.js.map +1 -0
- package/dist/modules/subscription/types.d.ts +37 -1
- package/dist/modules/subscription/types.d.ts.map +1 -1
- package/dist/modules/subscriptionPlan/const.d.ts +5 -0
- package/dist/modules/subscriptionPlan/const.d.ts.map +1 -0
- package/dist/modules/subscriptionPlan/const.js +106 -0
- package/dist/modules/subscriptionPlan/const.js.map +1 -0
- package/dist/modules/subscriptionPlan/index.d.ts +5 -0
- package/dist/modules/subscriptionPlan/index.d.ts.map +1 -0
- package/dist/modules/subscriptionPlan/index.js +21 -0
- package/dist/modules/subscriptionPlan/index.js.map +1 -0
- package/dist/modules/subscriptionPlan/repository.d.ts +22 -0
- package/dist/modules/subscriptionPlan/repository.d.ts.map +1 -0
- package/dist/modules/subscriptionPlan/repository.js +95 -0
- package/dist/modules/subscriptionPlan/repository.js.map +1 -0
- package/dist/modules/subscriptionPlan/service.d.ts +21 -0
- package/dist/modules/subscriptionPlan/service.d.ts.map +1 -0
- package/dist/modules/subscriptionPlan/service.js +128 -0
- package/dist/modules/subscriptionPlan/service.js.map +1 -0
- package/dist/modules/subscriptionPlan/types.d.ts +40 -0
- package/dist/modules/subscriptionPlan/types.d.ts.map +1 -0
- package/dist/modules/subscriptionPlan/types.js +3 -0
- package/dist/modules/subscriptionPlan/types.js.map +1 -0
- package/dist/modules/token/const.d.ts +7 -0
- package/dist/modules/token/const.d.ts.map +1 -0
- package/dist/modules/token/const.js +66 -0
- package/dist/modules/token/const.js.map +1 -0
- package/dist/modules/token/index.d.ts +4 -0
- package/dist/modules/token/index.d.ts.map +1 -0
- package/dist/modules/token/index.js +20 -0
- package/dist/modules/token/index.js.map +1 -0
- package/dist/modules/token/service.d.ts +46 -0
- package/dist/modules/token/service.d.ts.map +1 -0
- package/dist/modules/token/service.js +249 -0
- package/dist/modules/token/service.js.map +1 -0
- package/dist/modules/token/types.d.ts +109 -0
- package/dist/modules/token/types.d.ts.map +1 -0
- package/dist/modules/token/types.js +3 -0
- package/dist/modules/token/types.js.map +1 -0
- package/dist/modules/tokenPack/const.d.ts +4 -0
- package/dist/modules/tokenPack/const.d.ts.map +1 -0
- package/dist/modules/tokenPack/const.js +10 -0
- package/dist/modules/tokenPack/const.js.map +1 -0
- package/dist/modules/tokenPack/index.d.ts +5 -0
- package/dist/modules/tokenPack/index.d.ts.map +1 -0
- package/dist/modules/tokenPack/index.js +21 -0
- package/dist/modules/tokenPack/index.js.map +1 -0
- package/dist/modules/tokenPack/repository.d.ts +32 -0
- package/dist/modules/tokenPack/repository.d.ts.map +1 -0
- package/dist/modules/tokenPack/repository.js +103 -0
- package/dist/modules/tokenPack/repository.js.map +1 -0
- package/dist/modules/tokenPack/service.d.ts +28 -0
- package/dist/modules/tokenPack/service.d.ts.map +1 -0
- package/dist/modules/tokenPack/service.js +106 -0
- package/dist/modules/tokenPack/service.js.map +1 -0
- package/dist/modules/tokenPack/types.d.ts +124 -0
- package/dist/modules/tokenPack/types.d.ts.map +1 -0
- package/dist/modules/tokenPack/types.js +3 -0
- package/dist/modules/tokenPack/types.js.map +1 -0
- package/package.json +9 -5
- package/src/config/ConfigurationManager.ts +159 -0
- package/src/config/defaults.ts +27 -0
- package/src/config/environment.ts +94 -0
- package/src/config/index.ts +22 -0
- package/src/config/types.ts +56 -0
- package/src/index.ts +29 -0
- package/src/modules/cache/InMemoryCache.ts +98 -0
- package/src/modules/cache/index.ts +2 -0
- package/src/modules/cache/types.ts +60 -0
- package/src/modules/cancellableAPI/utils.ts +60 -0
- package/src/modules/errors/index.ts +16 -0
- package/src/modules/errors/types.ts +201 -0
- package/src/modules/invoice/const.ts +7 -0
- package/src/modules/invoice/index.ts +4 -0
- package/src/modules/invoice/repository.ts +52 -0
- package/src/modules/invoice/service.ts +44 -0
- package/src/modules/invoice/types.ts +47 -0
- package/src/modules/logger/types.ts +8 -0
- package/src/modules/network/utils.ts +24 -0
- package/src/modules/payments/api.ts +289 -0
- package/src/modules/payments/const.ts +11 -0
- package/src/modules/payments/index.ts +14 -0
- package/src/modules/payments/repository.ts +125 -0
- package/src/modules/payments/service.test.ts +400 -0
- package/src/modules/payments/service.ts +365 -0
- package/src/modules/payments/subscription-check-webhook.handler.integration.test.ts +935 -0
- package/src/modules/payments/subscription-check-webhook.handler.ts +211 -0
- package/src/modules/payments/subscription-check-webhook.service.ts +398 -0
- package/src/modules/payments/subscription-check-webhook.types.ts +29 -0
- package/src/modules/payments/types.ts +193 -0
- package/src/modules/payments/utils.ts +428 -0
- package/src/modules/payments/wayforpay.service.test.ts +375 -0
- package/src/modules/payments/wayforpay.service.ts +284 -0
- package/src/modules/payments/wayforpay.types.ts +138 -0
- package/src/modules/payments/webhook.handler.integration.test.ts +975 -0
- package/src/modules/payments/webhook.handler.ts +219 -0
- package/src/modules/payments/webhook.service.ts +812 -0
- package/src/modules/payments/webhook.types.ts +38 -0
- package/src/modules/subscription/change.service.ts +317 -0
- package/src/modules/subscription/const.ts +9 -0
- package/src/modules/subscription/index.ts +5 -0
- package/src/modules/subscription/repository.ts +277 -0
- package/src/modules/subscription/service.test.ts +665 -0
- package/src/modules/subscription/service.ts +328 -0
- package/src/modules/subscription/status-check.handler.ts +254 -0
- package/src/modules/subscription/types.ts +267 -0
- package/src/modules/subscription/utils.ts +5 -0
- package/src/modules/subscriptionPlan/const.ts +106 -0
- package/src/modules/subscriptionPlan/index.ts +4 -0
- package/src/modules/subscriptionPlan/repository.ts +129 -0
- package/src/modules/subscriptionPlan/service.test.ts +401 -0
- package/src/modules/subscriptionPlan/service.ts +148 -0
- package/src/modules/subscriptionPlan/types.ts +67 -0
- package/src/modules/token/const.ts +64 -0
- package/src/modules/token/index.ts +3 -0
- package/src/modules/token/service.test.ts +499 -0
- package/src/modules/token/service.ts +297 -0
- package/src/modules/token/types.ts +124 -0
- package/src/modules/tokenPack/const.ts +9 -0
- package/src/modules/tokenPack/index.ts +4 -0
- package/src/modules/tokenPack/repository.ts +144 -0
- package/src/modules/tokenPack/service.ts +119 -0
- package/src/modules/tokenPack/types.ts +131 -0
- package/src/modules/user/index.ts +3 -0
- package/src/modules/user/types.ts +143 -0
- package/src/modules/user/userRepository.ts +64 -0
- package/src/modules/user/userService.ts +68 -0
- package/src/types/extend-express.d.ts +16 -0
- package/src/types/function.ts +5 -0
- package/src/types/utilities.ts +22 -0
- package/src/utils.ts +53 -0
- package/tsconfig.json +29 -0
- package/dist/modules/subscription/subscriptionPlan.d.ts +0 -4
- package/dist/modules/subscription/subscriptionPlan.d.ts.map +0 -1
- package/dist/modules/subscription/subscriptionPlan.js +0 -67
- package/dist/modules/subscription/subscriptionPlan.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NestedPathsAccess } from '../../types/utilities';
|
|
2
|
+
type PaymentType = 'subscription' | 'token_pack' | 'subscription_upgrade';
|
|
2
3
|
type PaymentEntity = {
|
|
3
4
|
/** Auto-generated unique ID (document ID) */
|
|
4
5
|
id?: string;
|
|
@@ -10,8 +11,10 @@ type PaymentEntity = {
|
|
|
10
11
|
status: 'pending' | 'completed' | 'failed' | 'expired';
|
|
11
12
|
/** The URL from Wayforpay that is sent to the user */
|
|
12
13
|
paymentLink: string;
|
|
13
|
-
/** The plan the user is attempting to purchase */
|
|
14
|
+
/** The plan or pack ID the user is attempting to purchase */
|
|
14
15
|
planId: string;
|
|
16
|
+
/** The type of payment (subscription or token_pack) */
|
|
17
|
+
paymentType: PaymentType;
|
|
15
18
|
/** The amount to be charged */
|
|
16
19
|
amount: number;
|
|
17
20
|
/** Currency of the payment */
|
|
@@ -64,6 +67,13 @@ interface IPaymentRepository {
|
|
|
64
67
|
hoursOld?: number;
|
|
65
68
|
}): Promise<PaymentEntity[]>;
|
|
66
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Result of signature validation.
|
|
72
|
+
*/
|
|
73
|
+
type SignatureValidationResult = {
|
|
74
|
+
isValid: boolean;
|
|
75
|
+
error?: string;
|
|
76
|
+
};
|
|
67
77
|
/**
|
|
68
78
|
* Interface for payment service operations.
|
|
69
79
|
* Defines the contract for business logic layer.
|
|
@@ -91,9 +101,18 @@ interface IPaymentService {
|
|
|
91
101
|
* @returns Promise resolving to created PaymentEntity with ID
|
|
92
102
|
*/
|
|
93
103
|
create(paymentData: Omit<PaymentEntity, 'id'>): Promise<PaymentEntity>;
|
|
104
|
+
/**
|
|
105
|
+
* Updates the status of a payment.
|
|
106
|
+
* @param params - Update parameters containing id and new status
|
|
107
|
+
*/
|
|
108
|
+
updateStatus(params: {
|
|
109
|
+
id: string;
|
|
110
|
+
status: PaymentEntity['status'];
|
|
111
|
+
}): Promise<void>;
|
|
94
112
|
/**
|
|
95
113
|
* Updates specific fields of a payment.
|
|
96
114
|
* @param params - Update parameters
|
|
115
|
+
* @deprecated Use updateStatus instead for status changes
|
|
97
116
|
*/
|
|
98
117
|
changeStatus(params: {
|
|
99
118
|
id: string;
|
|
@@ -123,6 +142,54 @@ interface IPaymentService {
|
|
|
123
142
|
regularMode?: 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
124
143
|
language?: string;
|
|
125
144
|
}): Promise<PaymentEntity>;
|
|
145
|
+
/**
|
|
146
|
+
* Creates a payment intent for a token pack purchase.
|
|
147
|
+
* @param params - Payment intent parameters
|
|
148
|
+
* @returns Promise resolving to the created PaymentEntity with payment link
|
|
149
|
+
*/
|
|
150
|
+
createTokenPackPaymentIntent(params: {
|
|
151
|
+
userId: string;
|
|
152
|
+
platform: string;
|
|
153
|
+
packId: string;
|
|
154
|
+
productName: string;
|
|
155
|
+
productPrice: number;
|
|
156
|
+
currency: 'UAH' | 'USD';
|
|
157
|
+
language?: string;
|
|
158
|
+
returnUrl?: string;
|
|
159
|
+
}): Promise<PaymentEntity>;
|
|
160
|
+
/**
|
|
161
|
+
* Validates the signature of payment callback data.
|
|
162
|
+
* @param callbackData - The callback data from the payment provider
|
|
163
|
+
* @returns Validation result indicating if signature is valid
|
|
164
|
+
*/
|
|
165
|
+
validateSignature(callbackData: {
|
|
166
|
+
merchantAccount: string;
|
|
167
|
+
orderReference: string;
|
|
168
|
+
amount: number;
|
|
169
|
+
currency: string;
|
|
170
|
+
authCode: string;
|
|
171
|
+
cardPan: string;
|
|
172
|
+
transactionStatus: string;
|
|
173
|
+
reasonCode: string | number;
|
|
174
|
+
merchantSignature: string;
|
|
175
|
+
}): SignatureValidationResult;
|
|
176
|
+
/**
|
|
177
|
+
* Creates a payment intent for a subscription upgrade.
|
|
178
|
+
* @param params - Payment intent parameters
|
|
179
|
+
* @returns Promise resolving to the created PaymentEntity with payment link
|
|
180
|
+
*/
|
|
181
|
+
createUpgradePaymentIntent(params: {
|
|
182
|
+
userId: string;
|
|
183
|
+
platform: string;
|
|
184
|
+
currentPlanId: string;
|
|
185
|
+
newPlanId: string;
|
|
186
|
+
productName: string;
|
|
187
|
+
upgradeCost: number;
|
|
188
|
+
currency: 'UAH' | 'USD';
|
|
189
|
+
regularMode?: 'daily' | 'monthly' | 'yearly';
|
|
190
|
+
regularCount?: number;
|
|
191
|
+
language?: string;
|
|
192
|
+
}): Promise<PaymentEntity>;
|
|
126
193
|
}
|
|
127
|
-
export type { PaymentEntity, PaymentFieldPath, IPaymentRepository, IPaymentService };
|
|
194
|
+
export type { PaymentEntity, PaymentType, PaymentFieldPath, IPaymentRepository, IPaymentService, SignatureValidationResult };
|
|
128
195
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -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;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,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/types.ts"],"names":[],"mappings":"AAAA,OAA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C;QAC1B,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;QAC5B,iBAAiB,EAAE,MAAM,CAAC;KAC7B,GAAG,yBAAyB,CAAC;IAE9B;;;;OAIG;IACH,0BAA0B,CAAC,MAAM,EAAE;QAC/B,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC;QACxB,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;QAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC9B;AAED,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -1,10 +1,69 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Payment type for order references
|
|
3
|
+
*/
|
|
4
|
+
type OrderReferencePaymentType = 'sub' | 'tkn' | 'upg';
|
|
5
|
+
/**
|
|
6
|
+
* Parameters for creating a subscription order reference
|
|
7
|
+
*/
|
|
8
|
+
interface CreateSubscriptionOrderReferenceParams {
|
|
2
9
|
userId: string;
|
|
3
10
|
platform: string;
|
|
4
11
|
planId: string;
|
|
5
12
|
utcDate: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parameters for creating a token pack order reference
|
|
16
|
+
*/
|
|
17
|
+
interface CreateTokenPackOrderReferenceParams {
|
|
18
|
+
userId: string;
|
|
19
|
+
platform: string;
|
|
20
|
+
packId: string;
|
|
21
|
+
utcDate: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parameters for creating an upgrade order reference
|
|
25
|
+
*/
|
|
26
|
+
interface CreateUpgradeOrderReferenceParams {
|
|
27
|
+
userId: string;
|
|
28
|
+
platform: string;
|
|
29
|
+
currentPlanId: string;
|
|
30
|
+
newPlanId: string;
|
|
31
|
+
utcDate: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parsed upgrade order reference
|
|
35
|
+
*/
|
|
36
|
+
interface ParsedUpgradeOrderReference {
|
|
37
|
+
appName: string;
|
|
38
|
+
platform: string;
|
|
39
|
+
serviceType: string;
|
|
40
|
+
userId: string;
|
|
41
|
+
paymentType: 'upg';
|
|
42
|
+
currentPlanId: string;
|
|
43
|
+
newPlanId: string;
|
|
44
|
+
version: string;
|
|
45
|
+
timestamp: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parsed order reference with payment type discrimination
|
|
49
|
+
*/
|
|
50
|
+
interface ParsedOrderReference {
|
|
51
|
+
appName: string;
|
|
52
|
+
platform: string;
|
|
53
|
+
serviceType: string;
|
|
54
|
+
userId: string;
|
|
55
|
+
/** Payment type: 'sub' for subscription, 'tkn' for token pack */
|
|
56
|
+
paymentType: OrderReferencePaymentType;
|
|
57
|
+
/** Plan ID for subscriptions, Pack ID for token packs */
|
|
58
|
+
itemId: string;
|
|
59
|
+
version: string;
|
|
60
|
+
timestamp: string;
|
|
61
|
+
chargeId?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Legacy parsed reference string (backward compatibility)
|
|
65
|
+
*/
|
|
66
|
+
interface ParsedReferenceString {
|
|
8
67
|
appName: string;
|
|
9
68
|
platform: string;
|
|
10
69
|
serviceType: string;
|
|
@@ -14,6 +73,93 @@ export interface ParsedReferenceString {
|
|
|
14
73
|
timestamp: string;
|
|
15
74
|
chargeId?: string;
|
|
16
75
|
}
|
|
17
|
-
declare
|
|
18
|
-
|
|
76
|
+
declare const ORDER_REFERENCE_VERSION = "v2";
|
|
77
|
+
declare const ORDER_REFERENCE_APP_NAME = "miia";
|
|
78
|
+
declare const ORDER_REFERENCE_SERVICE_TYPE = "bot";
|
|
79
|
+
/**
|
|
80
|
+
* Creates a unique order reference for subscription payments.
|
|
81
|
+
* Format: miia_{platform}_bot_{userId}_sub_{planId}_v2_{utcDate}
|
|
82
|
+
*
|
|
83
|
+
* @param params - Parameters for generating the order reference
|
|
84
|
+
* @returns A unique order reference string
|
|
85
|
+
*/
|
|
86
|
+
declare function createSubscriptionOrderReference({ userId, platform, planId, utcDate, }: CreateSubscriptionOrderReferenceParams): string;
|
|
87
|
+
/**
|
|
88
|
+
* Creates a unique order reference for token pack payments.
|
|
89
|
+
* Format: miia_{platform}_bot_{userId}_tkn_{packId}_v2_{utcDate}
|
|
90
|
+
*
|
|
91
|
+
* @param params - Parameters for generating the order reference
|
|
92
|
+
* @returns A unique order reference string
|
|
93
|
+
*/
|
|
94
|
+
declare function createTokenPackOrderReference({ userId, platform, packId, utcDate, }: CreateTokenPackOrderReferenceParams): string;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a unique order reference for subscription upgrade payments.
|
|
97
|
+
* Format: miia_{platform}_bot_{userId}_upg_{currentPlanId}_to_{newPlanId}_v2_{utcDate}
|
|
98
|
+
*
|
|
99
|
+
* @param params - Parameters for generating the order reference
|
|
100
|
+
* @returns A unique order reference string
|
|
101
|
+
*/
|
|
102
|
+
declare function createUpgradeOrderReference({ userId, platform, currentPlanId, newPlanId, utcDate, }: CreateUpgradeOrderReferenceParams): string;
|
|
103
|
+
/**
|
|
104
|
+
* Checks if an order reference is for a subscription payment.
|
|
105
|
+
*
|
|
106
|
+
* @param orderReference - The order reference string to check
|
|
107
|
+
* @returns True if the order reference is for a subscription
|
|
108
|
+
*/
|
|
109
|
+
declare function isSubscriptionOrderReference(orderReference: string): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Checks if an order reference is for a token pack payment.
|
|
112
|
+
*
|
|
113
|
+
* @param orderReference - The order reference string to check
|
|
114
|
+
* @returns True if the order reference is for a token pack
|
|
115
|
+
*/
|
|
116
|
+
declare function isTokenPackOrderReference(orderReference: string): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Checks if an order reference is for a subscription upgrade payment.
|
|
119
|
+
*
|
|
120
|
+
* @param orderReference - The order reference string to check
|
|
121
|
+
* @returns True if the order reference is for an upgrade
|
|
122
|
+
*/
|
|
123
|
+
declare function isUpgradeOrderReference(orderReference: string): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Parses an upgrade order reference to extract both plan IDs.
|
|
126
|
+
*
|
|
127
|
+
* @param orderReference - The order reference string to parse
|
|
128
|
+
* @returns Parsed upgrade reference with currentPlanId and newPlanId, or null if invalid
|
|
129
|
+
*/
|
|
130
|
+
declare function parseUpgradeOrderReference(orderReference: string): ParsedUpgradeOrderReference | null;
|
|
131
|
+
/**
|
|
132
|
+
* Extracts the payment type from an order reference.
|
|
133
|
+
*
|
|
134
|
+
* @param orderReference - The order reference string
|
|
135
|
+
* @returns The payment type ('sub' or 'tkn'), or null if invalid
|
|
136
|
+
*/
|
|
137
|
+
declare function getOrderReferencePaymentType(orderReference: string): OrderReferencePaymentType | null;
|
|
138
|
+
/**
|
|
139
|
+
* Extracts the item ID (plan ID or pack ID) from an order reference.
|
|
140
|
+
*
|
|
141
|
+
* @param orderReference - The order reference string
|
|
142
|
+
* @returns The item ID, or null if invalid
|
|
143
|
+
*/
|
|
144
|
+
declare function getOrderReferenceItemId(orderReference: string): string | null;
|
|
145
|
+
/**
|
|
146
|
+
* Extracts the user ID from an order reference.
|
|
147
|
+
*
|
|
148
|
+
* @param orderReference - The order reference string
|
|
149
|
+
* @returns The user ID, or null if invalid
|
|
150
|
+
*/
|
|
151
|
+
declare function getOrderReferenceUserId(orderReference: string): string | null;
|
|
152
|
+
/**
|
|
153
|
+
* Parses an order reference string into its components.
|
|
154
|
+
* Supports both v1 (legacy) and v2 (new) formats.
|
|
155
|
+
*
|
|
156
|
+
* v1 format: miia_{platform}_bot_{userId}_{planId}_v1_{timestamp}
|
|
157
|
+
* v2 format: miia_{platform}_bot_{userId}_{type}_{itemId}_v2_{timestamp}
|
|
158
|
+
*
|
|
159
|
+
* @param referenceString - The order reference string to parse
|
|
160
|
+
* @returns Parsed reference object or null if invalid
|
|
161
|
+
*/
|
|
162
|
+
declare function parseOrderReference(referenceString: string): (ParsedOrderReference | ParsedReferenceString) | null;
|
|
163
|
+
export type { OrderReferencePaymentType, CreateSubscriptionOrderReferenceParams, CreateTokenPackOrderReferenceParams, CreateUpgradeOrderReferenceParams, ParsedOrderReference, ParsedReferenceString, ParsedUpgradeOrderReference, };
|
|
164
|
+
export { ORDER_REFERENCE_VERSION, ORDER_REFERENCE_APP_NAME, ORDER_REFERENCE_SERVICE_TYPE, createSubscriptionOrderReference, createTokenPackOrderReference, createUpgradeOrderReference, isSubscriptionOrderReference, isTokenPackOrderReference, isUpgradeOrderReference, getOrderReferencePaymentType, getOrderReferenceItemId, getOrderReferenceUserId, parseUpgradeOrderReference, parseOrderReference, };
|
|
19
165
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -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;;GAEG;AACH,KAAK,yBAAyB,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAEvD;;GAEG;AACH,UAAU,sCAAsC;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,UAAU,mCAAmC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,C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ACnC,iCAAiC,EACjC,oBAAoB,EACpB,qBAAqB,EACrB,2BAA2B,GAC9B,CAAC;AAEF,OAAO,EAEH,uBAAuB,EACvB,wBAAwB,EACxB,4BAA4B,EAE5B,gCAAgC,EAChC,6BAA6B,EAC7B,2BAA2B,EAE3B,4BAA4B,EAC5B,yBAAyB,EACzB,uBAAuB,EACvB,4BAA4B,EAC5B,uBAAuB,EACvB,uBAAuB,EAEvB,0BAA0B,EAE1B,mBAAmB,GACtB,CAAC"}
|
|
@@ -1,20 +1,264 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ORDER_REFERENCE_SERVICE_TYPE = exports.ORDER_REFERENCE_APP_NAME = exports.ORDER_REFERENCE_VERSION = void 0;
|
|
4
|
+
exports.createSubscriptionOrderReference = createSubscriptionOrderReference;
|
|
5
|
+
exports.createTokenPackOrderReference = createTokenPackOrderReference;
|
|
6
|
+
exports.createUpgradeOrderReference = createUpgradeOrderReference;
|
|
7
|
+
exports.isSubscriptionOrderReference = isSubscriptionOrderReference;
|
|
8
|
+
exports.isTokenPackOrderReference = isTokenPackOrderReference;
|
|
9
|
+
exports.isUpgradeOrderReference = isUpgradeOrderReference;
|
|
10
|
+
exports.getOrderReferencePaymentType = getOrderReferencePaymentType;
|
|
11
|
+
exports.getOrderReferenceItemId = getOrderReferenceItemId;
|
|
12
|
+
exports.getOrderReferenceUserId = getOrderReferenceUserId;
|
|
13
|
+
exports.parseUpgradeOrderReference = parseUpgradeOrderReference;
|
|
4
14
|
exports.parseOrderReference = parseOrderReference;
|
|
5
|
-
|
|
6
|
-
|
|
15
|
+
const ORDER_REFERENCE_VERSION = 'v2';
|
|
16
|
+
exports.ORDER_REFERENCE_VERSION = ORDER_REFERENCE_VERSION;
|
|
17
|
+
const ORDER_REFERENCE_APP_NAME = 'miia';
|
|
18
|
+
exports.ORDER_REFERENCE_APP_NAME = ORDER_REFERENCE_APP_NAME;
|
|
19
|
+
const ORDER_REFERENCE_SERVICE_TYPE = 'bot';
|
|
20
|
+
exports.ORDER_REFERENCE_SERVICE_TYPE = ORDER_REFERENCE_SERVICE_TYPE;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a unique order reference for subscription payments.
|
|
23
|
+
* Format: miia_{platform}_bot_{userId}_sub_{planId}_v2_{utcDate}
|
|
24
|
+
*
|
|
25
|
+
* @param params - Parameters for generating the order reference
|
|
26
|
+
* @returns A unique order reference string
|
|
27
|
+
*/
|
|
28
|
+
function createSubscriptionOrderReference({ userId, platform, planId, utcDate, }) {
|
|
29
|
+
return `${ORDER_REFERENCE_APP_NAME}_${platform}_${ORDER_REFERENCE_SERVICE_TYPE}_${userId}_sub_${planId}_${ORDER_REFERENCE_VERSION}_${utcDate}`;
|
|
7
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a unique order reference for token pack payments.
|
|
33
|
+
* Format: miia_{platform}_bot_{userId}_tkn_{packId}_v2_{utcDate}
|
|
34
|
+
*
|
|
35
|
+
* @param params - Parameters for generating the order reference
|
|
36
|
+
* @returns A unique order reference string
|
|
37
|
+
*/
|
|
38
|
+
function createTokenPackOrderReference({ userId, platform, packId, utcDate, }) {
|
|
39
|
+
return `${ORDER_REFERENCE_APP_NAME}_${platform}_${ORDER_REFERENCE_SERVICE_TYPE}_${userId}_tkn_${packId}_${ORDER_REFERENCE_VERSION}_${utcDate}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates a unique order reference for subscription upgrade payments.
|
|
43
|
+
* Format: miia_{platform}_bot_{userId}_upg_{currentPlanId}_to_{newPlanId}_v2_{utcDate}
|
|
44
|
+
*
|
|
45
|
+
* @param params - Parameters for generating the order reference
|
|
46
|
+
* @returns A unique order reference string
|
|
47
|
+
*/
|
|
48
|
+
function createUpgradeOrderReference({ userId, platform, currentPlanId, newPlanId, utcDate, }) {
|
|
49
|
+
return `${ORDER_REFERENCE_APP_NAME}_${platform}_${ORDER_REFERENCE_SERVICE_TYPE}_${userId}_upg_${currentPlanId}_to_${newPlanId}_${ORDER_REFERENCE_VERSION}_${utcDate}`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Checks if an order reference is for a subscription payment.
|
|
53
|
+
*
|
|
54
|
+
* @param orderReference - The order reference string to check
|
|
55
|
+
* @returns True if the order reference is for a subscription
|
|
56
|
+
*/
|
|
57
|
+
function isSubscriptionOrderReference(orderReference) {
|
|
58
|
+
const parsed = parseOrderReference(orderReference);
|
|
59
|
+
if (!parsed)
|
|
60
|
+
return false;
|
|
61
|
+
// v2 format with explicit type
|
|
62
|
+
if ('paymentType' in parsed && parsed.paymentType === 'sub') {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
// v1 legacy format (all were subscriptions)
|
|
66
|
+
if (parsed.version === 'v1') {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Checks if an order reference is for a token pack payment.
|
|
73
|
+
*
|
|
74
|
+
* @param orderReference - The order reference string to check
|
|
75
|
+
* @returns True if the order reference is for a token pack
|
|
76
|
+
*/
|
|
77
|
+
function isTokenPackOrderReference(orderReference) {
|
|
78
|
+
const parsed = parseOrderReference(orderReference);
|
|
79
|
+
if (!parsed)
|
|
80
|
+
return false;
|
|
81
|
+
return 'paymentType' in parsed && parsed.paymentType === 'tkn';
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Checks if an order reference is for a subscription upgrade payment.
|
|
85
|
+
*
|
|
86
|
+
* @param orderReference - The order reference string to check
|
|
87
|
+
* @returns True if the order reference is for an upgrade
|
|
88
|
+
*/
|
|
89
|
+
function isUpgradeOrderReference(orderReference) {
|
|
90
|
+
const parsed = parseOrderReference(orderReference);
|
|
91
|
+
if (!parsed)
|
|
92
|
+
return false;
|
|
93
|
+
return 'paymentType' in parsed && parsed.paymentType === 'upg';
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parses an upgrade order reference to extract both plan IDs.
|
|
97
|
+
*
|
|
98
|
+
* @param orderReference - The order reference string to parse
|
|
99
|
+
* @returns Parsed upgrade reference with currentPlanId and newPlanId, or null if invalid
|
|
100
|
+
*/
|
|
101
|
+
function parseUpgradeOrderReference(orderReference) {
|
|
102
|
+
const parts = orderReference.split('_');
|
|
103
|
+
// Format: miia_{platform}_bot_{userId}_upg_{currentPlanId}_to_{newPlanId}_v2_{timestamp}
|
|
104
|
+
// Minimum parts: appName, platform, serviceType, userId, upg, currentPlanId, to, newPlanId, version, timestamp
|
|
105
|
+
if (parts.length < 10) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const [appName, platform, serviceType, userId, paymentType] = parts;
|
|
109
|
+
if (paymentType !== 'upg') {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
// Find the 'to' separator to extract plan IDs
|
|
113
|
+
const toIndex = parts.indexOf('to', 5);
|
|
114
|
+
if (toIndex === -1) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
// currentPlanId is between 'upg' (index 4) and 'to'
|
|
118
|
+
const currentPlanId = parts.slice(5, toIndex).join('_');
|
|
119
|
+
// newPlanId is between 'to' and version (which starts with 'v')
|
|
120
|
+
// Find the version index (starts with 'v' and is followed by a number)
|
|
121
|
+
let versionIndex = -1;
|
|
122
|
+
for (let i = toIndex + 1; i < parts.length; i++) {
|
|
123
|
+
if (parts[i].match(/^v\d+$/)) {
|
|
124
|
+
versionIndex = i;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (versionIndex === -1) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const newPlanId = parts.slice(toIndex + 1, versionIndex).join('_');
|
|
132
|
+
const version = parts[versionIndex];
|
|
133
|
+
const timestamp = parts.slice(versionIndex + 1).join('_');
|
|
134
|
+
return {
|
|
135
|
+
appName,
|
|
136
|
+
platform,
|
|
137
|
+
serviceType,
|
|
138
|
+
userId,
|
|
139
|
+
paymentType: 'upg',
|
|
140
|
+
currentPlanId,
|
|
141
|
+
newPlanId,
|
|
142
|
+
version,
|
|
143
|
+
timestamp,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Extracts the payment type from an order reference.
|
|
148
|
+
*
|
|
149
|
+
* @param orderReference - The order reference string
|
|
150
|
+
* @returns The payment type ('sub' or 'tkn'), or null if invalid
|
|
151
|
+
*/
|
|
152
|
+
function getOrderReferencePaymentType(orderReference) {
|
|
153
|
+
const parsed = parseOrderReference(orderReference);
|
|
154
|
+
if (!parsed)
|
|
155
|
+
return null;
|
|
156
|
+
if ('paymentType' in parsed) {
|
|
157
|
+
return parsed.paymentType;
|
|
158
|
+
}
|
|
159
|
+
// v1 legacy format was always subscription
|
|
160
|
+
if (parsed.version === 'v1') {
|
|
161
|
+
return 'sub';
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Extracts the item ID (plan ID or pack ID) from an order reference.
|
|
167
|
+
*
|
|
168
|
+
* @param orderReference - The order reference string
|
|
169
|
+
* @returns The item ID, or null if invalid
|
|
170
|
+
*/
|
|
171
|
+
function getOrderReferenceItemId(orderReference) {
|
|
172
|
+
const parsed = parseOrderReference(orderReference);
|
|
173
|
+
if (!parsed)
|
|
174
|
+
return null;
|
|
175
|
+
if ('itemId' in parsed) {
|
|
176
|
+
return parsed.itemId;
|
|
177
|
+
}
|
|
178
|
+
// v1 legacy format
|
|
179
|
+
if ('planId' in parsed) {
|
|
180
|
+
return parsed.planId;
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Extracts the user ID from an order reference.
|
|
186
|
+
*
|
|
187
|
+
* @param orderReference - The order reference string
|
|
188
|
+
* @returns The user ID, or null if invalid
|
|
189
|
+
*/
|
|
190
|
+
function getOrderReferenceUserId(orderReference) {
|
|
191
|
+
const parsed = parseOrderReference(orderReference);
|
|
192
|
+
return parsed?.userId ?? null;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Parses an order reference string into its components.
|
|
196
|
+
* Supports both v1 (legacy) and v2 (new) formats.
|
|
197
|
+
*
|
|
198
|
+
* v1 format: miia_{platform}_bot_{userId}_{planId}_v1_{timestamp}
|
|
199
|
+
* v2 format: miia_{platform}_bot_{userId}_{type}_{itemId}_v2_{timestamp}
|
|
200
|
+
*
|
|
201
|
+
* @param referenceString - The order reference string to parse
|
|
202
|
+
* @returns Parsed reference object or null if invalid
|
|
203
|
+
*/
|
|
8
204
|
function parseOrderReference(referenceString) {
|
|
9
|
-
|
|
10
|
-
|
|
205
|
+
const parts = referenceString.split('_');
|
|
206
|
+
// Minimum parts: appName, platform, serviceType, userId, planId/type, version, timestamp
|
|
207
|
+
if (parts.length < 7) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
const [appName, platform, serviceType, userId] = parts;
|
|
211
|
+
// Validate required fields
|
|
11
212
|
if (typeof appName !== 'string' ||
|
|
12
213
|
typeof platform !== 'string' ||
|
|
13
214
|
typeof serviceType !== 'string' ||
|
|
14
|
-
typeof userId !== 'string'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
215
|
+
typeof userId !== 'string') {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
// Check for v2 format (has payment type indicator)
|
|
219
|
+
const potentialType = parts[4];
|
|
220
|
+
const isV2Format = potentialType === 'sub' || potentialType === 'tkn' || potentialType === 'upg';
|
|
221
|
+
// Handle upgrade references separately (they have a different structure)
|
|
222
|
+
if (potentialType === 'upg') {
|
|
223
|
+
const upgradeParsed = parseUpgradeOrderReference(referenceString);
|
|
224
|
+
if (upgradeParsed) {
|
|
225
|
+
return {
|
|
226
|
+
appName: upgradeParsed.appName,
|
|
227
|
+
platform: upgradeParsed.platform,
|
|
228
|
+
serviceType: upgradeParsed.serviceType,
|
|
229
|
+
userId: upgradeParsed.userId,
|
|
230
|
+
paymentType: 'upg',
|
|
231
|
+
itemId: upgradeParsed.newPlanId, // Use newPlanId as itemId for compatibility
|
|
232
|
+
version: upgradeParsed.version,
|
|
233
|
+
timestamp: upgradeParsed.timestamp,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
if (isV2Format) {
|
|
239
|
+
// v2 format: miia_{platform}_bot_{userId}_{type}_{itemId}_v2_{timestamp}[_{chargeId}]
|
|
240
|
+
const [, , , , paymentType, itemId, version, timestamp, chargeId] = parts;
|
|
241
|
+
if (typeof paymentType !== 'string' ||
|
|
242
|
+
typeof itemId !== 'string' ||
|
|
243
|
+
typeof version !== 'string' ||
|
|
244
|
+
typeof timestamp !== 'string') {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
appName,
|
|
249
|
+
platform,
|
|
250
|
+
serviceType,
|
|
251
|
+
userId,
|
|
252
|
+
paymentType: paymentType,
|
|
253
|
+
itemId,
|
|
254
|
+
version,
|
|
255
|
+
timestamp,
|
|
256
|
+
chargeId,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
// v1 legacy format: miia_{platform}_bot_{userId}_{planId}_v1_{timestamp}[_{chargeId}]
|
|
260
|
+
const [, , , , planId, version, timestamp, chargeId] = parts;
|
|
261
|
+
if (typeof planId !== 'string' || typeof version !== 'string' || typeof timestamp !== 'string') {
|
|
18
262
|
return null;
|
|
19
263
|
}
|
|
20
264
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/modules/payments/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/modules/payments/utils.ts"],"names":[],"mappings":";;;AA6ZI,4EAAgC;AAChC,sEAA6B;AAC7B,kEAA2B;AAE3B,oEAA4B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EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC;IAE7D,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAC7F,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO;QACH,OAAO;QACP,QAAQ;QACR,WAAW;QACX,MAAM;QACN,MAAM;QACN,OAAO;QACP,SAAS;QACT,QAAQ;KACX,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Logger } from '../logger/types';
|
|
2
|
+
import type { IWayForPayService, GenerateSubscriptionPaymentParams, GenerateOneTimePaymentParams, PaymentUrlResult, SignatureVerificationResult, WayForPayCallbackData, WayForPayWebhookResponse } from './wayforpay.types';
|
|
3
|
+
/**
|
|
4
|
+
* WayForPayService provides integration with the WayForPay payment provider.
|
|
5
|
+
* Supports both subscription (regular) and one-time payment flows.
|
|
6
|
+
*/
|
|
7
|
+
export declare class WayForPayService implements IWayForPayService {
|
|
8
|
+
private readonly logger;
|
|
9
|
+
private readonly merchantAccount;
|
|
10
|
+
private readonly merchantSecretKey;
|
|
11
|
+
private readonly merchantDomainName;
|
|
12
|
+
private readonly serviceUrl?;
|
|
13
|
+
constructor({ logger, merchantAccount, merchantSecretKey, merchantDomainName, serviceUrl, }: {
|
|
14
|
+
logger: Logger;
|
|
15
|
+
merchantAccount?: string;
|
|
16
|
+
merchantSecretKey?: string;
|
|
17
|
+
merchantDomainName?: string;
|
|
18
|
+
serviceUrl?: string;
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Generates a payment URL for subscription (regular) payments.
|
|
22
|
+
*/
|
|
23
|
+
generateSubscriptionPaymentUrl(params: GenerateSubscriptionPaymentParams): Promise<PaymentUrlResult | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Generates a payment URL for one-time payments.
|
|
26
|
+
*/
|
|
27
|
+
generateOneTimePaymentUrl(params: GenerateOneTimePaymentParams): Promise<PaymentUrlResult | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Verifies the signature of a WayForPay webhook callback.
|
|
30
|
+
* The signature is calculated as HMAC_MD5 of concatenated values.
|
|
31
|
+
*/
|
|
32
|
+
verifyCallbackSignature(callbackData: WayForPayCallbackData): SignatureVerificationResult;
|
|
33
|
+
/**
|
|
34
|
+
* Builds a response to send back to WayForPay after processing a webhook.
|
|
35
|
+
* WayForPay expects a signed response to confirm receipt.
|
|
36
|
+
*/
|
|
37
|
+
buildWebhookResponse(orderReference: string, status: 'accept' | 'decline'): WayForPayWebhookResponse;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=wayforpay.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wayforpay.service.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/wayforpay.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,KAAK,EACR,iBAAiB,EACjB,iCAAiC,EACjC,4BAA4B,EAC5B,gBAAgB,EAChB,2BAA2B,EAC3B,qBAAqB,EACrB,wBAAwB,EAC3B,MAAM,mBAAmB,CAAC;AAS3B;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,iBAAiB;IACtD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAS;IAC5C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAS;gBAEzB,EACR,MAAM,EACN,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,GACb,EAAE;QACC,MAAM,EAAE,MAAM,CAAC;QACf,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,iBAAiB,CAAC,EAAE,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