@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,58 @@
1
+ "use strict";
2
+
3
+ import { SwichPayValidationException } from './core/index.js';
4
+
5
+ /**
6
+ * How a checkout is shown: `sheet` rises from the bottom and is only as tall as its content;
7
+ * `full` covers the screen (web pages with no intrinsic height: hosted checkout, 3-D Secure).
8
+ */
9
+
10
+ /** A checkout shown by `SwichPay.present*` / `useSwichPay().present*`. */
11
+
12
+ let stack = [];
13
+ let seq = 0;
14
+ let hosts = 0;
15
+ const listeners = new Set();
16
+ const notify = () => listeners.forEach(listener => listener());
17
+ export const presenter = {
18
+ subscribe(listener) {
19
+ listeners.add(listener);
20
+ return () => listeners.delete(listener);
21
+ },
22
+ getStack() {
23
+ return stack;
24
+ },
25
+ hasHost() {
26
+ return hosts > 0;
27
+ },
28
+ attachHost() {
29
+ hosts += 1;
30
+ return () => {
31
+ hosts -= 1;
32
+ };
33
+ },
34
+ /** Shows `render` as a bottom sheet (or full screen); resolves with the checkout's result (`null` = dismissed). */
35
+ present(title, render, variant = 'sheet') {
36
+ if (hosts === 0) {
37
+ return Promise.reject(new SwichPayValidationException('SwichPay can only present a checkout inside <SwichPayProvider>. Wrap your app (or screen) with it.'));
38
+ }
39
+ return new Promise(resolve => {
40
+ const entry = {
41
+ id: ++seq,
42
+ title,
43
+ variant,
44
+ render,
45
+ resolve
46
+ };
47
+ stack = [...stack, entry];
48
+ notify();
49
+ });
50
+ },
51
+ finish(id, result) {
52
+ const entry = stack.find(e => e.id === id);
53
+ if (!entry) return;
54
+ stack = stack.filter(e => e.id !== id);
55
+ notify();
56
+ entry.resolve(result);
57
+ }
58
+ };
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+
3
+ import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
4
+ import { Animated, Dimensions, KeyboardAvoidingView, Modal, Platform, Pressable, SafeAreaView, StyleSheet, View } from 'react-native';
5
+ import { SwichPay as CoreSwichPay } from './core/swichpay.js';
6
+ import { SwichPayClient } from './core/index.js';
7
+ import { DismissContext, SwichPayContext, nativeFlowServices } from './context.js';
8
+ import { presenter } from './presenter.js';
9
+ import { FILL, colors } from './theme.js';
10
+ import { DeviceDataCollectionHost } from './webviews.js';
11
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
+ /**
13
+ * Put this once at the root of your app:
14
+ * it renders checkouts opened with `SwichPay.present*` / `useSwichPay()`, and
15
+ * runs 3-D Secure device checks.
16
+ */
17
+ export function SwichPayProvider(props) {
18
+ // Options are read once.initialize (remount the provider to change them).
19
+ const [ownClient] = useState(() => !props.client && props.options ? new SwichPayClient(props.options) : null);
20
+ // The provider's client also backs the static facade (SwichPay.pay, SwichPay.onResult, ...).
21
+ useEffect(() => {
22
+ if (!ownClient) return;
23
+ CoreSwichPay.attach(ownClient);
24
+ return () => CoreSwichPay.detach(ownClient);
25
+ }, [ownClient]);
26
+ const client = props.client ?? ownClient ?? CoreSwichPay.client;
27
+ const services = useMemo(() => ({
28
+ ...nativeFlowServices,
29
+ ...props.services
30
+ }), [props.services]);
31
+ const value = useMemo(() => ({
32
+ client,
33
+ services
34
+ }), [client, services]);
35
+ useEffect(() => presenter.attachHost(), []);
36
+ const stack = useSyncExternalStore(presenter.subscribe, presenter.getStack, presenter.getStack);
37
+ return /*#__PURE__*/_jsxs(SwichPayContext.Provider, {
38
+ value: value,
39
+ children: [props.children, stack.length === 0 ? /*#__PURE__*/_jsx(DeviceDataCollectionHost, {}) : null, stack.map((entry, index) => /*#__PURE__*/_jsx(PresentedModal, {
40
+ entry: entry,
41
+ top: index === stack.length - 1
42
+ }, entry.id))]
43
+ });
44
+ }
45
+ function PresentedModal({
46
+ entry,
47
+ top
48
+ }) {
49
+ const dismissRef = useRef(null);
50
+ const register = useCallback(handler => {
51
+ dismissRef.current = handler;
52
+ }, []);
53
+ const finish = useCallback(result => presenter.finish(entry.id, result), [entry.id]);
54
+ const content = useMemo(() => entry.render(finish), [entry, finish]);
55
+ const dismiss = useCallback(() => dismissRef.current ? dismissRef.current() : finish(null), [finish]);
56
+ if (entry.variant === 'full') {
57
+ return /*#__PURE__*/_jsx(Modal, {
58
+ visible: true,
59
+ animationType: "slide",
60
+ presentationStyle: Platform.OS === 'ios' ? 'pageSheet' : 'fullScreen',
61
+ statusBarTranslucent: false,
62
+ onRequestClose: dismiss,
63
+ accessibilityViewIsModal: true,
64
+ children: /*#__PURE__*/_jsx(DismissContext.Provider, {
65
+ value: register,
66
+ children: /*#__PURE__*/_jsxs(SafeAreaView, {
67
+ style: styles.safe,
68
+ accessibilityLabel: entry.title,
69
+ children: [/*#__PURE__*/_jsx(View, {
70
+ style: styles.body,
71
+ children: content
72
+ }), top ? /*#__PURE__*/_jsx(DeviceDataCollectionHost, {}) : null]
73
+ })
74
+ })
75
+ });
76
+ }
77
+
78
+ // Bottom sheet: as tall as its content, up to 92% of the screen (then the content scrolls).
79
+ return /*#__PURE__*/_jsx(Modal, {
80
+ visible: true,
81
+ transparent: true,
82
+ animationType: "fade",
83
+ statusBarTranslucent: true,
84
+ onRequestClose: dismiss,
85
+ accessibilityViewIsModal: true,
86
+ children: /*#__PURE__*/_jsx(DismissContext.Provider, {
87
+ value: register,
88
+ children: /*#__PURE__*/_jsxs(View, {
89
+ style: styles.backdrop,
90
+ children: [/*#__PURE__*/_jsx(Pressable, {
91
+ style: FILL,
92
+ accessibilityLabel: "Close",
93
+ accessibilityRole: "button",
94
+ onPress: dismiss
95
+ }), /*#__PURE__*/_jsx(KeyboardAvoidingView, {
96
+ behavior: Platform.OS === 'ios' ? 'padding' : undefined,
97
+ style: styles.sheetWrap,
98
+ pointerEvents: "box-none",
99
+ children: /*#__PURE__*/_jsx(SheetRise, {
100
+ children: /*#__PURE__*/_jsxs(View, {
101
+ style: styles.sheet,
102
+ accessibilityLabel: entry.title,
103
+ children: [/*#__PURE__*/_jsx(View, {
104
+ style: styles.handle
105
+ }), /*#__PURE__*/_jsx(View, {
106
+ style: styles.sheetBody,
107
+ children: content
108
+ }), top ? /*#__PURE__*/_jsx(DeviceDataCollectionHost, {}) : null]
109
+ })
110
+ })
111
+ })]
112
+ })
113
+ })
114
+ });
115
+ }
116
+
117
+ /** Slides the sheet up while the backdrop fades in (the Modal itself only fades). */
118
+ function SheetRise({
119
+ children
120
+ }) {
121
+ const offset = useRef(new Animated.Value(Dimensions.get('window').height * 0.4)).current;
122
+ useEffect(() => {
123
+ Animated.spring(offset, {
124
+ toValue: 0,
125
+ useNativeDriver: true,
126
+ damping: 22,
127
+ stiffness: 220,
128
+ mass: 0.9
129
+ }).start();
130
+ }, [offset]);
131
+ return /*#__PURE__*/_jsx(Animated.View, {
132
+ style: [styles.rise, {
133
+ transform: [{
134
+ translateY: offset
135
+ }]
136
+ }],
137
+ children: children
138
+ });
139
+ }
140
+ const styles = StyleSheet.create({
141
+ safe: {
142
+ flex: 1,
143
+ backgroundColor: colors.surface
144
+ },
145
+ body: {
146
+ flex: 1
147
+ },
148
+ backdrop: {
149
+ flex: 1,
150
+ justifyContent: 'flex-end',
151
+ backgroundColor: colors.overlay
152
+ },
153
+ sheetWrap: {
154
+ maxHeight: '92%',
155
+ flexShrink: 1
156
+ },
157
+ rise: {
158
+ flexShrink: 1
159
+ },
160
+ sheet: {
161
+ flexShrink: 1,
162
+ backgroundColor: colors.surface,
163
+ borderTopLeftRadius: 20,
164
+ borderTopRightRadius: 20,
165
+ overflow: 'hidden',
166
+ paddingBottom: Platform.OS === 'ios' ? 28 : 12,
167
+ shadowColor: '#000',
168
+ shadowOpacity: 0.12,
169
+ shadowRadius: 16,
170
+ shadowOffset: {
171
+ width: 0,
172
+ height: -4
173
+ },
174
+ elevation: 16
175
+ },
176
+ handle: {
177
+ alignSelf: 'center',
178
+ width: 36,
179
+ height: 4,
180
+ borderRadius: 2,
181
+ backgroundColor: colors.border,
182
+ marginTop: 8,
183
+ marginBottom: 2
184
+ },
185
+ sheetBody: {
186
+ flexShrink: 1
187
+ }
188
+ });
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+
3
+ import { useEffect, useMemo } from 'react';
4
+ import { View } from 'react-native';
5
+ import { SwichPay as CoreSwichPay } from './core/swichpay.js';
6
+ import { nativeFlowServices, useSwichPayClient } from './context.js';
7
+ import { useAsync, useLatest } from './hooks.js';
8
+ import { presenter } from './presenter.js';
9
+ import { runHeadlessCardPayment, runHeadlessWalletPayment, SwichPayValidationException } from './core/index.js';
10
+ import { StepUpView } from './webviews.js';
11
+ import { SheetHeader } from './ui.js';
12
+ import { HostedCheckout } from './HostedCheckout.js';
13
+ import { PaymentSheet } from './checkouts/PaymentSheet.js';
14
+ import { BankTransferCheckout, CardCheckout, EwalletCheckout, OneBillCheckout, QrCheckout, RtpEwalletCheckout, RtpNowCheckout } from './checkouts/direct.js';
15
+
16
+ /** Same event data the step-up view sends for its manual fallback. */
17
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
18
+ const MANUAL_COMPLETION = JSON.stringify({
19
+ type: 'manual'
20
+ });
21
+
22
+ /** The bank's 3-D Secure page, full screen - the only UI an own-screen card payment shows. */
23
+ function presentStepUp(challenge, isCompletionUrl) {
24
+ return new Promise(resolve => {
25
+ let data = MANUAL_COMPLETION;
26
+ presenter.present('Verify with your bank', finish => /*#__PURE__*/_jsxs(_Fragment, {
27
+ children: [/*#__PURE__*/_jsx(SheetHeader, {
28
+ title: "Verify with your bank",
29
+ onClose: () => finish(null)
30
+ }), /*#__PURE__*/_jsx(View, {
31
+ style: {
32
+ flex: 1,
33
+ padding: 16
34
+ },
35
+ children: /*#__PURE__*/_jsx(StepUpView, {
36
+ challenge: challenge,
37
+ isCompletionUrl: isCompletionUrl,
38
+ onComplete: eventData => {
39
+ data = eventData;
40
+ finish(null);
41
+ }
42
+ })
43
+ })]
44
+ }), 'full').then(() => resolve(data), () => resolve(data));
45
+ });
46
+ }
47
+
48
+ /** Payments for your own screen: call a method, no SDK screen. */
49
+
50
+ function direct(getClient) {
51
+ return {
52
+ payWithCard: async input => {
53
+ if (!presenter.hasHost()) {
54
+ throw new SwichPayValidationException('payWithCard needs <SwichPayProvider> mounted (it runs the 3-D Secure check).');
55
+ }
56
+ return runHeadlessCardPayment(getClient(), input, {
57
+ services: nativeFlowServices,
58
+ presentStepUp
59
+ });
60
+ },
61
+ payWithWallet: input => runHeadlessWalletPayment(getClient(), input)
62
+ };
63
+ }
64
+
65
+ /** Every checkout the SDK can present (`SwichPay.present*`). */
66
+
67
+ function presenters() {
68
+ const open = presenter.present;
69
+ return {
70
+ presentPaymentSheet: (details, options) => open('SwichPay checkout', finish => /*#__PURE__*/_jsx(PaymentSheet, {
71
+ details: details,
72
+ categories: options?.categories,
73
+ onFinish: finish
74
+ })),
75
+ presentHostedCheckout: (details, options) => open('Payment Session', finish => /*#__PURE__*/_jsx(HostedCheckout, {
76
+ details: details,
77
+ categories: options?.categories,
78
+ onFinish: finish
79
+ }), 'full'),
80
+ presentHostedCheckoutSheet: (details, options) => open('Payment Session', finish => /*#__PURE__*/_jsx(HostedCheckout, {
81
+ details: details,
82
+ categories: options?.categories,
83
+ onFinish: finish
84
+ }), 'full'),
85
+ presentEwalletCheckout: details => open('Pay with Wallet', finish => /*#__PURE__*/_jsx(EwalletCheckout, {
86
+ details: details,
87
+ onFinish: finish
88
+ })),
89
+ presentBankTransferCheckout: details => open('Pay with Bank Account', finish => /*#__PURE__*/_jsx(BankTransferCheckout, {
90
+ details: details,
91
+ onFinish: finish
92
+ })),
93
+ presentCardCheckout: (details, options) => open('Pay with Card', finish => /*#__PURE__*/_jsx(CardCheckout, {
94
+ details: details,
95
+ allowSaveCard: options?.allowSaveCard,
96
+ onFinish: finish
97
+ })),
98
+ presentOneBillCheckout: details => open('Pay via 1Bill', finish => /*#__PURE__*/_jsx(OneBillCheckout, {
99
+ details: details,
100
+ onFinish: finish
101
+ })),
102
+ presentQrCheckout: details => open('Pay with QR', finish => /*#__PURE__*/_jsx(QrCheckout, {
103
+ details: details,
104
+ onFinish: finish
105
+ })),
106
+ presentRtpNowCheckout: details => open('RTP Now', finish => /*#__PURE__*/_jsx(RtpNowCheckout, {
107
+ details: details,
108
+ onFinish: finish
109
+ })),
110
+ presentRtpEwalletCheckout: details => open('RTP E-Wallet', finish => /*#__PURE__*/_jsx(RtpEwalletCheckout, {
111
+ details: details,
112
+ onFinish: finish
113
+ }))
114
+ };
115
+ }
116
+
117
+ /**
118
+ * The `SwichPay` facade for React Native:
119
+ *
120
+ * ```ts
121
+ * SwichPay.initialize({ clientId, referrer, merchantId, appId, environment, proxyUrl });
122
+ * const result = await SwichPay.presentPaymentSheet(details);
123
+ * ```
124
+ *
125
+ * `present*` methods need `<SwichPayProvider>` mounted at the root of the app.
126
+ */
127
+ export const SwichPay = {
128
+ ...presenters(),
129
+ ...direct(() => CoreSwichPay.client),
130
+ /** Call once, as early as possible. Calling again replaces (and disposes) the previous client. */
131
+ initialize(options, deps) {
132
+ return CoreSwichPay.initialize(options, deps);
133
+ },
134
+ /** The live client; throws `SwichPayNotInitializedException` before `initialize`. */
135
+ get client() {
136
+ return CoreSwichPay.client;
137
+ },
138
+ get isInitialized() {
139
+ return CoreSwichPay.isInitialized;
140
+ },
141
+ /** Submits a card payment directly against your own form. */
142
+ pay(input) {
143
+ return CoreSwichPay.pay(input);
144
+ },
145
+ /** Listens for every payment result. Returns an unsubscribe function (also `.cancel()`). */
146
+ onResult(callback) {
147
+ return CoreSwichPay.onResult(callback);
148
+ },
149
+ availableCategories() {
150
+ return CoreSwichPay.availableCategories();
151
+ },
152
+ inquirePaymentSession(input) {
153
+ return CoreSwichPay.inquirePaymentSession(input);
154
+ },
155
+ dispose() {
156
+ CoreSwichPay.dispose();
157
+ }
158
+ };
159
+ /** Everything `SwichPay` offers, bound to the nearest `<SwichPayProvider>`'s client. */
160
+ export function useSwichPay() {
161
+ const client = useSwichPayClient();
162
+ return useMemo(() => ({
163
+ ...presenters(),
164
+ ...direct(() => client),
165
+ client,
166
+ pay: input => client.pay(input),
167
+ onResult: callback => client.onResult(callback),
168
+ availableCategories: () => client.availableCategories(),
169
+ inquirePaymentSession: input => client.inquirePaymentSession(input)
170
+ }), [client]);
171
+ }
172
+
173
+ /** Subscribes to every payment result and unsubscribes on unmount. */
174
+ export function usePaymentResult(callback) {
175
+ const client = useSwichPayClient();
176
+ const ref = useLatest(callback);
177
+ useEffect(() => {
178
+ const subscription = client.onResult(result => ref.current(result));
179
+ return () => subscription.cancel();
180
+ }, [client, ref]);
181
+ }
182
+
183
+ /** The merchant's enabled payment categories, loaded on mount. */
184
+ export function useAvailableCategories() {
185
+ const client = useSwichPayClient();
186
+ return useAsync(() => client.availableCategories(), [client]);
187
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ /** Colours and sizes shared by every SwichPay screen (same palette on every SwichPay SDK). */
4
+ export const colors = {
5
+ accentFrom: '#1dcd9f',
6
+ accentTo: '#2563eb',
7
+ blue: '#2563eb',
8
+ text: '#111827',
9
+ muted: '#4b5563',
10
+ faint: '#6b7280',
11
+ border: '#d1d5db',
12
+ fieldBorder: '#6b7280',
13
+ surface: '#ffffff',
14
+ surfaceAlt: '#f3f4f6',
15
+ danger: '#dc2626',
16
+ dangerBg: '#fef2f2',
17
+ dangerBorder: '#fecaca',
18
+ success: '#059669',
19
+ successBg: '#ecfdf5',
20
+ successBorder: '#a7f3d0',
21
+ overlay: 'rgba(17, 24, 39, 0.5)',
22
+ dark: '#111827'
23
+ };
24
+ export const radius = {
25
+ sm: 6,
26
+ md: 10,
27
+ lg: 16,
28
+ pill: 999
29
+ };
30
+ export const space = {
31
+ xs: 4,
32
+ sm: 8,
33
+ md: 12,
34
+ lg: 16,
35
+ xl: 24
36
+ };
37
+ export const font = {
38
+ sm: 12,
39
+ md: 14,
40
+ lg: 16,
41
+ xl: 20
42
+ };
43
+ /** Covers the parent (StyleSheet.absoluteFillObject was removed in React Native 0.81+). */
44
+ export const FILL = {
45
+ position: 'absolute',
46
+ left: 0,
47
+ right: 0,
48
+ top: 0,
49
+ bottom: 0
50
+ };