cmi-node 1.0.0

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 (197) hide show
  1. package/LICENSE +21 -0
  2. package/dist/constants/confirmationModes.cjs +19 -0
  3. package/dist/constants/confirmationModes.d.ts +5 -0
  4. package/dist/constants/confirmationModes.d.ts.map +1 -0
  5. package/dist/constants/confirmationModes.js.map +1 -0
  6. package/dist/constants/confirmationModes.mjs +15 -0
  7. package/dist/constants/currencies.cjs +73 -0
  8. package/dist/constants/currencies.d.ts +219 -0
  9. package/dist/constants/currencies.d.ts.map +1 -0
  10. package/dist/constants/currencies.js.map +1 -0
  11. package/dist/constants/currencies.mjs +66 -0
  12. package/dist/constants/fields.cjs +54 -0
  13. package/dist/constants/fields.d.ts +9 -0
  14. package/dist/constants/fields.d.ts.map +1 -0
  15. package/dist/constants/fields.js.map +1 -0
  16. package/dist/constants/fields.mjs +48 -0
  17. package/dist/constants/index.cjs +7 -0
  18. package/dist/constants/index.d.ts +7 -0
  19. package/dist/constants/index.d.ts.map +1 -0
  20. package/dist/constants/index.js.map +1 -0
  21. package/dist/constants/index.mjs +7 -0
  22. package/dist/constants/languages.cjs +56 -0
  23. package/dist/constants/languages.d.ts +5 -0
  24. package/dist/constants/languages.d.ts.map +1 -0
  25. package/dist/constants/languages.js.map +1 -0
  26. package/dist/constants/languages.mjs +52 -0
  27. package/dist/constants/storeTypes.cjs +26 -0
  28. package/dist/constants/storeTypes.d.ts +5 -0
  29. package/dist/constants/storeTypes.d.ts.map +1 -0
  30. package/dist/constants/storeTypes.js.map +1 -0
  31. package/dist/constants/storeTypes.mjs +22 -0
  32. package/dist/constants/tranTypes.cjs +22 -0
  33. package/dist/constants/tranTypes.d.ts +5 -0
  34. package/dist/constants/tranTypes.d.ts.map +1 -0
  35. package/dist/constants/tranTypes.js.map +1 -0
  36. package/dist/constants/tranTypes.mjs +18 -0
  37. package/dist/core/CMIPaymentGateway.cjs +94 -0
  38. package/dist/core/CMIPaymentGateway.d.ts +29 -0
  39. package/dist/core/CMIPaymentGateway.d.ts.map +1 -0
  40. package/dist/core/CMIPaymentGateway.js.map +1 -0
  41. package/dist/core/CMIPaymentGateway.mjs +92 -0
  42. package/dist/core/CallbackHandler.cjs +92 -0
  43. package/dist/core/CallbackHandler.d.ts +16 -0
  44. package/dist/core/CallbackHandler.d.ts.map +1 -0
  45. package/dist/core/CallbackHandler.js.map +1 -0
  46. package/dist/core/CallbackHandler.mjs +90 -0
  47. package/dist/core/CallbackVerifier.cjs +92 -0
  48. package/dist/core/CallbackVerifier.d.ts +12 -0
  49. package/dist/core/CallbackVerifier.d.ts.map +1 -0
  50. package/dist/core/CallbackVerifier.js.map +1 -0
  51. package/dist/core/CallbackVerifier.mjs +90 -0
  52. package/dist/core/FormGenerator.cjs +44 -0
  53. package/dist/core/FormGenerator.d.ts +7 -0
  54. package/dist/core/FormGenerator.d.ts.map +1 -0
  55. package/dist/core/FormGenerator.js.map +1 -0
  56. package/dist/core/FormGenerator.mjs +42 -0
  57. package/dist/core/PaymentBuilder.cjs +63 -0
  58. package/dist/core/PaymentBuilder.d.ts +17 -0
  59. package/dist/core/PaymentBuilder.d.ts.map +1 -0
  60. package/dist/core/PaymentBuilder.js.map +1 -0
  61. package/dist/core/PaymentBuilder.mjs +61 -0
  62. package/dist/core/index.cjs +12 -0
  63. package/dist/core/index.d.ts +7 -0
  64. package/dist/core/index.d.ts.map +1 -0
  65. package/dist/core/index.js.map +1 -0
  66. package/dist/core/index.mjs +6 -0
  67. package/dist/index.cjs +44 -0
  68. package/dist/index.d.ts +12 -0
  69. package/dist/index.d.ts.map +1 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/index.mjs +11 -0
  72. package/dist/logger/index.cjs +55 -0
  73. package/dist/logger/index.d.ts +16 -0
  74. package/dist/logger/index.d.ts.map +1 -0
  75. package/dist/logger/index.js.map +1 -0
  76. package/dist/logger/index.mjs +51 -0
  77. package/dist/middleware/express.middleware.cjs +12 -0
  78. package/dist/middleware/express.middleware.d.ts +5 -0
  79. package/dist/middleware/express.middleware.d.ts.map +1 -0
  80. package/dist/middleware/express.middleware.js.map +1 -0
  81. package/dist/middleware/express.middleware.mjs +9 -0
  82. package/dist/middleware/fastify.helper.cjs +25 -0
  83. package/dist/middleware/fastify.helper.d.ts +6 -0
  84. package/dist/middleware/fastify.helper.d.ts.map +1 -0
  85. package/dist/middleware/fastify.helper.js.map +1 -0
  86. package/dist/middleware/fastify.helper.mjs +22 -0
  87. package/dist/middleware/hono.helper.cjs +32 -0
  88. package/dist/middleware/hono.helper.d.ts +6 -0
  89. package/dist/middleware/hono.helper.d.ts.map +1 -0
  90. package/dist/middleware/hono.helper.js.map +1 -0
  91. package/dist/middleware/hono.helper.mjs +29 -0
  92. package/dist/middleware/index.cjs +6 -0
  93. package/dist/middleware/index.d.ts +6 -0
  94. package/dist/middleware/index.d.ts.map +1 -0
  95. package/dist/middleware/index.js.map +1 -0
  96. package/dist/middleware/index.mjs +6 -0
  97. package/dist/middleware/nestjs.helper.cjs +33 -0
  98. package/dist/middleware/nestjs.helper.d.ts +10 -0
  99. package/dist/middleware/nestjs.helper.d.ts.map +1 -0
  100. package/dist/middleware/nestjs.helper.js.map +1 -0
  101. package/dist/middleware/nestjs.helper.mjs +30 -0
  102. package/dist/middleware/nextjs.helper.cjs +44 -0
  103. package/dist/middleware/nextjs.helper.d.ts +4 -0
  104. package/dist/middleware/nextjs.helper.d.ts.map +1 -0
  105. package/dist/middleware/nextjs.helper.js.map +1 -0
  106. package/dist/middleware/nextjs.helper.mjs +42 -0
  107. package/dist/types/callback-handler.types.cjs +2 -0
  108. package/dist/types/callback-handler.types.d.ts +28 -0
  109. package/dist/types/callback-handler.types.d.ts.map +1 -0
  110. package/dist/types/callback-handler.types.js.map +1 -0
  111. package/dist/types/callback-handler.types.mjs +2 -0
  112. package/dist/types/callback.types.cjs +2 -0
  113. package/dist/types/callback.types.d.ts +14 -0
  114. package/dist/types/callback.types.d.ts.map +1 -0
  115. package/dist/types/callback.types.js.map +1 -0
  116. package/dist/types/callback.types.mjs +2 -0
  117. package/dist/types/config.types.cjs +2 -0
  118. package/dist/types/config.types.d.ts +11 -0
  119. package/dist/types/config.types.d.ts.map +1 -0
  120. package/dist/types/config.types.js.map +1 -0
  121. package/dist/types/config.types.mjs +2 -0
  122. package/dist/types/confirmation-mode.types.cjs +2 -0
  123. package/dist/types/confirmation-mode.types.d.ts +2 -0
  124. package/dist/types/confirmation-mode.types.d.ts.map +1 -0
  125. package/dist/types/confirmation-mode.types.js.map +1 -0
  126. package/dist/types/confirmation-mode.types.mjs +2 -0
  127. package/dist/types/gateway.types.cjs +2 -0
  128. package/dist/types/gateway.types.d.ts +16 -0
  129. package/dist/types/gateway.types.d.ts.map +1 -0
  130. package/dist/types/gateway.types.js.map +1 -0
  131. package/dist/types/gateway.types.mjs +2 -0
  132. package/dist/types/index.cjs +6 -0
  133. package/dist/types/index.d.ts +6 -0
  134. package/dist/types/index.d.ts.map +1 -0
  135. package/dist/types/index.js.map +1 -0
  136. package/dist/types/index.mjs +6 -0
  137. package/dist/types/payment.types.cjs +2 -0
  138. package/dist/types/payment.types.d.ts +29 -0
  139. package/dist/types/payment.types.d.ts.map +1 -0
  140. package/dist/types/payment.types.js.map +1 -0
  141. package/dist/types/payment.types.mjs +2 -0
  142. package/dist/utils/crypto/index.cjs +2 -0
  143. package/dist/utils/crypto/index.d.ts +2 -0
  144. package/dist/utils/crypto/index.d.ts.map +1 -0
  145. package/dist/utils/crypto/index.js.map +1 -0
  146. package/dist/utils/crypto/index.mjs +2 -0
  147. package/dist/utils/crypto/timing-safe.util.cjs +23 -0
  148. package/dist/utils/crypto/timing-safe.util.d.ts +3 -0
  149. package/dist/utils/crypto/timing-safe.util.d.ts.map +1 -0
  150. package/dist/utils/crypto/timing-safe.util.js.map +1 -0
  151. package/dist/utils/crypto/timing-safe.util.mjs +20 -0
  152. package/dist/utils/formatter.util.cjs +42 -0
  153. package/dist/utils/formatter.util.d.ts +9 -0
  154. package/dist/utils/formatter.util.d.ts.map +1 -0
  155. package/dist/utils/formatter.util.js.map +1 -0
  156. package/dist/utils/formatter.util.mjs +40 -0
  157. package/dist/utils/generator.util.cjs +14 -0
  158. package/dist/utils/generator.util.d.ts +5 -0
  159. package/dist/utils/generator.util.d.ts.map +1 -0
  160. package/dist/utils/generator.util.js.map +1 -0
  161. package/dist/utils/generator.util.mjs +12 -0
  162. package/dist/utils/hash.util.cjs +42 -0
  163. package/dist/utils/hash.util.d.ts +4 -0
  164. package/dist/utils/hash.util.d.ts.map +1 -0
  165. package/dist/utils/hash.util.js.map +1 -0
  166. package/dist/utils/hash.util.mjs +40 -0
  167. package/dist/utils/index.cjs +6 -0
  168. package/dist/utils/index.d.ts +6 -0
  169. package/dist/utils/index.d.ts.map +1 -0
  170. package/dist/utils/index.js.map +1 -0
  171. package/dist/utils/index.mjs +6 -0
  172. package/dist/utils/sanitization.util.cjs +26 -0
  173. package/dist/utils/sanitization.util.d.ts +6 -0
  174. package/dist/utils/sanitization.util.d.ts.map +1 -0
  175. package/dist/utils/sanitization.util.js.map +1 -0
  176. package/dist/utils/sanitization.util.mjs +24 -0
  177. package/dist/validators/config.validator.cjs +53 -0
  178. package/dist/validators/config.validator.d.ts +8 -0
  179. package/dist/validators/config.validator.d.ts.map +1 -0
  180. package/dist/validators/config.validator.js.map +1 -0
  181. package/dist/validators/config.validator.mjs +51 -0
  182. package/dist/validators/index.cjs +4 -0
  183. package/dist/validators/index.d.ts +4 -0
  184. package/dist/validators/index.d.ts.map +1 -0
  185. package/dist/validators/index.js.map +1 -0
  186. package/dist/validators/index.mjs +4 -0
  187. package/dist/validators/payment.validator.cjs +161 -0
  188. package/dist/validators/payment.validator.d.ts +7 -0
  189. package/dist/validators/payment.validator.d.ts.map +1 -0
  190. package/dist/validators/payment.validator.js.map +1 -0
  191. package/dist/validators/payment.validator.mjs +159 -0
  192. package/dist/validators/validator.cjs +50 -0
  193. package/dist/validators/validator.d.ts +10 -0
  194. package/dist/validators/validator.d.ts.map +1 -0
  195. package/dist/validators/validator.js.map +1 -0
  196. package/dist/validators/validator.mjs +48 -0
  197. package/package.json +88 -0
