@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.
- package/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +82 -2
- package/docs/checkouts.md +98 -0
- package/docs/getting-started.md +140 -0
- package/docs/going-live.md +45 -0
- package/docs/own-screen.md +81 -0
- package/docs/results-and-errors.md +75 -0
- package/docs/server.md +163 -0
- package/docs/troubleshooting.md +57 -0
- package/lib/commonjs/HostedCheckout.js +115 -0
- package/lib/commonjs/checkout-webview.js +85 -0
- package/lib/commonjs/checkouts/PaymentSheet.js +1317 -0
- package/lib/commonjs/checkouts/direct.js +671 -0
- package/lib/commonjs/context.js +64 -0
- package/lib/commonjs/core/api/direct-payment-api.js +425 -0
- package/lib/commonjs/core/api/discount-api.js +19 -0
- package/lib/commonjs/core/api/gateway-api.js +366 -0
- package/lib/commonjs/core/api/payments-api.js +79 -0
- package/lib/commonjs/core/api/repositories.js +5 -0
- package/lib/commonjs/core/assets/images.js +12 -0
- package/lib/commonjs/core/assets/method-logos.js +19 -0
- package/lib/commonjs/core/assets/pwa-images.js +13 -0
- package/lib/commonjs/core/browser/clipboard.js +30 -0
- package/lib/commonjs/core/browser/dom.js +71 -0
- package/lib/commonjs/core/browser/hosted-checkout.js +107 -0
- package/lib/commonjs/core/browser/index.js +119 -0
- package/lib/commonjs/core/browser/qr.js +109 -0
- package/lib/commonjs/core/browser/three-ds.js +151 -0
- package/lib/commonjs/core/client.js +344 -0
- package/lib/commonjs/core/config.js +132 -0
- package/lib/commonjs/core/environment.js +34 -0
- package/lib/commonjs/core/errors.js +138 -0
- package/lib/commonjs/core/events.js +57 -0
- package/lib/commonjs/core/flows/controller.js +106 -0
- package/lib/commonjs/core/flows/countdown.js +41 -0
- package/lib/commonjs/core/flows/direct-bank-transfer.js +236 -0
- package/lib/commonjs/core/flows/direct-card.js +354 -0
- package/lib/commonjs/core/flows/direct-ewallet.js +124 -0
- package/lib/commonjs/core/flows/direct-one-bill.js +172 -0
- package/lib/commonjs/core/flows/direct-qr.js +109 -0
- package/lib/commonjs/core/flows/direct-rtp.js +302 -0
- package/lib/commonjs/core/flows/discount-lookup.js +80 -0
- package/lib/commonjs/core/flows/headless.js +94 -0
- package/lib/commonjs/core/flows/payment-sheet.js +1321 -0
- package/lib/commonjs/core/flows/services.js +31 -0
- package/lib/commonjs/core/flows/shared.js +90 -0
- package/lib/commonjs/core/http/api-client.js +208 -0
- package/lib/commonjs/core/http/endpoints.js +61 -0
- package/lib/commonjs/core/http/token-manager.js +46 -0
- package/lib/commonjs/core/http/transport.js +134 -0
- package/lib/commonjs/core/index.js +688 -0
- package/lib/commonjs/core/models/category.js +113 -0
- package/lib/commonjs/core/models/discount.js +51 -0
- package/lib/commonjs/core/models/payment.js +95 -0
- package/lib/commonjs/core/models/session.js +131 -0
- package/lib/commonjs/core/server/index.js +64 -0
- package/lib/commonjs/core/server/node.js +60 -0
- package/lib/commonjs/core/server/proxy.js +194 -0
- package/lib/commonjs/core/server/verify.js +122 -0
- package/lib/commonjs/core/swichpay.js +72 -0
- package/lib/commonjs/core/utils/crypto.js +78 -0
- package/lib/commonjs/core/utils/formatters.js +68 -0
- package/lib/commonjs/core/utils/json.js +110 -0
- package/lib/commonjs/core/utils/log.js +75 -0
- package/lib/commonjs/core/utils/runtime.js +34 -0
- package/lib/commonjs/core/utils/validators.js +59 -0
- package/lib/commonjs/hooks.js +77 -0
- package/lib/commonjs/index.js +203 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/polyfills.js +3 -0
- package/lib/commonjs/presenter.js +61 -0
- package/lib/commonjs/provider.js +192 -0
- package/lib/commonjs/swichpay.js +192 -0
- package/lib/commonjs/theme.js +54 -0
- package/lib/commonjs/ui.js +1142 -0
- package/lib/commonjs/webviews.js +279 -0
- package/lib/module/HostedCheckout.js +111 -0
- package/lib/module/checkout-webview.js +83 -0
- package/lib/module/checkouts/PaymentSheet.js +1313 -0
- package/lib/module/checkouts/direct.js +661 -0
- package/lib/module/context.js +58 -0
- package/lib/module/core/api/direct-payment-api.js +413 -0
- package/lib/module/core/api/discount-api.js +14 -0
- package/lib/module/core/api/gateway-api.js +358 -0
- package/lib/module/core/api/payments-api.js +73 -0
- package/lib/module/core/api/repositories.js +3 -0
- package/lib/module/core/assets/images.js +8 -0
- package/lib/module/core/assets/method-logos.js +15 -0
- package/lib/module/core/assets/pwa-images.js +9 -0
- package/lib/module/core/browser/clipboard.js +27 -0
- package/lib/module/core/browser/dom.js +63 -0
- package/lib/module/core/browser/hosted-checkout.js +102 -0
- package/lib/module/core/browser/index.js +12 -0
- package/lib/module/core/browser/qr.js +100 -0
- package/lib/module/core/browser/three-ds.js +145 -0
- package/lib/module/core/client.js +338 -0
- package/lib/module/core/config.js +128 -0
- package/lib/module/core/environment.js +29 -0
- package/lib/module/core/errors.js +125 -0
- package/lib/module/core/events.js +51 -0
- package/lib/module/core/flows/controller.js +101 -0
- package/lib/module/core/flows/countdown.js +36 -0
- package/lib/module/core/flows/direct-bank-transfer.js +231 -0
- package/lib/module/core/flows/direct-card.js +349 -0
- package/lib/module/core/flows/direct-ewallet.js +119 -0
- package/lib/module/core/flows/direct-one-bill.js +167 -0
- package/lib/module/core/flows/direct-qr.js +104 -0
- package/lib/module/core/flows/direct-rtp.js +297 -0
- package/lib/module/core/flows/discount-lookup.js +75 -0
- package/lib/module/core/flows/headless.js +90 -0
- package/lib/module/core/flows/payment-sheet.js +1315 -0
- package/lib/module/core/flows/services.js +27 -0
- package/lib/module/core/flows/shared.js +78 -0
- package/lib/module/core/http/api-client.js +203 -0
- package/lib/module/core/http/endpoints.js +57 -0
- package/lib/module/core/http/token-manager.js +41 -0
- package/lib/module/core/http/transport.js +126 -0
- package/lib/module/core/index.js +52 -0
- package/lib/module/core/models/category.js +104 -0
- package/lib/module/core/models/discount.js +46 -0
- package/lib/module/core/models/payment.js +89 -0
- package/lib/module/core/models/session.js +120 -0
- package/lib/module/core/server/index.js +11 -0
- package/lib/module/core/server/node.js +56 -0
- package/lib/module/core/server/proxy.js +191 -0
- package/lib/module/core/server/verify.js +115 -0
- package/lib/module/core/swichpay.js +68 -0
- package/lib/module/core/utils/crypto.js +72 -0
- package/lib/module/core/utils/formatters.js +56 -0
- package/lib/module/core/utils/json.js +94 -0
- package/lib/module/core/utils/log.js +67 -0
- package/lib/module/core/utils/runtime.js +28 -0
- package/lib/module/core/utils/validators.js +54 -0
- package/lib/module/hooks.js +72 -0
- package/lib/module/index.js +36 -0
- package/lib/module/polyfills.js +4 -0
- package/lib/module/presenter.js +58 -0
- package/lib/module/provider.js +188 -0
- package/lib/module/swichpay.js +187 -0
- package/lib/module/theme.js +50 -0
- package/lib/module/ui.js +1116 -0
- package/lib/module/webviews.js +272 -0
- package/lib/typescript/commonjs/HostedCheckout.d.ts +17 -0
- package/lib/typescript/commonjs/checkout-webview.d.ts +14 -0
- package/lib/typescript/commonjs/checkouts/PaymentSheet.d.ts +14 -0
- package/lib/typescript/commonjs/checkouts/direct.d.ts +18 -0
- package/lib/typescript/commonjs/context.d.ts +20 -0
- package/lib/typescript/commonjs/core/api/direct-payment-api.d.ts +103 -0
- package/lib/typescript/commonjs/core/api/discount-api.d.ts +10 -0
- package/lib/typescript/commonjs/core/api/gateway-api.d.ts +150 -0
- package/lib/typescript/commonjs/core/api/payments-api.d.ts +22 -0
- package/lib/typescript/commonjs/core/api/repositories.d.ts +86 -0
- package/lib/typescript/commonjs/core/assets/images.d.ts +5 -0
- package/lib/typescript/commonjs/core/assets/method-logos.d.ts +12 -0
- package/lib/typescript/commonjs/core/assets/pwa-images.d.ts +7 -0
- package/lib/typescript/commonjs/core/browser/clipboard.d.ts +3 -0
- package/lib/typescript/commonjs/core/browser/dom.d.ts +11 -0
- package/lib/typescript/commonjs/core/browser/hosted-checkout.d.ts +27 -0
- package/lib/typescript/commonjs/core/browser/index.d.ts +11 -0
- package/lib/typescript/commonjs/core/browser/qr.d.ts +18 -0
- package/lib/typescript/commonjs/core/browser/three-ds.d.ts +45 -0
- package/lib/typescript/commonjs/core/client.d.ts +181 -0
- package/lib/typescript/commonjs/core/config.d.ts +86 -0
- package/lib/typescript/commonjs/core/environment.d.ts +22 -0
- package/lib/typescript/commonjs/core/errors.d.ts +78 -0
- package/lib/typescript/commonjs/core/events.d.ts +19 -0
- package/lib/typescript/commonjs/core/flows/controller.d.ts +41 -0
- package/lib/typescript/commonjs/core/flows/countdown.d.ts +15 -0
- package/lib/typescript/commonjs/core/flows/direct-bank-transfer.d.ts +49 -0
- package/lib/typescript/commonjs/core/flows/direct-card.d.ts +94 -0
- package/lib/typescript/commonjs/core/flows/direct-ewallet.d.ts +39 -0
- package/lib/typescript/commonjs/core/flows/direct-one-bill.d.ts +38 -0
- package/lib/typescript/commonjs/core/flows/direct-qr.d.ts +25 -0
- package/lib/typescript/commonjs/core/flows/direct-rtp.d.ts +72 -0
- package/lib/typescript/commonjs/core/flows/discount-lookup.d.ts +37 -0
- package/lib/typescript/commonjs/core/flows/headless.d.ts +38 -0
- package/lib/typescript/commonjs/core/flows/payment-sheet.d.ts +263 -0
- package/lib/typescript/commonjs/core/flows/services.d.ts +22 -0
- package/lib/typescript/commonjs/core/flows/shared.d.ts +40 -0
- package/lib/typescript/commonjs/core/http/api-client.d.ts +37 -0
- package/lib/typescript/commonjs/core/http/endpoints.d.ts +39 -0
- package/lib/typescript/commonjs/core/http/token-manager.d.ts +19 -0
- package/lib/typescript/commonjs/core/http/transport.d.ts +37 -0
- package/lib/typescript/commonjs/core/index.d.ts +42 -0
- package/lib/typescript/commonjs/core/models/category.d.ts +35 -0
- package/lib/typescript/commonjs/core/models/discount.d.ts +41 -0
- package/lib/typescript/commonjs/core/models/payment.d.ts +104 -0
- package/lib/typescript/commonjs/core/models/session.d.ts +87 -0
- package/lib/typescript/commonjs/core/server/index.d.ts +10 -0
- package/lib/typescript/commonjs/core/server/node.d.ts +19 -0
- package/lib/typescript/commonjs/core/server/proxy.d.ts +30 -0
- package/lib/typescript/commonjs/core/server/verify.d.ts +61 -0
- package/lib/typescript/commonjs/core/swichpay.d.ts +40 -0
- package/lib/typescript/commonjs/core/utils/crypto.d.ts +19 -0
- package/lib/typescript/commonjs/core/utils/formatters.d.ts +19 -0
- package/lib/typescript/commonjs/core/utils/json.d.ts +27 -0
- package/lib/typescript/commonjs/core/utils/log.d.ts +15 -0
- package/lib/typescript/commonjs/core/utils/runtime.d.ts +12 -0
- package/lib/typescript/commonjs/core/utils/validators.d.ts +23 -0
- package/lib/typescript/commonjs/hooks.d.ts +21 -0
- package/lib/typescript/commonjs/index.d.ts +26 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/polyfills.d.ts +2 -0
- package/lib/typescript/commonjs/presenter.d.ts +25 -0
- package/lib/typescript/commonjs/provider.d.ts +22 -0
- package/lib/typescript/commonjs/swichpay.d.ts +125 -0
- package/lib/typescript/commonjs/theme.d.ts +52 -0
- package/lib/typescript/commonjs/ui.d.ts +583 -0
- package/lib/typescript/commonjs/webviews.d.ts +40 -0
- package/lib/typescript/module/HostedCheckout.d.ts +17 -0
- package/lib/typescript/module/checkout-webview.d.ts +14 -0
- package/lib/typescript/module/checkouts/PaymentSheet.d.ts +14 -0
- package/lib/typescript/module/checkouts/direct.d.ts +18 -0
- package/lib/typescript/module/context.d.ts +20 -0
- package/lib/typescript/module/core/api/direct-payment-api.d.ts +103 -0
- package/lib/typescript/module/core/api/discount-api.d.ts +10 -0
- package/lib/typescript/module/core/api/gateway-api.d.ts +150 -0
- package/lib/typescript/module/core/api/payments-api.d.ts +22 -0
- package/lib/typescript/module/core/api/repositories.d.ts +86 -0
- package/lib/typescript/module/core/assets/images.d.ts +5 -0
- package/lib/typescript/module/core/assets/method-logos.d.ts +12 -0
- package/lib/typescript/module/core/assets/pwa-images.d.ts +7 -0
- package/lib/typescript/module/core/browser/clipboard.d.ts +3 -0
- package/lib/typescript/module/core/browser/dom.d.ts +11 -0
- package/lib/typescript/module/core/browser/hosted-checkout.d.ts +27 -0
- package/lib/typescript/module/core/browser/index.d.ts +11 -0
- package/lib/typescript/module/core/browser/qr.d.ts +18 -0
- package/lib/typescript/module/core/browser/three-ds.d.ts +45 -0
- package/lib/typescript/module/core/client.d.ts +181 -0
- package/lib/typescript/module/core/config.d.ts +86 -0
- package/lib/typescript/module/core/environment.d.ts +22 -0
- package/lib/typescript/module/core/errors.d.ts +78 -0
- package/lib/typescript/module/core/events.d.ts +19 -0
- package/lib/typescript/module/core/flows/controller.d.ts +41 -0
- package/lib/typescript/module/core/flows/countdown.d.ts +15 -0
- package/lib/typescript/module/core/flows/direct-bank-transfer.d.ts +49 -0
- package/lib/typescript/module/core/flows/direct-card.d.ts +94 -0
- package/lib/typescript/module/core/flows/direct-ewallet.d.ts +39 -0
- package/lib/typescript/module/core/flows/direct-one-bill.d.ts +38 -0
- package/lib/typescript/module/core/flows/direct-qr.d.ts +25 -0
- package/lib/typescript/module/core/flows/direct-rtp.d.ts +72 -0
- package/lib/typescript/module/core/flows/discount-lookup.d.ts +37 -0
- package/lib/typescript/module/core/flows/headless.d.ts +38 -0
- package/lib/typescript/module/core/flows/payment-sheet.d.ts +263 -0
- package/lib/typescript/module/core/flows/services.d.ts +22 -0
- package/lib/typescript/module/core/flows/shared.d.ts +40 -0
- package/lib/typescript/module/core/http/api-client.d.ts +37 -0
- package/lib/typescript/module/core/http/endpoints.d.ts +39 -0
- package/lib/typescript/module/core/http/token-manager.d.ts +19 -0
- package/lib/typescript/module/core/http/transport.d.ts +37 -0
- package/lib/typescript/module/core/index.d.ts +42 -0
- package/lib/typescript/module/core/models/category.d.ts +35 -0
- package/lib/typescript/module/core/models/discount.d.ts +41 -0
- package/lib/typescript/module/core/models/payment.d.ts +104 -0
- package/lib/typescript/module/core/models/session.d.ts +87 -0
- package/lib/typescript/module/core/server/index.d.ts +10 -0
- package/lib/typescript/module/core/server/node.d.ts +19 -0
- package/lib/typescript/module/core/server/proxy.d.ts +30 -0
- package/lib/typescript/module/core/server/verify.d.ts +61 -0
- package/lib/typescript/module/core/swichpay.d.ts +40 -0
- package/lib/typescript/module/core/utils/crypto.d.ts +19 -0
- package/lib/typescript/module/core/utils/formatters.d.ts +19 -0
- package/lib/typescript/module/core/utils/json.d.ts +27 -0
- package/lib/typescript/module/core/utils/log.d.ts +15 -0
- package/lib/typescript/module/core/utils/runtime.d.ts +12 -0
- package/lib/typescript/module/core/utils/validators.d.ts +23 -0
- package/lib/typescript/module/hooks.d.ts +21 -0
- package/lib/typescript/module/index.d.ts +26 -0
- package/lib/typescript/module/polyfills.d.ts +2 -0
- package/lib/typescript/module/presenter.d.ts +25 -0
- package/lib/typescript/module/provider.d.ts +22 -0
- package/lib/typescript/module/swichpay.d.ts +125 -0
- package/lib/typescript/module/theme.d.ts +52 -0
- package/lib/typescript/module/ui.d.ts +583 -0
- package/lib/typescript/module/webviews.d.ts +40 -0
- package/package.json +129 -4
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
4
|
+
import { StyleSheet, View } from 'react-native';
|
|
5
|
+
import { WebView } from 'react-native-webview';
|
|
6
|
+
import { stepUpRequest } from './core/browser/three-ds.js';
|
|
7
|
+
import { messageDataAsObject } from './core/browser/dom.js';
|
|
8
|
+
import { useLatest } from './hooks.js';
|
|
9
|
+
import { Button, Spinner } from './ui.js';
|
|
10
|
+
import { FILL, colors } from './theme.js';
|
|
11
|
+
|
|
12
|
+
/** Hosts Cardinal Commerce serves its 3-D Secure pages from (same rule as the web SDK). */
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
const CARDINAL_HOST = /(^|\.)(cardinalcommerce\.com|cardinaltrusted\.com)$/i;
|
|
15
|
+
/** SwichPay / JazzCash hosts - a TRANSACTION_COMPLETE from them ends the challenge. */
|
|
16
|
+
const SWICHPAY_HOST = /(^|\.)(swichnow\.com|jazzcash\.com\.pk)$/i;
|
|
17
|
+
function hostMatches(origin, pattern) {
|
|
18
|
+
const match = /^[a-z][a-z0-9+.-]*:\/\/([^/:?#]+)/i.exec(origin);
|
|
19
|
+
return !!match && pattern.test(match[1]);
|
|
20
|
+
}
|
|
21
|
+
function escapeHtml(value) {
|
|
22
|
+
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** `http://` - a page that would load without TLS. */
|
|
26
|
+
export function isPlainHttp(url) {
|
|
27
|
+
return /^http:\/\//i.test(url);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A page that POSTs `fields` to `action` inside an iframe and forwards every `message` event to
|
|
32
|
+
* React Native as `{ origin, fromFrame, data }` - the same signals the web SDK reads from
|
|
33
|
+
* `window` (the 3-D Secure pages talk to `window.parent`, which is this wrapper).
|
|
34
|
+
*/
|
|
35
|
+
export function postFormPage(action, fields, visible) {
|
|
36
|
+
const inputs = Object.entries(fields).map(([name, value]) => `<input type="hidden" name="${escapeHtml(name)}" value="${escapeHtml(value)}">`).join('');
|
|
37
|
+
const frameStyle = visible ? 'position:fixed;inset:0;width:100%;height:100%;border:0;' : 'width:1px;height:1px;border:0;opacity:0;';
|
|
38
|
+
return `<!doctype html><html><head><meta name="viewport" content="width=device-width,initial-scale=1"></head>
|
|
39
|
+
<body style="margin:0;background:#fff">
|
|
40
|
+
<iframe name="sp-frame" id="sp-frame" style="${frameStyle}" allow="payment"></iframe>
|
|
41
|
+
<form id="sp-form" method="POST" action="${escapeHtml(action)}" target="sp-frame" enctype="application/x-www-form-urlencoded" style="display:none">${inputs}</form>
|
|
42
|
+
<script>
|
|
43
|
+
(function () {
|
|
44
|
+
var frame = document.getElementById('sp-frame');
|
|
45
|
+
window.addEventListener('message', function (e) {
|
|
46
|
+
var data = e.data;
|
|
47
|
+
try { JSON.stringify(data); } catch (err) { data = String(data); }
|
|
48
|
+
var payload = { origin: e.origin, fromFrame: !!frame && e.source === frame.contentWindow, data: data };
|
|
49
|
+
if (window.ReactNativeWebView) window.ReactNativeWebView.postMessage(JSON.stringify(payload));
|
|
50
|
+
});
|
|
51
|
+
document.getElementById('sp-form').submit();
|
|
52
|
+
})();
|
|
53
|
+
</script></body></html>`;
|
|
54
|
+
}
|
|
55
|
+
export function parseForwarded(event) {
|
|
56
|
+
try {
|
|
57
|
+
const parsed = JSON.parse(event.nativeEvent.data);
|
|
58
|
+
if (typeof parsed !== 'object' || parsed === null) return null;
|
|
59
|
+
return {
|
|
60
|
+
origin: String(parsed.origin ?? ''),
|
|
61
|
+
fromFrame: parsed.fromFrame === true,
|
|
62
|
+
data: parsed.data
|
|
63
|
+
};
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** `event.data` serialized as a string. */
|
|
70
|
+
function serialize(data) {
|
|
71
|
+
try {
|
|
72
|
+
return JSON.stringify(data) ?? 'null';
|
|
73
|
+
} catch {
|
|
74
|
+
return String(data);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ── Device data collection (hidden) ───────────────────────────────────────────
|
|
79
|
+
|
|
80
|
+
let ddcQueue = [];
|
|
81
|
+
let ddcSeq = 0;
|
|
82
|
+
let ddcHosts = 0;
|
|
83
|
+
const ddcListeners = new Set();
|
|
84
|
+
const notifyDdc = () => ddcListeners.forEach(l => l());
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* `FlowServices.runDeviceDataCollection` for React Native: renders Cardinal's collection page in
|
|
88
|
+
* a hidden WebView (inside `<SwichPayProvider>`) and resolves `true` on `profile.complete`,
|
|
89
|
+
* `false` after `timeoutMs` (hidden WebView).
|
|
90
|
+
*/
|
|
91
|
+
export function runDeviceDataCollectionNative(input) {
|
|
92
|
+
return new Promise(resolve => {
|
|
93
|
+
if (ddcHosts === 0) {
|
|
94
|
+
// No host mounted: nothing can run the page, so verification can't complete.
|
|
95
|
+
resolve(false);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const request = {
|
|
99
|
+
id: ++ddcSeq,
|
|
100
|
+
...input,
|
|
101
|
+
resolve
|
|
102
|
+
};
|
|
103
|
+
ddcQueue = [...ddcQueue, request];
|
|
104
|
+
notifyDdc();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function finishDdc(id, completed) {
|
|
108
|
+
const request = ddcQueue.find(r => r.id === id);
|
|
109
|
+
if (!request) return;
|
|
110
|
+
ddcQueue = ddcQueue.filter(r => r.id !== id);
|
|
111
|
+
notifyDdc();
|
|
112
|
+
request.resolve(completed);
|
|
113
|
+
}
|
|
114
|
+
const subscribeDdc = listener => {
|
|
115
|
+
ddcListeners.add(listener);
|
|
116
|
+
return () => ddcListeners.delete(listener);
|
|
117
|
+
};
|
|
118
|
+
function DdcFrame({
|
|
119
|
+
request
|
|
120
|
+
}) {
|
|
121
|
+
const html = useMemo(() => postFormPage(request.url, request.formFields, false), [request]);
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
const timer = setTimeout(() => finishDdc(request.id, false), request.timeoutMs);
|
|
124
|
+
return () => clearTimeout(timer);
|
|
125
|
+
}, [request]);
|
|
126
|
+
return /*#__PURE__*/_jsx(WebView, {
|
|
127
|
+
source: {
|
|
128
|
+
html
|
|
129
|
+
},
|
|
130
|
+
originWhitelist: ['*'],
|
|
131
|
+
javaScriptEnabled: true,
|
|
132
|
+
style: styles.hidden
|
|
133
|
+
// Card-scheme device checks are always TLS; never post device data over plain HTTP.
|
|
134
|
+
,
|
|
135
|
+
onShouldStartLoadWithRequest: request => !isPlainHttp(request.url),
|
|
136
|
+
onMessage: event => {
|
|
137
|
+
const message = parseForwarded(event);
|
|
138
|
+
if (!message) return;
|
|
139
|
+
if (!message.fromFrame && !hostMatches(message.origin, CARDINAL_HOST)) return;
|
|
140
|
+
if (messageDataAsObject(message.data)?.MessageType === 'profile.complete') finishDdc(request.id, true);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Mounted once by `<SwichPayProvider>`; runs queued device-data collections off-screen. */
|
|
146
|
+
export function DeviceDataCollectionHost() {
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
ddcHosts += 1;
|
|
149
|
+
return () => {
|
|
150
|
+
ddcHosts -= 1;
|
|
151
|
+
};
|
|
152
|
+
}, []);
|
|
153
|
+
const queue = useSyncExternalStore(subscribeDdc, () => ddcQueue, () => ddcQueue);
|
|
154
|
+
if (queue.length === 0) return null;
|
|
155
|
+
return /*#__PURE__*/_jsx(View, {
|
|
156
|
+
style: styles.hiddenHost,
|
|
157
|
+
pointerEvents: "none",
|
|
158
|
+
accessibilityElementsHidden: true,
|
|
159
|
+
importantForAccessibility: "no-hide-descendants",
|
|
160
|
+
children: queue.map(request => /*#__PURE__*/_jsx(DdcFrame, {
|
|
161
|
+
request: request
|
|
162
|
+
}, request.id))
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ── Step-up challenge (visible) ───────────────────────────────────────────────
|
|
167
|
+
|
|
168
|
+
/** Same event data the web SDK sends for the manual fallback. */
|
|
169
|
+
const MANUAL_COMPLETION = JSON.stringify({
|
|
170
|
+
type: 'manual'
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The issuer's 3-D Secure challenge. Completes on the challenge frame's first message, on a
|
|
175
|
+
* SwichPay `TRANSACTION_COMPLETE`, on a navigation to a completion URL, or on the manual
|
|
176
|
+
* "I've completed verification" button.
|
|
177
|
+
*/
|
|
178
|
+
export function StepUpView(props) {
|
|
179
|
+
const [loading, setLoading] = useState(true);
|
|
180
|
+
const done = useRef(false);
|
|
181
|
+
const onComplete = useLatest(props.onComplete);
|
|
182
|
+
const html = useMemo(() => {
|
|
183
|
+
const {
|
|
184
|
+
action,
|
|
185
|
+
fields
|
|
186
|
+
} = stepUpRequest(props.challenge.url, props.challenge.jwt);
|
|
187
|
+
return postFormPage(action, fields, true);
|
|
188
|
+
}, [props.challenge.url, props.challenge.jwt]);
|
|
189
|
+
const complete = data => {
|
|
190
|
+
if (done.current) return;
|
|
191
|
+
done.current = true;
|
|
192
|
+
onComplete.current(data);
|
|
193
|
+
};
|
|
194
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
195
|
+
style: {
|
|
196
|
+
gap: 8
|
|
197
|
+
},
|
|
198
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
199
|
+
style: [styles.frame, {
|
|
200
|
+
height: props.height ?? 520
|
|
201
|
+
}],
|
|
202
|
+
children: [/*#__PURE__*/_jsx(WebView, {
|
|
203
|
+
source: {
|
|
204
|
+
html
|
|
205
|
+
},
|
|
206
|
+
originWhitelist: ['*'],
|
|
207
|
+
javaScriptEnabled: true,
|
|
208
|
+
domStorageEnabled: true,
|
|
209
|
+
onLoadEnd: () => setLoading(false),
|
|
210
|
+
onMessage: event => {
|
|
211
|
+
const message = parseForwarded(event);
|
|
212
|
+
if (!message) return;
|
|
213
|
+
const isSwichPayCompletion = hostMatches(message.origin, SWICHPAY_HOST) && messageDataAsObject(message.data)?.type === 'TRANSACTION_COMPLETE';
|
|
214
|
+
if (!message.fromFrame && !isSwichPayCompletion) return;
|
|
215
|
+
complete(serialize(message.data));
|
|
216
|
+
},
|
|
217
|
+
onShouldStartLoadWithRequest: request => {
|
|
218
|
+
try {
|
|
219
|
+
const url = new URL(request.url);
|
|
220
|
+
if (props.isCompletionUrl(url)) complete(JSON.stringify({
|
|
221
|
+
type: 'redirect',
|
|
222
|
+
url: url.href
|
|
223
|
+
}));
|
|
224
|
+
} catch {
|
|
225
|
+
// not a URL we can read (about:blank, data:)
|
|
226
|
+
}
|
|
227
|
+
// 3-D Secure pages are always TLS (EMV 3DS); a completion URL was caught above.
|
|
228
|
+
return !isPlainHttp(request.url);
|
|
229
|
+
}
|
|
230
|
+
}), loading ? /*#__PURE__*/_jsx(View, {
|
|
231
|
+
style: styles.loading,
|
|
232
|
+
children: /*#__PURE__*/_jsx(Spinner, {
|
|
233
|
+
dark: true,
|
|
234
|
+
large: true,
|
|
235
|
+
label: "Loading verification"
|
|
236
|
+
})
|
|
237
|
+
}) : null]
|
|
238
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
239
|
+
variant: "ghost",
|
|
240
|
+
onPress: () => complete(MANUAL_COMPLETION),
|
|
241
|
+
children: "I've completed verification"
|
|
242
|
+
})]
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
const styles = StyleSheet.create({
|
|
246
|
+
hidden: {
|
|
247
|
+
width: 1,
|
|
248
|
+
height: 1,
|
|
249
|
+
opacity: 0
|
|
250
|
+
},
|
|
251
|
+
hiddenHost: {
|
|
252
|
+
position: 'absolute',
|
|
253
|
+
width: 1,
|
|
254
|
+
height: 1,
|
|
255
|
+
left: -10,
|
|
256
|
+
top: -10,
|
|
257
|
+
opacity: 0
|
|
258
|
+
},
|
|
259
|
+
frame: {
|
|
260
|
+
borderWidth: 1,
|
|
261
|
+
borderColor: colors.border,
|
|
262
|
+
borderRadius: 10,
|
|
263
|
+
overflow: 'hidden',
|
|
264
|
+
backgroundColor: '#fff'
|
|
265
|
+
},
|
|
266
|
+
loading: {
|
|
267
|
+
...FILL,
|
|
268
|
+
alignItems: 'center',
|
|
269
|
+
justifyContent: 'center',
|
|
270
|
+
backgroundColor: 'rgba(255,255,255,0.8)'
|
|
271
|
+
}
|
|
272
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PaymentCategory, type PaymentDetails, type PaymentResult } from './core/index.js';
|
|
2
|
+
export interface HostedCheckoutProps {
|
|
3
|
+
details: PaymentDetails;
|
|
4
|
+
categories?: readonly PaymentCategory[];
|
|
5
|
+
/** A URL from `client.createHostedCheckoutUrl` - skips creating one. */
|
|
6
|
+
url?: string;
|
|
7
|
+
onFinish: (result: PaymentResult | null) => void;
|
|
8
|
+
/** Called when the session URL can't be created. */
|
|
9
|
+
onError?: (error: unknown) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* SwichPay's hosted checkout page: resolves from the redirect
|
|
13
|
+
* to `successRedirectUrl` / `failedRedirectUrl` or from the page's
|
|
14
|
+
* `redirecttocustomer` / `closewindow` messages. Close resolves `null`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function HostedCheckout(props: HostedCheckoutProps): import("react").JSX.Element;
|
|
17
|
+
//# sourceMappingURL=HostedCheckout.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A full-screen SwichPay page. `onNavigate` sees every top-level navigation first and returns
|
|
3
|
+
* `true` to stop it (a redirect URL that ends the checkout - it is never loaded, so it can be any
|
|
4
|
+
* URL, even one that doesn't exist). `onPageMessage` receives the page's `postMessage`s.
|
|
5
|
+
*/
|
|
6
|
+
export declare function CheckoutWebView(props: {
|
|
7
|
+
url: string;
|
|
8
|
+
onNavigate?: (url: string) => boolean;
|
|
9
|
+
onPageMessage?: (origin: string, data: unknown) => void;
|
|
10
|
+
testID?: string;
|
|
11
|
+
/** Allow plain-HTTP pages (sandbox with a local backend). Off: only https:// pages load. */
|
|
12
|
+
allowInsecure?: boolean;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=checkout-webview.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PaymentCategory, type FlowServices, type PaymentDetails, type PaymentResult, type PaymentSheetControllerOptions } from '../core/index.js';
|
|
2
|
+
export interface PaymentSheetProps {
|
|
3
|
+
details: PaymentDetails;
|
|
4
|
+
/** Restricts which of the merchant's enabled categories are shown. */
|
|
5
|
+
categories?: readonly PaymentCategory[];
|
|
6
|
+
/** `null` = dismissed or startup failure. */
|
|
7
|
+
onFinish: (result: PaymentResult | null) => void;
|
|
8
|
+
services?: Partial<FlowServices>;
|
|
9
|
+
/** Timing overrides (tests). */
|
|
10
|
+
timing?: PaymentSheetControllerOptions['timing'];
|
|
11
|
+
}
|
|
12
|
+
/** The built-in payment sheet. */
|
|
13
|
+
export declare function PaymentSheet(props: PaymentSheetProps): import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=PaymentSheet.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type FlowServices, type PaymentDetails, type PaymentResult } from '../core/index.js';
|
|
2
|
+
export interface CheckoutProps {
|
|
3
|
+
details: PaymentDetails;
|
|
4
|
+
/** Called once with the outcome; `null` means dismissed without a result. */
|
|
5
|
+
onFinish: (result: PaymentResult | null) => void;
|
|
6
|
+
/** Replace side effects (tests, custom share/clipboard). */
|
|
7
|
+
services?: Partial<FlowServices>;
|
|
8
|
+
}
|
|
9
|
+
export declare function EwalletCheckout(props: CheckoutProps): import("react").JSX.Element;
|
|
10
|
+
export declare function BankTransferCheckout(props: CheckoutProps): import("react").JSX.Element;
|
|
11
|
+
export declare function CardCheckout(props: CheckoutProps & {
|
|
12
|
+
allowSaveCard?: boolean;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
14
|
+
export declare function OneBillCheckout(props: CheckoutProps): import("react").JSX.Element;
|
|
15
|
+
export declare function QrCheckout(props: CheckoutProps): import("react").JSX.Element;
|
|
16
|
+
export declare function RtpNowCheckout(props: CheckoutProps): import("react").JSX.Element;
|
|
17
|
+
export declare function RtpEwalletCheckout(props: CheckoutProps): import("react").JSX.Element;
|
|
18
|
+
//# sourceMappingURL=direct.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type FlowServices } from './core/flows/services.js';
|
|
2
|
+
import type { SwichPayClient } from './core/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* `FlowServices` for React Native: 3-D Secure device-data collection in a hidden WebView;
|
|
5
|
+
* "copy" / QR save and share open the system share sheet (React Native has no built-in
|
|
6
|
+
* clipboard or file APIs, and the SDK adds no native dependencies for them).
|
|
7
|
+
*/
|
|
8
|
+
export declare const nativeFlowServices: FlowServices;
|
|
9
|
+
export interface SwichPayContextValue {
|
|
10
|
+
client: SwichPayClient;
|
|
11
|
+
services: FlowServices;
|
|
12
|
+
}
|
|
13
|
+
export declare const SwichPayContext: import("react").Context<SwichPayContextValue | null>;
|
|
14
|
+
/** The provider's client, or the one from `SwichPay.initialize()` when used outside a provider. */
|
|
15
|
+
export declare function useSwichPayClient(): SwichPayClient;
|
|
16
|
+
export declare function useFlowServices(overrides?: Partial<FlowServices>): FlowServices;
|
|
17
|
+
/** A presented checkout registers what Android's back button / swipe-down should do. */
|
|
18
|
+
export declare const DismissContext: import("react").Context<((handler: (() => void) | null) => void) | null>;
|
|
19
|
+
export declare function useDismissHandler(handler: () => void): void;
|
|
20
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { ApiClient } from '../http/api-client.js';
|
|
2
|
+
import { type CardDetails, type PaymentResult, type ResolvedPaymentDetails } from '../models/payment.js';
|
|
3
|
+
import { type DirectBank } from '../models/session.js';
|
|
4
|
+
import { type JsonMap } from '../utils/json.js';
|
|
5
|
+
import type { DirectPaymentRepository } from './repositories.js';
|
|
6
|
+
/** Strips vendor messages to whatever's between `[` and `]` when present. */
|
|
7
|
+
export declare function extractVendorMessage(message: string | null): string | null;
|
|
8
|
+
/** `code` in {0000, 0, 00} (string or number) or `status == success`. */
|
|
9
|
+
export declare function isSuccessCode(json: JsonMap): boolean;
|
|
10
|
+
/** Shared shape for e-wallet / bank transfer; OTP required = success code && !isTransactionCompleted. */
|
|
11
|
+
export declare function parseDirectPaymentResponse(json: JsonMap): PaymentResult;
|
|
12
|
+
/** Shared shape for RTP Now / RTP E-wallet; prefers `success`, falls back to code/status. */
|
|
13
|
+
export declare function parseRtpResponse(json: JsonMap): PaymentResult;
|
|
14
|
+
/**
|
|
15
|
+
* `PaymentV3`: `nextAction.type == "iframe_collect"` is a DDC step; any other non-`complete`
|
|
16
|
+
* `nextAction` with a `url` is a step-up; `complete` (or no `nextAction` with code 0000) is final.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseDirectCardResult(json: JsonMap, fallbackVendorTransactionId: string): PaymentResult;
|
|
19
|
+
/**
|
|
20
|
+
* `CompleteTokenPayment`: the step-up is under `next_action` (snake_case), whose `nextAction` is a
|
|
21
|
+
* string step type and whose `token` is the JWT to POST.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseTokenizedPaymentResult(json: JsonMap, fallbackVendorTransactionId: string): PaymentResult;
|
|
24
|
+
/** `InquireV3`: `transactionStatus` is authoritative; `Initiated` means still pending. */
|
|
25
|
+
export declare function parseDirectCardStatus(json: JsonMap, tracker: string): PaymentResult;
|
|
26
|
+
export interface DirectCardPaymentInput {
|
|
27
|
+
details: ResolvedPaymentDetails;
|
|
28
|
+
card: CardDetails;
|
|
29
|
+
clientId: string;
|
|
30
|
+
/** `recievedCheckSum`; empty in proxy mode, where the proxy signs the request. */
|
|
31
|
+
checksum: string;
|
|
32
|
+
merchantId: number;
|
|
33
|
+
doCardOnFile?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface DirectRtpNowPaymentInput {
|
|
36
|
+
details: ResolvedPaymentDetails;
|
|
37
|
+
msisdn: string;
|
|
38
|
+
rtpId: string;
|
|
39
|
+
bankCode?: string | null;
|
|
40
|
+
accountTitle?: string | null;
|
|
41
|
+
accountNumber?: string | null;
|
|
42
|
+
accountNumberAlias?: string | null;
|
|
43
|
+
transactionType?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ConfirmDirectBankTransferInput {
|
|
46
|
+
customerTransactionId: string;
|
|
47
|
+
billReferenceNo?: string | null;
|
|
48
|
+
transactionId: string;
|
|
49
|
+
orderId: string;
|
|
50
|
+
transactionReferenceNo: string;
|
|
51
|
+
retreivalReferenceNo: string;
|
|
52
|
+
otp: string;
|
|
53
|
+
}
|
|
54
|
+
/** Direct (session-less) payments on the gateway's `payin` endpoints and the payment-api host. */
|
|
55
|
+
export declare class DirectPaymentApi implements DirectPaymentRepository {
|
|
56
|
+
private readonly client;
|
|
57
|
+
private readonly now;
|
|
58
|
+
constructor(client: ApiClient, now?: () => number);
|
|
59
|
+
directEwalletPayment(input: {
|
|
60
|
+
details: ResolvedPaymentDetails;
|
|
61
|
+
channelId: number;
|
|
62
|
+
msisdn: string;
|
|
63
|
+
categoryId?: number;
|
|
64
|
+
}): Promise<PaymentResult>;
|
|
65
|
+
directBankTransfer(input: {
|
|
66
|
+
details: ResolvedPaymentDetails;
|
|
67
|
+
bankCode: string;
|
|
68
|
+
accountNo: string;
|
|
69
|
+
}): Promise<PaymentResult>;
|
|
70
|
+
confirmDirectBankTransfer(input: ConfirmDirectBankTransferInput): Promise<PaymentResult>;
|
|
71
|
+
fetchDirectBankList(): Promise<DirectBank[]>;
|
|
72
|
+
generateDirectOneBill(input: {
|
|
73
|
+
details: ResolvedPaymentDetails;
|
|
74
|
+
ucid?: string;
|
|
75
|
+
bankMnemonic?: string;
|
|
76
|
+
prefix?: string;
|
|
77
|
+
reserved?: string;
|
|
78
|
+
categoryId?: number;
|
|
79
|
+
channelId?: number;
|
|
80
|
+
}): Promise<PaymentResult>;
|
|
81
|
+
checkDirectOneBillStatus(customerTransactionId: string): Promise<PaymentResult>;
|
|
82
|
+
generateDirectQrPayment(details: ResolvedPaymentDetails): Promise<PaymentResult>;
|
|
83
|
+
checkDirectQrStatus(customerTransactionId: string): Promise<PaymentResult>;
|
|
84
|
+
fetchDirectRtpNowBanks(): Promise<DirectBank[]>;
|
|
85
|
+
directRtpNowPayment(input: DirectRtpNowPaymentInput): Promise<PaymentResult>;
|
|
86
|
+
fetchDirectRtpEwalletBanks(): Promise<DirectBank[]>;
|
|
87
|
+
directRtpEwalletPayment(input: {
|
|
88
|
+
details: ResolvedPaymentDetails;
|
|
89
|
+
bankCode: string;
|
|
90
|
+
msisdn?: string;
|
|
91
|
+
iban?: string;
|
|
92
|
+
}): Promise<PaymentResult>;
|
|
93
|
+
directCardPayment(input: DirectCardPaymentInput): Promise<PaymentResult>;
|
|
94
|
+
executeDirectCardTokenizedPayment(input: {
|
|
95
|
+
customerTransactionId: string;
|
|
96
|
+
billReferenceNo: string;
|
|
97
|
+
vendorTransactionId: string;
|
|
98
|
+
sessionId: string;
|
|
99
|
+
}): Promise<PaymentResult>;
|
|
100
|
+
checkDirectCardPaymentStatus(tracker: string): Promise<PaymentResult>;
|
|
101
|
+
private fetchBanks;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=direct-payment-api.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ApiClient } from '../http/api-client.js';
|
|
2
|
+
import { type DiscountRequest, type DiscountResult } from '../models/discount.js';
|
|
3
|
+
import type { DiscountRepository } from './repositories.js';
|
|
4
|
+
/** Calls to the standalone Discount API host. */
|
|
5
|
+
export declare class DiscountApi implements DiscountRepository {
|
|
6
|
+
private readonly client;
|
|
7
|
+
constructor(client: ApiClient);
|
|
8
|
+
getDiscount(request: DiscountRequest): Promise<DiscountResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=discount-api.d.ts.map
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { ApiClient } from '../http/api-client.js';
|
|
2
|
+
import { PaymentCategory } from '../models/category.js';
|
|
3
|
+
import { type CardDetails, type PaymentResult, type ResolvedPaymentDetails } from '../models/payment.js';
|
|
4
|
+
import { type MobileAppInitResult, type PaymentSessionDetails, type PaymentSessionInquiryResult } from '../models/session.js';
|
|
5
|
+
import { type JsonMap } from '../utils/json.js';
|
|
6
|
+
import type { GatewayRepository } from './repositories.js';
|
|
7
|
+
export interface ProcessCardPaymentInput {
|
|
8
|
+
paymentSessionGuid: string;
|
|
9
|
+
card: CardDetails;
|
|
10
|
+
/** The user's "save this card" choice (wire field `saveCard`). */
|
|
11
|
+
doCardOnFile?: boolean;
|
|
12
|
+
categoryId?: number | null;
|
|
13
|
+
savedCardId?: number | null;
|
|
14
|
+
isSavedCardSelected?: boolean | null;
|
|
15
|
+
clientId?: string | null;
|
|
16
|
+
/** Best-effort; not part of ProcessPayment's documented contract. */
|
|
17
|
+
discountAmount?: number | null;
|
|
18
|
+
/** Sent as `amount` when a discount applies. */
|
|
19
|
+
finalAmount?: number | null;
|
|
20
|
+
}
|
|
21
|
+
export interface ProcessEwalletPaymentInput {
|
|
22
|
+
paymentSessionGuid: string;
|
|
23
|
+
ewalletType?: string | null;
|
|
24
|
+
channelId: number;
|
|
25
|
+
msisdn?: string | null;
|
|
26
|
+
/** Default `"ewallet"`; `"rtpewalletpayment"` for RTP E-wallet. */
|
|
27
|
+
categoryCode?: string;
|
|
28
|
+
bankCode?: string | null;
|
|
29
|
+
accountNumber?: string | null;
|
|
30
|
+
accountNumberAlias?: string | null;
|
|
31
|
+
iban?: string | null;
|
|
32
|
+
mobileNumber?: string | null;
|
|
33
|
+
categoryId?: number | null;
|
|
34
|
+
clientId?: string | null;
|
|
35
|
+
discountAmount?: number | null;
|
|
36
|
+
finalAmount?: number | null;
|
|
37
|
+
}
|
|
38
|
+
export interface ProcessBankAccountPaymentInput {
|
|
39
|
+
paymentSessionGuid: string;
|
|
40
|
+
bankCode: string;
|
|
41
|
+
/** Always sent as 0 - the real bank channelId makes the request hang. */
|
|
42
|
+
channelId: number;
|
|
43
|
+
cnic: string;
|
|
44
|
+
accountNumber: string;
|
|
45
|
+
msisdn: string;
|
|
46
|
+
otp?: string | null;
|
|
47
|
+
categoryId?: number | null;
|
|
48
|
+
clientId?: string | null;
|
|
49
|
+
}
|
|
50
|
+
export interface ProcessBillerPaymentInput {
|
|
51
|
+
paymentSessionGuid: string;
|
|
52
|
+
msisdn: string;
|
|
53
|
+
consumerNumber?: string | null;
|
|
54
|
+
categoryId?: number | null;
|
|
55
|
+
clientId?: string | null;
|
|
56
|
+
}
|
|
57
|
+
export interface ProcessQrPaymentInput {
|
|
58
|
+
paymentSessionGuid: string;
|
|
59
|
+
/** `"dqrcpayment"` (default) or `"sqrcpayment"`. */
|
|
60
|
+
categoryCode?: string;
|
|
61
|
+
isVerify?: boolean;
|
|
62
|
+
categoryId?: number | null;
|
|
63
|
+
clientId?: string | null;
|
|
64
|
+
}
|
|
65
|
+
export interface ProcessRtpNowPaymentInput {
|
|
66
|
+
paymentSessionGuid: string;
|
|
67
|
+
mobileNumber?: string | null;
|
|
68
|
+
iban?: string | null;
|
|
69
|
+
bankCode?: string | null;
|
|
70
|
+
channelId?: number | null;
|
|
71
|
+
accountNumber?: string | null;
|
|
72
|
+
accountNumberAlias?: string | null;
|
|
73
|
+
categoryId?: number | null;
|
|
74
|
+
clientId?: string | null;
|
|
75
|
+
}
|
|
76
|
+
export interface SubmitPaymentEnrollmentInput {
|
|
77
|
+
customerTransactionId: string;
|
|
78
|
+
billReferenceNo: string;
|
|
79
|
+
/** Sent as `eventData`. */
|
|
80
|
+
sessionId: string;
|
|
81
|
+
paymentSetup: Record<string, unknown>;
|
|
82
|
+
doCapture?: boolean;
|
|
83
|
+
doCardOnFile?: boolean;
|
|
84
|
+
dynamicRedirectUrls?: Record<string, unknown>;
|
|
85
|
+
vendorTransactionId?: string | null;
|
|
86
|
+
}
|
|
87
|
+
interface ProcessPaymentFields {
|
|
88
|
+
paymentSessionGuid: string;
|
|
89
|
+
categoryCode: string;
|
|
90
|
+
categoryId?: number;
|
|
91
|
+
clientId?: string | null;
|
|
92
|
+
cardNumber?: string;
|
|
93
|
+
expiryDate?: string;
|
|
94
|
+
cvc?: string;
|
|
95
|
+
saveCard?: boolean;
|
|
96
|
+
isSavedCardSelected?: boolean;
|
|
97
|
+
savedCardId?: number;
|
|
98
|
+
ewalletType?: string;
|
|
99
|
+
channelId?: number;
|
|
100
|
+
msisdn?: string;
|
|
101
|
+
bankCode?: string;
|
|
102
|
+
cnic?: string | null;
|
|
103
|
+
accountNumber?: string;
|
|
104
|
+
otp?: string;
|
|
105
|
+
mobileNumber?: string;
|
|
106
|
+
checksum?: string;
|
|
107
|
+
isVerify?: boolean;
|
|
108
|
+
accountNumberAlias?: string;
|
|
109
|
+
iban?: string;
|
|
110
|
+
finalAmount?: number | null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Builds a `ProcessPayment` body with every field always present (unset ones as `""`/`0`/`false`),
|
|
114
|
+
* matching native's `ProcessPaymentRequestDto`. `clientId`/`cnic`/`amount` are omitted when null.
|
|
115
|
+
*/
|
|
116
|
+
export declare function processPaymentBody(f: ProcessPaymentFields): JsonMap;
|
|
117
|
+
/**
|
|
118
|
+
* Parses a `ProcessPayment` / `PaymentEnrollment` response. Fields are read from the root, then
|
|
119
|
+
* from `data`, and coerced instead of cast.
|
|
120
|
+
*/
|
|
121
|
+
export declare function parseGatewayResult(json: JsonMap): PaymentResult;
|
|
122
|
+
/**
|
|
123
|
+
* `CheckCardPaymentStatus` - different shape: `transactionStatus`/`redirectUrl`. Only
|
|
124
|
+
* success/successful/approved count as success; `message` comes from `redirectUrl`'s query.
|
|
125
|
+
*/
|
|
126
|
+
export declare function parseCardStatusResult(json: JsonMap, tracker: string): PaymentResult;
|
|
127
|
+
/** Calls to the SwichPay gateway host. */
|
|
128
|
+
export declare class GatewayApi implements GatewayRepository {
|
|
129
|
+
private readonly client;
|
|
130
|
+
constructor(client: ApiClient);
|
|
131
|
+
mobileAppInit(appId: string): Promise<MobileAppInitResult>;
|
|
132
|
+
/** Validates `attempts` (1-10) and `expiryMinutes` (1-30) before any network call. */
|
|
133
|
+
createPaymentSession(details: ResolvedPaymentDetails, categories: readonly PaymentCategory[]): Promise<{
|
|
134
|
+
url: string;
|
|
135
|
+
guid: string;
|
|
136
|
+
}>;
|
|
137
|
+
getPaymentSessionDetails(paymentSessionGuid: string): Promise<PaymentSessionDetails>;
|
|
138
|
+
processCardPayment(input: ProcessCardPaymentInput): Promise<PaymentResult>;
|
|
139
|
+
processEwalletPayment(input: ProcessEwalletPaymentInput): Promise<PaymentResult>;
|
|
140
|
+
processBankAccountPayment(input: ProcessBankAccountPaymentInput): Promise<PaymentResult>;
|
|
141
|
+
processBillerPayment(input: ProcessBillerPaymentInput): Promise<PaymentResult>;
|
|
142
|
+
processQrPayment(input: ProcessQrPaymentInput): Promise<PaymentResult>;
|
|
143
|
+
processRtpNowPayment(input: ProcessRtpNowPaymentInput): Promise<PaymentResult>;
|
|
144
|
+
submitPaymentEnrollment(input: SubmitPaymentEnrollmentInput): Promise<PaymentResult>;
|
|
145
|
+
checkCardPaymentStatus(tracker: string, forceTimeout?: boolean): Promise<PaymentResult>;
|
|
146
|
+
cancelSession(paymentSessionGuid: string): Promise<void>;
|
|
147
|
+
inquirePaymentSession(paymentSessionGuid: string): Promise<PaymentSessionInquiryResult>;
|
|
148
|
+
}
|
|
149
|
+
export {};
|
|
150
|
+
//# sourceMappingURL=gateway-api.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ApiClient } from '../http/api-client.js';
|
|
2
|
+
import { type CardDetails, type PaymentResult, type ResolvedPaymentDetails } from '../models/payment.js';
|
|
3
|
+
import { type JsonMap } from '../utils/json.js';
|
|
4
|
+
import type { PaymentsRepository } from './repositories.js';
|
|
5
|
+
/** `/iframe/Payment` response. */
|
|
6
|
+
export declare function parseCheckoutPaymentResult(json: JsonMap): PaymentResult;
|
|
7
|
+
/** Calls to the SwichPay checkout host. */
|
|
8
|
+
export declare class PaymentsApi implements PaymentsRepository {
|
|
9
|
+
private readonly client;
|
|
10
|
+
private readonly today;
|
|
11
|
+
constructor(client: ApiClient, today?: () => string);
|
|
12
|
+
/** Rejects with `SwichPayApiException` if the client id / referrer pair isn't recognized. */
|
|
13
|
+
init(sessionToken: string): Promise<void>;
|
|
14
|
+
pay(input: {
|
|
15
|
+
details: ResolvedPaymentDetails;
|
|
16
|
+
card: CardDetails;
|
|
17
|
+
clientId: string;
|
|
18
|
+
merchantId: number;
|
|
19
|
+
sessionToken: string;
|
|
20
|
+
}): Promise<PaymentResult>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=payments-api.d.ts.map
|