@swichpay/react-native 0.0.0-stage → 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 (277) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/LICENSE +21 -0
  3. package/README.md +82 -2
  4. package/docs/checkouts.md +98 -0
  5. package/docs/getting-started.md +140 -0
  6. package/docs/going-live.md +45 -0
  7. package/docs/own-screen.md +81 -0
  8. package/docs/results-and-errors.md +75 -0
  9. package/docs/server.md +163 -0
  10. package/docs/troubleshooting.md +57 -0
  11. package/lib/commonjs/HostedCheckout.js +115 -0
  12. package/lib/commonjs/checkout-webview.js +85 -0
  13. package/lib/commonjs/checkouts/PaymentSheet.js +1317 -0
  14. package/lib/commonjs/checkouts/direct.js +671 -0
  15. package/lib/commonjs/context.js +64 -0
  16. package/lib/commonjs/core/api/direct-payment-api.js +425 -0
  17. package/lib/commonjs/core/api/discount-api.js +19 -0
  18. package/lib/commonjs/core/api/gateway-api.js +366 -0
  19. package/lib/commonjs/core/api/payments-api.js +79 -0
  20. package/lib/commonjs/core/api/repositories.js +5 -0
  21. package/lib/commonjs/core/assets/images.js +12 -0
  22. package/lib/commonjs/core/assets/method-logos.js +19 -0
  23. package/lib/commonjs/core/assets/pwa-images.js +13 -0
  24. package/lib/commonjs/core/browser/clipboard.js +30 -0
  25. package/lib/commonjs/core/browser/dom.js +71 -0
  26. package/lib/commonjs/core/browser/hosted-checkout.js +107 -0
  27. package/lib/commonjs/core/browser/index.js +119 -0
  28. package/lib/commonjs/core/browser/qr.js +109 -0
  29. package/lib/commonjs/core/browser/three-ds.js +151 -0
  30. package/lib/commonjs/core/client.js +344 -0
  31. package/lib/commonjs/core/config.js +132 -0
  32. package/lib/commonjs/core/environment.js +34 -0
  33. package/lib/commonjs/core/errors.js +138 -0
  34. package/lib/commonjs/core/events.js +57 -0
  35. package/lib/commonjs/core/flows/controller.js +106 -0
  36. package/lib/commonjs/core/flows/countdown.js +41 -0
  37. package/lib/commonjs/core/flows/direct-bank-transfer.js +236 -0
  38. package/lib/commonjs/core/flows/direct-card.js +354 -0
  39. package/lib/commonjs/core/flows/direct-ewallet.js +124 -0
  40. package/lib/commonjs/core/flows/direct-one-bill.js +172 -0
  41. package/lib/commonjs/core/flows/direct-qr.js +109 -0
  42. package/lib/commonjs/core/flows/direct-rtp.js +302 -0
  43. package/lib/commonjs/core/flows/discount-lookup.js +80 -0
  44. package/lib/commonjs/core/flows/headless.js +94 -0
  45. package/lib/commonjs/core/flows/payment-sheet.js +1321 -0
  46. package/lib/commonjs/core/flows/services.js +31 -0
  47. package/lib/commonjs/core/flows/shared.js +90 -0
  48. package/lib/commonjs/core/http/api-client.js +208 -0
  49. package/lib/commonjs/core/http/endpoints.js +61 -0
  50. package/lib/commonjs/core/http/token-manager.js +46 -0
  51. package/lib/commonjs/core/http/transport.js +134 -0
  52. package/lib/commonjs/core/index.js +688 -0
  53. package/lib/commonjs/core/models/category.js +113 -0
  54. package/lib/commonjs/core/models/discount.js +51 -0
  55. package/lib/commonjs/core/models/payment.js +95 -0
  56. package/lib/commonjs/core/models/session.js +131 -0
  57. package/lib/commonjs/core/server/index.js +64 -0
  58. package/lib/commonjs/core/server/node.js +60 -0
  59. package/lib/commonjs/core/server/proxy.js +194 -0
  60. package/lib/commonjs/core/server/verify.js +122 -0
  61. package/lib/commonjs/core/swichpay.js +72 -0
  62. package/lib/commonjs/core/utils/crypto.js +78 -0
  63. package/lib/commonjs/core/utils/formatters.js +68 -0
  64. package/lib/commonjs/core/utils/json.js +110 -0
  65. package/lib/commonjs/core/utils/log.js +75 -0
  66. package/lib/commonjs/core/utils/runtime.js +34 -0
  67. package/lib/commonjs/core/utils/validators.js +59 -0
  68. package/lib/commonjs/hooks.js +77 -0
  69. package/lib/commonjs/index.js +203 -0
  70. package/lib/commonjs/package.json +1 -0
  71. package/lib/commonjs/polyfills.js +3 -0
  72. package/lib/commonjs/presenter.js +61 -0
  73. package/lib/commonjs/provider.js +192 -0
  74. package/lib/commonjs/swichpay.js +192 -0
  75. package/lib/commonjs/theme.js +54 -0
  76. package/lib/commonjs/ui.js +1142 -0
  77. package/lib/commonjs/webviews.js +279 -0
  78. package/lib/module/HostedCheckout.js +111 -0
  79. package/lib/module/checkout-webview.js +83 -0
  80. package/lib/module/checkouts/PaymentSheet.js +1313 -0
  81. package/lib/module/checkouts/direct.js +661 -0
  82. package/lib/module/context.js +58 -0
  83. package/lib/module/core/api/direct-payment-api.js +413 -0
  84. package/lib/module/core/api/discount-api.js +14 -0
  85. package/lib/module/core/api/gateway-api.js +358 -0
  86. package/lib/module/core/api/payments-api.js +73 -0
  87. package/lib/module/core/api/repositories.js +3 -0
  88. package/lib/module/core/assets/images.js +8 -0
  89. package/lib/module/core/assets/method-logos.js +15 -0
  90. package/lib/module/core/assets/pwa-images.js +9 -0
  91. package/lib/module/core/browser/clipboard.js +27 -0
  92. package/lib/module/core/browser/dom.js +63 -0
  93. package/lib/module/core/browser/hosted-checkout.js +102 -0
  94. package/lib/module/core/browser/index.js +12 -0
  95. package/lib/module/core/browser/qr.js +100 -0
  96. package/lib/module/core/browser/three-ds.js +145 -0
  97. package/lib/module/core/client.js +338 -0
  98. package/lib/module/core/config.js +128 -0
  99. package/lib/module/core/environment.js +29 -0
  100. package/lib/module/core/errors.js +125 -0
  101. package/lib/module/core/events.js +51 -0
  102. package/lib/module/core/flows/controller.js +101 -0
  103. package/lib/module/core/flows/countdown.js +36 -0
  104. package/lib/module/core/flows/direct-bank-transfer.js +231 -0
  105. package/lib/module/core/flows/direct-card.js +349 -0
  106. package/lib/module/core/flows/direct-ewallet.js +119 -0
  107. package/lib/module/core/flows/direct-one-bill.js +167 -0
  108. package/lib/module/core/flows/direct-qr.js +104 -0
  109. package/lib/module/core/flows/direct-rtp.js +297 -0
  110. package/lib/module/core/flows/discount-lookup.js +75 -0
  111. package/lib/module/core/flows/headless.js +90 -0
  112. package/lib/module/core/flows/payment-sheet.js +1315 -0
  113. package/lib/module/core/flows/services.js +27 -0
  114. package/lib/module/core/flows/shared.js +78 -0
  115. package/lib/module/core/http/api-client.js +203 -0
  116. package/lib/module/core/http/endpoints.js +57 -0
  117. package/lib/module/core/http/token-manager.js +41 -0
  118. package/lib/module/core/http/transport.js +126 -0
  119. package/lib/module/core/index.js +52 -0
  120. package/lib/module/core/models/category.js +104 -0
  121. package/lib/module/core/models/discount.js +46 -0
  122. package/lib/module/core/models/payment.js +89 -0
  123. package/lib/module/core/models/session.js +120 -0
  124. package/lib/module/core/server/index.js +11 -0
  125. package/lib/module/core/server/node.js +56 -0
  126. package/lib/module/core/server/proxy.js +191 -0
  127. package/lib/module/core/server/verify.js +115 -0
  128. package/lib/module/core/swichpay.js +68 -0
  129. package/lib/module/core/utils/crypto.js +72 -0
  130. package/lib/module/core/utils/formatters.js +56 -0
  131. package/lib/module/core/utils/json.js +94 -0
  132. package/lib/module/core/utils/log.js +67 -0
  133. package/lib/module/core/utils/runtime.js +28 -0
  134. package/lib/module/core/utils/validators.js +54 -0
  135. package/lib/module/hooks.js +72 -0
  136. package/lib/module/index.js +36 -0
  137. package/lib/module/polyfills.js +4 -0
  138. package/lib/module/presenter.js +58 -0
  139. package/lib/module/provider.js +188 -0
  140. package/lib/module/swichpay.js +187 -0
  141. package/lib/module/theme.js +50 -0
  142. package/lib/module/ui.js +1116 -0
  143. package/lib/module/webviews.js +272 -0
  144. package/lib/typescript/commonjs/HostedCheckout.d.ts +17 -0
  145. package/lib/typescript/commonjs/checkout-webview.d.ts +14 -0
  146. package/lib/typescript/commonjs/checkouts/PaymentSheet.d.ts +14 -0
  147. package/lib/typescript/commonjs/checkouts/direct.d.ts +18 -0
  148. package/lib/typescript/commonjs/context.d.ts +20 -0
  149. package/lib/typescript/commonjs/core/api/direct-payment-api.d.ts +103 -0
  150. package/lib/typescript/commonjs/core/api/discount-api.d.ts +10 -0
  151. package/lib/typescript/commonjs/core/api/gateway-api.d.ts +150 -0
  152. package/lib/typescript/commonjs/core/api/payments-api.d.ts +22 -0
  153. package/lib/typescript/commonjs/core/api/repositories.d.ts +86 -0
  154. package/lib/typescript/commonjs/core/assets/images.d.ts +5 -0
  155. package/lib/typescript/commonjs/core/assets/method-logos.d.ts +12 -0
  156. package/lib/typescript/commonjs/core/assets/pwa-images.d.ts +7 -0
  157. package/lib/typescript/commonjs/core/browser/clipboard.d.ts +3 -0
  158. package/lib/typescript/commonjs/core/browser/dom.d.ts +11 -0
  159. package/lib/typescript/commonjs/core/browser/hosted-checkout.d.ts +27 -0
  160. package/lib/typescript/commonjs/core/browser/index.d.ts +11 -0
  161. package/lib/typescript/commonjs/core/browser/qr.d.ts +18 -0
  162. package/lib/typescript/commonjs/core/browser/three-ds.d.ts +45 -0
  163. package/lib/typescript/commonjs/core/client.d.ts +181 -0
  164. package/lib/typescript/commonjs/core/config.d.ts +86 -0
  165. package/lib/typescript/commonjs/core/environment.d.ts +22 -0
  166. package/lib/typescript/commonjs/core/errors.d.ts +78 -0
  167. package/lib/typescript/commonjs/core/events.d.ts +19 -0
  168. package/lib/typescript/commonjs/core/flows/controller.d.ts +41 -0
  169. package/lib/typescript/commonjs/core/flows/countdown.d.ts +15 -0
  170. package/lib/typescript/commonjs/core/flows/direct-bank-transfer.d.ts +49 -0
  171. package/lib/typescript/commonjs/core/flows/direct-card.d.ts +94 -0
  172. package/lib/typescript/commonjs/core/flows/direct-ewallet.d.ts +39 -0
  173. package/lib/typescript/commonjs/core/flows/direct-one-bill.d.ts +38 -0
  174. package/lib/typescript/commonjs/core/flows/direct-qr.d.ts +25 -0
  175. package/lib/typescript/commonjs/core/flows/direct-rtp.d.ts +72 -0
  176. package/lib/typescript/commonjs/core/flows/discount-lookup.d.ts +37 -0
  177. package/lib/typescript/commonjs/core/flows/headless.d.ts +38 -0
  178. package/lib/typescript/commonjs/core/flows/payment-sheet.d.ts +263 -0
  179. package/lib/typescript/commonjs/core/flows/services.d.ts +22 -0
  180. package/lib/typescript/commonjs/core/flows/shared.d.ts +40 -0
  181. package/lib/typescript/commonjs/core/http/api-client.d.ts +37 -0
  182. package/lib/typescript/commonjs/core/http/endpoints.d.ts +39 -0
  183. package/lib/typescript/commonjs/core/http/token-manager.d.ts +19 -0
  184. package/lib/typescript/commonjs/core/http/transport.d.ts +37 -0
  185. package/lib/typescript/commonjs/core/index.d.ts +42 -0
  186. package/lib/typescript/commonjs/core/models/category.d.ts +35 -0
  187. package/lib/typescript/commonjs/core/models/discount.d.ts +41 -0
  188. package/lib/typescript/commonjs/core/models/payment.d.ts +104 -0
  189. package/lib/typescript/commonjs/core/models/session.d.ts +87 -0
  190. package/lib/typescript/commonjs/core/server/index.d.ts +10 -0
  191. package/lib/typescript/commonjs/core/server/node.d.ts +19 -0
  192. package/lib/typescript/commonjs/core/server/proxy.d.ts +30 -0
  193. package/lib/typescript/commonjs/core/server/verify.d.ts +61 -0
  194. package/lib/typescript/commonjs/core/swichpay.d.ts +40 -0
  195. package/lib/typescript/commonjs/core/utils/crypto.d.ts +19 -0
  196. package/lib/typescript/commonjs/core/utils/formatters.d.ts +19 -0
  197. package/lib/typescript/commonjs/core/utils/json.d.ts +27 -0
  198. package/lib/typescript/commonjs/core/utils/log.d.ts +15 -0
  199. package/lib/typescript/commonjs/core/utils/runtime.d.ts +12 -0
  200. package/lib/typescript/commonjs/core/utils/validators.d.ts +23 -0
  201. package/lib/typescript/commonjs/hooks.d.ts +21 -0
  202. package/lib/typescript/commonjs/index.d.ts +26 -0
  203. package/lib/typescript/commonjs/package.json +1 -0
  204. package/lib/typescript/commonjs/polyfills.d.ts +2 -0
  205. package/lib/typescript/commonjs/presenter.d.ts +25 -0
  206. package/lib/typescript/commonjs/provider.d.ts +22 -0
  207. package/lib/typescript/commonjs/swichpay.d.ts +125 -0
  208. package/lib/typescript/commonjs/theme.d.ts +52 -0
  209. package/lib/typescript/commonjs/ui.d.ts +583 -0
  210. package/lib/typescript/commonjs/webviews.d.ts +40 -0
  211. package/lib/typescript/module/HostedCheckout.d.ts +17 -0
  212. package/lib/typescript/module/checkout-webview.d.ts +14 -0
  213. package/lib/typescript/module/checkouts/PaymentSheet.d.ts +14 -0
  214. package/lib/typescript/module/checkouts/direct.d.ts +18 -0
  215. package/lib/typescript/module/context.d.ts +20 -0
  216. package/lib/typescript/module/core/api/direct-payment-api.d.ts +103 -0
  217. package/lib/typescript/module/core/api/discount-api.d.ts +10 -0
  218. package/lib/typescript/module/core/api/gateway-api.d.ts +150 -0
  219. package/lib/typescript/module/core/api/payments-api.d.ts +22 -0
  220. package/lib/typescript/module/core/api/repositories.d.ts +86 -0
  221. package/lib/typescript/module/core/assets/images.d.ts +5 -0
  222. package/lib/typescript/module/core/assets/method-logos.d.ts +12 -0
  223. package/lib/typescript/module/core/assets/pwa-images.d.ts +7 -0
  224. package/lib/typescript/module/core/browser/clipboard.d.ts +3 -0
  225. package/lib/typescript/module/core/browser/dom.d.ts +11 -0
  226. package/lib/typescript/module/core/browser/hosted-checkout.d.ts +27 -0
  227. package/lib/typescript/module/core/browser/index.d.ts +11 -0
  228. package/lib/typescript/module/core/browser/qr.d.ts +18 -0
  229. package/lib/typescript/module/core/browser/three-ds.d.ts +45 -0
  230. package/lib/typescript/module/core/client.d.ts +181 -0
  231. package/lib/typescript/module/core/config.d.ts +86 -0
  232. package/lib/typescript/module/core/environment.d.ts +22 -0
  233. package/lib/typescript/module/core/errors.d.ts +78 -0
  234. package/lib/typescript/module/core/events.d.ts +19 -0
  235. package/lib/typescript/module/core/flows/controller.d.ts +41 -0
  236. package/lib/typescript/module/core/flows/countdown.d.ts +15 -0
  237. package/lib/typescript/module/core/flows/direct-bank-transfer.d.ts +49 -0
  238. package/lib/typescript/module/core/flows/direct-card.d.ts +94 -0
  239. package/lib/typescript/module/core/flows/direct-ewallet.d.ts +39 -0
  240. package/lib/typescript/module/core/flows/direct-one-bill.d.ts +38 -0
  241. package/lib/typescript/module/core/flows/direct-qr.d.ts +25 -0
  242. package/lib/typescript/module/core/flows/direct-rtp.d.ts +72 -0
  243. package/lib/typescript/module/core/flows/discount-lookup.d.ts +37 -0
  244. package/lib/typescript/module/core/flows/headless.d.ts +38 -0
  245. package/lib/typescript/module/core/flows/payment-sheet.d.ts +263 -0
  246. package/lib/typescript/module/core/flows/services.d.ts +22 -0
  247. package/lib/typescript/module/core/flows/shared.d.ts +40 -0
  248. package/lib/typescript/module/core/http/api-client.d.ts +37 -0
  249. package/lib/typescript/module/core/http/endpoints.d.ts +39 -0
  250. package/lib/typescript/module/core/http/token-manager.d.ts +19 -0
  251. package/lib/typescript/module/core/http/transport.d.ts +37 -0
  252. package/lib/typescript/module/core/index.d.ts +42 -0
  253. package/lib/typescript/module/core/models/category.d.ts +35 -0
  254. package/lib/typescript/module/core/models/discount.d.ts +41 -0
  255. package/lib/typescript/module/core/models/payment.d.ts +104 -0
  256. package/lib/typescript/module/core/models/session.d.ts +87 -0
  257. package/lib/typescript/module/core/server/index.d.ts +10 -0
  258. package/lib/typescript/module/core/server/node.d.ts +19 -0
  259. package/lib/typescript/module/core/server/proxy.d.ts +30 -0
  260. package/lib/typescript/module/core/server/verify.d.ts +61 -0
  261. package/lib/typescript/module/core/swichpay.d.ts +40 -0
  262. package/lib/typescript/module/core/utils/crypto.d.ts +19 -0
  263. package/lib/typescript/module/core/utils/formatters.d.ts +19 -0
  264. package/lib/typescript/module/core/utils/json.d.ts +27 -0
  265. package/lib/typescript/module/core/utils/log.d.ts +15 -0
  266. package/lib/typescript/module/core/utils/runtime.d.ts +12 -0
  267. package/lib/typescript/module/core/utils/validators.d.ts +23 -0
  268. package/lib/typescript/module/hooks.d.ts +21 -0
  269. package/lib/typescript/module/index.d.ts +26 -0
  270. package/lib/typescript/module/polyfills.d.ts +2 -0
  271. package/lib/typescript/module/presenter.d.ts +25 -0
  272. package/lib/typescript/module/provider.d.ts +22 -0
  273. package/lib/typescript/module/swichpay.d.ts +125 -0
  274. package/lib/typescript/module/theme.d.ts +52 -0
  275. package/lib/typescript/module/ui.d.ts +583 -0
  276. package/lib/typescript/module/webviews.d.ts +40 -0
  277. package/package.json +129 -4
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SENSITIVE_DATA_KEYS = void 0;
7
+ exports.createLog = createLog;
8
+ exports.redactForLog = redactForLog;
9
+ exports.redactHeaders = redactHeaders;
10
+ exports.safeJson = safeJson;
11
+ /**
12
+ * Logging. The SDK prints nothing by default.
13
+ * Pass `logger` to `SwichPay.initialize()` to receive redacted debug lines.
14
+ */
15
+
16
+ /** Request/response body keys never logged in full. */
17
+ const SENSITIVE_DATA_KEYS = exports.SENSITIVE_DATA_KEYS = new Set(['cardNumber', 'cvc', 'cvv', 'expiryDate', 'cnic', 'msisdn', 'mobileNumber', 'accountNumber', 'accountNo', 'accountNumberAlias', 'iban', 'otp',
18
+ // Discount API's referenceValue can carry a full card PAN for card-payment lookups.
19
+ 'refrenceValue',
20
+ // Never present in a logged response today; masked defensively.
21
+ 'clientSecret', 'client_secret', 'access_token', 'recievedCheckSum']);
22
+
23
+ /** Copies `data` with sensitive keys masked at any depth (nested objects and arrays), for logging only. */
24
+ function redactForLog(data) {
25
+ if (data == null) return null;
26
+ return redactObject(data, 0);
27
+ }
28
+
29
+ /** Deeper than any SwichPay payload; stops a cyclic or hostile value from recursing forever. */
30
+ const MAX_REDACT_DEPTH = 8;
31
+ function redactValue(value, depth) {
32
+ if (Array.isArray(value)) return depth >= MAX_REDACT_DEPTH ? '<truncated>' : value.map(v => redactValue(v, depth + 1));
33
+ if (value !== null && typeof value === 'object') {
34
+ return depth >= MAX_REDACT_DEPTH ? '<truncated>' : redactObject(value, depth + 1);
35
+ }
36
+ return value;
37
+ }
38
+ function redactObject(data, depth) {
39
+ const out = {};
40
+ for (const [key, value] of Object.entries(data)) {
41
+ out[key] = SENSITIVE_DATA_KEYS.has(key) ? '<redacted>' : redactValue(value, depth);
42
+ }
43
+ return out;
44
+ }
45
+
46
+ /** Headers that carry credentials or session keys (lower-case). */
47
+ const SENSITIVE_HEADERS = new Set(['authorization', 'cookie', 'publickey', 'x-public-key']);
48
+
49
+ /** Copies `headers` with credentials masked, for logging only. */
50
+ function redactHeaders(headers) {
51
+ const out = {};
52
+ for (const [key, value] of Object.entries(headers)) {
53
+ out[key] = SENSITIVE_HEADERS.has(key.toLowerCase()) ? '<redacted>' : value;
54
+ }
55
+ return out;
56
+ }
57
+
58
+ /** Wraps an optional logger so callers can log unconditionally. */
59
+ function createLog(logger) {
60
+ if (!logger) return () => {};
61
+ return message => {
62
+ try {
63
+ logger(message);
64
+ } catch {
65
+ // A broken logger must never break a payment.
66
+ }
67
+ };
68
+ }
69
+ function safeJson(value) {
70
+ try {
71
+ return JSON.stringify(value);
72
+ } catch {
73
+ return String(value);
74
+ }
75
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assertBrowser = assertBrowser;
7
+ exports.isBrowser = isBrowser;
8
+ exports.isClientRuntime = isClientRuntime;
9
+ exports.isReactNative = isReactNative;
10
+ var _errors = require("../errors.js");
11
+ /** `true` in a browser (or jsdom); `false` during SSR, in Node and in workers without a DOM. */
12
+ function isBrowser() {
13
+ return typeof window !== 'undefined' && typeof document !== 'undefined';
14
+ }
15
+
16
+ /** `true` inside a React Native app (Hermes/JSC), where there is a `window` but no `document`. */
17
+ function isReactNative() {
18
+ return typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
19
+ }
20
+
21
+ /**
22
+ * `true` when the code runs on an end user's device - a browser or a mobile app - where any
23
+ * value in the bundle can be read by whoever has the app.
24
+ */
25
+ function isClientRuntime() {
26
+ return isBrowser() || isReactNative();
27
+ }
28
+
29
+ /** Throws a `SwichPayValidationException` when a browser-only feature is used during SSR. */
30
+ function assertBrowser(feature) {
31
+ if (!isBrowser()) {
32
+ throw new _errors.SwichPayValidationException(`${feature} needs a browser and can't run during server-side rendering.`);
33
+ }
34
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CardValidators = exports.AccountValidators = void 0;
7
+ exports.parseExpiry = parseExpiry;
8
+ /** Client-side card validation, run before anything leaves the device. */
9
+ const CardValidators = exports.CardValidators = {
10
+ /** Digits-only and 12-19 long after removing whitespace. No Luhn: sandbox test cards fail it. */
11
+ isValidNumber(number) {
12
+ const digits = String(number ?? '').replace(/\s+/g, '');
13
+ return digits !== '' && /^\d{12,19}$/.test(digits);
14
+ },
15
+ /** Month 1-12 and not expired; a 2-digit year means 20xx. Valid through the end of the month. */
16
+ isValidExpiry(month, year, now = new Date()) {
17
+ if (!Number.isInteger(month) || !Number.isInteger(year)) return false;
18
+ if (month < 1 || month > 12) return false;
19
+ const normalizedYear = year < 100 ? 2000 + year : year;
20
+ // First instant of the following month, local time - same as Dart's DateTime(year, month + 1).
21
+ const expiry = new Date(normalizedYear, month, 1, 0, 0, 0, 0);
22
+ return expiry.getTime() > now.getTime();
23
+ },
24
+ isValidCvv(cvv) {
25
+ return /^\d{3,4}$/.test(String(cvv ?? ''));
26
+ },
27
+ detectBrand(number) {
28
+ const digits = String(number ?? '').replace(/\s+/g, '');
29
+ if (digits.startsWith('4')) return 'visa';
30
+ if (/^5[1-5]/.test(digits)) return 'mastercard';
31
+ if (/^3[47]/.test(digits)) return 'amex';
32
+ return 'unknown';
33
+ }
34
+ };
35
+ const PK_IBAN = /^PK\d{2}[A-Z]{4}[A-Z0-9]{16}$/;
36
+
37
+ /** Client-side validation for bank/RTP account identifiers. */
38
+ const AccountValidators = exports.AccountValidators = {
39
+ /** Spaces removed and upper-cased - the form IBANs are sent in. */
40
+ normalizeIban(input) {
41
+ return String(input ?? '').replace(/\s+/g, '').toUpperCase();
42
+ },
43
+ /** `PK` + 2 check digits + 4-letter bank code + 16 characters. Format only, no mod-97. */
44
+ isValidPkIban(input) {
45
+ return PK_IBAN.test(AccountValidators.normalizeIban(input));
46
+ }
47
+ };
48
+
49
+ /** Parses `MM/YY` into numbers, or `null` when it isn't that shape. */
50
+ function parseExpiry(value) {
51
+ const parts = String(value ?? '').split('/');
52
+ if (parts.length !== 2) return null;
53
+ const [m, y] = parts;
54
+ if (!/^\d+$/.test(m) || !/^\d+$/.test(y)) return null;
55
+ return {
56
+ month: Number(m),
57
+ year: Number(y)
58
+ };
59
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAsync = useAsync;
7
+ exports.useController = useController;
8
+ exports.useLatest = useLatest;
9
+ var _react = require("react");
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+
12
+ /**
13
+ * Owns a headless controller for the component's lifetime and subscribes to its state. `start`
14
+ * runs one tick after mount, so StrictMode's mount → unmount → mount starts it exactly once
15
+ * (a second start would create a second payment session, which SwichPay rejects).
16
+ */
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ function useController(create, start) {
19
+ const startRef = useLatest(start);
20
+ const createRef = useLatest(create);
21
+ const [controller, setController] = (0, _react.useState)(() => create());
22
+ (0, _react.useEffect)(() => {
23
+ if (controller.disposed) {
24
+ setController(createRef.current());
25
+ return;
26
+ }
27
+ const timer = setTimeout(() => startRef.current?.(controller), 0);
28
+ return () => {
29
+ clearTimeout(timer);
30
+ controller.dispose();
31
+ };
32
+ }, [controller, createRef, startRef]);
33
+ const state = (0, _react.useSyncExternalStore)(controller.subscribe, controller.getState, controller.getState);
34
+ return [controller, state];
35
+ }
36
+
37
+ /** The latest value, readable from callbacks without re-subscribing. */
38
+ function useLatest(value) {
39
+ const ref = (0, _react.useRef)(value);
40
+ ref.current = value;
41
+ return ref;
42
+ }
43
+ /** Runs `load` on mount (and on `reload()`), ignoring results that arrive after unmount. */
44
+ function useAsync(load, deps) {
45
+ const [state, setState] = (0, _react.useState)({
46
+ data: undefined,
47
+ error: undefined,
48
+ loading: true
49
+ });
50
+ const [nonce, setNonce] = (0, _react.useState)(0);
51
+ const loadRef = useLatest(load);
52
+ (0, _react.useEffect)(() => {
53
+ let active = true;
54
+ setState(s => ({
55
+ ...s,
56
+ loading: true,
57
+ error: undefined
58
+ }));
59
+ loadRef.current().then(data => active && setState({
60
+ data,
61
+ error: undefined,
62
+ loading: false
63
+ }), error => active && setState({
64
+ data: undefined,
65
+ error,
66
+ loading: false
67
+ }));
68
+ return () => {
69
+ active = false;
70
+ };
71
+ // eslint-disable-next-line react-hooks/exhaustive-deps
72
+ }, [...deps, nonce]);
73
+ return {
74
+ ...state,
75
+ reload: () => setNonce(n => n + 1)
76
+ };
77
+ }
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ SwichPay: true,
8
+ useSwichPay: true,
9
+ usePaymentResult: true,
10
+ useAvailableCategories: true,
11
+ SwichPayProvider: true,
12
+ useSwichPayClient: true,
13
+ useFlowServices: true,
14
+ nativeFlowServices: true,
15
+ useController: true,
16
+ useAsync: true,
17
+ PaymentSheet: true,
18
+ BankTransferCheckout: true,
19
+ CardCheckout: true,
20
+ EwalletCheckout: true,
21
+ OneBillCheckout: true,
22
+ QrCheckout: true,
23
+ RtpEwalletCheckout: true,
24
+ RtpNowCheckout: true,
25
+ HostedCheckout: true,
26
+ StepUpView: true,
27
+ DeviceDataCollectionHost: true,
28
+ QrCode: true,
29
+ swichPayColors: true
30
+ };
31
+ Object.defineProperty(exports, "BankTransferCheckout", {
32
+ enumerable: true,
33
+ get: function () {
34
+ return _direct.BankTransferCheckout;
35
+ }
36
+ });
37
+ Object.defineProperty(exports, "CardCheckout", {
38
+ enumerable: true,
39
+ get: function () {
40
+ return _direct.CardCheckout;
41
+ }
42
+ });
43
+ Object.defineProperty(exports, "DeviceDataCollectionHost", {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _webviews.DeviceDataCollectionHost;
47
+ }
48
+ });
49
+ Object.defineProperty(exports, "EwalletCheckout", {
50
+ enumerable: true,
51
+ get: function () {
52
+ return _direct.EwalletCheckout;
53
+ }
54
+ });
55
+ Object.defineProperty(exports, "HostedCheckout", {
56
+ enumerable: true,
57
+ get: function () {
58
+ return _HostedCheckout.HostedCheckout;
59
+ }
60
+ });
61
+ Object.defineProperty(exports, "OneBillCheckout", {
62
+ enumerable: true,
63
+ get: function () {
64
+ return _direct.OneBillCheckout;
65
+ }
66
+ });
67
+ Object.defineProperty(exports, "PaymentSheet", {
68
+ enumerable: true,
69
+ get: function () {
70
+ return _PaymentSheet.PaymentSheet;
71
+ }
72
+ });
73
+ Object.defineProperty(exports, "QrCheckout", {
74
+ enumerable: true,
75
+ get: function () {
76
+ return _direct.QrCheckout;
77
+ }
78
+ });
79
+ Object.defineProperty(exports, "QrCode", {
80
+ enumerable: true,
81
+ get: function () {
82
+ return _ui.QrCode;
83
+ }
84
+ });
85
+ Object.defineProperty(exports, "RtpEwalletCheckout", {
86
+ enumerable: true,
87
+ get: function () {
88
+ return _direct.RtpEwalletCheckout;
89
+ }
90
+ });
91
+ Object.defineProperty(exports, "RtpNowCheckout", {
92
+ enumerable: true,
93
+ get: function () {
94
+ return _direct.RtpNowCheckout;
95
+ }
96
+ });
97
+ Object.defineProperty(exports, "StepUpView", {
98
+ enumerable: true,
99
+ get: function () {
100
+ return _webviews.StepUpView;
101
+ }
102
+ });
103
+ Object.defineProperty(exports, "SwichPay", {
104
+ enumerable: true,
105
+ get: function () {
106
+ return _swichpay.SwichPay;
107
+ }
108
+ });
109
+ Object.defineProperty(exports, "SwichPayProvider", {
110
+ enumerable: true,
111
+ get: function () {
112
+ return _provider.SwichPayProvider;
113
+ }
114
+ });
115
+ Object.defineProperty(exports, "nativeFlowServices", {
116
+ enumerable: true,
117
+ get: function () {
118
+ return _context.nativeFlowServices;
119
+ }
120
+ });
121
+ Object.defineProperty(exports, "swichPayColors", {
122
+ enumerable: true,
123
+ get: function () {
124
+ return _theme.colors;
125
+ }
126
+ });
127
+ Object.defineProperty(exports, "useAsync", {
128
+ enumerable: true,
129
+ get: function () {
130
+ return _hooks.useAsync;
131
+ }
132
+ });
133
+ Object.defineProperty(exports, "useAvailableCategories", {
134
+ enumerable: true,
135
+ get: function () {
136
+ return _swichpay.useAvailableCategories;
137
+ }
138
+ });
139
+ Object.defineProperty(exports, "useController", {
140
+ enumerable: true,
141
+ get: function () {
142
+ return _hooks.useController;
143
+ }
144
+ });
145
+ Object.defineProperty(exports, "useFlowServices", {
146
+ enumerable: true,
147
+ get: function () {
148
+ return _context.useFlowServices;
149
+ }
150
+ });
151
+ Object.defineProperty(exports, "usePaymentResult", {
152
+ enumerable: true,
153
+ get: function () {
154
+ return _swichpay.usePaymentResult;
155
+ }
156
+ });
157
+ Object.defineProperty(exports, "useSwichPay", {
158
+ enumerable: true,
159
+ get: function () {
160
+ return _swichpay.useSwichPay;
161
+ }
162
+ });
163
+ Object.defineProperty(exports, "useSwichPayClient", {
164
+ enumerable: true,
165
+ get: function () {
166
+ return _context.useSwichPayClient;
167
+ }
168
+ });
169
+ require("./polyfills.js");
170
+ var _swichpay = require("./swichpay.js");
171
+ var _provider = require("./provider.js");
172
+ var _context = require("./context.js");
173
+ var _hooks = require("./hooks.js");
174
+ var _PaymentSheet = require("./checkouts/PaymentSheet.js");
175
+ var _direct = require("./checkouts/direct.js");
176
+ var _HostedCheckout = require("./HostedCheckout.js");
177
+ var _webviews = require("./webviews.js");
178
+ var _ui = require("./ui.js");
179
+ var _theme = require("./theme.js");
180
+ var _methodLogos = require("./core/assets/method-logos.js");
181
+ Object.keys(_methodLogos).forEach(function (key) {
182
+ if (key === "default" || key === "__esModule") return;
183
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
184
+ if (key in exports && exports[key] === _methodLogos[key]) return;
185
+ Object.defineProperty(exports, key, {
186
+ enumerable: true,
187
+ get: function () {
188
+ return _methodLogos[key];
189
+ }
190
+ });
191
+ });
192
+ var _index = require("./core/index.js");
193
+ Object.keys(_index).forEach(function (key) {
194
+ if (key === "default" || key === "__esModule") return;
195
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
196
+ if (key in exports && exports[key] === _index[key]) return;
197
+ Object.defineProperty(exports, key, {
198
+ enumerable: true,
199
+ get: function () {
200
+ return _index[key];
201
+ }
202
+ });
203
+ });
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ require("react-native-url-polyfill/auto");
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.presenter = void 0;
7
+ var _index = require("./core/index.js");
8
+ /**
9
+ * How a checkout is shown: `sheet` rises from the bottom and is only as tall as its content;
10
+ * `full` covers the screen (web pages with no intrinsic height: hosted checkout, 3-D Secure).
11
+ */
12
+
13
+ /** A checkout shown by `SwichPay.present*` / `useSwichPay().present*`. */
14
+
15
+ let stack = [];
16
+ let seq = 0;
17
+ let hosts = 0;
18
+ const listeners = new Set();
19
+ const notify = () => listeners.forEach(listener => listener());
20
+ const presenter = exports.presenter = {
21
+ subscribe(listener) {
22
+ listeners.add(listener);
23
+ return () => listeners.delete(listener);
24
+ },
25
+ getStack() {
26
+ return stack;
27
+ },
28
+ hasHost() {
29
+ return hosts > 0;
30
+ },
31
+ attachHost() {
32
+ hosts += 1;
33
+ return () => {
34
+ hosts -= 1;
35
+ };
36
+ },
37
+ /** Shows `render` as a bottom sheet (or full screen); resolves with the checkout's result (`null` = dismissed). */
38
+ present(title, render, variant = 'sheet') {
39
+ if (hosts === 0) {
40
+ return Promise.reject(new _index.SwichPayValidationException('SwichPay can only present a checkout inside <SwichPayProvider>. Wrap your app (or screen) with it.'));
41
+ }
42
+ return new Promise(resolve => {
43
+ const entry = {
44
+ id: ++seq,
45
+ title,
46
+ variant,
47
+ render,
48
+ resolve
49
+ };
50
+ stack = [...stack, entry];
51
+ notify();
52
+ });
53
+ },
54
+ finish(id, result) {
55
+ const entry = stack.find(e => e.id === id);
56
+ if (!entry) return;
57
+ stack = stack.filter(e => e.id !== id);
58
+ notify();
59
+ entry.resolve(result);
60
+ }
61
+ };