@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
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all custom errors in the payment system.
|
|
3
|
+
* Provides consistent error structure with code, message, and optional context.
|
|
4
|
+
*/
|
|
5
|
+
export abstract class BaseError extends Error {
|
|
6
|
+
public readonly code: string;
|
|
7
|
+
public readonly context?: Record<string, unknown>;
|
|
8
|
+
public readonly timestamp: Date;
|
|
9
|
+
|
|
10
|
+
constructor(message: string, code: string, context?: Record<string, unknown>) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = this.constructor.name;
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.timestamp = new Date();
|
|
16
|
+
|
|
17
|
+
// Maintains proper stack trace for where error was thrown (only in V8)
|
|
18
|
+
if (Error.captureStackTrace) {
|
|
19
|
+
Error.captureStackTrace(this, this.constructor);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns a structured representation of the error for logging
|
|
25
|
+
*/
|
|
26
|
+
public toJSON(): Record<string, unknown> {
|
|
27
|
+
return {
|
|
28
|
+
name: this.name,
|
|
29
|
+
message: this.message,
|
|
30
|
+
code: this.code,
|
|
31
|
+
context: this.context,
|
|
32
|
+
timestamp: this.timestamp.toISOString(),
|
|
33
|
+
stack: this.stack,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Error codes for payment-related failures
|
|
40
|
+
*/
|
|
41
|
+
export enum PaymentErrorCode {
|
|
42
|
+
CREATE_FAILED = 'PAYMENT_CREATE_FAILED',
|
|
43
|
+
UPDATE_FAILED = 'PAYMENT_UPDATE_FAILED',
|
|
44
|
+
PROCESSING_FAILED = 'PAYMENT_PROCESSING_FAILED',
|
|
45
|
+
CALLBACK_FAILED = 'PAYMENT_CALLBACK_FAILED',
|
|
46
|
+
INVALID_RESPONSE = 'PAYMENT_INVALID_RESPONSE',
|
|
47
|
+
PROVIDER_ERROR = 'PAYMENT_PROVIDER_ERROR',
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Error class for payment-related failures.
|
|
52
|
+
* Use for errors during payment creation, processing, or provider communication.
|
|
53
|
+
*/
|
|
54
|
+
export class PaymentError extends BaseError {
|
|
55
|
+
constructor(
|
|
56
|
+
message: string,
|
|
57
|
+
code: PaymentErrorCode = PaymentErrorCode.PROCESSING_FAILED,
|
|
58
|
+
context?: Record<string, unknown>
|
|
59
|
+
) {
|
|
60
|
+
super(message, code, context);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Error codes for subscription-related failures
|
|
66
|
+
*/
|
|
67
|
+
export enum SubscriptionErrorCode {
|
|
68
|
+
CREATE_FAILED = 'SUBSCRIPTION_CREATE_FAILED',
|
|
69
|
+
UPDATE_FAILED = 'SUBSCRIPTION_UPDATE_FAILED',
|
|
70
|
+
CANCEL_FAILED = 'SUBSCRIPTION_CANCEL_FAILED',
|
|
71
|
+
RENEWAL_FAILED = 'SUBSCRIPTION_RENEWAL_FAILED',
|
|
72
|
+
INVALID_STATUS = 'SUBSCRIPTION_INVALID_STATUS',
|
|
73
|
+
EXPIRED = 'SUBSCRIPTION_EXPIRED',
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Error class for subscription-related failures.
|
|
78
|
+
* Use for errors during subscription lifecycle operations.
|
|
79
|
+
*/
|
|
80
|
+
export class SubscriptionError extends BaseError {
|
|
81
|
+
constructor(
|
|
82
|
+
message: string,
|
|
83
|
+
code: SubscriptionErrorCode = SubscriptionErrorCode.UPDATE_FAILED,
|
|
84
|
+
context?: Record<string, unknown>
|
|
85
|
+
) {
|
|
86
|
+
super(message, code, context);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Error codes for validation failures
|
|
92
|
+
*/
|
|
93
|
+
export enum ValidationErrorCode {
|
|
94
|
+
INVALID_SIGNATURE = 'VALIDATION_INVALID_SIGNATURE',
|
|
95
|
+
INVALID_INPUT = 'VALIDATION_INVALID_INPUT',
|
|
96
|
+
MISSING_REQUIRED_FIELD = 'VALIDATION_MISSING_REQUIRED_FIELD',
|
|
97
|
+
INVALID_FORMAT = 'VALIDATION_INVALID_FORMAT',
|
|
98
|
+
SIGNATURE_MISMATCH = 'VALIDATION_SIGNATURE_MISMATCH',
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Error class for signature and input validation failures.
|
|
103
|
+
* Use for errors when validating signatures, inputs, or data formats.
|
|
104
|
+
*/
|
|
105
|
+
export class ValidationError extends BaseError {
|
|
106
|
+
public readonly field?: string;
|
|
107
|
+
|
|
108
|
+
constructor(
|
|
109
|
+
message: string,
|
|
110
|
+
code: ValidationErrorCode = ValidationErrorCode.INVALID_INPUT,
|
|
111
|
+
context?: Record<string, unknown>,
|
|
112
|
+
field?: string
|
|
113
|
+
) {
|
|
114
|
+
super(message, code, context);
|
|
115
|
+
this.field = field;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public toJSON(): Record<string, unknown> {
|
|
119
|
+
return {
|
|
120
|
+
...super.toJSON(),
|
|
121
|
+
field: this.field,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Error codes for not found errors
|
|
128
|
+
*/
|
|
129
|
+
export enum NotFoundErrorCode {
|
|
130
|
+
PAYMENT_NOT_FOUND = 'NOT_FOUND_PAYMENT',
|
|
131
|
+
SUBSCRIPTION_NOT_FOUND = 'NOT_FOUND_SUBSCRIPTION',
|
|
132
|
+
USER_NOT_FOUND = 'NOT_FOUND_USER',
|
|
133
|
+
PLAN_NOT_FOUND = 'NOT_FOUND_PLAN',
|
|
134
|
+
INVOICE_NOT_FOUND = 'NOT_FOUND_INVOICE',
|
|
135
|
+
TOKEN_PACK_NOT_FOUND = 'NOT_FOUND_TOKEN_PACK',
|
|
136
|
+
RESOURCE_NOT_FOUND = 'NOT_FOUND_RESOURCE',
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Error class for missing resources.
|
|
141
|
+
* Use when a requested entity cannot be found.
|
|
142
|
+
*/
|
|
143
|
+
export class NotFoundError extends BaseError {
|
|
144
|
+
public readonly resourceType?: string;
|
|
145
|
+
public readonly resourceId?: string;
|
|
146
|
+
|
|
147
|
+
constructor(
|
|
148
|
+
message: string,
|
|
149
|
+
code: NotFoundErrorCode = NotFoundErrorCode.RESOURCE_NOT_FOUND,
|
|
150
|
+
context?: Record<string, unknown>,
|
|
151
|
+
resourceType?: string,
|
|
152
|
+
resourceId?: string
|
|
153
|
+
) {
|
|
154
|
+
super(message, code, context);
|
|
155
|
+
this.resourceType = resourceType;
|
|
156
|
+
this.resourceId = resourceId;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public toJSON(): Record<string, unknown> {
|
|
160
|
+
return {
|
|
161
|
+
...super.toJSON(),
|
|
162
|
+
resourceType: this.resourceType,
|
|
163
|
+
resourceId: this.resourceId,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Type guard to check if an error is a BaseError
|
|
170
|
+
*/
|
|
171
|
+
export function isBaseError(error: unknown): error is BaseError {
|
|
172
|
+
return error instanceof BaseError;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Type guard to check if an error is a PaymentError
|
|
177
|
+
*/
|
|
178
|
+
export function isPaymentError(error: unknown): error is PaymentError {
|
|
179
|
+
return error instanceof PaymentError;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Type guard to check if an error is a SubscriptionError
|
|
184
|
+
*/
|
|
185
|
+
export function isSubscriptionError(error: unknown): error is SubscriptionError {
|
|
186
|
+
return error instanceof SubscriptionError;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Type guard to check if an error is a ValidationError
|
|
191
|
+
*/
|
|
192
|
+
export function isValidationError(error: unknown): error is ValidationError {
|
|
193
|
+
return error instanceof ValidationError;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Type guard to check if an error is a NotFoundError
|
|
198
|
+
*/
|
|
199
|
+
export function isNotFoundError(error: unknown): error is NotFoundError {
|
|
200
|
+
return error instanceof NotFoundError;
|
|
201
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Firestore, getFirestore, QueryDocumentSnapshot } from 'firebase-admin/firestore';
|
|
2
|
+
import { InvoiceEntity, IInvoiceRepository } from './types';
|
|
3
|
+
import { DEFAULT_INVOICE_ENTITY } from './const';
|
|
4
|
+
|
|
5
|
+
class InvoiceRepository implements IInvoiceRepository {
|
|
6
|
+
private readonly db: Firestore;
|
|
7
|
+
private readonly collectionName = 'invoices';
|
|
8
|
+
|
|
9
|
+
constructor({ db }: { db?: Firestore } = {}) {
|
|
10
|
+
this.db = db || getFirestore();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public async getByOrderReference(orderReference: string): Promise<InvoiceEntity | null> {
|
|
14
|
+
const querySnapshot = await this.db
|
|
15
|
+
.collection(this.collectionName)
|
|
16
|
+
.where('orderReference', '==', orderReference)
|
|
17
|
+
.limit(1)
|
|
18
|
+
.get();
|
|
19
|
+
|
|
20
|
+
if (querySnapshot.empty) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const doc = querySnapshot.docs[0];
|
|
25
|
+
return this.mapDocumentToEntity(doc);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public async create(invoiceData: Omit<InvoiceEntity, 'id'>): Promise<InvoiceEntity> {
|
|
29
|
+
// Generate a new document reference to get the ID first
|
|
30
|
+
const docRef = this.db.collection(this.collectionName).doc();
|
|
31
|
+
|
|
32
|
+
const invoiceEntity: InvoiceEntity = {
|
|
33
|
+
id: docRef.id,
|
|
34
|
+
...DEFAULT_INVOICE_ENTITY,
|
|
35
|
+
...invoiceData,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Use set() to create the document with the ID included in the data
|
|
39
|
+
await docRef.set(invoiceEntity);
|
|
40
|
+
|
|
41
|
+
return invoiceEntity;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private mapDocumentToEntity(doc: QueryDocumentSnapshot): InvoiceEntity {
|
|
45
|
+
return {
|
|
46
|
+
id: doc.id,
|
|
47
|
+
...doc.data(),
|
|
48
|
+
} as InvoiceEntity;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { InvoiceRepository };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Logger } from '../logger/types';
|
|
2
|
+
import { InvoiceRepository } from './repository';
|
|
3
|
+
import { InvoiceEntity, IInvoiceRepository, IInvoiceService } from './types';
|
|
4
|
+
|
|
5
|
+
export class InvoiceService implements IInvoiceService {
|
|
6
|
+
private readonly logger: Logger;
|
|
7
|
+
private readonly repository: IInvoiceRepository;
|
|
8
|
+
|
|
9
|
+
constructor({ logger, repository }: { logger: Logger; repository?: IInvoiceRepository }) {
|
|
10
|
+
this.logger = logger;
|
|
11
|
+
this.repository = repository || new InvoiceRepository();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public async create(invoiceData: Omit<InvoiceEntity, 'id'>): Promise<InvoiceEntity> {
|
|
15
|
+
try {
|
|
16
|
+
return await this.repository.create(invoiceData);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
this.logger.error({
|
|
19
|
+
message: 'Error in invoice service create',
|
|
20
|
+
payload: {
|
|
21
|
+
orderReference: invoiceData.orderReference,
|
|
22
|
+
error: JSON.stringify(error),
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public async getByOrderReference(orderReference: string): Promise<InvoiceEntity | null> {
|
|
31
|
+
try {
|
|
32
|
+
return await this.repository.getByOrderReference(orderReference);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
this.logger.error({
|
|
35
|
+
message: 'Error in invoice service getByOrderReference',
|
|
36
|
+
payload: {
|
|
37
|
+
orderReference,
|
|
38
|
+
error: JSON.stringify(error),
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
type InvoiceEntity = {
|
|
2
|
+
id: string;
|
|
3
|
+
merchantAccount: string;
|
|
4
|
+
orderReference: string;
|
|
5
|
+
merchantSignature: string;
|
|
6
|
+
reasonCode: number;
|
|
7
|
+
reason: string;
|
|
8
|
+
createdDate: string;
|
|
9
|
+
processingDate: string;
|
|
10
|
+
currency: string;
|
|
11
|
+
amount: number;
|
|
12
|
+
chargeId?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Interface for invoice repository operations.
|
|
17
|
+
* Defines the contract for data access layer.
|
|
18
|
+
*/
|
|
19
|
+
interface IInvoiceRepository {
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves an invoice by its order reference.
|
|
22
|
+
*/
|
|
23
|
+
getByOrderReference(orderReference: string): Promise<InvoiceEntity | null>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new invoice record in the database.
|
|
27
|
+
*/
|
|
28
|
+
create(invoiceData: Omit<InvoiceEntity, 'id'>): Promise<InvoiceEntity>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Interface for invoice service operations.
|
|
33
|
+
* Defines the contract for business logic layer.
|
|
34
|
+
*/
|
|
35
|
+
interface IInvoiceService {
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new invoice.
|
|
38
|
+
*/
|
|
39
|
+
create(invoiceData: Omit<InvoiceEntity, 'id'>): Promise<InvoiceEntity>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves an invoice by order reference.
|
|
43
|
+
*/
|
|
44
|
+
getByOrderReference(orderReference: string): Promise<InvoiceEntity | null>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type { InvoiceEntity, IInvoiceRepository, IInvoiceService };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function mockTimeoutResponse({
|
|
2
|
+
// timeout = 12000,
|
|
3
|
+
timeout = 1002000,
|
|
4
|
+
rejectedCode = 'RESPONSE_TIMEOUT',
|
|
5
|
+
} = {}): {
|
|
6
|
+
promise: Promise<never>;
|
|
7
|
+
cleanUp: () => void;
|
|
8
|
+
} {
|
|
9
|
+
let timeoutId;
|
|
10
|
+
const promise = new Promise<never>(function (_, reject) {
|
|
11
|
+
timeoutId = setTimeout(() => {
|
|
12
|
+
reject({
|
|
13
|
+
code: rejectedCode,
|
|
14
|
+
});
|
|
15
|
+
}, timeout);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
promise,
|
|
20
|
+
cleanUp: () => clearTimeout(timeoutId),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { mockTimeoutResponse };
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import {
|
|
3
|
+
Currency,
|
|
4
|
+
editRegularPurchase,
|
|
5
|
+
generateRegularPurchase,
|
|
6
|
+
generatePurchase,
|
|
7
|
+
Language,
|
|
8
|
+
} from '@misterhomer1992/wayforpay-api';
|
|
9
|
+
import { isObject, isBadOrEmptyString } from '../../utils';
|
|
10
|
+
import { createSubscriptionOrderReference, createTokenPackOrderReference, createUpgradeOrderReference } from './utils';
|
|
11
|
+
|
|
12
|
+
interface WayforpayResponse {
|
|
13
|
+
url?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a payment API URL for regular purchases via Wayforpay.
|
|
19
|
+
* Generates a unique order reference and creates a payment URL with the provided parameters.
|
|
20
|
+
*
|
|
21
|
+
* @param params - Payment creation parameters
|
|
22
|
+
* @param params.userId - The unique identifier of the user making the payment
|
|
23
|
+
* @param params.platform - The application namespace (e.g., 'app' or 'telegram')
|
|
24
|
+
* @param params.productName - The name of the product being purchased
|
|
25
|
+
* @param params.productPrice - The price of the product
|
|
26
|
+
* @param params.planId - The identifier of the subscription plan
|
|
27
|
+
* @param params.dateNext - Optional date for the next payment in the regular purchase cycle
|
|
28
|
+
* @param params.currency - The currency code (e.g., 'UAH', 'USD')
|
|
29
|
+
* @param params.regularCount - Optional number of regular payments (defaults to 3)
|
|
30
|
+
* @returns Promise resolving to an object containing the payment URL and order reference, or null
|
|
31
|
+
* @throws Error with code 'CREATE_PAYMENT_API' if the API response is invalid or missing URL
|
|
32
|
+
*/
|
|
33
|
+
async function createPaymentAPI({
|
|
34
|
+
userId,
|
|
35
|
+
platform,
|
|
36
|
+
productName,
|
|
37
|
+
productPrice,
|
|
38
|
+
planId,
|
|
39
|
+
dateNext,
|
|
40
|
+
currency,
|
|
41
|
+
regularCount = 3,
|
|
42
|
+
regularMode = 'daily',
|
|
43
|
+
language = 'UA',
|
|
44
|
+
}: {
|
|
45
|
+
userId: string;
|
|
46
|
+
platform: string;
|
|
47
|
+
productName: string;
|
|
48
|
+
productPrice: number;
|
|
49
|
+
planId: string;
|
|
50
|
+
dateNext?: string;
|
|
51
|
+
currency: string;
|
|
52
|
+
regularCount?: number;
|
|
53
|
+
regularMode?: 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
54
|
+
language?: string;
|
|
55
|
+
}): Promise<{ url: string; orderReference: string } | null> {
|
|
56
|
+
const orderDate = Date.now();
|
|
57
|
+
const formattedUtc = moment.utc().toISOString();
|
|
58
|
+
const orderReference = createSubscriptionOrderReference({
|
|
59
|
+
userId,
|
|
60
|
+
platform,
|
|
61
|
+
planId,
|
|
62
|
+
utcDate: formattedUtc,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const response = (await generateRegularPurchase({
|
|
66
|
+
merchantAccount: process.env.WAYFORPAY_MERCHANT_ACCOUNT as string,
|
|
67
|
+
merchantDomainName: process.env.WAYFORPAY_MERCHANT_DOMAIN as string,
|
|
68
|
+
merchantSecretKey: process.env.WAYFORPAY_MERCHANT_SECRET_KEY as string,
|
|
69
|
+
orderDate,
|
|
70
|
+
orderReference,
|
|
71
|
+
productName: [productName],
|
|
72
|
+
productPrice: [productPrice],
|
|
73
|
+
currency: currency as Currency,
|
|
74
|
+
language: language as Language,
|
|
75
|
+
serviceUrl: process.env.WAYFORPAY_SERVICE_URL as string,
|
|
76
|
+
regularMode,
|
|
77
|
+
regularCount,
|
|
78
|
+
dateNext,
|
|
79
|
+
})) as WayforpayResponse;
|
|
80
|
+
|
|
81
|
+
if (!isObject(response) || isBadOrEmptyString(response.url)) {
|
|
82
|
+
throw {
|
|
83
|
+
code: 'CREATE_PAYMENT_API',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
url: response.url,
|
|
89
|
+
orderReference,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Edits an existing regular purchase via Wayforpay.
|
|
95
|
+
* Updates the parameters of an existing recurring payment schedule.
|
|
96
|
+
*
|
|
97
|
+
* @param params - Parameters for editing the regular purchase
|
|
98
|
+
* @param params.orderReference - The unique reference of the order to edit
|
|
99
|
+
* @param params.amount - The new payment amount
|
|
100
|
+
* @param params.dateBegin - The start date for the regular purchase in DD.MM.YYYY format
|
|
101
|
+
* @param params.dateEnd - The end date for the regular purchase in DD.MM.YYYY format
|
|
102
|
+
* @param params.regularMode - The frequency mode for regular payments
|
|
103
|
+
* @returns Promise resolving to the Wayforpay API response
|
|
104
|
+
* @throws Error with code 'EDIT_REGULAR_PURCHASE_API' if the API response is invalid
|
|
105
|
+
*/
|
|
106
|
+
async function editRegularPurchaseAPI({
|
|
107
|
+
orderReference,
|
|
108
|
+
amount,
|
|
109
|
+
dateBegin,
|
|
110
|
+
dateEnd,
|
|
111
|
+
regularMode,
|
|
112
|
+
currency,
|
|
113
|
+
}: {
|
|
114
|
+
orderReference: string;
|
|
115
|
+
amount: number;
|
|
116
|
+
dateBegin: string;
|
|
117
|
+
dateEnd: string;
|
|
118
|
+
regularMode: 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
119
|
+
currency: string;
|
|
120
|
+
}): Promise<WayforpayResponse> {
|
|
121
|
+
const response = await editRegularPurchase({
|
|
122
|
+
merchantAccount: process.env.WAYFORPAY_MERCHANT_ACCOUNT as string,
|
|
123
|
+
merchantPassword: process.env.WAYFORPAY_MERCHANT_PASSWORD as string,
|
|
124
|
+
orderReference,
|
|
125
|
+
amount,
|
|
126
|
+
dateBegin,
|
|
127
|
+
dateEnd,
|
|
128
|
+
regularMode,
|
|
129
|
+
currency: currency as Currency,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (!isObject(response)) {
|
|
133
|
+
throw {
|
|
134
|
+
code: 'EDIT_REGULAR_PURCHASE_API',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return response;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates a one-time payment API URL for token pack purchases via Wayforpay.
|
|
143
|
+
* Generates a unique order reference using the v2 token pack format.
|
|
144
|
+
*
|
|
145
|
+
* @param params - Payment creation parameters
|
|
146
|
+
* @param params.userId - The unique identifier of the user making the payment
|
|
147
|
+
* @param params.platform - The application namespace (e.g., 'app' or 'telegram')
|
|
148
|
+
* @param params.productName - The name of the token pack being purchased
|
|
149
|
+
* @param params.productPrice - The price of the token pack
|
|
150
|
+
* @param params.packId - The identifier of the token pack
|
|
151
|
+
* @param params.currency - The currency code (e.g., 'UAH', 'USD')
|
|
152
|
+
* @param params.language - The language for the payment page (defaults to 'UA')
|
|
153
|
+
* @param params.returnUrl - Optional URL to redirect to after payment
|
|
154
|
+
* @returns Promise resolving to an object containing the payment URL and order reference, or null
|
|
155
|
+
* @throws Error with code 'CREATE_TOKEN_PACK_PAYMENT_API' if the API response is invalid or missing URL
|
|
156
|
+
*/
|
|
157
|
+
async function createTokenPackPaymentAPI({
|
|
158
|
+
userId,
|
|
159
|
+
platform,
|
|
160
|
+
productName,
|
|
161
|
+
productPrice,
|
|
162
|
+
packId,
|
|
163
|
+
currency,
|
|
164
|
+
language = 'UA',
|
|
165
|
+
returnUrl,
|
|
166
|
+
}: {
|
|
167
|
+
userId: string;
|
|
168
|
+
platform: string;
|
|
169
|
+
productName: string;
|
|
170
|
+
productPrice: number;
|
|
171
|
+
packId: string;
|
|
172
|
+
currency: string;
|
|
173
|
+
language?: string;
|
|
174
|
+
returnUrl?: string;
|
|
175
|
+
}): Promise<{ url: string; orderReference: string } | null> {
|
|
176
|
+
const orderDate = Date.now();
|
|
177
|
+
const formattedUtc = moment.utc().toISOString();
|
|
178
|
+
const orderReference = createTokenPackOrderReference({
|
|
179
|
+
userId,
|
|
180
|
+
platform,
|
|
181
|
+
packId,
|
|
182
|
+
utcDate: formattedUtc,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const response = (await generatePurchase({
|
|
186
|
+
merchantAccount: process.env.WAYFORPAY_MERCHANT_ACCOUNT as string,
|
|
187
|
+
merchantDomainName: process.env.WAYFORPAY_MERCHANT_DOMAIN as string,
|
|
188
|
+
merchantSecretKey: process.env.WAYFORPAY_MERCHANT_SECRET_KEY as string,
|
|
189
|
+
orderDate,
|
|
190
|
+
orderReference,
|
|
191
|
+
productName: [productName],
|
|
192
|
+
productPrice: [productPrice],
|
|
193
|
+
currency: currency as Currency,
|
|
194
|
+
language: language as Language,
|
|
195
|
+
serviceUrl: process.env.WAYFORPAY_SERVICE_URL as string,
|
|
196
|
+
returnUrl,
|
|
197
|
+
})) as WayforpayResponse;
|
|
198
|
+
|
|
199
|
+
if (!isObject(response) || isBadOrEmptyString(response.url)) {
|
|
200
|
+
throw {
|
|
201
|
+
code: 'CREATE_TOKEN_PACK_PAYMENT_API',
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
url: response.url,
|
|
207
|
+
orderReference,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Creates a recurring payment API URL for subscription upgrades via Wayforpay.
|
|
213
|
+
* Generates a unique order reference using the upgrade format.
|
|
214
|
+
*
|
|
215
|
+
* @param params - Payment creation parameters
|
|
216
|
+
* @param params.userId - The unique identifier of the user making the payment
|
|
217
|
+
* @param params.platform - The application namespace (e.g., 'app' or 'telegram')
|
|
218
|
+
* @param params.currentPlanId - The identifier of the current subscription plan
|
|
219
|
+
* @param params.newPlanId - The identifier of the new subscription plan to upgrade to
|
|
220
|
+
* @param params.productName - The name of the upgraded plan being purchased
|
|
221
|
+
* @param params.productPrice - The price difference (upgrade cost)
|
|
222
|
+
* @param params.currency - The currency code (e.g., 'UAH', 'USD')
|
|
223
|
+
* @param params.regularMode - The frequency mode for regular payments
|
|
224
|
+
* @param params.regularCount - Number of regular payments (defaults to 3)
|
|
225
|
+
* @param params.language - The language for the payment page (defaults to 'UA')
|
|
226
|
+
* @returns Promise resolving to an object containing the payment URL and order reference, or null
|
|
227
|
+
* @throws Error with code 'CREATE_UPGRADE_PAYMENT_API' if the API response is invalid or missing URL
|
|
228
|
+
*/
|
|
229
|
+
async function createUpgradePaymentAPI({
|
|
230
|
+
userId,
|
|
231
|
+
platform,
|
|
232
|
+
currentPlanId,
|
|
233
|
+
newPlanId,
|
|
234
|
+
productName,
|
|
235
|
+
productPrice,
|
|
236
|
+
currency,
|
|
237
|
+
regularMode = 'monthly',
|
|
238
|
+
regularCount = 3,
|
|
239
|
+
language = 'UA',
|
|
240
|
+
}: {
|
|
241
|
+
userId: string;
|
|
242
|
+
platform: string;
|
|
243
|
+
currentPlanId: string;
|
|
244
|
+
newPlanId: string;
|
|
245
|
+
productName: string;
|
|
246
|
+
productPrice: number;
|
|
247
|
+
currency: string;
|
|
248
|
+
regularMode?: 'daily' | 'monthly' | 'yearly';
|
|
249
|
+
regularCount?: number;
|
|
250
|
+
language?: string;
|
|
251
|
+
}): Promise<{ url: string; orderReference: string } | null> {
|
|
252
|
+
const orderDate = Date.now();
|
|
253
|
+
const formattedUtc = moment.utc().toISOString();
|
|
254
|
+
const orderReference = createUpgradeOrderReference({
|
|
255
|
+
userId,
|
|
256
|
+
platform,
|
|
257
|
+
currentPlanId,
|
|
258
|
+
newPlanId,
|
|
259
|
+
utcDate: formattedUtc,
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const response = (await generateRegularPurchase({
|
|
263
|
+
merchantAccount: process.env.WAYFORPAY_MERCHANT_ACCOUNT as string,
|
|
264
|
+
merchantDomainName: process.env.WAYFORPAY_MERCHANT_DOMAIN as string,
|
|
265
|
+
merchantSecretKey: process.env.WAYFORPAY_MERCHANT_SECRET_KEY as string,
|
|
266
|
+
orderDate,
|
|
267
|
+
orderReference,
|
|
268
|
+
productName: [productName],
|
|
269
|
+
productPrice: [productPrice],
|
|
270
|
+
currency: currency as Currency,
|
|
271
|
+
language: language as Language,
|
|
272
|
+
serviceUrl: process.env.WAYFORPAY_SERVICE_URL as string,
|
|
273
|
+
regularMode,
|
|
274
|
+
regularCount,
|
|
275
|
+
})) as WayforpayResponse;
|
|
276
|
+
|
|
277
|
+
if (!isObject(response) || isBadOrEmptyString(response.url)) {
|
|
278
|
+
throw {
|
|
279
|
+
code: 'CREATE_UPGRADE_PAYMENT_API',
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return {
|
|
284
|
+
url: response.url,
|
|
285
|
+
orderReference,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export { createPaymentAPI, editRegularPurchaseAPI, createTokenPackPaymentAPI, createUpgradePaymentAPI };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PaymentEntity } from './types';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_PAYMENT_ENTITY: Partial<PaymentEntity> = {
|
|
4
|
+
status: 'pending',
|
|
5
|
+
provider: 'wayforpay',
|
|
6
|
+
platform: 'telegram',
|
|
7
|
+
currency: 'UAH',
|
|
8
|
+
paymentType: 'subscription',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { DEFAULT_PAYMENT_ENTITY };
|