@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.
Files changed (248) hide show
  1. package/dist/config/ConfigurationManager.d.ts +64 -0
  2. package/dist/config/ConfigurationManager.d.ts.map +1 -0
  3. package/dist/config/ConfigurationManager.js +144 -0
  4. package/dist/config/ConfigurationManager.js.map +1 -0
  5. package/dist/config/defaults.d.ts +18 -0
  6. package/dist/config/defaults.d.ts.map +1 -0
  7. package/dist/config/defaults.js +26 -0
  8. package/dist/config/defaults.js.map +1 -0
  9. package/dist/config/environment.d.ts +38 -0
  10. package/dist/config/environment.d.ts.map +1 -0
  11. package/dist/config/environment.js +91 -0
  12. package/dist/config/environment.js.map +1 -0
  13. package/dist/config/index.d.ts +5 -0
  14. package/dist/config/index.d.ts.map +1 -0
  15. package/dist/config/index.js +18 -0
  16. package/dist/config/index.js.map +1 -0
  17. package/dist/config/types.d.ts +53 -0
  18. package/dist/config/types.d.ts.map +1 -0
  19. package/dist/config/types.js +3 -0
  20. package/dist/config/types.js.map +1 -0
  21. package/dist/index.d.ts +21 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +23 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/modules/cache/InMemoryCache.d.ts +17 -0
  26. package/dist/modules/cache/InMemoryCache.d.ts.map +1 -0
  27. package/dist/modules/cache/InMemoryCache.js +77 -0
  28. package/dist/modules/cache/InMemoryCache.js.map +1 -0
  29. package/dist/modules/cache/index.d.ts +3 -0
  30. package/dist/modules/cache/index.d.ts.map +1 -0
  31. package/dist/modules/cache/index.js +19 -0
  32. package/dist/modules/cache/index.js.map +1 -0
  33. package/dist/modules/cache/types.d.ts +52 -0
  34. package/dist/modules/cache/types.d.ts.map +1 -0
  35. package/dist/modules/cache/types.js +3 -0
  36. package/dist/modules/cache/types.js.map +1 -0
  37. package/dist/modules/errors/index.d.ts +2 -0
  38. package/dist/modules/errors/index.d.ts.map +1 -0
  39. package/dist/modules/errors/index.js +19 -0
  40. package/dist/modules/errors/index.js.map +1 -0
  41. package/dist/modules/errors/types.d.ts +112 -0
  42. package/dist/modules/errors/types.d.ts.map +1 -0
  43. package/dist/modules/errors/types.js +174 -0
  44. package/dist/modules/errors/types.js.map +1 -0
  45. package/dist/modules/payments/api.d.ts +63 -1
  46. package/dist/modules/payments/api.d.ts.map +1 -1
  47. package/dist/modules/payments/api.js +103 -1
  48. package/dist/modules/payments/api.js.map +1 -1
  49. package/dist/modules/payments/const.d.ts.map +1 -1
  50. package/dist/modules/payments/const.js +1 -0
  51. package/dist/modules/payments/const.js.map +1 -1
  52. package/dist/modules/payments/index.d.ts +8 -0
  53. package/dist/modules/payments/index.d.ts.map +1 -1
  54. package/dist/modules/payments/index.js +8 -0
  55. package/dist/modules/payments/index.js.map +1 -1
  56. package/dist/modules/payments/service.d.ts +42 -2
  57. package/dist/modules/payments/service.d.ts.map +1 -1
  58. package/dist/modules/payments/service.js +132 -3
  59. package/dist/modules/payments/service.js.map +1 -1
  60. package/dist/modules/payments/subscription-check-webhook.handler.d.ts +85 -0
  61. package/dist/modules/payments/subscription-check-webhook.handler.d.ts.map +1 -0
  62. package/dist/modules/payments/subscription-check-webhook.handler.js +155 -0
  63. package/dist/modules/payments/subscription-check-webhook.handler.js.map +1 -0
  64. package/dist/modules/payments/subscription-check-webhook.service.d.ts +59 -0
  65. package/dist/modules/payments/subscription-check-webhook.service.d.ts.map +1 -0
  66. package/dist/modules/payments/subscription-check-webhook.service.js +330 -0
  67. package/dist/modules/payments/subscription-check-webhook.service.js.map +1 -0
  68. package/dist/modules/payments/subscription-check-webhook.types.d.ts +25 -0
  69. package/dist/modules/payments/subscription-check-webhook.types.d.ts.map +1 -0
  70. package/dist/modules/payments/subscription-check-webhook.types.js +3 -0
  71. package/dist/modules/payments/subscription-check-webhook.types.js.map +1 -0
  72. package/dist/modules/payments/types.d.ts +69 -2
  73. package/dist/modules/payments/types.d.ts.map +1 -1
  74. package/dist/modules/payments/utils.d.ts +151 -5
  75. package/dist/modules/payments/utils.d.ts.map +1 -1
  76. package/dist/modules/payments/utils.js +253 -9
  77. package/dist/modules/payments/utils.js.map +1 -1
  78. package/dist/modules/payments/wayforpay.service.d.ts +39 -0
  79. package/dist/modules/payments/wayforpay.service.d.ts.map +1 -0
  80. package/dist/modules/payments/wayforpay.service.js +217 -0
  81. package/dist/modules/payments/wayforpay.service.js.map +1 -0
  82. package/dist/modules/payments/wayforpay.types.d.ts +115 -0
  83. package/dist/modules/payments/wayforpay.types.d.ts.map +1 -0
  84. package/dist/modules/payments/wayforpay.types.js +3 -0
  85. package/dist/modules/payments/wayforpay.types.js.map +1 -0
  86. package/dist/modules/payments/webhook.handler.d.ts +98 -0
  87. package/dist/modules/payments/webhook.handler.d.ts.map +1 -0
  88. package/dist/modules/payments/webhook.handler.js +153 -0
  89. package/dist/modules/payments/webhook.handler.js.map +1 -0
  90. package/dist/modules/payments/webhook.service.d.ts +99 -0
  91. package/dist/modules/payments/webhook.service.d.ts.map +1 -0
  92. package/dist/modules/payments/webhook.service.js +672 -0
  93. package/dist/modules/payments/webhook.service.js.map +1 -0
  94. package/dist/modules/payments/webhook.types.d.ts +35 -0
  95. package/dist/modules/payments/webhook.types.d.ts.map +1 -0
  96. package/dist/modules/payments/webhook.types.js +3 -0
  97. package/dist/modules/payments/webhook.types.js.map +1 -0
  98. package/dist/modules/subscription/change.service.d.ts +80 -0
  99. package/dist/modules/subscription/change.service.d.ts.map +1 -0
  100. package/dist/modules/subscription/change.service.js +226 -0
  101. package/dist/modules/subscription/change.service.js.map +1 -0
  102. package/dist/modules/subscription/index.d.ts +2 -0
  103. package/dist/modules/subscription/index.d.ts.map +1 -1
  104. package/dist/modules/subscription/index.js +2 -0
  105. package/dist/modules/subscription/index.js.map +1 -1
  106. package/dist/modules/subscription/service.d.ts +8 -1
  107. package/dist/modules/subscription/service.d.ts.map +1 -1
  108. package/dist/modules/subscription/service.js +59 -2
  109. package/dist/modules/subscription/service.js.map +1 -1
  110. package/dist/modules/subscription/status-check.handler.d.ts +117 -0
  111. package/dist/modules/subscription/status-check.handler.d.ts.map +1 -0
  112. package/dist/modules/subscription/status-check.handler.js +164 -0
  113. package/dist/modules/subscription/status-check.handler.js.map +1 -0
  114. package/dist/modules/subscription/types.d.ts +37 -1
  115. package/dist/modules/subscription/types.d.ts.map +1 -1
  116. package/dist/modules/subscriptionPlan/const.d.ts +5 -0
  117. package/dist/modules/subscriptionPlan/const.d.ts.map +1 -0
  118. package/dist/modules/subscriptionPlan/const.js +106 -0
  119. package/dist/modules/subscriptionPlan/const.js.map +1 -0
  120. package/dist/modules/subscriptionPlan/index.d.ts +5 -0
  121. package/dist/modules/subscriptionPlan/index.d.ts.map +1 -0
  122. package/dist/modules/subscriptionPlan/index.js +21 -0
  123. package/dist/modules/subscriptionPlan/index.js.map +1 -0
  124. package/dist/modules/subscriptionPlan/repository.d.ts +22 -0
  125. package/dist/modules/subscriptionPlan/repository.d.ts.map +1 -0
  126. package/dist/modules/subscriptionPlan/repository.js +95 -0
  127. package/dist/modules/subscriptionPlan/repository.js.map +1 -0
  128. package/dist/modules/subscriptionPlan/service.d.ts +21 -0
  129. package/dist/modules/subscriptionPlan/service.d.ts.map +1 -0
  130. package/dist/modules/subscriptionPlan/service.js +128 -0
  131. package/dist/modules/subscriptionPlan/service.js.map +1 -0
  132. package/dist/modules/subscriptionPlan/types.d.ts +40 -0
  133. package/dist/modules/subscriptionPlan/types.d.ts.map +1 -0
  134. package/dist/modules/subscriptionPlan/types.js +3 -0
  135. package/dist/modules/subscriptionPlan/types.js.map +1 -0
  136. package/dist/modules/token/const.d.ts +7 -0
  137. package/dist/modules/token/const.d.ts.map +1 -0
  138. package/dist/modules/token/const.js +66 -0
  139. package/dist/modules/token/const.js.map +1 -0
  140. package/dist/modules/token/index.d.ts +4 -0
  141. package/dist/modules/token/index.d.ts.map +1 -0
  142. package/dist/modules/token/index.js +20 -0
  143. package/dist/modules/token/index.js.map +1 -0
  144. package/dist/modules/token/service.d.ts +46 -0
  145. package/dist/modules/token/service.d.ts.map +1 -0
  146. package/dist/modules/token/service.js +249 -0
  147. package/dist/modules/token/service.js.map +1 -0
  148. package/dist/modules/token/types.d.ts +109 -0
  149. package/dist/modules/token/types.d.ts.map +1 -0
  150. package/dist/modules/token/types.js +3 -0
  151. package/dist/modules/token/types.js.map +1 -0
  152. package/dist/modules/tokenPack/const.d.ts +4 -0
  153. package/dist/modules/tokenPack/const.d.ts.map +1 -0
  154. package/dist/modules/tokenPack/const.js +10 -0
  155. package/dist/modules/tokenPack/const.js.map +1 -0
  156. package/dist/modules/tokenPack/index.d.ts +5 -0
  157. package/dist/modules/tokenPack/index.d.ts.map +1 -0
  158. package/dist/modules/tokenPack/index.js +21 -0
  159. package/dist/modules/tokenPack/index.js.map +1 -0
  160. package/dist/modules/tokenPack/repository.d.ts +32 -0
  161. package/dist/modules/tokenPack/repository.d.ts.map +1 -0
  162. package/dist/modules/tokenPack/repository.js +103 -0
  163. package/dist/modules/tokenPack/repository.js.map +1 -0
  164. package/dist/modules/tokenPack/service.d.ts +28 -0
  165. package/dist/modules/tokenPack/service.d.ts.map +1 -0
  166. package/dist/modules/tokenPack/service.js +106 -0
  167. package/dist/modules/tokenPack/service.js.map +1 -0
  168. package/dist/modules/tokenPack/types.d.ts +124 -0
  169. package/dist/modules/tokenPack/types.d.ts.map +1 -0
  170. package/dist/modules/tokenPack/types.js +3 -0
  171. package/dist/modules/tokenPack/types.js.map +1 -0
  172. package/package.json +9 -5
  173. package/src/config/ConfigurationManager.ts +159 -0
  174. package/src/config/defaults.ts +27 -0
  175. package/src/config/environment.ts +94 -0
  176. package/src/config/index.ts +22 -0
  177. package/src/config/types.ts +56 -0
  178. package/src/index.ts +29 -0
  179. package/src/modules/cache/InMemoryCache.ts +98 -0
  180. package/src/modules/cache/index.ts +2 -0
  181. package/src/modules/cache/types.ts +60 -0
  182. package/src/modules/cancellableAPI/utils.ts +60 -0
  183. package/src/modules/errors/index.ts +16 -0
  184. package/src/modules/errors/types.ts +201 -0
  185. package/src/modules/invoice/const.ts +7 -0
  186. package/src/modules/invoice/index.ts +4 -0
  187. package/src/modules/invoice/repository.ts +52 -0
  188. package/src/modules/invoice/service.ts +44 -0
  189. package/src/modules/invoice/types.ts +47 -0
  190. package/src/modules/logger/types.ts +8 -0
  191. package/src/modules/network/utils.ts +24 -0
  192. package/src/modules/payments/api.ts +289 -0
  193. package/src/modules/payments/const.ts +11 -0
  194. package/src/modules/payments/index.ts +14 -0
  195. package/src/modules/payments/repository.ts +125 -0
  196. package/src/modules/payments/service.test.ts +400 -0
  197. package/src/modules/payments/service.ts +365 -0
  198. package/src/modules/payments/subscription-check-webhook.handler.integration.test.ts +935 -0
  199. package/src/modules/payments/subscription-check-webhook.handler.ts +211 -0
  200. package/src/modules/payments/subscription-check-webhook.service.ts +398 -0
  201. package/src/modules/payments/subscription-check-webhook.types.ts +29 -0
  202. package/src/modules/payments/types.ts +193 -0
  203. package/src/modules/payments/utils.ts +428 -0
  204. package/src/modules/payments/wayforpay.service.test.ts +375 -0
  205. package/src/modules/payments/wayforpay.service.ts +284 -0
  206. package/src/modules/payments/wayforpay.types.ts +138 -0
  207. package/src/modules/payments/webhook.handler.integration.test.ts +975 -0
  208. package/src/modules/payments/webhook.handler.ts +219 -0
  209. package/src/modules/payments/webhook.service.ts +812 -0
  210. package/src/modules/payments/webhook.types.ts +38 -0
  211. package/src/modules/subscription/change.service.ts +317 -0
  212. package/src/modules/subscription/const.ts +9 -0
  213. package/src/modules/subscription/index.ts +5 -0
  214. package/src/modules/subscription/repository.ts +277 -0
  215. package/src/modules/subscription/service.test.ts +665 -0
  216. package/src/modules/subscription/service.ts +328 -0
  217. package/src/modules/subscription/status-check.handler.ts +254 -0
  218. package/src/modules/subscription/types.ts +267 -0
  219. package/src/modules/subscription/utils.ts +5 -0
  220. package/src/modules/subscriptionPlan/const.ts +106 -0
  221. package/src/modules/subscriptionPlan/index.ts +4 -0
  222. package/src/modules/subscriptionPlan/repository.ts +129 -0
  223. package/src/modules/subscriptionPlan/service.test.ts +401 -0
  224. package/src/modules/subscriptionPlan/service.ts +148 -0
  225. package/src/modules/subscriptionPlan/types.ts +67 -0
  226. package/src/modules/token/const.ts +64 -0
  227. package/src/modules/token/index.ts +3 -0
  228. package/src/modules/token/service.test.ts +499 -0
  229. package/src/modules/token/service.ts +297 -0
  230. package/src/modules/token/types.ts +124 -0
  231. package/src/modules/tokenPack/const.ts +9 -0
  232. package/src/modules/tokenPack/index.ts +4 -0
  233. package/src/modules/tokenPack/repository.ts +144 -0
  234. package/src/modules/tokenPack/service.ts +119 -0
  235. package/src/modules/tokenPack/types.ts +131 -0
  236. package/src/modules/user/index.ts +3 -0
  237. package/src/modules/user/types.ts +143 -0
  238. package/src/modules/user/userRepository.ts +64 -0
  239. package/src/modules/user/userService.ts +68 -0
  240. package/src/types/extend-express.d.ts +16 -0
  241. package/src/types/function.ts +5 -0
  242. package/src/types/utilities.ts +22 -0
  243. package/src/utils.ts +53 -0
  244. package/tsconfig.json +29 -0
  245. package/dist/modules/subscription/subscriptionPlan.d.ts +0 -4
  246. package/dist/modules/subscription/subscriptionPlan.d.ts.map +0 -1
  247. package/dist/modules/subscription/subscriptionPlan.js +0 -67
  248. package/dist/modules/subscription/subscriptionPlan.js.map +0 -1
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SubscriptionCheckWebhookHandler = void 0;
4
+ exports.createSubscriptionCheckWebhookHandler = createSubscriptionCheckWebhookHandler;
5
+ const subscription_check_webhook_service_1 = require("./subscription-check-webhook.service");
6
+ /**
7
+ * SubscriptionCheckWebhookHandler provides HTTP request handling for WayForPay
8
+ * subscription status check callbacks. It validates incoming requests and delegates
9
+ * processing to the SubscriptionCheckWebhookService.
10
+ *
11
+ * Usage with Express:
12
+ * ```typescript
13
+ * const handler = new SubscriptionCheckWebhookHandler({ logger });
14
+ * app.post('/webhook/subscription-check', (req, res) => handler.handleRequest(req, res));
15
+ * ```
16
+ *
17
+ * Usage with Cloud Functions:
18
+ * ```typescript
19
+ * const handler = new SubscriptionCheckWebhookHandler({ logger });
20
+ * export const subscriptionCheckWebhook = (req, res) => handler.handleRequest(req, res);
21
+ * ```
22
+ */
23
+ class SubscriptionCheckWebhookHandler {
24
+ constructor(config) {
25
+ this.logger = config.logger;
26
+ this.webhookService =
27
+ config.webhookService ||
28
+ new subscription_check_webhook_service_1.SubscriptionCheckWebhookService({
29
+ logger: config.logger,
30
+ });
31
+ }
32
+ /**
33
+ * Handles an incoming HTTP request from WayForPay for subscription checks.
34
+ * Validates the request body, processes the subscription check callback,
35
+ * and returns the appropriate response.
36
+ *
37
+ * @param req - The HTTP request object
38
+ * @param res - The HTTP response object
39
+ */
40
+ async handleRequest(req, res) {
41
+ this.logger.info({
42
+ message: 'Received WayForPay subscription check webhook request',
43
+ payload: {},
44
+ });
45
+ // Parse and validate the request body
46
+ const parseResult = this.parseRequestBody(req.body);
47
+ if (!parseResult.success || !parseResult.data) {
48
+ this.logger.warning({
49
+ message: 'Invalid subscription check webhook request body',
50
+ payload: { error: parseResult.error },
51
+ });
52
+ res.status(400).json({
53
+ error: parseResult.error || 'Invalid request body',
54
+ });
55
+ return;
56
+ }
57
+ const callbackData = parseResult.data;
58
+ // Process the webhook
59
+ const result = await this.webhookService.processSubscriptionCheckWebhook(callbackData);
60
+ // Return the response to WayForPay
61
+ this.sendResponse(res, result);
62
+ }
63
+ /**
64
+ * Processes callback data directly without HTTP request parsing.
65
+ * Useful for testing or when data is already parsed.
66
+ *
67
+ * @param callbackData - The parsed callback data from WayForPay
68
+ * @returns Processing result with response to send back to WayForPay
69
+ */
70
+ async processCallback(callbackData) {
71
+ return this.webhookService.processSubscriptionCheckWebhook(callbackData);
72
+ }
73
+ /**
74
+ * Parses and validates the webhook request body.
75
+ */
76
+ parseRequestBody(body) {
77
+ if (!body || typeof body !== 'object') {
78
+ return {
79
+ success: false,
80
+ error: 'Request body must be a JSON object',
81
+ };
82
+ }
83
+ const data = body;
84
+ // Validate required fields for subscription check webhook
85
+ const requiredFields = [
86
+ 'merchantAccount',
87
+ 'orderReference',
88
+ 'merchantSignature',
89
+ 'amount',
90
+ 'currency',
91
+ 'transactionStatus',
92
+ ];
93
+ const missingFields = requiredFields.filter((field) => data[field] === undefined || data[field] === null);
94
+ if (missingFields.length > 0) {
95
+ return {
96
+ success: false,
97
+ error: `Missing required fields: ${missingFields.join(', ')}`,
98
+ };
99
+ }
100
+ // Validate transaction status
101
+ const validStatuses = ['Approved', 'Declined', 'Expired', 'Pending', 'InProcessing', 'Refunded'];
102
+ if (!validStatuses.includes(data.transactionStatus)) {
103
+ return {
104
+ success: false,
105
+ error: `Invalid transaction status: ${data.transactionStatus}`,
106
+ };
107
+ }
108
+ return {
109
+ success: true,
110
+ data: data,
111
+ };
112
+ }
113
+ /**
114
+ * Sends the response back to WayForPay.
115
+ * WayForPay expects a 200 status with a signed response body.
116
+ */
117
+ sendResponse(res, result) {
118
+ // WayForPay expects a 200 status code even for declined transactions
119
+ // The accept/decline status is communicated in the response body
120
+ res.status(200).json(result.response);
121
+ this.logger.info({
122
+ message: 'Subscription check webhook response sent',
123
+ payload: {
124
+ success: result.success,
125
+ status: result.response.status,
126
+ orderReference: result.response.orderReference,
127
+ },
128
+ });
129
+ }
130
+ }
131
+ exports.SubscriptionCheckWebhookHandler = SubscriptionCheckWebhookHandler;
132
+ /**
133
+ * Creates a subscription check webhook handler function for use with serverless platforms.
134
+ * Returns a function that can be directly used as a Cloud Function or Lambda handler.
135
+ *
136
+ * @param config - Configuration options for the webhook handler
137
+ * @returns An async function that handles webhook requests
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * // Firebase Cloud Functions
142
+ * import * as functions from 'firebase-functions';
143
+ * import { createSubscriptionCheckWebhookHandler } from 'miit-bot-payment';
144
+ *
145
+ * const logger = { info: console.log, warning: console.warn, error: console.error };
146
+ * export const subscriptionCheckWebhook = functions.https.onRequest(
147
+ * createSubscriptionCheckWebhookHandler({ logger })
148
+ * );
149
+ * ```
150
+ */
151
+ function createSubscriptionCheckWebhookHandler(config) {
152
+ const handler = new SubscriptionCheckWebhookHandler(config);
153
+ return (req, res) => handler.handleRequest(req, res);
154
+ }
155
+ //# sourceMappingURL=subscription-check-webhook.handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-check-webhook.handler.js","sourceRoot":"","sources":["../../../src/modules/payments/subscription-check-webhook.handler.ts"],"names":[],"mappings":";;;AAmMA,sFAKC;AAvMD,6FAAuF;AAyBvF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,+BAA+B;IAIxC,YAAY,MAA6C;QACrD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,cAAc;YACf,MAAM,CAAC,cAAc;gBACrB,IAAI,oEAA+B,CAAC;oBAChC,MAAM,EAAE,MAAM,CAAC,MAAM;iBACxB,CAAC,CAAC;IACX,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,aAAa,CAAC,GAAmB,EAAE,GAAoB;QAChE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACb,OAAO,EAAE,uDAAuD;YAChE,OAAO,EAAE,EAAE;SACd,CAAC,CAAC;QAEH,sCAAsC;QACtC,MAAM,WAAW,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAEpD,IAAI,CAAC,WAAW,CAAC,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;gBAChB,OAAO,EAAE,iDAAiD;gBAC1D,OAAO,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE;aACxC,CAAC,CAAC;YAEH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACjB,KAAK,EAAE,WAAW,CAA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AS,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;QACjG,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,iBAA2B,CAAC,EAAE,CAAC;YAC5D,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,+BAA+B,IAAI,CAAC,iBAAiB,EAAE;aACjE,CAAC;QACN,CAAC;QAED,OAAO;YACH,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,IAAwC;SACjD,CAAC;IACN,CAAC;IAED;;;OAGG;IACK,YAAY,CAAC,GAAoB,EAAE,MAAsC;QAC7E,qEAAqE;QACrE,iEAAiE;QACjE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAEtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACb,OAAO,EAAE,0CAA0C;YACnD,OAAO,EAAE;gBACL,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;gBAC9B,cAAc,EAAE,MAAM,CAAC,QAAQ,CAAC,cAAc;aACjD;SACJ,CAAC,CAAC;IACP,CAAC;CACJ;AAnID,0EAmIC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,qCAAqC,CACjD,MAA6C;IAE7C,MAAM,OAAO,GAAG,IAAI,+BAA+B,CAAC,MAAM,CAAC,CAAC;IAC5D,OAAO,CAAC,GAAmB,EAAE,GAAoB,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { Logger } from '../logger/types';
2
+ import type { WayForPayCallbackData, IWayForPayService } from './wayforpay.types';
3
+ import type { ISubscriptionService } from '../subscription/types';
4
+ import type { ISubscriptionPlanService } from '../subscriptionPlan/types';
5
+ import type { SubscriptionCheckWebhookResult, ISubscriptionCheckWebhookService } from './subscription-check-webhook.types';
6
+ import { GracePeriodConfig } from '../../config';
7
+ /**
8
+ * SubscriptionCheckWebhookService processes subscription status check webhooks from WayForPay.
9
+ * It handles signature verification, renewal status checks, and subscription updates.
10
+ *
11
+ * WayForPay sends subscription check webhooks for recurring payments to verify
12
+ * if the subscription should be renewed or deactivated.
13
+ */
14
+ export declare class SubscriptionCheckWebhookService implements ISubscriptionCheckWebhookService {
15
+ private readonly logger;
16
+ private readonly wayForPayService;
17
+ private readonly subscriptionService;
18
+ private readonly subscriptionPlanService;
19
+ private readonly gracePeriodConfig;
20
+ constructor({ logger, wayForPayService, subscriptionService, subscriptionPlanService, gracePeriodConfig, }: {
21
+ logger: Logger;
22
+ wayForPayService?: IWayForPayService;
23
+ subscriptionService?: ISubscriptionService;
24
+ subscriptionPlanService?: ISubscriptionPlanService;
25
+ gracePeriodConfig?: GracePeriodConfig;
26
+ });
27
+ private loadGracePeriodConfig;
28
+ /**
29
+ * Processes a subscription check webhook from WayForPay.
30
+ * This method handles the complete webhook flow:
31
+ * 1. Verifies the signature to validate request authenticity
32
+ * 2. Checks the renewal status from WayForPay
33
+ * 3. Renews subscription if payment was successful
34
+ * 4. Marks subscription for deactivation if payment failed
35
+ *
36
+ * @param callbackData - The callback data from WayForPay
37
+ * @returns Processing result with response to send back to WayForPay
38
+ */
39
+ processSubscriptionCheckWebhook(callbackData: WayForPayCallbackData): Promise<SubscriptionCheckWebhookResult>;
40
+ /**
41
+ * Handles a successful subscription renewal.
42
+ * Extends the subscription expiration date based on the plan.
43
+ */
44
+ private handleSuccessfulRenewal;
45
+ /**
46
+ * Handles a failed subscription renewal.
47
+ * Marks the subscription as cancelled initially, then deactivates after grace period.
48
+ */
49
+ private handleFailedRenewal;
50
+ /**
51
+ * Renews an existing subscription by extending its expiration date.
52
+ */
53
+ private renewSubscription;
54
+ /**
55
+ * Calculates the subscription expiration date based on the regular mode.
56
+ */
57
+ private calculateExpirationDate;
58
+ }
59
+ //# sourceMappingURL=subscription-check-webhook.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-check-webhook.service.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/subscription-check-webhook.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAezC,OAAO,KAAK,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,KAAK,EAAE,oBAAoB,EAAsB,MAAM,uBAAuB,CAAC;AACtF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,KAAK,EACR,8BAA8B,EAC9B,gCAAgC,EACnC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAwB,iBAAiB,EAA+B,MAAM,cAAc,CAAC;AAEpG;;;;;;GAMG;AACH,qBAAa,+BAAgC,YAAW,gCAAgC;IACpF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IACrD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAuB;IAC3D,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAA2B;IACnE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAoB;gBAE1C,EACR,MAAM,EACN,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,GACpB,EAAE;QACC,MAAM,EAAE,MAAM,CAAC;QACf,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;QACrC,mBAAmB,CAAC,EAAE,oBAAoB,CAAC;QAC3C,uBAAuB,CAAC,EAAE,wBAAwB,CAAC;QACnD,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;KACzC;IAQD,OAAO,CAAC,qBAAqB;IAS7B;;;;;;;;;;OAUG;IACU,+BAA+B,CACxC,YAAY,EAAE,qBAAqB,GACpC,OAAO,CAAC,8BAA8B,CAAC;IAiF1C;;;OAGG;YACW,uBAAuB;IAsErC;;;OAGG;YACW,mBAAmB;IAmGjC;;OAEG;YACW,iBAAiB;IAkC/B;;OAEG;IACH,OAAO,CAAC,uBAAuB;CAiBlC"}
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SubscriptionCheckWebhookService = void 0;
7
+ const moment_1 = __importDefault(require("moment"));
8
+ const APPROVED_STATUS = 'Approved';
9
+ const DECLINED_STATUS = 'Declined';
10
+ const EXPIRED_STATUS = 'Expired';
11
+ const wayforpay_service_1 = require("./wayforpay.service");
12
+ const service_1 = require("../subscription/service");
13
+ const service_2 = require("../subscriptionPlan/service");
14
+ const utils_1 = require("./utils");
15
+ const config_1 = require("../../config");
16
+ /**
17
+ * SubscriptionCheckWebhookService processes subscription status check webhooks from WayForPay.
18
+ * It handles signature verification, renewal status checks, and subscription updates.
19
+ *
20
+ * WayForPay sends subscription check webhooks for recurring payments to verify
21
+ * if the subscription should be renewed or deactivated.
22
+ */
23
+ class SubscriptionCheckWebhookService {
24
+ constructor({ logger, wayForPayService, subscriptionService, subscriptionPlanService, gracePeriodConfig, }) {
25
+ this.logger = logger;
26
+ this.wayForPayService = wayForPayService || new wayforpay_service_1.WayForPayService({ logger });
27
+ this.subscriptionService = subscriptionService || new service_1.SubscriptionService({ logger });
28
+ this.subscriptionPlanService = subscriptionPlanService || new service_2.SubscriptionPlanService({ logger });
29
+ this.gracePeriodConfig = gracePeriodConfig || this.loadGracePeriodConfig();
30
+ }
31
+ loadGracePeriodConfig() {
32
+ try {
33
+ const configManager = config_1.ConfigurationManager.getInstance();
34
+ return configManager.getGracePeriodConfig();
35
+ }
36
+ catch {
37
+ return config_1.DEFAULT_GRACE_PERIOD_CONFIG;
38
+ }
39
+ }
40
+ /**
41
+ * Processes a subscription check webhook from WayForPay.
42
+ * This method handles the complete webhook flow:
43
+ * 1. Verifies the signature to validate request authenticity
44
+ * 2. Checks the renewal status from WayForPay
45
+ * 3. Renews subscription if payment was successful
46
+ * 4. Marks subscription for deactivation if payment failed
47
+ *
48
+ * @param callbackData - The callback data from WayForPay
49
+ * @returns Processing result with response to send back to WayForPay
50
+ */
51
+ async processSubscriptionCheckWebhook(callbackData) {
52
+ const { orderReference, transactionStatus } = callbackData;
53
+ this.logger.info({
54
+ message: 'Processing subscription check webhook',
55
+ payload: {
56
+ orderReference,
57
+ transactionStatus,
58
+ regularOn: callbackData.regularOn,
59
+ },
60
+ });
61
+ try {
62
+ // Step 1: Verify signature to validate request authenticity
63
+ const signatureResult = this.wayForPayService.verifyCallbackSignature(callbackData);
64
+ if (!signatureResult.isValid) {
65
+ this.logger.warning({
66
+ message: 'Invalid subscription check webhook signature',
67
+ payload: {
68
+ orderReference,
69
+ error: signatureResult.error,
70
+ },
71
+ });
72
+ return {
73
+ success: false,
74
+ response: this.wayForPayService.buildWebhookResponse(orderReference, 'decline'),
75
+ error: signatureResult.error || 'Invalid signature',
76
+ };
77
+ }
78
+ // Step 2: Validate this is a subscription order reference
79
+ if (!(0, utils_1.isSubscriptionOrderReference)(orderReference)) {
80
+ this.logger.warning({
81
+ message: 'Subscription check webhook received for non-subscription order',
82
+ payload: { orderReference },
83
+ });
84
+ return {
85
+ success: true,
86
+ response: this.wayForPayService.buildWebhookResponse(orderReference, 'accept'),
87
+ };
88
+ }
89
+ // Step 3: Check renewal status and process accordingly
90
+ if (transactionStatus === APPROVED_STATUS) {
91
+ await this.handleSuccessfulRenewal(callbackData);
92
+ }
93
+ else if (transactionStatus === DECLINED_STATUS || transactionStatus === EXPIRED_STATUS) {
94
+ await this.handleFailedRenewal(callbackData);
95
+ }
96
+ else {
97
+ this.logger.info({
98
+ message: 'Subscription check webhook received with non-final status',
99
+ payload: {
100
+ orderReference,
101
+ transactionStatus,
102
+ },
103
+ });
104
+ }
105
+ return {
106
+ success: true,
107
+ response: this.wayForPayService.buildWebhookResponse(orderReference, 'accept'),
108
+ };
109
+ }
110
+ catch (error) {
111
+ this.logger.error({
112
+ message: 'Error processing subscription check webhook',
113
+ payload: {
114
+ orderReference,
115
+ error: JSON.stringify(error),
116
+ },
117
+ });
118
+ return {
119
+ success: false,
120
+ response: this.wayForPayService.buildWebhookResponse(orderReference, 'decline'),
121
+ error: error instanceof Error ? error.message : 'Unknown error',
122
+ };
123
+ }
124
+ }
125
+ /**
126
+ * Handles a successful subscription renewal.
127
+ * Extends the subscription expiration date based on the plan.
128
+ */
129
+ async handleSuccessfulRenewal(callbackData) {
130
+ const { orderReference } = callbackData;
131
+ const parsedReference = (0, utils_1.parseOrderReference)(orderReference);
132
+ if (!parsedReference) {
133
+ this.logger.warning({
134
+ message: 'Could not parse order reference for successful renewal',
135
+ payload: { orderReference },
136
+ });
137
+ return;
138
+ }
139
+ const userId = (0, utils_1.getOrderReferenceUserId)(orderReference);
140
+ const planId = (0, utils_1.getOrderReferenceItemId)(orderReference);
141
+ const { platform } = parsedReference;
142
+ if (!userId || !planId) {
143
+ this.logger.warning({
144
+ message: 'Could not extract userId or planId from order reference',
145
+ payload: { orderReference },
146
+ });
147
+ return;
148
+ }
149
+ // Find active subscription for user
150
+ const existingSubscription = await this.subscriptionService.getByUser({
151
+ userId,
152
+ platform,
153
+ status: 'active',
154
+ });
155
+ if (!existingSubscription) {
156
+ this.logger.warning({
157
+ message: 'No active subscription found for successful renewal',
158
+ payload: { userId, platform, orderReference },
159
+ });
160
+ return;
161
+ }
162
+ // Get subscription plan to calculate new expiration
163
+ const subscriptionPlan = await this.subscriptionPlanService.getById(planId);
164
+ if (!subscriptionPlan) {
165
+ this.logger.warning({
166
+ message: 'Subscription plan not found for renewal',
167
+ payload: { planId, orderReference },
168
+ });
169
+ return;
170
+ }
171
+ // Calculate new expiration date
172
+ const newExpiresAt = this.calculateExpirationDate(subscriptionPlan.regularMode, subscriptionPlan.count);
173
+ // Renew subscription
174
+ await this.renewSubscription(existingSubscription, newExpiresAt);
175
+ this.logger.info({
176
+ message: 'Subscription renewed successfully via check webhook',
177
+ payload: {
178
+ subscriptionId: existingSubscription.id,
179
+ userId,
180
+ platform,
181
+ planId,
182
+ newExpiresAt,
183
+ },
184
+ });
185
+ }
186
+ /**
187
+ * Handles a failed subscription renewal.
188
+ * Marks the subscription as cancelled initially, then deactivates after grace period.
189
+ */
190
+ async handleFailedRenewal(callbackData) {
191
+ const { orderReference, reason, reasonCode, transactionStatus } = callbackData;
192
+ const parsedReference = (0, utils_1.parseOrderReference)(orderReference);
193
+ if (!parsedReference) {
194
+ this.logger.warning({
195
+ message: 'Could not parse order reference for failed renewal',
196
+ payload: { orderReference },
197
+ });
198
+ return;
199
+ }
200
+ const userId = (0, utils_1.getOrderReferenceUserId)(orderReference);
201
+ const { platform } = parsedReference;
202
+ if (!userId) {
203
+ this.logger.warning({
204
+ message: 'Could not extract userId from order reference for failed renewal',
205
+ payload: { orderReference },
206
+ });
207
+ return;
208
+ }
209
+ // Find active subscription for user
210
+ const existingSubscription = await this.subscriptionService.getByUser({
211
+ userId,
212
+ platform,
213
+ status: 'active',
214
+ });
215
+ if (!existingSubscription) {
216
+ this.logger.info({
217
+ message: 'No active subscription found for failed renewal check',
218
+ payload: { userId, platform, orderReference },
219
+ });
220
+ return;
221
+ }
222
+ // Check if subscription has expired past the grace period
223
+ const now = moment_1.default.utc();
224
+ const expiresAt = moment_1.default.utc(existingSubscription.expiresAt);
225
+ const gracePeriodMs = this.gracePeriodConfig.enabled ? this.gracePeriodConfig.durationMs : 0;
226
+ const gracePeriodEnd = expiresAt.clone().add(gracePeriodMs, 'milliseconds');
227
+ if (now.isAfter(gracePeriodEnd)) {
228
+ // Subscription has expired past grace period and renewal failed - deactivate it
229
+ await this.subscriptionService.deactivateSubscription({ id: existingSubscription.id });
230
+ this.logger.info({
231
+ message: 'Subscription deactivated due to failed renewal check (past grace period)',
232
+ payload: {
233
+ subscriptionId: existingSubscription.id,
234
+ userId,
235
+ platform,
236
+ orderReference,
237
+ transactionStatus,
238
+ reason,
239
+ reasonCode,
240
+ expiresAt: existingSubscription.expiresAt,
241
+ gracePeriodMs,
242
+ gracePeriodEnd: gracePeriodEnd.toISOString(),
243
+ },
244
+ });
245
+ }
246
+ else if (expiresAt.isBefore(now)) {
247
+ // Subscription has expired but still within grace period - cancel (mark for future deactivation)
248
+ await this.subscriptionService.cancelSubscription({ id: existingSubscription.id });
249
+ this.logger.info({
250
+ message: 'Subscription cancelled due to failed renewal (within grace period)',
251
+ payload: {
252
+ subscriptionId: existingSubscription.id,
253
+ userId,
254
+ platform,
255
+ orderReference,
256
+ expiresAt: existingSubscription.expiresAt,
257
+ gracePeriodEnd: gracePeriodEnd.toISOString(),
258
+ transactionStatus,
259
+ reason,
260
+ reasonCode,
261
+ },
262
+ });
263
+ }
264
+ else {
265
+ // Subscription not yet expired - log for monitoring but don't deactivate
266
+ this.logger.info({
267
+ message: 'Failed renewal check for subscription that has not yet expired',
268
+ payload: {
269
+ subscriptionId: existingSubscription.id,
270
+ userId,
271
+ platform,
272
+ orderReference,
273
+ expiresAt: existingSubscription.expiresAt,
274
+ transactionStatus,
275
+ reason,
276
+ reasonCode,
277
+ },
278
+ });
279
+ }
280
+ }
281
+ /**
282
+ * Renews an existing subscription by extending its expiration date.
283
+ */
284
+ async renewSubscription(existingSubscription, newExpiresAt) {
285
+ // If the subscription hasn't expired yet, extend from current expiration
286
+ const currentExpiration = moment_1.default.utc(existingSubscription.expiresAt);
287
+ const now = moment_1.default.utc();
288
+ let extendedExpiresAt;
289
+ if (currentExpiration.isAfter(now)) {
290
+ // Extend from current expiration date
291
+ const durationToAdd = moment_1.default.utc(newExpiresAt).diff(moment_1.default.utc(), 'milliseconds');
292
+ extendedExpiresAt = currentExpiration.add(durationToAdd, 'milliseconds').toISOString();
293
+ }
294
+ else {
295
+ // Subscription has expired, use the new expiration date
296
+ extendedExpiresAt = newExpiresAt;
297
+ }
298
+ await this.subscriptionService.renewSubscription({
299
+ userId: existingSubscription.userId,
300
+ platform: existingSubscription.platform,
301
+ expiresAt: extendedExpiresAt,
302
+ });
303
+ this.logger.info({
304
+ message: 'Subscription renewed via check webhook',
305
+ payload: {
306
+ subscriptionId: existingSubscription.id,
307
+ previousExpiresAt: existingSubscription.expiresAt,
308
+ newExpiresAt: extendedExpiresAt,
309
+ },
310
+ });
311
+ }
312
+ /**
313
+ * Calculates the subscription expiration date based on the regular mode.
314
+ */
315
+ calculateExpirationDate(regularMode, count) {
316
+ const now = moment_1.default.utc();
317
+ switch (regularMode) {
318
+ case 'daily':
319
+ return now.add(count, 'days').toISOString();
320
+ case 'monthly':
321
+ return now.add(count, 'months').toISOString();
322
+ case 'yearly':
323
+ return now.add(count, 'years').toISOString();
324
+ default:
325
+ return now.add(count, 'months').toISOString();
326
+ }
327
+ }
328
+ }
329
+ exports.SubscriptionCheckWebhookService = SubscriptionCheckWebhookService;
330
+ //# sourceMappingURL=subscription-check-webhook.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-check-webhook.service.js","sourceRoot":"","sources":["../../../src/modules/payments/subscription-check-webhook.service.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAI5B,MAAM,eAAe,GAA8B,UAAU,CAAC;AAC9D,MAAM,eAAe,GAA8B,UAAU,CAAC;AAC9D,MAAM,cAAc,GAA8B,SAAS,CAAC;AAE5D,2DAAuD;AACvD,qDAA8D;AAC9D,yDAAsE;AACtE,mCAKiB;AAQjB,yCAAoG;AAEpG;;;;;;GAMG;AACH,MAAa,+BAA+B;IAOxC,YAAY,EACR,MAAM,EACN,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,GAOpB;QACG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,IAAI,IAAI,oCAAgB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,IAAI,IAAI,6BAAmB,CAAC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,CAAC;YAClD,KAAK,QAAQ;gBACT,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;YACjD;gBACI,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;QACtD,CAAC;IACL,CAAC;CACJ;AA5WD,0EA4WC"}
@@ -0,0 +1,25 @@
1
+ import { WayForPayCallbackData, WayForPayWebhookResponse } from './wayforpay.types';
2
+ /**
3
+ * Result of processing a subscription check webhook callback
4
+ */
5
+ type SubscriptionCheckWebhookResult = {
6
+ success: boolean;
7
+ response: WayForPayWebhookResponse;
8
+ error?: string;
9
+ };
10
+ /**
11
+ * Interface for subscription check webhook handler service operations.
12
+ * Handles subscription status check webhooks from WayForPay.
13
+ */
14
+ interface ISubscriptionCheckWebhookService {
15
+ /**
16
+ * Processes a subscription check webhook from WayForPay.
17
+ * Verifies signature, checks renewal status, and updates subscription accordingly.
18
+ *
19
+ * @param callbackData - The callback data from WayForPay
20
+ * @returns Processing result with response to send back to WayForPay
21
+ */
22
+ processSubscriptionCheckWebhook(callbackData: WayForPayCallbackData): Promise<SubscriptionCheckWebhookResult>;
23
+ }
24
+ export type { SubscriptionCheckWebhookResult, ISubscriptionCheckWebhookService };
25
+ //# sourceMappingURL=subscription-check-webhook.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-check-webhook.types.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/subscription-check-webhook.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAEpF;;GAEG;AACH,KAAK,8BAA8B,GAAG;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,wBAAwB,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;GAGG;AACH,UAAU,gCAAgC;IACtC;;;;;;OAMG;IACH,+BAA+B,CAC3B,YAAY,EAAE,qBAAqB,GACpC,OAAO,CAAC,8BAA8B,CAAC,CAAC;CAC9C;AAED,YAAY,EAAE,8BAA8B,EAAE,gCAAgC,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=subscription-check-webhook.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-check-webhook.types.js","sourceRoot":"","sources":["../../../src/modules/payments/subscription-check-webhook.types.ts"],"names":[],"mappings":""}