@misterhomer1992/miit-bot-payment 1.1.7 → 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 +58 -1
  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,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryCache = void 0;
4
+ class InMemoryCache {
5
+ constructor(options) {
6
+ this.cache = new Map();
7
+ this.defaultTtl = options.ttl;
8
+ this.maxSize = options.maxSize || Infinity;
9
+ }
10
+ get(key) {
11
+ const entry = this.cache.get(key);
12
+ if (!entry) {
13
+ return undefined;
14
+ }
15
+ if (this.isExpired(entry)) {
16
+ this.cache.delete(key);
17
+ return undefined;
18
+ }
19
+ return entry.value;
20
+ }
21
+ set(key, value, ttl) {
22
+ if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
23
+ this.evictOldest();
24
+ }
25
+ const expiresAt = Date.now() + (ttl ?? this.defaultTtl);
26
+ this.cache.set(key, {
27
+ value,
28
+ expiresAt,
29
+ });
30
+ }
31
+ has(key) {
32
+ const entry = this.cache.get(key);
33
+ if (!entry) {
34
+ return false;
35
+ }
36
+ if (this.isExpired(entry)) {
37
+ this.cache.delete(key);
38
+ return false;
39
+ }
40
+ return true;
41
+ }
42
+ delete(key) {
43
+ return this.cache.delete(key);
44
+ }
45
+ clear() {
46
+ this.cache.clear();
47
+ }
48
+ size() {
49
+ return this.cache.size;
50
+ }
51
+ cleanup() {
52
+ const now = Date.now();
53
+ for (const [key, entry] of this.cache.entries()) {
54
+ if (entry.expiresAt <= now) {
55
+ this.cache.delete(key);
56
+ }
57
+ }
58
+ }
59
+ isExpired(entry) {
60
+ return entry.expiresAt <= Date.now();
61
+ }
62
+ evictOldest() {
63
+ let oldestKey = null;
64
+ let oldestTime = Infinity;
65
+ for (const [key, entry] of this.cache.entries()) {
66
+ if (entry.expiresAt < oldestTime) {
67
+ oldestTime = entry.expiresAt;
68
+ oldestKey = key;
69
+ }
70
+ }
71
+ if (oldestKey) {
72
+ this.cache.delete(oldestKey);
73
+ }
74
+ }
75
+ }
76
+ exports.InMemoryCache = InMemoryCache;
77
+ //# sourceMappingURL=InMemoryCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryCache.js","sourceRoot":"","sources":["../../../src/modules/cache/InMemoryCache.ts"],"names":[],"mappings":";;;AAEA,MAAa,aAAa;IAKtB,YAAY,OAAsB;QAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC;IAC/C,CAAC;IAEM,GAAG,CAAC,GAAW;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,KAA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K;QACR,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAEM,IAAI;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IAC3B,CAAC;IAEM,OAAO;QACV,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC9C,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC;gBACzB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC;QACL,CAAC;IACL,CAAC;IAEO,SAAS,CAAC,KAAoB;QAClC,OAAO,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IACzC,CAAC;IAEO,WAAW;QACf,IAAI,SAAS,GAAkB,IAAI,CAAC;QACpC,IAAI,UAAU,GAAG,QAAQ,CAAC;QAE1B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC9C,IAAI,KAAK,CAAC,SAAS,GAAG,UAAU,EAAE,CAAC;gBAC/B,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC;gBAC7B,SAAS,GAAG,GAAG,CAAC;YACpB,CAAC;QACL,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACZ,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;IACL,CAAC;CACJ;AA/FD,sCA+FC"}
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './InMemoryCache';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/cache/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./InMemoryCache"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/cache/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,kDAAgC"}
@@ -0,0 +1,52 @@
1
+ interface CacheEntry<T> {
2
+ value: T;
3
+ expiresAt: number;
4
+ }
5
+ interface ICacheOptions {
6
+ /** Time to live in milliseconds */
7
+ ttl: number;
8
+ /** Maximum number of entries in the cache */
9
+ maxSize?: number;
10
+ }
11
+ interface ICache<T> {
12
+ /**
13
+ * Gets a value from the cache.
14
+ * @param key - The cache key
15
+ * @returns The cached value or undefined if not found or expired
16
+ */
17
+ get(key: string): T | undefined;
18
+ /**
19
+ * Sets a value in the cache.
20
+ * @param key - The cache key
21
+ * @param value - The value to cache
22
+ * @param ttl - Optional TTL override in milliseconds
23
+ */
24
+ set(key: string, value: T, ttl?: number): void;
25
+ /**
26
+ * Checks if a key exists in the cache and is not expired.
27
+ * @param key - The cache key
28
+ * @returns True if the key exists and is not expired
29
+ */
30
+ has(key: string): boolean;
31
+ /**
32
+ * Deletes a key from the cache.
33
+ * @param key - The cache key
34
+ * @returns True if the key was deleted
35
+ */
36
+ delete(key: string): boolean;
37
+ /**
38
+ * Clears all entries from the cache.
39
+ */
40
+ clear(): void;
41
+ /**
42
+ * Gets the number of entries in the cache.
43
+ * @returns The number of entries
44
+ */
45
+ size(): number;
46
+ /**
47
+ * Removes all expired entries from the cache.
48
+ */
49
+ cleanup(): void;
50
+ }
51
+ export type { CacheEntry, ICacheOptions, ICache };
52
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/cache/types.ts"],"names":[],"mappings":"AAAA,UAAU,UAAU,CAAC,CAAC;IAClB,KAAK,EAAE,CAAC,CAAC;IACT,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,aAAa;IACnB,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,MAAM,CAAC,CAAC;IACd;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAEhC;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/C;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAE1B;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAE7B;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;;OAGG;IACH,IAAI,IAAI,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACnB;AAED,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/modules/cache/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { BaseError, PaymentError, PaymentErrorCode, SubscriptionError, SubscriptionErrorCode, ValidationError, ValidationErrorCode, NotFoundError, NotFoundErrorCode, isBaseError, isPaymentError, isSubscriptionError, isValidationError, isNotFoundError, } from './types';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,GAClB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNotFoundError = exports.isValidationError = exports.isSubscriptionError = exports.isPaymentError = exports.isBaseError = exports.NotFoundErrorCode = exports.NotFoundError = exports.ValidationErrorCode = exports.ValidationError = exports.SubscriptionErrorCode = exports.SubscriptionError = exports.PaymentErrorCode = exports.PaymentError = exports.BaseError = void 0;
4
+ var types_1 = require("./types");
5
+ Object.defineProperty(exports, "BaseError", { enumerable: true, get: function () { return types_1.BaseError; } });
6
+ Object.defineProperty(exports, "PaymentError", { enumerable: true, get: function () { return types_1.PaymentError; } });
7
+ Object.defineProperty(exports, "PaymentErrorCode", { enumerable: true, get: function () { return types_1.PaymentErrorCode; } });
8
+ Object.defineProperty(exports, "SubscriptionError", { enumerable: true, get: function () { return types_1.SubscriptionError; } });
9
+ Object.defineProperty(exports, "SubscriptionErrorCode", { enumerable: true, get: function () { return types_1.SubscriptionErrorCode; } });
10
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return types_1.ValidationError; } });
11
+ Object.defineProperty(exports, "ValidationErrorCode", { enumerable: true, get: function () { return types_1.ValidationErrorCode; } });
12
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return types_1.NotFoundError; } });
13
+ Object.defineProperty(exports, "NotFoundErrorCode", { enumerable: true, get: function () { return types_1.NotFoundErrorCode; } });
14
+ Object.defineProperty(exports, "isBaseError", { enumerable: true, get: function () { return types_1.isBaseError; } });
15
+ Object.defineProperty(exports, "isPaymentError", { enumerable: true, get: function () { return types_1.isPaymentError; } });
16
+ Object.defineProperty(exports, "isSubscriptionError", { enumerable: true, get: function () { return types_1.isSubscriptionError; } });
17
+ Object.defineProperty(exports, "isValidationError", { enumerable: true, get: function () { return types_1.isValidationError; } });
18
+ Object.defineProperty(exports, "isNotFoundError", { enumerable: true, get: function () { return types_1.isNotFoundError; } });
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/errors/index.ts"],"names":[],"mappings":";;;AAAA,iCAeiB;AAdb,kGAAA,SAAS,OAAA;AACT,qGAAA,YAAY,OAAA;AACZ,yGAAA,gBAAgB,OAAA;AAChB,0GAAA,iBAAiB,OAAA;AACjB,8GAAA,qBAAqB,OAAA;AACrB,wGAAA,eAAe,OAAA;AACf,4GAAA,mBAAmB,OAAA;AACnB,sGAAA,aAAa,OAAA;AACb,0GAAA,iBAAiB,OAAA;AACjB,oGAAA,WAAW,OAAA;AACX,uGAAA,cAAc,OAAA;AACd,4GAAA,mBAAmB,OAAA;AACnB,0GAAA,iBAAiB,OAAA;AACjB,wGAAA,eAAe,OAAA"}
@@ -0,0 +1,112 @@
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 declare abstract class BaseError extends Error {
6
+ readonly code: string;
7
+ readonly context?: Record<string, unknown>;
8
+ readonly timestamp: Date;
9
+ constructor(message: string, code: string, context?: Record<string, unknown>);
10
+ /**
11
+ * Returns a structured representation of the error for logging
12
+ */
13
+ toJSON(): Record<string, unknown>;
14
+ }
15
+ /**
16
+ * Error codes for payment-related failures
17
+ */
18
+ export declare enum PaymentErrorCode {
19
+ CREATE_FAILED = "PAYMENT_CREATE_FAILED",
20
+ UPDATE_FAILED = "PAYMENT_UPDATE_FAILED",
21
+ PROCESSING_FAILED = "PAYMENT_PROCESSING_FAILED",
22
+ CALLBACK_FAILED = "PAYMENT_CALLBACK_FAILED",
23
+ INVALID_RESPONSE = "PAYMENT_INVALID_RESPONSE",
24
+ PROVIDER_ERROR = "PAYMENT_PROVIDER_ERROR"
25
+ }
26
+ /**
27
+ * Error class for payment-related failures.
28
+ * Use for errors during payment creation, processing, or provider communication.
29
+ */
30
+ export declare class PaymentError extends BaseError {
31
+ constructor(message: string, code?: PaymentErrorCode, context?: Record<string, unknown>);
32
+ }
33
+ /**
34
+ * Error codes for subscription-related failures
35
+ */
36
+ export declare enum SubscriptionErrorCode {
37
+ CREATE_FAILED = "SUBSCRIPTION_CREATE_FAILED",
38
+ UPDATE_FAILED = "SUBSCRIPTION_UPDATE_FAILED",
39
+ CANCEL_FAILED = "SUBSCRIPTION_CANCEL_FAILED",
40
+ RENEWAL_FAILED = "SUBSCRIPTION_RENEWAL_FAILED",
41
+ INVALID_STATUS = "SUBSCRIPTION_INVALID_STATUS",
42
+ EXPIRED = "SUBSCRIPTION_EXPIRED"
43
+ }
44
+ /**
45
+ * Error class for subscription-related failures.
46
+ * Use for errors during subscription lifecycle operations.
47
+ */
48
+ export declare class SubscriptionError extends BaseError {
49
+ constructor(message: string, code?: SubscriptionErrorCode, context?: Record<string, unknown>);
50
+ }
51
+ /**
52
+ * Error codes for validation failures
53
+ */
54
+ export declare enum ValidationErrorCode {
55
+ INVALID_SIGNATURE = "VALIDATION_INVALID_SIGNATURE",
56
+ INVALID_INPUT = "VALIDATION_INVALID_INPUT",
57
+ MISSING_REQUIRED_FIELD = "VALIDATION_MISSING_REQUIRED_FIELD",
58
+ INVALID_FORMAT = "VALIDATION_INVALID_FORMAT",
59
+ SIGNATURE_MISMATCH = "VALIDATION_SIGNATURE_MISMATCH"
60
+ }
61
+ /**
62
+ * Error class for signature and input validation failures.
63
+ * Use for errors when validating signatures, inputs, or data formats.
64
+ */
65
+ export declare class ValidationError extends BaseError {
66
+ readonly field?: string;
67
+ constructor(message: string, code?: ValidationErrorCode, context?: Record<string, unknown>, field?: string);
68
+ toJSON(): Record<string, unknown>;
69
+ }
70
+ /**
71
+ * Error codes for not found errors
72
+ */
73
+ export declare enum NotFoundErrorCode {
74
+ PAYMENT_NOT_FOUND = "NOT_FOUND_PAYMENT",
75
+ SUBSCRIPTION_NOT_FOUND = "NOT_FOUND_SUBSCRIPTION",
76
+ USER_NOT_FOUND = "NOT_FOUND_USER",
77
+ PLAN_NOT_FOUND = "NOT_FOUND_PLAN",
78
+ INVOICE_NOT_FOUND = "NOT_FOUND_INVOICE",
79
+ TOKEN_PACK_NOT_FOUND = "NOT_FOUND_TOKEN_PACK",
80
+ RESOURCE_NOT_FOUND = "NOT_FOUND_RESOURCE"
81
+ }
82
+ /**
83
+ * Error class for missing resources.
84
+ * Use when a requested entity cannot be found.
85
+ */
86
+ export declare class NotFoundError extends BaseError {
87
+ readonly resourceType?: string;
88
+ readonly resourceId?: string;
89
+ constructor(message: string, code?: NotFoundErrorCode, context?: Record<string, unknown>, resourceType?: string, resourceId?: string);
90
+ toJSON(): Record<string, unknown>;
91
+ }
92
+ /**
93
+ * Type guard to check if an error is a BaseError
94
+ */
95
+ export declare function isBaseError(error: unknown): error is BaseError;
96
+ /**
97
+ * Type guard to check if an error is a PaymentError
98
+ */
99
+ export declare function isPaymentError(error: unknown): error is PaymentError;
100
+ /**
101
+ * Type guard to check if an error is a SubscriptionError
102
+ */
103
+ export declare function isSubscriptionError(error: unknown): error is SubscriptionError;
104
+ /**
105
+ * Type guard to check if an error is a ValidationError
106
+ */
107
+ export declare function isValidationError(error: unknown): error is ValidationError;
108
+ /**
109
+ * Type guard to check if an error is a NotFoundError
110
+ */
111
+ export declare function isNotFoundError(error: unknown): error is NotFoundError;
112
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/errors/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,8BAAsB,SAAU,SAAQ,KAAK;IACzC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,SAAgB,SAAS,EAAE,IAAI,CAAC;gBAEpB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAa5E;;OAEG;IACI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAU3C;AAED;;GAEG;AACH,oBAAY,gBAAgB;IACxB,aAAa,0BAA0B;IACvC,aAAa,0BAA0B;IACvC,iBAAiB,8BAA8B;IAC/C,eAAe,4BAA4B;IAC3C,gBAAgB,6BAA6B;IAC7C,cAAc,2BAA2B;CAC5C;AAED;;;GAGG;AACH,qBAAa,YAAa,SAAQ,SAAS;gBAEnC,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,gBAAqD,EAC3D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIxC;AAED;;GAEG;AACH,oBAAY,qBAAqB;IAC7B,aAAa,+BAA+B;IAC5C,aAAa,+BAA+B;IAC5C,aAAa,+BAA+B;IAC5C,cAAc,gCAAgC;IAC9C,cAAc,gCAAgC;IAC9C,OAAO,yBAAyB;CACnC;AAED;;;GAGG;AACH,qBAAa,i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9D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAE9E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAE1E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE"}
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotFoundError = exports.NotFoundErrorCode = exports.ValidationError = exports.ValidationErrorCode = exports.SubscriptionError = exports.SubscriptionErrorCode = exports.PaymentError = exports.PaymentErrorCode = exports.BaseError = void 0;
4
+ exports.isBaseError = isBaseError;
5
+ exports.isPaymentError = isPaymentError;
6
+ exports.isSubscriptionError = isSubscriptionError;
7
+ exports.isValidationError = isValidationError;
8
+ exports.isNotFoundError = isNotFoundError;
9
+ /**
10
+ * Base error class for all custom errors in the payment system.
11
+ * Provides consistent error structure with code, message, and optional context.
12
+ */
13
+ class BaseError extends Error {
14
+ constructor(message, code, context) {
15
+ super(message);
16
+ this.name = this.constructor.name;
17
+ this.code = code;
18
+ this.context = context;
19
+ this.timestamp = new Date();
20
+ // Maintains proper stack trace for where error was thrown (only in V8)
21
+ if (Error.captureStackTrace) {
22
+ Error.captureStackTrace(this, this.constructor);
23
+ }
24
+ }
25
+ /**
26
+ * Returns a structured representation of the error for logging
27
+ */
28
+ toJSON() {
29
+ return {
30
+ name: this.name,
31
+ message: this.message,
32
+ code: this.code,
33
+ context: this.context,
34
+ timestamp: this.timestamp.toISOString(),
35
+ stack: this.stack,
36
+ };
37
+ }
38
+ }
39
+ exports.BaseError = BaseError;
40
+ /**
41
+ * Error codes for payment-related failures
42
+ */
43
+ var PaymentErrorCode;
44
+ (function (PaymentErrorCode) {
45
+ PaymentErrorCode["CREATE_FAILED"] = "PAYMENT_CREATE_FAILED";
46
+ PaymentErrorCode["UPDATE_FAILED"] = "PAYMENT_UPDATE_FAILED";
47
+ PaymentErrorCode["PROCESSING_FAILED"] = "PAYMENT_PROCESSING_FAILED";
48
+ PaymentErrorCode["CALLBACK_FAILED"] = "PAYMENT_CALLBACK_FAILED";
49
+ PaymentErrorCode["INVALID_RESPONSE"] = "PAYMENT_INVALID_RESPONSE";
50
+ PaymentErrorCode["PROVIDER_ERROR"] = "PAYMENT_PROVIDER_ERROR";
51
+ })(PaymentErrorCode || (exports.PaymentErrorCode = PaymentErrorCode = {}));
52
+ /**
53
+ * Error class for payment-related failures.
54
+ * Use for errors during payment creation, processing, or provider communication.
55
+ */
56
+ class PaymentError extends BaseError {
57
+ constructor(message, code = PaymentErrorCode.PROCESSING_FAILED, context) {
58
+ super(message, code, context);
59
+ }
60
+ }
61
+ exports.PaymentError = PaymentError;
62
+ /**
63
+ * Error codes for subscription-related failures
64
+ */
65
+ var SubscriptionErrorCode;
66
+ (function (SubscriptionErrorCode) {
67
+ SubscriptionErrorCode["CREATE_FAILED"] = "SUBSCRIPTION_CREATE_FAILED";
68
+ SubscriptionErrorCode["UPDATE_FAILED"] = "SUBSCRIPTION_UPDATE_FAILED";
69
+ SubscriptionErrorCode["CANCEL_FAILED"] = "SUBSCRIPTION_CANCEL_FAILED";
70
+ SubscriptionErrorCode["RENEWAL_FAILED"] = "SUBSCRIPTION_RENEWAL_FAILED";
71
+ SubscriptionErrorCode["INVALID_STATUS"] = "SUBSCRIPTION_INVALID_STATUS";
72
+ SubscriptionErrorCode["EXPIRED"] = "SUBSCRIPTION_EXPIRED";
73
+ })(SubscriptionErrorCode || (exports.SubscriptionErrorCode = SubscriptionErrorCode = {}));
74
+ /**
75
+ * Error class for subscription-related failures.
76
+ * Use for errors during subscription lifecycle operations.
77
+ */
78
+ class SubscriptionError extends BaseError {
79
+ constructor(message, code = SubscriptionErrorCode.UPDATE_FAILED, context) {
80
+ super(message, code, context);
81
+ }
82
+ }
83
+ exports.SubscriptionError = SubscriptionError;
84
+ /**
85
+ * Error codes for validation failures
86
+ */
87
+ var ValidationErrorCode;
88
+ (function (ValidationErrorCode) {
89
+ ValidationErrorCode["INVALID_SIGNATURE"] = "VALIDATION_INVALID_SIGNATURE";
90
+ ValidationErrorCode["INVALID_INPUT"] = "VALIDATION_INVALID_INPUT";
91
+ ValidationErrorCode["MISSING_REQUIRED_FIELD"] = "VALIDATION_MISSING_REQUIRED_FIELD";
92
+ ValidationErrorCode["INVALID_FORMAT"] = "VALIDATION_INVALID_FORMAT";
93
+ ValidationErrorCode["SIGNATURE_MISMATCH"] = "VALIDATION_SIGNATURE_MISMATCH";
94
+ })(ValidationErrorCode || (exports.ValidationErrorCode = ValidationErrorCode = {}));
95
+ /**
96
+ * Error class for signature and input validation failures.
97
+ * Use for errors when validating signatures, inputs, or data formats.
98
+ */
99
+ class ValidationError extends BaseError {
100
+ constructor(message, code = ValidationErrorCode.INVALID_INPUT, context, field) {
101
+ super(message, code, context);
102
+ this.field = field;
103
+ }
104
+ toJSON() {
105
+ return {
106
+ ...super.toJSON(),
107
+ field: this.field,
108
+ };
109
+ }
110
+ }
111
+ exports.ValidationError = ValidationError;
112
+ /**
113
+ * Error codes for not found errors
114
+ */
115
+ var NotFoundErrorCode;
116
+ (function (NotFoundErrorCode) {
117
+ NotFoundErrorCode["PAYMENT_NOT_FOUND"] = "NOT_FOUND_PAYMENT";
118
+ NotFoundErrorCode["SUBSCRIPTION_NOT_FOUND"] = "NOT_FOUND_SUBSCRIPTION";
119
+ NotFoundErrorCode["USER_NOT_FOUND"] = "NOT_FOUND_USER";
120
+ NotFoundErrorCode["PLAN_NOT_FOUND"] = "NOT_FOUND_PLAN";
121
+ NotFoundErrorCode["INVOICE_NOT_FOUND"] = "NOT_FOUND_INVOICE";
122
+ NotFoundErrorCode["TOKEN_PACK_NOT_FOUND"] = "NOT_FOUND_TOKEN_PACK";
123
+ NotFoundErrorCode["RESOURCE_NOT_FOUND"] = "NOT_FOUND_RESOURCE";
124
+ })(NotFoundErrorCode || (exports.NotFoundErrorCode = NotFoundErrorCode = {}));
125
+ /**
126
+ * Error class for missing resources.
127
+ * Use when a requested entity cannot be found.
128
+ */
129
+ class NotFoundError extends BaseError {
130
+ constructor(message, code = NotFoundErrorCode.RESOURCE_NOT_FOUND, context, resourceType, resourceId) {
131
+ super(message, code, context);
132
+ this.resourceType = resourceType;
133
+ this.resourceId = resourceId;
134
+ }
135
+ toJSON() {
136
+ return {
137
+ ...super.toJSON(),
138
+ resourceType: this.resourceType,
139
+ resourceId: this.resourceId,
140
+ };
141
+ }
142
+ }
143
+ exports.NotFoundError = NotFoundError;
144
+ /**
145
+ * Type guard to check if an error is a BaseError
146
+ */
147
+ function isBaseError(error) {
148
+ return error instanceof BaseError;
149
+ }
150
+ /**
151
+ * Type guard to check if an error is a PaymentError
152
+ */
153
+ function isPaymentError(error) {
154
+ return error instanceof PaymentError;
155
+ }
156
+ /**
157
+ * Type guard to check if an error is a SubscriptionError
158
+ */
159
+ function isSubscriptionError(error) {
160
+ return error instanceof SubscriptionError;
161
+ }
162
+ /**
163
+ * Type guard to check if an error is a ValidationError
164
+ */
165
+ function isValidationError(error) {
166
+ return error instanceof ValidationError;
167
+ }
168
+ /**
169
+ * Type guard to check if an error is a NotFoundError
170
+ */
171
+ function isNotFoundError(error) {
172
+ return error instanceof NotFoundError;
173
+ }
174
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/modules/errors/types.ts"],"names":[],"mappings":";;;AA0KA,kCAEC;AAKD,wCAEC;AAKD,kDAEC;AAKD,8CAEC;AAKD,0CAEC;AAxMD;;;GAGG;AACH,MAAsB,SAAU,SAAQ,KAAK;IAKzC,YAAY,OAAe,EAAE,IAAY,EAAE,OAAiC;QACxE,KAAK,CAAC,OAAO,CAAC,CA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,OAAiC,EACjC,YAAqB,EACrB,UAAmB;QAEnB,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAEM,MAAM;QACT,OAAO;YACH,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,UAAU,EAAE,IAAI,CAAC,UAAU;SAC9B,CAAC;IACN,CAAC;CACJ;AAvBD,sCAuBC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAC,KAAc;IACtC,OAAO,KAAK,YAAY,SAAS,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAc;IACzC,OAAO,KAAK,YAAY,YAAY,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,KAAc;IAC9C,OAAO,KAAK,YAAY,iBAAiB,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAAc;IAC5C,OAAO,KAAK,YAAY,eAAe,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC1C,OAAO,KAAK,YAAY,aAAa,CAAC;AAC1C,CAAC"}
@@ -54,5 +54,67 @@ declare function editRegularPurchaseAPI({ orderReference, amount, dateBegin, dat
54
54
  regularMode: 'daily' | 'weekly' | 'monthly' | 'yearly';
55
55
  currency: string;
56
56
  }): Promise<WayforpayResponse>;