@@ -0,0 +1,56 @@
1
+ const SUPPORTED_LANGUAGES = [
2
+ 'en', 'tr', 'ar', 'fr', 'de', 'es', 'it', 'pt', 'ru',
3
+ 'zh', 'ja', 'ko', 'nl', 'pl', 'sv', 'no', 'da', 'fi',
4
+ 'cs', 'el', 'he', 'hi', 'th', 'id', 'vi', 'uk'
5
+ ];
6
+ const LANGUAGE_FULLNAME_TO_CODE = {
7
+ ENGLISH: 'en',
8
+ TURKISH: 'tr',
9
+ ARABIC: 'ar',
10
+ FRENCH: 'fr',
11
+ GERMAN: 'de',
12
+ SPANISH: 'es',
13
+ ITALIAN: 'it',
14
+ PORTUGUESE: 'pt',
15
+ RUSSIAN: 'ru',
16
+ CHINESE: 'zh',
17
+ JAPANESE: 'ja',
18
+ KOREAN: 'ko',
19
+ DUTCH: 'nl',
20
+ POLISH: 'pl',
21
+ SWEDISH: 'sv',
22
+ NORWEGIAN: 'no',
23
+ DANISH: 'da',
24
+ FINNISH: 'fi',
25
+ CZECH: 'cs',
26
+ GREEK: 'el',
27
+ HEBREW: 'he',
28
+ HINDI: 'hi',
29
+ THAI: 'th',
30
+ INDONESIAN: 'id',
31
+ VIETNAMESE: 'vi',
32
+ UKRAINIAN: 'uk',
33
+ };
34
+ function normalizeLanguage(lang) {
35
+ if (!lang) {
36
+ return undefined;
37
+ }
38
+ const trimmed = lang.trim();
39
+ if (SUPPORTED_LANGUAGES.includes(trimmed)) {
40
+ return trimmed;
41
+ }
42
+ const lower = trimmed.toLowerCase();
43
+ if (SUPPORTED_LANGUAGES.includes(lower)) {
44
+ return lower;
45
+ }
46
+ const upper = trimmed.toUpperCase();
47
+ return LANGUAGE_FULLNAME_TO_CODE[upper];
48
+ }
49
+ function isSupportedLanguage(lang) {
50
+ return normalizeLanguage(lang) !== undefined;
51
+ }
52
+ //# sourceMappingURL=languages.js.map
53
+
54
+ module.exports.SUPPORTED_LANGUAGES = SUPPORTED_LANGUAGES;
55
+ module.exports.normalizeLanguage = normalizeLanguage;
56
+ module.exports.isSupportedLanguage = isSupportedLanguage;
@@ -0,0 +1,5 @@
1
+ export declare const SUPPORTED_LANGUAGES: readonly ["en", "tr", "ar", "fr", "de", "es", "it", "pt", "ru", "zh", "ja", "ko", "nl", "pl", "sv", "no", "da", "fi", "cs", "el", "he", "hi", "th", "id", "vi", "uk"];
2
+ export type Language = typeof SUPPORTED_LANGUAGES[number];
3
+ export declare function normalizeLanguage(lang: string | undefined): Language | undefined;
4
+ export declare function isSupportedLanguage(lang: string): lang is Language;
5
+ //# sourceMappingURL=languages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"languages.d.ts","sourceRoot":"","sources":["../../src/constants/languages.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,uKAItB,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAuC1D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAqBhF;AAMD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,QAAQ,CAElE"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"languages.js","sourceRoot":"","sources":["../../src/constants/languages.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACpD,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACpD,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,E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;AAMD,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,iBAAiB,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,52 @@
1
+ export const SUPPORTED_LANGUAGES = [
2
+ 'en', 'tr', 'ar', 'fr', 'de', 'es', 'it', 'pt', 'ru',
3
+ 'zh', 'ja', 'ko', 'nl', 'pl', 'sv', 'no', 'da', 'fi',
4
+ 'cs', 'el', 'he', 'hi', 'th', 'id', 'vi', 'uk'
5
+ ];
6
+ const LANGUAGE_FULLNAME_TO_CODE = {
7
+ ENGLISH: 'en',
8
+ TURKISH: 'tr',
9
+ ARABIC: 'ar',
10
+ FRENCH: 'fr',
11
+ GERMAN: 'de',
12
+ SPANISH: 'es',
13
+ ITALIAN: 'it',
14
+ PORTUGUESE: 'pt',
15
+ RUSSIAN: 'ru',
16
+ CHINESE: 'zh',
17
+ JAPANESE: 'ja',
18
+ KOREAN: 'ko',
19
+ DUTCH: 'nl',
20
+ POLISH: 'pl',
21
+ SWEDISH: 'sv',
22
+ NORWEGIAN: 'no',
23
+ DANISH: 'da',
24
+ FINNISH: 'fi',
25
+ CZECH: 'cs',
26
+ GREEK: 'el',
27
+ HEBREW: 'he',
28
+ HINDI: 'hi',
29
+ THAI: 'th',
30
+ INDONESIAN: 'id',
31
+ VIETNAMESE: 'vi',
32
+ UKRAINIAN: 'uk',
33
+ };
34
+ export function normalizeLanguage(lang) {
35
+ if (!lang) {
36
+ return undefined;
37
+ }
38
+ const trimmed = lang.trim();
39
+ if (SUPPORTED_LANGUAGES.includes(trimmed)) {
40
+ return trimmed;
41
+ }
42
+ const lower = trimmed.toLowerCase();
43
+ if (SUPPORTED_LANGUAGES.includes(lower)) {
44
+ return lower;
45
+ }
46
+ const upper = trimmed.toUpperCase();
47
+ return LANGUAGE_FULLNAME_TO_CODE[upper];
48
+ }
49
+ export function isSupportedLanguage(lang) {
50
+ return normalizeLanguage(lang) !== undefined;
51
+ }
52
+ //# sourceMappingURL=languages.js.map
@@ -0,0 +1,26 @@
1
+ const SUPPORTED_STORE_TYPES = [
2
+ '3d',
3
+ '3d_pay',
4
+ '3d_half',
5
+ '3d_full',
6
+ '3d_hosting',
7
+ '3d_pay_hosting',
8
+ 'pay_hosting',
9
+ 'pay',
10
+ 'opt_pay_hosting'
11
+ ];
12
+ function isSupportedStoreType(type) {
13
+ return SUPPORTED_STORE_TYPES.includes(type.toLowerCase());
14
+ }
15
+ function normalizeStoreType(type) {
16
+ const normalized = type.toLowerCase();
17
+ if (!SUPPORTED_STORE_TYPES.includes(normalized)) {
18
+ throw new Error(`Unsupported store type: ${type}. Supported types: ${SUPPORTED_STORE_TYPES.join(', ')}`);
19
+ }
20
+ return normalized;
21
+ }
22
+ //# sourceMappingURL=storeTypes.js.map
23
+
24
+ module.exports.SUPPORTED_STORE_TYPES = SUPPORTED_STORE_TYPES;
25
+ module.exports.isSupportedStoreType = isSupportedStoreType;
26
+ module.exports.normalizeStoreType = normalizeStoreType;
@@ -0,0 +1,5 @@
1
+ export declare const SUPPORTED_STORE_TYPES: readonly ["3d", "3d_pay", "3d_half", "3d_full", "3d_hosting", "3d_pay_hosting", "pay_hosting", "pay", "opt_pay_hosting"];
2
+ export type StoreType = typeof SUPPORTED_STORE_TYPES[number];
3
+ export declare function isSupportedStoreType(type: string): type is StoreType;
4
+ export declare function normalizeStoreType(type: string): StoreType;
5
+ //# sourceMappingURL=storeTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storeTypes.d.ts","sourceRoot":"","sources":["../../src/constants/storeTypes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,0HAUxB,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAE7D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,SAAS,CAEpE;AAKD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAM1D"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storeTypes.js","sourceRoot":"","sources":["../../src/constants/storeTypes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI;IACJ,QAAQ;IACR,SAAS;IACT,SAAS;IACT,YAAY;IACZ,gBAAgB;IAChB,aAAa;IACb,KAAK;IACL,iBAAiB;CACT,CAAC;AAIX,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,OAAO,qBAAqB,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAe,CAAC,CAAC;AACzE,CAAC;AAKD,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAe,CAAC;IACnD,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,sBAAsB,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3G,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,22 @@
1
+ export const SUPPORTED_STORE_TYPES = [
2
+ '3d',
3
+ '3d_pay',
4
+ '3d_half',
5
+ '3d_full',
6
+ '3d_hosting',
7
+ '3d_pay_hosting',
8
+ 'pay_hosting',
9
+ 'pay',
10
+ 'opt_pay_hosting'
11
+ ];
12
+ export function isSupportedStoreType(type) {
13
+ return SUPPORTED_STORE_TYPES.includes(type.toLowerCase());
14
+ }
15
+ export function normalizeStoreType(type) {
16
+ const normalized = type.toLowerCase();
17
+ if (!SUPPORTED_STORE_TYPES.includes(normalized)) {
18
+ throw new Error(`Unsupported store type: ${type}. Supported types: ${SUPPORTED_STORE_TYPES.join(', ')}`);
19
+ }
20
+ return normalized;
21
+ }
22
+ //# sourceMappingURL=storeTypes.js.map
@@ -0,0 +1,22 @@
1
+ const SUPPORTED_TRAN_TYPES = [
2
+ 'preauth',
3
+ 'auth',
4
+ 'postauth',
5
+ 'void',
6
+ 'credit',
7
+ ];
8
+ function isSupportedTranType(type) {
9
+ return SUPPORTED_TRAN_TYPES.includes(type.toLowerCase());
10
+ }
11
+ function normalizeTranType(type) {
12
+ const normalized = type.toLowerCase();
13
+ if (!SUPPORTED_TRAN_TYPES.includes(normalized)) {
14
+ throw new Error(`Unsupported transaction type: ${type}. Supported types: ${SUPPORTED_TRAN_TYPES.join(', ')}`);
15
+ }
16
+ return normalized;
17
+ }
18
+ //# sourceMappingURL=tranTypes.js.map
19
+
20
+ module.exports.SUPPORTED_TRAN_TYPES = SUPPORTED_TRAN_TYPES;
21
+ module.exports.isSupportedTranType = isSupportedTranType;
22
+ module.exports.normalizeTranType = normalizeTranType;
@@ -0,0 +1,5 @@
1
+ export declare const SUPPORTED_TRAN_TYPES: readonly ["preauth", "auth", "postauth", "void", "credit"];
2
+ export type TranType = typeof SUPPORTED_TRAN_TYPES[number];
3
+ export declare function isSupportedTranType(type: string): boolean;
4
+ export declare function normalizeTranType(type: string): TranType;
5
+ //# sourceMappingURL=tranTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tranTypes.d.ts","sourceRoot":"","sources":["../../src/constants/tranTypes.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,oBAAoB,4DAMvB,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAK3D,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAKD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAMxD"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tranTypes.js","sourceRoot":"","sources":["../../src/constants/tranTypes.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAChC,SAAS;IACT,MAAM;IACN,UAAU;IACV,MAAM;IACN,QAAQ;CACF,CAAC;AAOX,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC5C,OAAO,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAc,CAAC,CAAC;AACzE,CAAC;AAKD,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC1C,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAc,CAAC;IAClD,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,iCAAiC,IAAI,sBAAsB,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClH,CAAC;IACD,OAAO,UAAU,CAAC;AACtB,CAAC"}
@@ -0,0 +1,18 @@
1
+ export const SUPPORTED_TRAN_TYPES = [
2
+ 'preauth',
3
+ 'auth',
4
+ 'postauth',
5
+ 'void',
6
+ 'credit',
7
+ ];
8
+ export function isSupportedTranType(type) {
9
+ return SUPPORTED_TRAN_TYPES.includes(type.toLowerCase());
10
+ }
11
+ export function normalizeTranType(type) {
12
+ const normalized = type.toLowerCase();
13
+ if (!SUPPORTED_TRAN_TYPES.includes(normalized)) {
14
+ throw new Error(`Unsupported transaction type: ${type}. Supported types: ${SUPPORTED_TRAN_TYPES.join(', ')}`);
15
+ }
16
+ return normalized;
17
+ }
18
+ //# sourceMappingURL=tranTypes.js.map
@@ -0,0 +1,94 @@
1
+ const { ConfigValidator } = require("../validators/index.cjs");
2
+ const { CallbackHandler } = require("./CallbackHandler.cjs");
3
+ const { PaymentBuilder } = require("./PaymentBuilder.cjs");
4
+ const { FormGenerator } = require("./FormGenerator.cjs");
5
+ const { CallbackVerifier } = require("./CallbackVerifier.cjs");
6
+ class CMIPaymentGateway {
7
+ constructor(config, options = {}) {
8
+ this.callbackHandler = null;
9
+ this.middleware = null;
10
+ ConfigValidator.validate(config);
11
+ const normalizedConfirmationMode = ConfigValidator.validateConfirmationMode(config.confirmationMode);
12
+ this.config = {
13
+ ...config,
14
+ confirmationMode: normalizedConfirmationMode,
15
+ };
16
+ this.paymentBuilder = new PaymentBuilder({
17
+ clientId: this.config.clientId,
18
+ storeKey: this.config.storeKey,
19
+ storetype: this.config.storetype,
20
+ trantype: this.config.trantype,
21
+ shopUrl: this.config.shopUrl,
22
+ callbackUrl: this.config.callbackUrl,
23
+ });
24
+ this.formGenerator = new FormGenerator(this.config.gatewayUrl);
25
+ this.callbackVerifier = new CallbackVerifier({
26
+ storeKey: this.config.storeKey,
27
+ confirmationMode: this.config.confirmationMode ?? 'manual',
28
+ });
29
+ this.initializeCallbackHandler(options.callbackConfig);
30
+ if (options.app) {
31
+ const callbackPath = options.callbackPath ?? '/api/payment/callback';
32
+ this.registerExpressMiddleware(options.app, callbackPath);
33
+ }
34
+ }
35
+ initializeCallbackHandler(userCallbackConfig) {
36
+ this.callbackHandler = new CallbackHandler(this, {
37
+ onSuccess: userCallbackConfig?.onSuccess,
38
+ onFailure: userCallbackConfig?.onFailure,
39
+ autoRespond: userCallbackConfig?.autoRespond ?? true,
40
+ successResponse: userCallbackConfig?.successResponse,
41
+ failureResponse: userCallbackConfig?.failureResponse,
42
+ supportGetMethod: userCallbackConfig?.supportGetMethod ?? true,
43
+ });
44
+ this.middleware = this.callbackHandler.middleware();
45
+ }
46
+ getCallbackMiddleware() {
47
+ if (!this.middleware) {
48
+ throw new Error("Callback middleware not initialized. Please ensure CMIPaymentGateway is properly constructed.");
49
+ }
50
+ return this.middleware;
51
+ }
52
+ registerExpressMiddleware(app, callbackPath) {
53
+ if (!this.middleware)
54
+ return;
55
+ try {
56
+ app.post(callbackPath, this.middleware);
57
+ console.log(`✅ CMI Payment Gateway: Callback handler auto-registered at POST ${callbackPath}`);
58
+ console.log(`⚙️ Confirmation Mode: ${this.config.confirmationMode || "auto"}`);
59
+ }
60
+ catch (error) {
61
+ console.error("Failed to auto-register Express callback middleware:", error);
62
+ }
63
+ }
64
+ createCallbackHandler(options) {
65
+ return new CallbackHandler(this, options);
66
+ }
67
+ createPaymentParams(paymentRequest) {
68
+ return this.paymentBuilder.build(paymentRequest);
69
+ }
70
+ generatePaymentForm(params) {
71
+ return this.formGenerator.generate(params);
72
+ }
73
+ verifyCallback(callbackParams) {
74
+ return this.callbackVerifier.verify(callbackParams);
75
+ }
76
+ getConfirmationMode() {
77
+ return this.config.confirmationMode ?? 'manual';
78
+ }
79
+ getConfig() {
80
+ return this.config;
81
+ }
82
+ getPaymentBuilder() {
83
+ return this.paymentBuilder;
84
+ }
85
+ getFormGenerator() {
86
+ return this.formGenerator;
87
+ }
88
+ getCallbackVerifier() {
89
+ return this.callbackVerifier;
90
+ }
91
+ }
92
+ //# sourceMappingURL=CMIPaymentGateway.js.map
93
+
94
+ module.exports.CMIPaymentGateway = CMIPaymentGateway;
@@ -0,0 +1,29 @@
1
+ import { PaymentConfig, PaymentRequest, CallbackResult, ConfirmationMode, CallbackMiddleware, CMIPaymentGatewayOptions } from "../types/index.js";
2
+ import { CallbackHandler } from "./CallbackHandler.js";
3
+ import { PaymentBuilder } from "./PaymentBuilder.js";
4
+ import { FormGenerator } from "./FormGenerator.js";
5
+ import { CallbackVerifier } from "./CallbackVerifier.js";
6
+ export declare class CMIPaymentGateway {
7
+ private readonly config;
8
+ private readonly paymentBuilder;
9
+ private readonly formGenerator;
10
+ private readonly callbackVerifier;
11
+ private callbackHandler;
12
+ private middleware;
13
+ constructor(config: PaymentConfig & {
14
+ confirmationMode?: ConfirmationMode | string;
15
+ }, options?: CMIPaymentGatewayOptions);
16
+ private initializeCallbackHandler;
17
+ getCallbackMiddleware(): CallbackMiddleware;
18
+ private registerExpressMiddleware;
19
+ createCallbackHandler(options?: CMIPaymentGatewayOptions["callbackConfig"]): CallbackHandler;
20
+ createPaymentParams(paymentRequest: PaymentRequest): Record<string, any>;
21
+ generatePaymentForm(params: Record<string, any>): string;
22
+ verifyCallback(callbackParams: Record<string, any>): CallbackResult;
23
+ getConfirmationMode(): ConfirmationMode;
24
+ getConfig(): PaymentConfig;
25
+ getPaymentBuilder(): PaymentBuilder;
26
+ getFormGenerator(): FormGenerator;
27
+ getCallbackVerifier(): CallbackVerifier;
28
+ }
29
+ //# sourceMappingURL=CMIPaymentGateway.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CMIPaymentGateway.d.ts","sourceRoot":"","sources":["../../src/core/CMIPaymentGateway.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,EACzB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAwBtD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAErB;IAGF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAmB;IAEpD,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,UAAU,CAAmC;gBAWnD,MAAM,EAAE,aAAa,GAAG;QAAE,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAAA;KAAE,EACxE,OAAO,GAAE,wBAA6B;IAgDxC,OAAO,CAAC,yBAAyB;IA0B1B,qBAAqB,IAAI,kBAAkB;IAiBlD,OAAO,CAAC,yBAAyB;IAuBjC,qBAAqB,CACnB,OAAO,CAAC,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,GACnD,eAAe;IAsBlB,mBAAmB,CAAC,cAAc,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC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;QACd,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAKD,mBAAmB;QACjB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,92 @@
1
+ import { ConfigValidator } from '../validators/index.mjs';
2
+ import { CallbackHandler } from './CallbackHandler.mjs';
3
+ import { PaymentBuilder } from './PaymentBuilder.mjs';
4
+ import { FormGenerator } from './FormGenerator.mjs';
5
+ import { CallbackVerifier } from './CallbackVerifier.mjs';
6
+ export class CMIPaymentGateway {
7
+ constructor(config, options = {}) {
8
+ this.callbackHandler = null;
9
+ this.middleware = null;
10
+ ConfigValidator.validate(config);
11
+ const normalizedConfirmationMode = ConfigValidator.validateConfirmationMode(config.confirmationMode);
12
+ this.config = {
13
+ ...config,
14
+ confirmationMode: normalizedConfirmationMode,
15
+ };
16
+ this.paymentBuilder = new PaymentBuilder({
17
+ clientId: this.config.clientId,
18
+ storeKey: this.config.storeKey,
19
+ storetype: this.config.storetype,
20
+ trantype: this.config.trantype,
21
+ shopUrl: this.config.shopUrl,
22
+ callbackUrl: this.config.callbackUrl,
23
+ });
24
+ this.formGenerator = new FormGenerator(this.config.gatewayUrl);
25
+ this.callbackVerifier = new CallbackVerifier({
26
+ storeKey: this.config.storeKey,
27
+ confirmationMode: this.config.confirmationMode ?? 'manual',
28
+ });
29
+ this.initializeCallbackHandler(options.callbackConfig);
30
+ if (options.app) {
31
+ const callbackPath = options.callbackPath ?? '/api/payment/callback';
32
+ this.registerExpressMiddleware(options.app, callbackPath);
33
+ }
34
+ }
35
+ initializeCallbackHandler(userCallbackConfig) {
36
+ this.callbackHandler = new CallbackHandler(this, {
37
+ onSuccess: userCallbackConfig?.onSuccess,
38
+ onFailure: userCallbackConfig?.onFailure,
39
+ autoRespond: userCallbackConfig?.autoRespond ?? true,
40
+ successResponse: userCallbackConfig?.successResponse,
41
+ failureResponse: userCallbackConfig?.failureResponse,
42
+ supportGetMethod: userCallbackConfig?.supportGetMethod ?? true,
43
+ });
44
+ this.middleware = this.callbackHandler.middleware();
45
+ }
46
+ getCallbackMiddleware() {
47
+ if (!this.middleware) {
48
+ throw new Error("Callback middleware not initialized. Please ensure CMIPaymentGateway is properly constructed.");
49
+ }
50
+ return this.middleware;
51
+ }
52
+ registerExpressMiddleware(app, callbackPath) {
53
+ if (!this.middleware)
54
+ return;
55
+ try {
56
+ app.post(callbackPath, this.middleware);
57
+ console.log(`✅ CMI Payment Gateway: Callback handler auto-registered at POST ${callbackPath}`);
58
+ console.log(`⚙️ Confirmation Mode: ${this.config.confirmationMode || "auto"}`);
59
+ }
60
+ catch (error) {
61
+ console.error("Failed to auto-register Express callback middleware:", error);
62
+ }
63
+ }
64
+ createCallbackHandler(options) {
65
+ return new CallbackHandler(this, options);
66
+ }
67
+ createPaymentParams(paymentRequest) {
68
+ return this.paymentBuilder.build(paymentRequest);
69
+ }
70
+ generatePaymentForm(params) {
71
+ return this.formGenerator.generate(params);
72
+ }
73
+ verifyCallback(callbackParams) {
74
+ return this.callbackVerifier.verify(callbackParams);
75
+ }
76
+ getConfirmationMode() {
77
+ return this.config.confirmationMode ?? 'manual';
78
+ }
79
+ getConfig() {
80
+ return this.config;
81
+ }
82
+ getPaymentBuilder() {
83
+ return this.paymentBuilder;
84
+ }
85
+ getFormGenerator() {
86
+ return this.formGenerator;
87
+ }
88
+ getCallbackVerifier() {
89
+ return this.callbackVerifier;
90
+ }
91
+ }
92
+ //# sourceMappingURL=CMIPaymentGateway.js.map
@@ -0,0 +1,92 @@
1
+ class CallbackHandler {
2
+ constructor(gateway, options) {
3
+ this.gateway = gateway;
4
+ this.options = {
5
+ autoRespond: options?.autoRespond ?? true,
6
+ successResponse: options?.successResponse ?? "",
7
+ failureResponse: options?.failureResponse ?? "FAILURE",
8
+ onSuccess: options?.onSuccess ?? (() => { }),
9
+ onFailure: options?.onFailure ?? (() => { }),
10
+ supportGetMethod: options?.supportGetMethod ?? true,
11
+ };
12
+ }
13
+ middleware() {
14
+ return async (req, res, next) => {
15
+ try {
16
+ const params = this.extractParams(req);
17
+ const result = this.gateway.verifyCallback(params);
18
+ if (result.success) {
19
+ await Promise.resolve(this.options.onSuccess(result));
20
+ }
21
+ else {
22
+ await Promise.resolve(this.options.onFailure(result));
23
+ }
24
+ if (this.options.autoRespond) {
25
+ this.sendResponse(res, result);
26
+ }
27
+ else if (next) {
28
+ req.paymentResult = result;
29
+ next();
30
+ }
31
+ }
32
+ catch (error) {
33
+ if (this.options.autoRespond) {
34
+ res.status(500).send("FAILURE");
35
+ }
36
+ else if (next) {
37
+ next(error);
38
+ }
39
+ }
40
+ };
41
+ }
42
+ extractParams(req) {
43
+ const method = (req.method || "POST").toUpperCase();
44
+ if (method === "POST") {
45
+ return req.body || {};
46
+ }
47
+ if (this.options.supportGetMethod) {
48
+ return req.query || req.body || {};
49
+ }
50
+ return req.body || {};
51
+ }
52
+ sendResponse(res, result) {
53
+ try {
54
+ if (result.success) {
55
+ const response = this.options.successResponse || result.status;
56
+ res.status(200).send(response);
57
+ }
58
+ else {
59
+ const response = this.options.failureResponse;
60
+ res.status(200).send(response);
61
+ }
62
+ }
63
+ catch {
64
+ res.status(500).send("ERROR");
65
+ }
66
+ }
67
+ async handle(params) {
68
+ const result = this.gateway.verifyCallback(params);
69
+ if (result.success) {
70
+ await Promise.resolve(this.options.onSuccess(result));
71
+ }
72
+ else {
73
+ await Promise.resolve(this.options.onFailure(result));
74
+ }
75
+ return result;
76
+ }
77
+ getResponse(result) {
78
+ if (result.success) {
79
+ return {
80
+ status: 200,
81
+ body: this.options.successResponse || result.status,
82
+ };
83
+ }
84
+ return {
85
+ status: 200,
86
+ body: this.options.failureResponse,
87
+ };
88
+ }
89
+ }
90
+ //# sourceMappingURL=CallbackHandler.js.map
91
+
92
+ module.exports.CallbackHandler = CallbackHandler;
@@ -0,0 +1,16 @@
1
+ import { CMIPaymentGateway } from "./CMIPaymentGateway.js";
2
+ import { CallbackHandlerOptions, CallbackResult, CallbackMiddleware } from "../types/index.js";
3
+ export declare class CallbackHandler {
4
+ private gateway;
5
+ private options;
6
+ constructor(gateway: CMIPaymentGateway, options?: CallbackHandlerOptions);
7
+ middleware(): CallbackMiddleware;
8
+ private extractParams;
9
+ private sendResponse;
10
+ handle(params: any): Promise<CallbackResult>;
11
+ getResponse(result: CallbackResult): {
12
+ status: number;
13
+ body: string;
14
+ };
15
+ }
16
+ //# sourceMappingURL=CallbackHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallbackHandler.d.ts","sourceRoot":"","sources":["../../src/core/CallbackHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,sBAAsB,EAGtB,cAAc,EACd,kBAAkB,EACnB,MAAM,QAAQ,CAAC;AAKhB,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,OAAO,CAAmC;gBAEtC,OAAO,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAaxE,UAAU,IAAI,kBAAkB;IAgChC,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,YAAY;IAcd,MAAM,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC;IAYlD,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;CAatE"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallbackHandler.js","sourceRoot":"","sources":["../../src/core/CallbackHandler.ts"],"names":[],"mappings":"AAaA,MAAM,OAAO,eAAe;IAI1B,YAAY,OAA0B,EAAE,OAAgC;QACtE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG;YACb,WAAW,EAAE,OAAO,EAAE,WAAW,IAAI,IAAI;YACzC,eAAe,EAAE,OAAO,EAAE,eAAe,IAAI,EAAE;YA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