@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,181 @@
1
+ import { type ConfirmDirectBankTransferInput } from './api/direct-payment-api.js';
2
+ import { type ProcessBankAccountPaymentInput, type ProcessBillerPaymentInput, type ProcessCardPaymentInput, type ProcessEwalletPaymentInput, type ProcessQrPaymentInput, type ProcessRtpNowPaymentInput, type SubmitPaymentEnrollmentInput } from './api/gateway-api.js';
3
+ import type { DirectPaymentRepository, DiscountRepository, GatewayRepository, PaymentsRepository } from './api/repositories.js';
4
+ import { type SwichPayConfig, type SwichPayOptions } from './config.js';
5
+ import { type Subscription } from './events.js';
6
+ import type { PaymentCategory } from './models/category.js';
7
+ import type { DiscountResult } from './models/discount.js';
8
+ import { type CardDetails, type PaymentDetails, type PaymentResult } from './models/payment.js';
9
+ import type { DirectBank, MobileAppInitResult, PaymentSessionDetails, PaymentSessionInquiryResult } from './models/session.js';
10
+ export interface SwichPayClientDependencies {
11
+ gatewayApi?: GatewayRepository;
12
+ paymentsApi?: PaymentsRepository;
13
+ directPaymentApi?: DirectPaymentRepository;
14
+ discountApi?: DiscountRepository;
15
+ }
16
+ /** Throws SwichPay's card validation errors. */
17
+ export declare function validateCard(card: CardDetails): void;
18
+ /**
19
+ * One live SDK session: config, API layers and the result stream behind `onResult`.
20
+ * Every completed payment attempt is emitted to that stream.
21
+ */
22
+ export declare class SwichPayClient {
23
+ readonly config: SwichPayConfig;
24
+ private readonly gateway;
25
+ private readonly payments;
26
+ private readonly direct;
27
+ private readonly discount;
28
+ private readonly results;
29
+ private disposed;
30
+ constructor(options: SwichPayOptions, deps?: SwichPayClientDependencies);
31
+ get isDisposed(): boolean;
32
+ /** Listens for every payment result. */
33
+ onResult(listener: (result: PaymentResult) => void): Subscription;
34
+ private emit;
35
+ pay(input: {
36
+ details: PaymentDetails;
37
+ card: CardDetails;
38
+ }): Promise<PaymentResult>;
39
+ /** Runs `/init` and returns `clientId`, the token that authenticates it. */
40
+ startSession(): Promise<string>;
41
+ payWithSession(input: {
42
+ sessionToken: string;
43
+ details: PaymentDetails;
44
+ card: CardDetails;
45
+ }): Promise<PaymentResult>;
46
+ /** Categories and logos enabled for this merchant; fetched fresh each time. */
47
+ loadMobileAppInit(): Promise<MobileAppInitResult>;
48
+ availableCategories(): Promise<PaymentCategory[]>;
49
+ /**
50
+ * URL of SwichPay's hosted checkout page. The session always gets every enabled category
51
+ * (matches native); `categories` exists for API symmetry only.
52
+ */
53
+ createHostedCheckoutUrl(input: {
54
+ details: PaymentDetails;
55
+ categories?: readonly PaymentCategory[] | null;
56
+ }): Promise<string>;
57
+ /**
58
+ * Creates a session and fetches its details. `categories` only restricts what the returned
59
+ * details list (what a sheet displays), not what the session supports.
60
+ */
61
+ startNativeCheckout(input: {
62
+ details: PaymentDetails;
63
+ categories?: readonly PaymentCategory[] | null;
64
+ }): Promise<PaymentSessionDetails>;
65
+ processCardPayment(input: ProcessCardPaymentInput): Promise<PaymentResult>;
66
+ /**
67
+ * Discount quote for a card payment (new card entry only - never for a saved card). Never
68
+ * emits. `ipAddress` defaults to `''` - a browser can't read the device IP.
69
+ */
70
+ getCardDiscount(input: {
71
+ details: PaymentDetails;
72
+ cardNumber: string;
73
+ categoryId?: string;
74
+ ipAddress?: string | null;
75
+ }): Promise<DiscountResult>;
76
+ processEwalletPayment(input: ProcessEwalletPaymentInput): Promise<PaymentResult>;
77
+ /**
78
+ * Discount quote for an e-wallet payment; `channelId` is the wallet's channel (8 EasyPaisa,
79
+ * 10 JazzCash). Never emits. `ipAddress` defaults to `"127.0.0.1"`
80
+ */
81
+ getEwalletDiscount(input: {
82
+ details: PaymentDetails;
83
+ msisdn: string;
84
+ channelId: number;
85
+ categoryId?: string;
86
+ ipAddress?: string | null;
87
+ }): Promise<DiscountResult>;
88
+ /** If the result has `otpRequired`, call again with `otp`. */
89
+ processBankAccountPayment(input: ProcessBankAccountPaymentInput): Promise<PaymentResult>;
90
+ /** Called twice: first with `msisdn` for the consumer number, then with `consumerNumber` to verify. */
91
+ processBillerPayment(input: ProcessBillerPaymentInput): Promise<PaymentResult>;
92
+ submitPaymentEnrollment(input: SubmitPaymentEnrollmentInput): Promise<PaymentResult>;
93
+ /**
94
+ * `tracker` is ProcessPayment's `vendorTransactionId`. With `orderId` and a payment-api host,
95
+ * asks `InquireV3` instead (resolves session card payments by `orderId`).
96
+ */
97
+ checkCardPaymentStatus(input: {
98
+ tracker: string;
99
+ orderId?: string | null;
100
+ forceTimeout?: boolean;
101
+ }): Promise<PaymentResult>;
102
+ processQrPayment(input: ProcessQrPaymentInput): Promise<PaymentResult>;
103
+ processRtpNowPayment(input: ProcessRtpNowPaymentInput): Promise<PaymentResult>;
104
+ /** For when the user explicitly closes/cancels a payment sheet. */
105
+ cancelSession(input: {
106
+ paymentSessionGuid: string;
107
+ }): Promise<void>;
108
+ inquirePaymentSession(input: {
109
+ paymentSessionGuid: string;
110
+ }): Promise<PaymentSessionInquiryResult>;
111
+ directEwalletPayment(input: {
112
+ details: PaymentDetails;
113
+ channelId: number;
114
+ msisdn: string;
115
+ }): Promise<PaymentResult>;
116
+ /** Step 1 of a bank transfer; if `otpRequired`, call `confirmDirectBankTransfer`. Never emits. */
117
+ directBankTransfer(input: {
118
+ details: PaymentDetails;
119
+ bankCode: string;
120
+ accountNo: string;
121
+ }): Promise<PaymentResult>;
122
+ confirmDirectBankTransfer(input: ConfirmDirectBankTransferInput): Promise<PaymentResult>;
123
+ fetchDirectBankList(): Promise<DirectBank[]>;
124
+ /** The result's `consumerNumber` is what the customer pays against. Never emits. */
125
+ generateDirectOneBill(input: {
126
+ details: PaymentDetails;
127
+ }): Promise<PaymentResult>;
128
+ /** Emits on success only. */
129
+ checkDirectOneBillStatus(input: {
130
+ customerTransactionId: string;
131
+ }): Promise<PaymentResult>;
132
+ /** The result's `qrString` is the payload to render. Never emits. */
133
+ generateDirectQrPayment(input: {
134
+ details: PaymentDetails;
135
+ }): Promise<PaymentResult>;
136
+ /** Emits on success only. */
137
+ checkDirectQrStatus(input: {
138
+ customerTransactionId: string;
139
+ }): Promise<PaymentResult>;
140
+ fetchDirectRtpNowBanks(): Promise<DirectBank[]>;
141
+ directRtpNowPayment(input: {
142
+ details: PaymentDetails;
143
+ msisdn: string;
144
+ rtpId: string;
145
+ bankCode?: string | null;
146
+ accountTitle?: string | null;
147
+ accountNumber?: string | null;
148
+ accountNumberAlias?: string | null;
149
+ }): Promise<PaymentResult>;
150
+ fetchDirectRtpEwalletBanks(): Promise<DirectBank[]>;
151
+ directRtpEwalletPayment(input: {
152
+ details: PaymentDetails;
153
+ bankCode: string;
154
+ msisdn?: string;
155
+ iban?: string;
156
+ }): Promise<PaymentResult>;
157
+ /**
158
+ * Submits a direct card payment. Needs a checksum source: `secretHashKey`, `getChecksum`, or a
159
+ * proxy (which signs server-side). Emits unless a device-data-collection step follows.
160
+ */
161
+ directCardPayment(input: {
162
+ details: PaymentDetails;
163
+ card: CardDetails;
164
+ doCardOnFile?: boolean;
165
+ }): Promise<PaymentResult>;
166
+ private checksumFor;
167
+ /** Completes a direct card payment after device-data-collection. Emits unless a step-up follows. */
168
+ executeDirectCardTokenizedPayment(input: {
169
+ customerTransactionId: string;
170
+ billReferenceNo: string;
171
+ tracker: string;
172
+ sessionId: string;
173
+ }): Promise<PaymentResult>;
174
+ /** `tracker` is `vendorTransactionId` from `directCardPayment`. Emits unless still pending. */
175
+ checkDirectCardPaymentStatus(input: {
176
+ tracker: string;
177
+ }): Promise<PaymentResult>;
178
+ /** Stops result delivery and drops every listener. */
179
+ dispose(): void;
180
+ }
181
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,86 @@
1
+ import { type Environment, type SwichPayHosts } from './environment.js';
2
+ import { type SwichPayLogger } from './utils/log.js';
3
+ /** An access token returned by a merchant-hosted token endpoint. */
4
+ export interface AccessToken {
5
+ accessToken: string;
6
+ /** Seconds until expiry. Defaults to 3600, like the OAuth response. */
7
+ expiresIn?: number;
8
+ }
9
+ export interface ChecksumInput {
10
+ currency: string;
11
+ amount: number;
12
+ customerTransactionId: string;
13
+ }
14
+ /**
15
+ * Options for `SwichPay.initialize()` / `new SwichPayClient()`.
16
+ *
17
+ * The first six are the standard SwichPay merchant settings. The rest are optional,
18
+ * because a browser can't keep a secret and SwichPay's hosts don't send CORS headers to
19
+ * arbitrary origins - see docs/authentication.md.
20
+ */
21
+ export interface SwichPayOptions {
22
+ /** Public client id from your SwichPay dashboard. */
23
+ clientId: string;
24
+ /** Must match what SwichPay has registered (sent as `Referer` on checkout-host calls). */
25
+ referrer: string;
26
+ merchantId: number;
27
+ /** Your app identifier as registered with SwichPay. */
28
+ appId: string;
29
+ environment: Environment;
30
+ /** Replaces the checkout host (`/init`, `/iframe/Payment`), e.g. for a local backend. */
31
+ baseUrlOverride?: string;
32
+ /** Replaces any other host. Takes precedence over `proxyUrl`. */
33
+ hosts?: Partial<SwichPayHosts>;
34
+ /**
35
+ * OAuth2 `client_credentials` secret. Safe on a server. In a browser it is readable by
36
+ * anyone, so it's refused unless `dangerouslyAllowBrowserSecrets` is set - prefer `proxyUrl`.
37
+ */
38
+ clientSecret?: string;
39
+ /** HMAC key for the direct card payment checksum. A different secret than `clientSecret`. */
40
+ secretHashKey?: string;
41
+ /** Allows `clientSecret` / `secretHashKey` in a browser or React Native app. Only for local testing. */
42
+ dangerouslyAllowBrowserSecrets?: boolean;
43
+ /**
44
+ * Base URL of a server proxy created with `createSwichPayProxy` (`@swichpay/core/server`).
45
+ * Every call goes through it; the proxy adds authentication, the `Referer` header and the
46
+ * card checksum, so no secret is needed in the browser. Recommended for web apps.
47
+ */
48
+ proxyUrl?: string;
49
+ /** Returns a bearer token from your own backend (alternative to `clientSecret`). */
50
+ getAccessToken?: () => Promise<AccessToken | string>;
51
+ /** Returns the direct card checksum from your own backend (alternative to `secretHashKey`). */
52
+ getChecksum?: (input: ChecksumInput) => Promise<string>;
53
+ /** Custom `fetch` (tests, polyfills, instrumentation). Defaults to `globalThis.fetch`. */
54
+ fetch?: typeof fetch;
55
+ /** Receives redacted debug lines. The SDK is silent without it. */
56
+ logger?: SwichPayLogger;
57
+ /** Overrides request timeouts in milliseconds. */
58
+ timeouts?: Partial<SwichPayTimeouts>;
59
+ }
60
+ export interface SwichPayTimeouts {
61
+ /** Every call except discount lookups. */
62
+ request: number;
63
+ /** Discount lookups run while the user types. */
64
+ discount: number;
65
+ }
66
+ export declare const DEFAULT_TIMEOUTS: Readonly<SwichPayTimeouts>;
67
+ export type AuthMode = 'proxy' | 'token-provider' | 'client-secret' | 'public-key';
68
+ export interface SwichPayConfig {
69
+ readonly clientId: string;
70
+ readonly referrer: string;
71
+ readonly merchantId: number;
72
+ readonly appId: string;
73
+ readonly environment: Environment;
74
+ readonly hosts: Readonly<SwichPayHosts>;
75
+ readonly clientSecret: string | null;
76
+ readonly secretHashKey: string | null;
77
+ readonly authMode: AuthMode;
78
+ readonly getAccessToken: SwichPayOptions['getAccessToken'] | null;
79
+ readonly getChecksum: SwichPayOptions['getChecksum'] | null;
80
+ readonly fetch: typeof fetch;
81
+ readonly log: SwichPayLogger;
82
+ readonly timeouts: Readonly<SwichPayTimeouts>;
83
+ }
84
+ /** Validates options and resolves hosts, auth mode and defaults. */
85
+ export declare function resolveConfig(options: SwichPayOptions): SwichPayConfig;
86
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1,22 @@
1
+ /** The backend environment a SwichPay client talks to. */
2
+ export type Environment = 'sandbox' | 'production';
3
+ export declare const Environment: {
4
+ readonly sandbox: "sandbox";
5
+ readonly production: "production";
6
+ };
7
+ export interface SwichPayHosts {
8
+ /** `/init` and `/iframe/Payment`. */
9
+ checkout: string;
10
+ /** `/gateway/...` - sessions, process payment, direct `payin` flows, bank lists. */
11
+ gateway: string;
12
+ /** `/connect/token` - OAuth2 `client_credentials`. */
13
+ auth: string;
14
+ /** `/api/Discount/GetDiscount`; `null` where the environment has none. */
15
+ discount: string | null;
16
+ /** `/api/Payment/...` - direct card flow; `null` where the environment has none. */
17
+ paymentApi: string | null;
18
+ }
19
+ /** SwichPay hosts per environment. */
20
+ export declare const ENVIRONMENT_HOSTS: Readonly<Record<Environment, Readonly<SwichPayHosts>>>;
21
+ export declare function isEnvironment(value: unknown): value is Environment;
22
+ //# sourceMappingURL=environment.d.ts.map
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Error hierarchy - every SDK error is a `SwichPayException`.
3
+ * Every SDK call rejects with one of these instead of a raw fetch/parse error.
4
+ */
5
+ export type SwichPayErrorKind = 'not_initialized' | 'validation' | 'network' | 'api';
6
+ export declare abstract class SwichPayException extends Error {
7
+ /** Discriminator, handy where `instanceof` is awkward (e.g. across bundles). */
8
+ abstract readonly kind: SwichPayErrorKind;
9
+ constructor(message: string);
10
+ /**
11
+ * Short, non-technical text safe to show to the paying user. `message` is technical detail
12
+ * (URLs, HTTP codes, field names) - log it, never show it.
13
+ */
14
+ abstract get userMessage(): string;
15
+ toString(): string;
16
+ }
17
+ /** Thrown when a method is called before `SwichPay.initialize()`. */
18
+ export declare class SwichPayNotInitializedException extends SwichPayException {
19
+ readonly kind: "not_initialized";
20
+ constructor();
21
+ get userMessage(): string;
22
+ }
23
+ /** Thrown for malformed input (bad card number, missing fields, etc.) before any network call. */
24
+ export declare class SwichPayValidationException extends SwichPayException {
25
+ readonly kind: "validation";
26
+ get userMessage(): string;
27
+ }
28
+ /** Thrown when the SDK fails to reach the SwichPay API. */
29
+ export declare class SwichPayNetworkException extends SwichPayException {
30
+ readonly kind: "network";
31
+ readonly cause: unknown;
32
+ constructor(message: string, options?: {
33
+ cause?: unknown;
34
+ });
35
+ get userMessage(): string;
36
+ toString(): string;
37
+ }
38
+ export interface SwichPayApiExceptionInit {
39
+ statusCode: number;
40
+ code?: string | null;
41
+ serverMessage?: string | null;
42
+ serverStatus?: string | null;
43
+ orderId?: string | null;
44
+ }
45
+ /** Thrown when the SwichPay API returns an error response. */
46
+ export declare class SwichPayApiException extends SwichPayException {
47
+ readonly kind: "api";
48
+ readonly statusCode: number;
49
+ readonly code: string | null;
50
+ /** The response body's own `message` (e.g. "Invalid OTP."), when the server sent one. */
51
+ readonly serverMessage: string | null;
52
+ /**
53
+ * The response body's own `status` (e.g. `"failed"`, `"pending"`) - a 4xx isn't always a
54
+ * decline: direct card payments answer a vendor-side pending with HTTP 400 + `"pending"`.
55
+ */
56
+ readonly serverStatus: string | null;
57
+ /** The response body's `orderId`, when the server created an order before erroring. */
58
+ readonly orderId: string | null;
59
+ constructor(message: string, init: SwichPayApiExceptionInit);
60
+ get isPending(): boolean;
61
+ get userMessage(): string;
62
+ toString(): string;
63
+ }
64
+ export declare function isSwichPayException(error: unknown): error is SwichPayException;
65
+ /** `userMessage` for SwichPay errors, a generic fallback for anything else. */
66
+ export declare function swichpayUserMessage(error: unknown): string;
67
+ /**
68
+ * User-facing text for `error`; `fallback` replaces the generic text for errors that aren't a
69
+ * `SwichPayException`.
70
+ */
71
+ export declare function swichpayUserError(error: unknown, fallback?: string): string;
72
+ /**
73
+ * Whether a failed attempt reached the gateway - and so used up the checkout's
74
+ * `customerTransactionId`, which the gateway refuses to see twice. Only a request that never
75
+ * left the device (network) or never got built (validation) is safe to resend.
76
+ */
77
+ export declare function attemptUsedTransactionId(error: unknown): boolean;
78
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,19 @@
1
+ /** Returned by `onResult`: call it (or `.cancel()`) to stop listening. */
2
+ export interface Subscription {
3
+ (): void;
4
+ cancel(): void;
5
+ }
6
+ export declare function createSubscription(off: () => void): Subscription;
7
+ /**
8
+ * Minimal broadcast emitter. Like a Dart broadcast `StreamController`, events are delivered
9
+ * asynchronously (next microtask), and a throwing listener never affects the others.
10
+ */
11
+ export declare class Emitter<T> {
12
+ private readonly listeners;
13
+ private closed;
14
+ get listenerCount(): number;
15
+ on(listener: (value: T) => void): Subscription;
16
+ emit(value: T): void;
17
+ close(): void;
18
+ }
19
+ //# sourceMappingURL=events.d.ts.map
@@ -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