@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,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import qrcode from 'qrcode-generator';
|
|
4
|
+
import { assertBrowser } from '../utils/runtime.js';
|
|
5
|
+
/** Encodes `text` as a QR matrix (error correction M, automatic version). Pure - SSR-safe. */
|
|
6
|
+
export function encodeQr(text) {
|
|
7
|
+
const qr = qrcode(0, 'M');
|
|
8
|
+
qr.addData(text, 'Byte');
|
|
9
|
+
qr.make();
|
|
10
|
+
return {
|
|
11
|
+
size: qr.getModuleCount(),
|
|
12
|
+
isDark: (r, c) => qr.isDark(r, c)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** An SVG string for `text`, scalable to any size. Pure - safe to render on the server. */
|
|
17
|
+
export function qrSvg(text, options = {}) {
|
|
18
|
+
const matrix = encodeQr(text);
|
|
19
|
+
const margin = options.margin ?? 4;
|
|
20
|
+
const dim = matrix.size + margin * 2;
|
|
21
|
+
let path = '';
|
|
22
|
+
for (let r = 0; r < matrix.size; r++) {
|
|
23
|
+
for (let c = 0; c < matrix.size; c++) {
|
|
24
|
+
if (matrix.isDark(r, c)) path += `M${c + margin} ${r + margin}h1v1h-1z`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const title = options.title ? `<title>${escapeXml(options.title)}</title>` : '';
|
|
28
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${dim} ${dim}" shape-rendering="crispEdges" role="img">` + `${title}<rect width="100%" height="100%" fill="#fff"/><path d="${path}" fill="#000"/></svg>`;
|
|
29
|
+
}
|
|
30
|
+
function escapeXml(value) {
|
|
31
|
+
return value.replace(/[<>&"']/g, ch => `&#${ch.charCodeAt(0)};`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Rasterizes the QR to a PNG blob (for download/share). Browser only. */
|
|
35
|
+
export async function qrPngBlob(text, pixels = 660) {
|
|
36
|
+
assertBrowser('QR image export');
|
|
37
|
+
const matrix = encodeQr(text);
|
|
38
|
+
const margin = 4;
|
|
39
|
+
const dim = matrix.size + margin * 2;
|
|
40
|
+
const cell = Math.max(1, Math.floor(pixels / dim));
|
|
41
|
+
const canvas = document.createElement('canvas');
|
|
42
|
+
canvas.width = canvas.height = dim * cell;
|
|
43
|
+
const ctx = canvas.getContext('2d');
|
|
44
|
+
if (!ctx) throw new Error('Canvas 2D is unavailable.');
|
|
45
|
+
ctx.fillStyle = '#fff';
|
|
46
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
47
|
+
ctx.fillStyle = '#000';
|
|
48
|
+
for (let r = 0; r < matrix.size; r++) {
|
|
49
|
+
for (let c = 0; c < matrix.size; c++) {
|
|
50
|
+
if (matrix.isDark(r, c)) ctx.fillRect((c + margin) * cell, (r + margin) * cell, cell, cell);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
canvas.toBlob(blob => blob ? resolve(blob) : reject(new Error('Could not encode the QR image.')), 'image/png');
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function qrFileName(now = Date.now()) {
|
|
58
|
+
return `swichpay_qr_${now}.png`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Saves the QR as a PNG file. */
|
|
62
|
+
export async function downloadQrCode(text, fileName = qrFileName()) {
|
|
63
|
+
const blob = await qrPngBlob(text);
|
|
64
|
+
const url = URL.createObjectURL(blob);
|
|
65
|
+
try {
|
|
66
|
+
const link = document.createElement('a');
|
|
67
|
+
link.href = url;
|
|
68
|
+
link.download = fileName;
|
|
69
|
+
link.rel = 'noopener';
|
|
70
|
+
link.style.display = 'none';
|
|
71
|
+
document.body.appendChild(link);
|
|
72
|
+
link.click();
|
|
73
|
+
link.remove();
|
|
74
|
+
} finally {
|
|
75
|
+
// Give the browser a moment to start the download before revoking.
|
|
76
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Shares the QR PNG with the Web Share API when it can share files; downloads it otherwise. */
|
|
81
|
+
export async function shareQrCode(text) {
|
|
82
|
+
const blob = await qrPngBlob(text);
|
|
83
|
+
const fileName = qrFileName();
|
|
84
|
+
const nav = navigator;
|
|
85
|
+
if (typeof File === 'function' && typeof nav.share === 'function' && typeof nav.canShare === 'function') {
|
|
86
|
+
const file = new File([blob], fileName, {
|
|
87
|
+
type: 'image/png'
|
|
88
|
+
});
|
|
89
|
+
const data = {
|
|
90
|
+
files: [file],
|
|
91
|
+
text: 'SwichPay QR code'
|
|
92
|
+
};
|
|
93
|
+
if (nav.canShare(data)) {
|
|
94
|
+
await nav.share(data);
|
|
95
|
+
return 'shared';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
await downloadQrCode(text, fileName);
|
|
99
|
+
return 'downloaded';
|
|
100
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { assertBrowser } from '../utils/runtime.js';
|
|
4
|
+
import { createPostForm, messageDataAsObject, readFrameUrl, serializeMessageData, uniqueName } from './dom.js';
|
|
5
|
+
|
|
6
|
+
/** Hosts Cardinal Commerce serves its 3-D Secure pages from. */
|
|
7
|
+
const CARDINAL_HOST = /(^|\.)(cardinalcommerce\.com|cardinaltrusted\.com)$/i;
|
|
8
|
+
|
|
9
|
+
/** SwichPay / JazzCash hosts - a return to these means "challenge finished". */
|
|
10
|
+
const SWICHPAY_HOST = /(^|\.)(swichnow\.com|jazzcash\.com\.pk)$/i;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The checkout host's 3-D Secure return page (`CallBack.cshtml` in Swich.CardPayment) posts
|
|
14
|
+
* `{ type: "TRANSACTION_COMPLETE", status }` to `window.parent` once the issuer step is over.
|
|
15
|
+
*/
|
|
16
|
+
export const TRANSACTION_COMPLETE = 'TRANSACTION_COMPLETE';
|
|
17
|
+
function hostMatches(origin, pattern) {
|
|
18
|
+
try {
|
|
19
|
+
return pattern.test(new URL(origin).hostname);
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function isFromFrameOrCardinal(event, iframe) {
|
|
25
|
+
if (event.source != null && event.source === iframe.contentWindow) return true;
|
|
26
|
+
return hostMatches(event.origin, CARDINAL_HOST);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Runs Cardinal Cruise device-data-collection invisibly: POSTs `formFields` (the `JWT`) to `url`
|
|
31
|
+
* in a hidden iframe and resolves `true` on its `profile.complete` message, `false` after
|
|
32
|
+
* `timeoutMs`.
|
|
33
|
+
*/
|
|
34
|
+
export function runDeviceDataCollection(input) {
|
|
35
|
+
assertBrowser('3-D Secure device data collection');
|
|
36
|
+
return new Promise(resolve => {
|
|
37
|
+
const name = uniqueName('swichpay-ddc');
|
|
38
|
+
const iframe = document.createElement('iframe');
|
|
39
|
+
iframe.name = name;
|
|
40
|
+
iframe.title = 'Card verification';
|
|
41
|
+
iframe.setAttribute('aria-hidden', 'true');
|
|
42
|
+
iframe.tabIndex = -1;
|
|
43
|
+
iframe.style.cssText = 'position:absolute;width:1px;height:1px;border:0;left:-9999px;top:-9999px;opacity:0;pointer-events:none;';
|
|
44
|
+
const form = createPostForm(input.url, input.formFields, name);
|
|
45
|
+
let done = false;
|
|
46
|
+
const finish = completed => {
|
|
47
|
+
if (done) return;
|
|
48
|
+
done = true;
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
window.removeEventListener('message', onMessage);
|
|
51
|
+
iframe.remove();
|
|
52
|
+
form.remove();
|
|
53
|
+
resolve(completed);
|
|
54
|
+
};
|
|
55
|
+
const onMessage = event => {
|
|
56
|
+
if (!isFromFrameOrCardinal(event, iframe)) return;
|
|
57
|
+
if (messageDataAsObject(event.data)?.MessageType === 'profile.complete') finish(true);
|
|
58
|
+
};
|
|
59
|
+
const timer = setTimeout(() => finish(false), input.timeoutMs);
|
|
60
|
+
window.addEventListener('message', onMessage);
|
|
61
|
+
document.body.append(iframe, form);
|
|
62
|
+
form.submit();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** The form a step-up challenge is POSTed with. */
|
|
66
|
+
export function stepUpRequest(url, jwt) {
|
|
67
|
+
if (jwt != null) return {
|
|
68
|
+
action: url,
|
|
69
|
+
fields: {
|
|
70
|
+
JWT: jwt
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
// Meezan's 3DS2 page rejects GET and wants its own query params as the body - only there.
|
|
74
|
+
const [base] = url.split('?');
|
|
75
|
+
let fields = {};
|
|
76
|
+
try {
|
|
77
|
+
fields = Object.fromEntries(new URL(url).searchParams.entries());
|
|
78
|
+
} catch {
|
|
79
|
+
fields = {};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
action: base ?? url,
|
|
83
|
+
fields
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Shows the issuer's 3-D Secure challenge in an iframe inside `container`. Completes on:
|
|
89
|
+
* - the first `postMessage` from the challenge frame -
|
|
90
|
+
* in practice SwichPay's return page's `{ type: "TRANSACTION_COMPLETE", status }`;
|
|
91
|
+
* - a `TRANSACTION_COMPLETE` message from a SwichPay/JazzCash origin posted by a nested frame;
|
|
92
|
+
* - a navigation to a completion URL we can read (same-origin only - browsers hide others).
|
|
93
|
+
* UIs also offer a manual "I've completed verification" action as a last resort.
|
|
94
|
+
*/
|
|
95
|
+
export function mountStepUpChallenge(container, options) {
|
|
96
|
+
assertBrowser('The 3-D Secure challenge');
|
|
97
|
+
const name = uniqueName('swichpay-3ds');
|
|
98
|
+
const iframe = document.createElement('iframe');
|
|
99
|
+
iframe.name = name;
|
|
100
|
+
iframe.title = 'Card verification with your bank';
|
|
101
|
+
iframe.className = 'sp-frame';
|
|
102
|
+
iframe.setAttribute('allow', 'payment');
|
|
103
|
+
const {
|
|
104
|
+
action,
|
|
105
|
+
fields
|
|
106
|
+
} = stepUpRequest(options.url, options.jwt);
|
|
107
|
+
const form = createPostForm(action, fields, name);
|
|
108
|
+
let completed = false;
|
|
109
|
+
let destroyed = false;
|
|
110
|
+
const complete = data => {
|
|
111
|
+
if (completed || destroyed) return;
|
|
112
|
+
completed = true;
|
|
113
|
+
options.onComplete(data);
|
|
114
|
+
};
|
|
115
|
+
const onMessage = event => {
|
|
116
|
+
const fromFrame = event.source != null && event.source === iframe.contentWindow;
|
|
117
|
+
const isSwichPayCompletion = hostMatches(event.origin, SWICHPAY_HOST) && messageDataAsObject(event.data)?.type === TRANSACTION_COMPLETE;
|
|
118
|
+
if (!fromFrame && !isSwichPayCompletion) return;
|
|
119
|
+
complete(serializeMessageData(event.data));
|
|
120
|
+
};
|
|
121
|
+
const onLoad = () => {
|
|
122
|
+
options.onLoadingChange?.(false);
|
|
123
|
+
const url = readFrameUrl(iframe);
|
|
124
|
+
if (url && options.isCompletionUrl?.(url)) complete(JSON.stringify({
|
|
125
|
+
type: 'redirect',
|
|
126
|
+
url: url.href
|
|
127
|
+
}));
|
|
128
|
+
};
|
|
129
|
+
window.addEventListener('message', onMessage);
|
|
130
|
+
iframe.addEventListener('load', onLoad);
|
|
131
|
+
container.append(iframe, form);
|
|
132
|
+
options.onLoadingChange?.(true);
|
|
133
|
+
form.submit();
|
|
134
|
+
return {
|
|
135
|
+
iframe,
|
|
136
|
+
destroy() {
|
|
137
|
+
if (destroyed) return;
|
|
138
|
+
destroyed = true;
|
|
139
|
+
window.removeEventListener('message', onMessage);
|
|
140
|
+
iframe.removeEventListener('load', onLoad);
|
|
141
|
+
iframe.remove();
|
|
142
|
+
form.remove();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { DirectPaymentApi } from './api/direct-payment-api.js';
|
|
4
|
+
import { DiscountApi } from './api/discount-api.js';
|
|
5
|
+
import { GatewayApi } from './api/gateway-api.js';
|
|
6
|
+
import { PaymentsApi } from './api/payments-api.js';
|
|
7
|
+
import { resolveConfig } from './config.js';
|
|
8
|
+
import { SwichPayValidationException } from './errors.js';
|
|
9
|
+
import { Emitter } from './events.js';
|
|
10
|
+
import { ApiClient } from './http/api-client.js';
|
|
11
|
+
import { resolvePaymentDetails } from './models/payment.js';
|
|
12
|
+
import { generateTransactionCheckSum } from './utils/crypto.js';
|
|
13
|
+
import { CardValidators } from './utils/validators.js';
|
|
14
|
+
/** Throws SwichPay's card validation errors. */
|
|
15
|
+
export function validateCard(card) {
|
|
16
|
+
if (card == null || typeof card !== 'object') throw new SwichPayValidationException('Card details are required.');
|
|
17
|
+
if (!CardValidators.isValidNumber(card.number)) throw new SwichPayValidationException('Invalid card number.');
|
|
18
|
+
if (!CardValidators.isValidExpiry(card.expMonth, card.expYear)) {
|
|
19
|
+
throw new SwichPayValidationException('Card has expired or invalid expiry.');
|
|
20
|
+
}
|
|
21
|
+
if (!CardValidators.isValidCvv(card.cvv)) throw new SwichPayValidationException('Invalid CVV.');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* One live SDK session: config, API layers and the result stream behind `onResult`.
|
|
26
|
+
* Every completed payment attempt is emitted to that stream.
|
|
27
|
+
*/
|
|
28
|
+
export class SwichPayClient {
|
|
29
|
+
results = new Emitter();
|
|
30
|
+
disposed = false;
|
|
31
|
+
constructor(options, deps = {}) {
|
|
32
|
+
this.config = resolveConfig(options);
|
|
33
|
+
const api = new ApiClient(this.config);
|
|
34
|
+
this.gateway = deps.gatewayApi ?? new GatewayApi(api);
|
|
35
|
+
this.payments = deps.paymentsApi ?? new PaymentsApi(api);
|
|
36
|
+
this.direct = deps.directPaymentApi ?? new DirectPaymentApi(api);
|
|
37
|
+
this.discount = deps.discountApi ?? new DiscountApi(api);
|
|
38
|
+
}
|
|
39
|
+
get isDisposed() {
|
|
40
|
+
return this.disposed;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Listens for every payment result. */
|
|
44
|
+
onResult(listener) {
|
|
45
|
+
return this.results.on(listener);
|
|
46
|
+
}
|
|
47
|
+
emit(result) {
|
|
48
|
+
this.results.emit(result);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ── Checkout host (custom card UI) ──
|
|
53
|
+
|
|
54
|
+
async pay(input) {
|
|
55
|
+
const sessionToken = await this.startSession();
|
|
56
|
+
return this.payWithSession({
|
|
57
|
+
sessionToken,
|
|
58
|
+
...input
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Runs `/init` and returns `clientId`, the token that authenticates it. */
|
|
63
|
+
async startSession() {
|
|
64
|
+
await this.payments.init(this.config.clientId);
|
|
65
|
+
return this.config.clientId;
|
|
66
|
+
}
|
|
67
|
+
async payWithSession(input) {
|
|
68
|
+
validateCard(input.card);
|
|
69
|
+
const details = resolvePaymentDetails(input.details);
|
|
70
|
+
const result = await this.payments.pay({
|
|
71
|
+
details,
|
|
72
|
+
card: input.card,
|
|
73
|
+
clientId: this.config.clientId,
|
|
74
|
+
merchantId: this.config.merchantId,
|
|
75
|
+
sessionToken: input.sessionToken
|
|
76
|
+
});
|
|
77
|
+
return this.emit(result);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ── Session-based checkout ──
|
|
81
|
+
|
|
82
|
+
/** Categories and logos enabled for this merchant; fetched fresh each time. */
|
|
83
|
+
loadMobileAppInit() {
|
|
84
|
+
return this.gateway.mobileAppInit(this.config.appId);
|
|
85
|
+
}
|
|
86
|
+
async availableCategories() {
|
|
87
|
+
return (await this.loadMobileAppInit()).categories;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* URL of SwichPay's hosted checkout page. The session always gets every enabled category
|
|
92
|
+
* (matches native); `categories` exists for API symmetry only.
|
|
93
|
+
*/
|
|
94
|
+
async createHostedCheckoutUrl(input) {
|
|
95
|
+
const details = resolvePaymentDetails(input.details);
|
|
96
|
+
const created = await this.gateway.createPaymentSession(details, await this.availableCategories());
|
|
97
|
+
return created.url;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Creates a session and fetches its details. `categories` only restricts what the returned
|
|
102
|
+
* details list (what a sheet displays), not what the session supports.
|
|
103
|
+
*/
|
|
104
|
+
async startNativeCheckout(input) {
|
|
105
|
+
const details = resolvePaymentDetails(input.details);
|
|
106
|
+
const created = await this.gateway.createPaymentSession(details, await this.availableCategories());
|
|
107
|
+
const session = await this.gateway.getPaymentSessionDetails(created.guid);
|
|
108
|
+
if (input.categories == null) return session;
|
|
109
|
+
const allowed = new Set(input.categories);
|
|
110
|
+
return {
|
|
111
|
+
...session,
|
|
112
|
+
categories: session.categories.filter(c => allowed.has(c))
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async processCardPayment(input) {
|
|
116
|
+
if (input.isSavedCardSelected !== true) validateCard(input.card);
|
|
117
|
+
return this.emit(await this.gateway.processCardPayment(input));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Discount quote for a card payment (new card entry only - never for a saved card). Never
|
|
122
|
+
* emits. `ipAddress` defaults to `''` - a browser can't read the device IP.
|
|
123
|
+
*/
|
|
124
|
+
getCardDiscount(input) {
|
|
125
|
+
const details = resolvePaymentDetails(input.details);
|
|
126
|
+
return this.discount.getDiscount({
|
|
127
|
+
amount: details.amount,
|
|
128
|
+
referenceValue: input.cardNumber,
|
|
129
|
+
categoryId: input.categoryId ?? 'CardBins',
|
|
130
|
+
merchantId: this.config.merchantId,
|
|
131
|
+
customerTransactionId: details.customerTransactionId,
|
|
132
|
+
ipAddress: input.ipAddress ?? '',
|
|
133
|
+
discountableAmount: details.amount,
|
|
134
|
+
msisdn: details.msisdn
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
async processEwalletPayment(input) {
|
|
138
|
+
return this.emit(await this.gateway.processEwalletPayment(input));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Discount quote for an e-wallet payment; `channelId` is the wallet's channel (8 EasyPaisa,
|
|
143
|
+
* 10 JazzCash). Never emits. `ipAddress` defaults to `"127.0.0.1"`
|
|
144
|
+
*/
|
|
145
|
+
getEwalletDiscount(input) {
|
|
146
|
+
const details = resolvePaymentDetails(input.details);
|
|
147
|
+
return this.discount.getDiscount({
|
|
148
|
+
amount: details.amount,
|
|
149
|
+
referenceValue: String(input.channelId),
|
|
150
|
+
categoryId: input.categoryId ?? 'Ewallet',
|
|
151
|
+
merchantId: this.config.merchantId,
|
|
152
|
+
customerTransactionId: details.customerTransactionId,
|
|
153
|
+
ipAddress: input.ipAddress === undefined ? '127.0.0.1' : input.ipAddress ?? '',
|
|
154
|
+
discountableAmount: details.amount,
|
|
155
|
+
msisdn: input.msisdn
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** If the result has `otpRequired`, call again with `otp`. */
|
|
160
|
+
async processBankAccountPayment(input) {
|
|
161
|
+
return this.emit(await this.gateway.processBankAccountPayment(input));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Called twice: first with `msisdn` for the consumer number, then with `consumerNumber` to verify. */
|
|
165
|
+
async processBillerPayment(input) {
|
|
166
|
+
return this.emit(await this.gateway.processBillerPayment(input));
|
|
167
|
+
}
|
|
168
|
+
async submitPaymentEnrollment(input) {
|
|
169
|
+
return this.emit(await this.gateway.submitPaymentEnrollment(input));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* `tracker` is ProcessPayment's `vendorTransactionId`. With `orderId` and a payment-api host,
|
|
174
|
+
* asks `InquireV3` instead (resolves session card payments by `orderId`).
|
|
175
|
+
*/
|
|
176
|
+
async checkCardPaymentStatus(input) {
|
|
177
|
+
const hasPaymentApi = !!this.config.hosts.paymentApi;
|
|
178
|
+
const result = input.orderId && hasPaymentApi ? await this.direct.checkDirectCardPaymentStatus(input.orderId) : await this.gateway.checkCardPaymentStatus(input.tracker, input.forceTimeout ?? false);
|
|
179
|
+
return this.emit(result);
|
|
180
|
+
}
|
|
181
|
+
async processQrPayment(input) {
|
|
182
|
+
return this.emit(await this.gateway.processQrPayment(input));
|
|
183
|
+
}
|
|
184
|
+
async processRtpNowPayment(input) {
|
|
185
|
+
return this.emit(await this.gateway.processRtpNowPayment(input));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** For when the user explicitly closes/cancels a payment sheet. */
|
|
189
|
+
cancelSession(input) {
|
|
190
|
+
return this.gateway.cancelSession(input.paymentSessionGuid);
|
|
191
|
+
}
|
|
192
|
+
inquirePaymentSession(input) {
|
|
193
|
+
return this.gateway.inquirePaymentSession(input.paymentSessionGuid);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ── Direct (session-less) payments ──
|
|
197
|
+
|
|
198
|
+
async directEwalletPayment(input) {
|
|
199
|
+
const details = resolvePaymentDetails(input.details);
|
|
200
|
+
return this.emit(await this.direct.directEwalletPayment({
|
|
201
|
+
details,
|
|
202
|
+
channelId: input.channelId,
|
|
203
|
+
msisdn: input.msisdn
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Step 1 of a bank transfer; if `otpRequired`, call `confirmDirectBankTransfer`. Never emits. */
|
|
208
|
+
directBankTransfer(input) {
|
|
209
|
+
const details = resolvePaymentDetails(input.details);
|
|
210
|
+
return this.direct.directBankTransfer({
|
|
211
|
+
details,
|
|
212
|
+
bankCode: input.bankCode,
|
|
213
|
+
accountNo: input.accountNo
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
async confirmDirectBankTransfer(input) {
|
|
217
|
+
return this.emit(await this.direct.confirmDirectBankTransfer(input));
|
|
218
|
+
}
|
|
219
|
+
fetchDirectBankList() {
|
|
220
|
+
return this.direct.fetchDirectBankList();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** The result's `consumerNumber` is what the customer pays against. Never emits. */
|
|
224
|
+
generateDirectOneBill(input) {
|
|
225
|
+
return this.direct.generateDirectOneBill({
|
|
226
|
+
details: resolvePaymentDetails(input.details)
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Emits on success only. */
|
|
231
|
+
async checkDirectOneBillStatus(input) {
|
|
232
|
+
const result = await this.direct.checkDirectOneBillStatus(input.customerTransactionId);
|
|
233
|
+
if (result.isSuccess) this.emit(result);
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** The result's `qrString` is the payload to render. Never emits. */
|
|
238
|
+
generateDirectQrPayment(input) {
|
|
239
|
+
return this.direct.generateDirectQrPayment(resolvePaymentDetails(input.details));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Emits on success only. */
|
|
243
|
+
async checkDirectQrStatus(input) {
|
|
244
|
+
const result = await this.direct.checkDirectQrStatus(input.customerTransactionId);
|
|
245
|
+
if (result.isSuccess) this.emit(result);
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
fetchDirectRtpNowBanks() {
|
|
249
|
+
return this.direct.fetchDirectRtpNowBanks();
|
|
250
|
+
}
|
|
251
|
+
async directRtpNowPayment(input) {
|
|
252
|
+
const details = resolvePaymentDetails(input.details);
|
|
253
|
+
return this.emit(await this.direct.directRtpNowPayment({
|
|
254
|
+
...input,
|
|
255
|
+
details
|
|
256
|
+
}));
|
|
257
|
+
}
|
|
258
|
+
fetchDirectRtpEwalletBanks() {
|
|
259
|
+
return this.direct.fetchDirectRtpEwalletBanks();
|
|
260
|
+
}
|
|
261
|
+
async directRtpEwalletPayment(input) {
|
|
262
|
+
const details = resolvePaymentDetails(input.details);
|
|
263
|
+
return this.emit(await this.direct.directRtpEwalletPayment({
|
|
264
|
+
details,
|
|
265
|
+
bankCode: input.bankCode,
|
|
266
|
+
msisdn: input.msisdn ?? '',
|
|
267
|
+
iban: input.iban ?? ''
|
|
268
|
+
}));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ── Direct card ──
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Submits a direct card payment. Needs a checksum source: `secretHashKey`, `getChecksum`, or a
|
|
275
|
+
* proxy (which signs server-side). Emits unless a device-data-collection step follows.
|
|
276
|
+
*/
|
|
277
|
+
async directCardPayment(input) {
|
|
278
|
+
validateCard(input.card);
|
|
279
|
+
const details = resolvePaymentDetails(input.details);
|
|
280
|
+
const checksum = await this.checksumFor(details.currency, details.amount, details.customerTransactionId);
|
|
281
|
+
const result = await this.direct.directCardPayment({
|
|
282
|
+
details,
|
|
283
|
+
card: input.card,
|
|
284
|
+
clientId: this.config.clientId,
|
|
285
|
+
checksum,
|
|
286
|
+
merchantId: this.config.merchantId,
|
|
287
|
+
doCardOnFile: input.doCardOnFile ?? false
|
|
288
|
+
});
|
|
289
|
+
if (result.ddcCollectionUrl == null) this.emit(result);
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
async checksumFor(currency, amount, customerTransactionId) {
|
|
293
|
+
const {
|
|
294
|
+
getChecksum,
|
|
295
|
+
secretHashKey,
|
|
296
|
+
authMode
|
|
297
|
+
} = this.config;
|
|
298
|
+
if (getChecksum) return getChecksum({
|
|
299
|
+
currency,
|
|
300
|
+
amount,
|
|
301
|
+
customerTransactionId
|
|
302
|
+
});
|
|
303
|
+
if (secretHashKey) return generateTransactionCheckSum({
|
|
304
|
+
currency,
|
|
305
|
+
amount,
|
|
306
|
+
customerTransactionId,
|
|
307
|
+
secretHashKey
|
|
308
|
+
});
|
|
309
|
+
// The proxy adds `recievedCheckSum` server-side.
|
|
310
|
+
if (authMode === 'proxy') return '';
|
|
311
|
+
throw new SwichPayValidationException('Direct card payment requires secretHashKey - pass secretHashKey (or getChecksum, or proxyUrl) to SwichPay.initialize().');
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Completes a direct card payment after device-data-collection. Emits unless a step-up follows. */
|
|
315
|
+
async executeDirectCardTokenizedPayment(input) {
|
|
316
|
+
const result = await this.direct.executeDirectCardTokenizedPayment({
|
|
317
|
+
customerTransactionId: input.customerTransactionId,
|
|
318
|
+
billReferenceNo: input.billReferenceNo,
|
|
319
|
+
vendorTransactionId: input.tracker,
|
|
320
|
+
sessionId: input.sessionId
|
|
321
|
+
});
|
|
322
|
+
if (result.stepUpUrl == null) this.emit(result);
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** `tracker` is `vendorTransactionId` from `directCardPayment`. Emits unless still pending. */
|
|
327
|
+
async checkDirectCardPaymentStatus(input) {
|
|
328
|
+
const result = await this.direct.checkDirectCardPaymentStatus(input.tracker);
|
|
329
|
+
if (result.status.toLowerCase() !== 'pending') this.emit(result);
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** Stops result delivery and drops every listener. */
|
|
334
|
+
dispose() {
|
|
335
|
+
this.disposed = true;
|
|
336
|
+
this.results.close();
|
|
337
|
+
}
|
|
338
|
+
}
|