@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,41 @@
1
+ import type { PaymentResult } from '../models/payment.js';
2
+ export type Listener = () => void;
3
+ /** Called once when a checkout finishes; `null` means dismissed without a result. */
4
+ export type FinishHandler = (result: PaymentResult | null) => void;
5
+ /**
6
+ * Base for the headless checkout controllers. Holds immutable state (a new object per change, so
7
+ * React's `useSyncExternalStore` and Vue's `shallowRef` can both track it), tracked timers, and
8
+ * a disposed flag that is checked after every `await`.
9
+ */
10
+ export declare abstract class FlowController<S extends object> {
11
+ private readonly onFinish?;
12
+ private state;
13
+ private readonly listeners;
14
+ private readonly timers;
15
+ private readonly intervals;
16
+ private finished;
17
+ private _disposed;
18
+ protected constructor(initial: S, onFinish?: FinishHandler | undefined);
19
+ getState: () => S;
20
+ subscribe: (listener: Listener) => (() => void);
21
+ get disposed(): boolean;
22
+ get isFinished(): boolean;
23
+ protected setState(patch: Partial<S> | ((state: S) => Partial<S>)): void;
24
+ /** Recomputes derived fields; override to keep labels/flags in sync with the inputs. */
25
+ protected derive(state: S): S;
26
+ /** Resolves the checkout once; later calls are ignored. */
27
+ protected finish(result: PaymentResult | null): void;
28
+ /**
29
+ * Backdrop / Escape. Dismissing this way resolves `null`;
30
+ * the payment sheet and the busy card checkout override it.
31
+ */
32
+ dismiss(): void;
33
+ protected setTimer(fn: () => void, ms: number): ReturnType<typeof setTimeout>;
34
+ protected clearTimer(id: ReturnType<typeof setTimeout> | null | undefined): void;
35
+ protected setIntervalTimer(fn: () => void, ms: number): ReturnType<typeof setInterval>;
36
+ protected clearIntervalTimer(id: ReturnType<typeof setInterval> | null | undefined): void;
37
+ /** Cancels every timer and stops all further state changes. Safe to call twice. */
38
+ dispose(): void;
39
+ protected onDispose(): void;
40
+ }
41
+ //# sourceMappingURL=controller.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { FlowController } from './controller.js';
2
+ export interface CountdownState {
3
+ secondsLeft: number;
4
+ /** `mm:ss` */
5
+ label: string;
6
+ done: boolean;
7
+ }
8
+ /** A display-only countdown (the PWA page's timer box). Call `start()`; `dispose()` stops it. */
9
+ export declare class CountdownController extends FlowController<CountdownState> {
10
+ private timer;
11
+ constructor(minutes: number);
12
+ protected derive(state: CountdownState): CountdownState;
13
+ start(): void;
14
+ }
15
+ //# sourceMappingURL=countdown.d.ts.map
@@ -0,0 +1,49 @@
1
+ import type { SwichPayClient } from '../client.js';
2
+ import { type PaymentResult, type ResolvedPaymentDetails } from '../models/payment.js';
3
+ import type { DirectBank } from '../models/session.js';
4
+ import { FlowController } from './controller.js';
5
+ import { type CheckoutControllerOptions, type FieldErrors, type FormMeta } from './shared.js';
6
+ export declare const OTP_RESEND_SECONDS = 60;
7
+ type Field = 'bank' | 'account' | 'otp';
8
+ export interface DirectBankTransferState {
9
+ details: ResolvedPaymentDetails;
10
+ banks: DirectBank[];
11
+ loadingBanks: boolean;
12
+ selectedBankCode: string | null;
13
+ account: string;
14
+ otp: string;
15
+ submitting: boolean;
16
+ error: string | null;
17
+ errors: FieldErrors<Field>;
18
+ meta: FormMeta<Field>;
19
+ /** Set once the OTP challenge arrives - the UI swaps the form for the OTP step. */
20
+ otpChallenge: PaymentResult | null;
21
+ resendSecondsLeft: number;
22
+ /** Only set from the first step; Resend OTP and a retried confirm reuse the same id by design. */
23
+ usedUpFailure: PaymentResult | null;
24
+ payLabel: string;
25
+ }
26
+ /** Direct bank transfer with OTP confirmation. */
27
+ export declare class DirectBankTransferController extends FlowController<DirectBankTransferState> {
28
+ private readonly client;
29
+ private resendTimer;
30
+ constructor(client: SwichPayClient, options: CheckoutControllerOptions);
31
+ static validate(s: Pick<DirectBankTransferState, 'otpChallenge' | 'selectedBankCode' | 'account' | 'otp'>): FieldErrors<Field>;
32
+ protected derive(state: DirectBankTransferState): DirectBankTransferState;
33
+ start(): Promise<void>;
34
+ private touch;
35
+ selectBank(code: string | null): void;
36
+ setAccount(value: string): void;
37
+ setOtp(value: string): void;
38
+ private startResendCountdown;
39
+ get canResendOtp(): boolean;
40
+ /** Step 1 (MAKE PAYMENT), also used by Resend OTP with the already-validated input. */
41
+ requestOtp(): Promise<void>;
42
+ resendOtp(): Promise<void>;
43
+ /** Step 2 (CONFIRM). A wrong OTP can be retried. */
44
+ confirmOtp(): Promise<void>;
45
+ closeWithFailure(): void;
46
+ cancel(): void;
47
+ }
48
+ export {};
49
+ //# sourceMappingURL=direct-bank-transfer.d.ts.map
@@ -0,0 +1,94 @@
1
+ import type { SwichPayClient } from '../client.js';
2
+ import { type PaymentResult, type ResolvedPaymentDetails } from '../models/payment.js';
3
+ import { type CardBrand } from '../utils/validators.js';
4
+ import { FlowController } from './controller.js';
5
+ import { type CheckoutControllerOptions, type FieldErrors, type FormMeta } from './shared.js';
6
+ export declare const DDC_TIMEOUT_MS = 15000;
7
+ export declare const DIRECT_CARD_MAX_POLLS = 12;
8
+ export declare const DIRECT_CARD_POLL_INTERVAL_MS = 5000;
9
+ type Field = 'number' | 'expiry' | 'cvv';
10
+ export interface StepUpChallenge {
11
+ url: string;
12
+ /** `null` for acquirers (e.g. Meezan 3DS2) that take the URL's own query as the POST body. */
13
+ jwt: string | null;
14
+ }
15
+ export interface DirectCardState {
16
+ details: ResolvedPaymentDetails;
17
+ allowSaveCard: boolean;
18
+ number: string;
19
+ expiry: string;
20
+ cvv: string;
21
+ saveCard: boolean;
22
+ brand: CardBrand;
23
+ submitting: boolean;
24
+ /** Device data collection is running in a hidden iframe ("Verifying your card..."). */
25
+ verifyingCard: boolean;
26
+ /** Show the issuer challenge (mount it with `mountStepUpChallenge`). */
27
+ stepUp: StepUpChallenge | null;
28
+ checkingStatus: boolean;
29
+ statusMessage: string | null;
30
+ /** An issuer decline - the "Payment declined" screen. */
31
+ declinedResult: PaymentResult | null;
32
+ /** An unexpected error - the "Something went wrong" screen. */
33
+ errorMessage: string | null;
34
+ errors: FieldErrors<Field>;
35
+ meta: FormMeta<Field>;
36
+ /** Any step in flight - inputs and close are disabled. */
37
+ busy: boolean;
38
+ payLabel: string;
39
+ }
40
+ export interface DirectCardControllerOptions extends CheckoutControllerOptions {
41
+ allowSaveCard?: boolean;
42
+ /** Test hooks. */
43
+ timing?: Partial<{
44
+ ddcTimeoutMs: number;
45
+ maxPolls: number;
46
+ pollIntervalMs: number;
47
+ }>;
48
+ }
49
+ /**
50
+ * Direct (session-less) card checkout - mirrors the native
51
+ * `CardBottomSheet`: submit, invisible device-data-collection, optional OTP step-up, then
52
+ * status polling.
53
+ */
54
+ export declare class DirectCardController extends FlowController<DirectCardState> {
55
+ private readonly client;
56
+ private readonly services;
57
+ private readonly timing;
58
+ /** The `tracker` for status polling. */
59
+ private vendorTransactionId;
60
+ constructor(client: SwichPayClient, options: DirectCardControllerOptions);
61
+ static validate(s: Pick<DirectCardState, 'number' | 'expiry' | 'cvv'>): FieldErrors<Field>;
62
+ protected derive(state: DirectCardState): DirectCardState;
63
+ private touch;
64
+ setNumber(value: string): void;
65
+ setExpiry(value: string): void;
66
+ setCvv(value: string): void;
67
+ setSaveCard(saveCard: boolean): void;
68
+ /** The challenge's return URLs (only readable when same-origin). */
69
+ isStepUpReturnUrl: (url: URL) => boolean;
70
+ submit(): Promise<void>;
71
+ private attempt;
72
+ /**
73
+ * The challenge finished (its message, a return URL, or the manual "I've completed
74
+ * verification" button) - poll for the final status.
75
+ */
76
+ completeStepUp(_eventData?: string): Promise<void>;
77
+ /** Polls InquireV3 while `pending`, up to the attempt cap (native `executePost3DSVerification`). */
78
+ private pollStatus;
79
+ /**
80
+ * Success closes; a decline shows the declined screen; `pending` is verified by polling first
81
+ * and, if still pending afterwards, returned as-is rather than shown as declined.
82
+ */
83
+ private complete;
84
+ /** The declined screen's Close - resolves the decline. */
85
+ closeDeclined(): void;
86
+ /** The error screen's Close. */
87
+ closeError(): void;
88
+ /** Backdrop / Escape - ignored while a step is in flight, so a payment is never orphaned. */
89
+ dismiss(): void;
90
+ /** Header close - ignored while a step is in flight */
91
+ cancel(): void;
92
+ }
93
+ export {};
94
+ //# sourceMappingURL=direct-card.d.ts.map
@@ -0,0 +1,39 @@
1
+ import type { SwichPayClient } from '../client.js';
2
+ import { type PaymentResult, type ResolvedPaymentDetails } from '../models/payment.js';
3
+ import { FlowController } from './controller.js';
4
+ import { type CheckoutControllerOptions, type FieldErrors, type FormMeta } from './shared.js';
5
+ export type WalletType = 'easyPaisa' | 'jazzCash';
6
+ export declare const WALLET_TYPES: readonly {
7
+ type: WalletType;
8
+ label: string;
9
+ channelId: number;
10
+ }[];
11
+ type Field = 'account';
12
+ export interface DirectEwalletState {
13
+ details: ResolvedPaymentDetails;
14
+ walletType: WalletType;
15
+ account: string;
16
+ submitting: boolean;
17
+ /** Inline error banner. */
18
+ error: string | null;
19
+ errors: FieldErrors<Field>;
20
+ meta: FormMeta<Field>;
21
+ /** Set once a failed attempt used up the transaction id - replace the pay button with CLOSE. */
22
+ usedUpFailure: PaymentResult | null;
23
+ payLabel: string;
24
+ }
25
+ /** Direct EasyPaisa/JazzCash checkout. */
26
+ export declare class DirectEwalletController extends FlowController<DirectEwalletState> {
27
+ private readonly client;
28
+ constructor(client: SwichPayClient, options: CheckoutControllerOptions);
29
+ static validate(state: Pick<DirectEwalletState, 'account'>): FieldErrors<Field>;
30
+ protected derive(state: DirectEwalletState): DirectEwalletState;
31
+ selectWallet(walletType: WalletType): void;
32
+ setAccount(value: string): void;
33
+ submit(): Promise<void>;
34
+ /** CLOSE after a used-up attempt - resolves the failed result. */
35
+ closeWithFailure(): void;
36
+ cancel(): void;
37
+ }
38
+ export {};
39
+ //# sourceMappingURL=direct-ewallet.d.ts.map
@@ -0,0 +1,38 @@
1
+ import type { SwichPayClient } from '../client.js';
2
+ import { type PaymentResult, type ResolvedPaymentDetails } from '../models/payment.js';
3
+ import { FlowController } from './controller.js';
4
+ import { type CheckoutControllerOptions, type FieldErrors, type FormMeta } from './shared.js';
5
+ type Field = 'mobile';
6
+ export interface DirectOneBillState {
7
+ details: ResolvedPaymentDetails;
8
+ mobile: string;
9
+ submitting: boolean;
10
+ checkingStatus: boolean;
11
+ error: string | null;
12
+ statusMessage: string | null;
13
+ errors: FieldErrors<Field>;
14
+ meta: FormMeta<Field>;
15
+ consumerNumber: string | null;
16
+ secondsLeft: number;
17
+ timeLeftLabel: string;
18
+ expired: boolean;
19
+ usedUpFailure: PaymentResult | null;
20
+ }
21
+ /** Direct 1Bill checkout - consumer number, copy, countdown, manual status check. */
22
+ export declare class DirectOneBillController extends FlowController<DirectOneBillState> {
23
+ private readonly client;
24
+ private readonly services;
25
+ private countdown;
26
+ constructor(client: SwichPayClient, options: CheckoutControllerOptions);
27
+ static validate(s: Pick<DirectOneBillState, 'mobile'>): FieldErrors<Field>;
28
+ protected derive(state: DirectOneBillState): DirectOneBillState;
29
+ setMobile(value: string): void;
30
+ private startCountdown;
31
+ generate(): Promise<void>;
32
+ checkStatus(): Promise<void>;
33
+ copyConsumerNumber(): Promise<boolean>;
34
+ closeWithFailure(): void;
35
+ cancel(): void;
36
+ }
37
+ export {};
38
+ //# sourceMappingURL=direct-one-bill.d.ts.map
@@ -0,0 +1,25 @@
1
+ import type { SwichPayClient } from '../client.js';
2
+ import { type ResolvedPaymentDetails } from '../models/payment.js';
3
+ import { FlowController } from './controller.js';
4
+ import { type CheckoutControllerOptions } from './shared.js';
5
+ export interface DirectQrState {
6
+ details: ResolvedPaymentDetails;
7
+ generating: boolean;
8
+ checkingStatus: boolean;
9
+ error: string | null;
10
+ statusMessage: string | null;
11
+ qrPayload: string | null;
12
+ }
13
+ /** Direct RAAST QR checkout - generates on start, verifies on a manual tap. */
14
+ export declare class DirectQrController extends FlowController<DirectQrState> {
15
+ private readonly client;
16
+ private readonly services;
17
+ constructor(client: SwichPayClient, options: CheckoutControllerOptions);
18
+ /** Generates the QR - call once after creating the controller. */
19
+ start(): Promise<void>;
20
+ checkStatus(): Promise<void>;
21
+ download(): Promise<void>;
22
+ share(): Promise<void>;
23
+ cancel(): void;
24
+ }
25
+ //# sourceMappingURL=direct-qr.d.ts.map
@@ -0,0 +1,72 @@
1
+ import type { SwichPayClient } from '../client.js';
2
+ import { type PaymentResult, type ResolvedPaymentDetails } from '../models/payment.js';
3
+ import type { DirectBank } from '../models/session.js';
4
+ import { FlowController } from './controller.js';
5
+ import { type CheckoutControllerOptions, type FieldErrors, type FormMeta } from './shared.js';
6
+ interface BankListState {
7
+ banks: DirectBank[];
8
+ loadingBanks: boolean;
9
+ selectedBankCode: string | null;
10
+ }
11
+ export type RtpNowMode = 'raastMobile' | 'raastIban' | 'bank';
12
+ type RtpNowField = 'mobile' | 'iban' | 'bankAccount';
13
+ export interface DirectRtpNowState extends BankListState {
14
+ details: ResolvedPaymentDetails;
15
+ mode: RtpNowMode;
16
+ mobile: string;
17
+ iban: string;
18
+ bankAccount: string;
19
+ submitting: boolean;
20
+ error: string | null;
21
+ errors: FieldErrors<RtpNowField>;
22
+ meta: FormMeta<RtpNowField>;
23
+ usedUpFailure: PaymentResult | null;
24
+ payLabel: string;
25
+ }
26
+ /** Direct RTP Now checkout - Raast mobile, Raast IBAN, or bank + account. */
27
+ export declare class DirectRtpNowController extends FlowController<DirectRtpNowState> {
28
+ private readonly client;
29
+ private readonly services;
30
+ constructor(client: SwichPayClient, options: CheckoutControllerOptions);
31
+ /** Only the active mode's field is validated. */
32
+ static validate(s: Pick<DirectRtpNowState, 'mode' | 'mobile' | 'iban' | 'bankAccount'>): FieldErrors<RtpNowField>;
33
+ protected derive(state: DirectRtpNowState): DirectRtpNowState;
34
+ /** Loads the bank list; call once after creating the controller. */
35
+ start(): Promise<void>;
36
+ setMode(mode: RtpNowMode): void;
37
+ setField(field: RtpNowField, value: string): void;
38
+ selectBank(code: string | null): void;
39
+ submit(): Promise<void>;
40
+ closeWithFailure(): void;
41
+ cancel(): void;
42
+ }
43
+ export type RtpEwalletMode = 'phone' | 'iban';
44
+ type RtpEwalletField = 'input';
45
+ export interface DirectRtpEwalletState extends BankListState {
46
+ details: ResolvedPaymentDetails;
47
+ mode: RtpEwalletMode;
48
+ input: string;
49
+ submitting: boolean;
50
+ error: string | null;
51
+ errors: FieldErrors<RtpEwalletField>;
52
+ meta: FormMeta<RtpEwalletField>;
53
+ usedUpFailure: PaymentResult | null;
54
+ payLabel: string;
55
+ }
56
+ /** Direct RTP E-wallet checkout - phone or IBAN plus a bank. */
57
+ export declare class DirectRtpEwalletController extends FlowController<DirectRtpEwalletState> {
58
+ private readonly client;
59
+ constructor(client: SwichPayClient, options: CheckoutControllerOptions);
60
+ static validate(s: Pick<DirectRtpEwalletState, 'mode' | 'input'>): FieldErrors<RtpEwalletField>;
61
+ protected derive(state: DirectRtpEwalletState): DirectRtpEwalletState;
62
+ start(): Promise<void>;
63
+ /** Switching mode clears the input. */
64
+ setMode(mode: RtpEwalletMode): void;
65
+ setInput(value: string): void;
66
+ selectBank(code: string | null): void;
67
+ submit(): Promise<void>;
68
+ closeWithFailure(): void;
69
+ cancel(): void;
70
+ }
71
+ export {};
72
+ //# sourceMappingURL=direct-rtp.d.ts.map
@@ -0,0 +1,37 @@
1
+ import { type DiscountResult } from '../models/discount.js';
2
+ import type { SwichPayLogger } from '../utils/log.js';
3
+ export interface DiscountState {
4
+ loading: boolean;
5
+ /** Only ever a *usable* result; inapplicable, failed or timed-out lookups leave it `null`. */
6
+ result: DiscountResult | null;
7
+ }
8
+ export declare const DISCOUNT_DEBOUNCE_MS = 600;
9
+ /**
10
+ * Debounced Discount API lookup with staleness and duplicate guards.
11
+ * One instance per form; `onChange` should push the new state to the UI.
12
+ */
13
+ export declare class DiscountLookup {
14
+ private readonly onChange;
15
+ private readonly log;
16
+ private readonly debounceMs;
17
+ private loading;
18
+ private result;
19
+ private debounce;
20
+ /** Bumped on every new lookup and every reset; a response under an older id is stale. */
21
+ private requestId;
22
+ private requestKey;
23
+ private disposed;
24
+ constructor(onChange: () => void, log?: SwichPayLogger, debounceMs?: number);
25
+ get state(): DiscountState;
26
+ /** Clears any applied/loading discount and invalidates in-flight lookups. */
27
+ reset(): void;
28
+ scheduleFetch(input: {
29
+ requestKey: string;
30
+ fetch: () => Promise<DiscountResult | null>;
31
+ requestedAmount: number;
32
+ debugLabel: string;
33
+ }): void;
34
+ private run;
35
+ dispose(): void;
36
+ }
37
+ //# sourceMappingURL=discount-lookup.d.ts.map
@@ -0,0 +1,38 @@
1
+ import type { SwichPayClient } from '../client.js';
2
+ import { type CardDetails, type PaymentDetails, type PaymentResult } from '../models/payment.js';
3
+ import { type StepUpChallenge } from './direct-card.js';
4
+ import type { FlowServices } from './services.js';
5
+ /**
6
+ * Shows the bank's 3-D Secure page and resolves with its completion data (any string) once the
7
+ * customer is done. The SDKs implement it with a WebView / iframe; it is the only UI a headless
8
+ * card payment ever needs, and only when the bank asks for an OTP.
9
+ */
10
+ export type StepUpPresenter = (challenge: StepUpChallenge, isCompletionUrl: (url: URL) => boolean) => Promise<string>;
11
+ export interface HeadlessCardInput {
12
+ details: PaymentDetails;
13
+ card: CardDetails;
14
+ /** Save the card for future payments (`doCardOnFile`). Default `false`. */
15
+ saveCard?: boolean;
16
+ }
17
+ /**
18
+ * Pays with a card from the merchant's own screen - the SDK's card checkout without its screen
19
+ * (same requests, device check, 3-D Secure and status polling as `presentCardCheckout`).
20
+ * Resolves with the final `PaymentResult` (success, decline, pending or error); rejects with a
21
+ * `SwichPayValidationException` before any network call when the card fields are invalid.
22
+ */
23
+ export declare function runHeadlessCardPayment(client: SwichPayClient, input: HeadlessCardInput, deps: {
24
+ services?: Partial<FlowServices>;
25
+ presentStepUp: StepUpPresenter;
26
+ }): Promise<PaymentResult>;
27
+ export type WalletName = 'jazzcash' | 'easypaisa';
28
+ /**
29
+ * Pays with JazzCash / EasyPaisa from the merchant's own screen. The customer approves the
30
+ * request in their wallet app; resolves when the wallet answers (same request as
31
+ * `presentEwalletCheckout`).
32
+ */
33
+ export declare function runHeadlessWalletPayment(client: SwichPayClient, input: {
34
+ details: PaymentDetails;
35
+ wallet: WalletName;
36
+ msisdn: string;
37
+ }): Promise<PaymentResult>;
38
+ //# sourceMappingURL=headless.d.ts.map