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