57
- export { createPaymentAPI, editRegularPurchaseAPI };
57
+ /**
58
+ * Creates a one-time payment API URL for token pack purchases via Wayforpay.
59
+ * Generates a unique order reference using the v2 token pack format.
60
+ *
61
+ * @param params - Payment creation parameters
62
+ * @param params.userId - The unique identifier of the user making the payment
63
+ * @param params.platform - The application namespace (e.g., 'app' or 'telegram')
64
+ * @param params.productName - The name of the token pack being purchased
65
+ * @param params.productPrice - The price of the token pack
66
+ * @param params.packId - The identifier of the token pack
67
+ * @param params.currency - The currency code (e.g., 'UAH', 'USD')
68
+ * @param params.language - The language for the payment page (defaults to 'UA')
69
+ * @param params.returnUrl - Optional URL to redirect to after payment
70
+ * @returns Promise resolving to an object containing the payment URL and order reference, or null
71
+ * @throws Error with code 'CREATE_TOKEN_PACK_PAYMENT_API' if the API response is invalid or missing URL
72
+ */
73
+ declare function createTokenPackPaymentAPI({ userId, platform, productName, productPrice, packId, currency, language, returnUrl, }: {
74
+ userId: string;
75
+ platform: string;
76
+ productName: string;
77
+ productPrice: number;
78
+ packId: string;
79
+ currency: string;
80
+ language?: string;
81
+ returnUrl?: string;
82
+ }): Promise<{
83
+ url: string;
84
+ orderReference: string;
85
+ } | null>;
86
+ /**
87
+ * Creates a recurring payment API URL for subscription upgrades via Wayforpay.
88
+ * Generates a unique order reference using the upgrade format.
89
+ *
90
+ * @param params - Payment creation parameters
91
+ * @param params.userId - The unique identifier of the user making the payment
92
+ * @param params.platform - The application namespace (e.g., 'app' or 'telegram')
93
+ * @param params.currentPlanId - The identifier of the current subscription plan
94
+ * @param params.newPlanId - The identifier of the new subscription plan to upgrade to
95
+ * @param params.productName - The name of the upgraded plan being purchased
96
+ * @param params.productPrice - The price difference (upgrade cost)
97
+ * @param params.currency - The currency code (e.g., 'UAH', 'USD')
98
+ * @param params.regularMode - The frequency mode for regular payments
99
+ * @param params.regularCount - Number of regular payments (defaults to 3)
100
+ * @param params.language - The language for the payment page (defaults to 'UA')
101
+ * @returns Promise resolving to an object containing the payment URL and order reference, or null
102
+ * @throws Error with code 'CREATE_UPGRADE_PAYMENT_API' if the API response is invalid or missing URL
103
+ */
104
+ declare function createUpgradePaymentAPI({ userId, platform, currentPlanId, newPlanId, productName, productPrice, currency, regularMode, regularCount, language, }: {
105
+ userId: string;
106
+ platform: string;
107
+ currentPlanId: string;
108
+ newPlanId: string;
109
+ productName: string;
110
+ productPrice: number;
111
+ currency: string;
112
+ regularMode?: 'daily' | 'monthly' | 'yearly';
113
+ regularCount?: number;
114
+ language?: string;
115
+ }): Promise<{
116
+ url: string;
117
+ orderReference: string;
118
+ } | null>;
119
+ export { createPaymentAPI, editRegularPurchaseAPI, createTokenPackPaymentAPI, createUpgradePaymentAPI };
58
120
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/api.ts"],"names":[],"mappings":"AAKA,UAAU,iBAAiB;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;GAeG;AACH,iBAAe,gBAAgB,CAAC,EAC5B,MAAM,EACN,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,YAAgB,EAChB,WAAqB,EACrB,QAAe,GAClB,EAAE;IACC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAoC1D;AAED;;;;;;;;;;;;GAYG;AACH,iBAAe,sBAAsB,CAAC,EAClC,cAAc,EACd,MAAM,EACN,SAAS,EACT,OAAO,EACP,WAAW,EACX,QAAQ,GACX,EAAE;IACC,cAAc,EAAE,MAAM,CAAC;IAC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