@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,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PaymentCategory = exports.ALL_PAYMENT_CATEGORIES = void 0;
|
|
7
|
+
exports.isPaymentCategory = isPaymentCategory;
|
|
8
|
+
exports.paymentCategoryCode = paymentCategoryCode;
|
|
9
|
+
exports.paymentCategoryFromApiValue = paymentCategoryFromApiValue;
|
|
10
|
+
exports.paymentCategoryLabel = paymentCategoryLabel;
|
|
11
|
+
exports.paymentCategoryLogoNames = paymentCategoryLogoNames;
|
|
12
|
+
/** A payment method category. Values are the Dart enum names. */
|
|
13
|
+
const PaymentCategory = exports.PaymentCategory = {
|
|
14
|
+
/** Local-only - opens the hosted checkout page full-screen. */
|
|
15
|
+
paymentSession: 'paymentSession',
|
|
16
|
+
/** Local-only - opens the hosted checkout page in a sheet. */
|
|
17
|
+
paymentSessionSheet: 'paymentSessionSheet',
|
|
18
|
+
/** Local-only - opens the SDK's direct card checkout. */
|
|
19
|
+
sdkCheckout: 'sdkCheckout',
|
|
20
|
+
ewallet: 'ewallet',
|
|
21
|
+
biller: 'biller',
|
|
22
|
+
bankAccount: 'bankAccount',
|
|
23
|
+
visaMasterCardPayment: 'visaMasterCardPayment',
|
|
24
|
+
unionPayCardPayment: 'unionPayCardPayment',
|
|
25
|
+
dqrcPayment: 'dqrcPayment',
|
|
26
|
+
sqrcPayment: 'sqrcPayment',
|
|
27
|
+
rtpNowPayment: 'rtpNowPayment',
|
|
28
|
+
rtpLaterPayment: 'rtpLaterPayment',
|
|
29
|
+
tokenization: 'tokenization',
|
|
30
|
+
rtpEwalletPayment: 'rtpEwalletPayment',
|
|
31
|
+
bnpl: 'bnpl',
|
|
32
|
+
/** An unrecognized category id, kept instead of dropped. */
|
|
33
|
+
unknown: 'unknown'
|
|
34
|
+
};
|
|
35
|
+
const ALL_PAYMENT_CATEGORIES = exports.ALL_PAYMENT_CATEGORIES = Object.values(PaymentCategory);
|
|
36
|
+
const API_VALUES = {
|
|
37
|
+
paymentSession: '',
|
|
38
|
+
paymentSessionSheet: '',
|
|
39
|
+
sdkCheckout: '',
|
|
40
|
+
ewallet: 'ewallet',
|
|
41
|
+
biller: 'biller',
|
|
42
|
+
bankAccount: 'bankaccount',
|
|
43
|
+
visaMasterCardPayment: 'visamastercardpayment',
|
|
44
|
+
unionPayCardPayment: 'unionpaycardpayment',
|
|
45
|
+
dqrcPayment: 'dqrcpayment',
|
|
46
|
+
sqrcPayment: 'sqrcpayment',
|
|
47
|
+
rtpNowPayment: 'rtpnowpayment',
|
|
48
|
+
rtpLaterPayment: 'rtplaterpayment',
|
|
49
|
+
tokenization: 'tokenization',
|
|
50
|
+
rtpEwalletPayment: 'rtpewalletpayment',
|
|
51
|
+
bnpl: 'bnpl',
|
|
52
|
+
unknown: ''
|
|
53
|
+
};
|
|
54
|
+
const LABELS = {
|
|
55
|
+
paymentSession: 'Payment Session (WebSDK)',
|
|
56
|
+
paymentSessionSheet: 'Payment Session (Sheet)',
|
|
57
|
+
sdkCheckout: 'My SDK Checkout',
|
|
58
|
+
ewallet: 'Ewallet',
|
|
59
|
+
biller: '1Bill',
|
|
60
|
+
bankAccount: 'Bank Transfer',
|
|
61
|
+
visaMasterCardPayment: 'Credit/Debit',
|
|
62
|
+
unionPayCardPayment: 'UnionPay Card',
|
|
63
|
+
dqrcPayment: 'QR',
|
|
64
|
+
sqrcPayment: 'QR',
|
|
65
|
+
rtpNowPayment: 'RTP',
|
|
66
|
+
rtpLaterPayment: 'RTP Later',
|
|
67
|
+
tokenization: 'Tokenization',
|
|
68
|
+
rtpEwalletPayment: 'RTP Ewallet',
|
|
69
|
+
bnpl: 'Buy Now, Pay Later',
|
|
70
|
+
unknown: 'Other'
|
|
71
|
+
};
|
|
72
|
+
const LOGO_NAMES = {
|
|
73
|
+
paymentSession: [],
|
|
74
|
+
paymentSessionSheet: [],
|
|
75
|
+
sdkCheckout: [],
|
|
76
|
+
ewallet: ['EasyPaisa', 'JazzCash'],
|
|
77
|
+
biller: ['1Bill'],
|
|
78
|
+
bankAccount: ['BankTransfer'],
|
|
79
|
+
visaMasterCardPayment: ['Visa', 'Mastercard', 'PayPak'],
|
|
80
|
+
unionPayCardPayment: ['UnionPay'],
|
|
81
|
+
dqrcPayment: ['QR'],
|
|
82
|
+
sqrcPayment: ['QR'],
|
|
83
|
+
rtpNowPayment: [],
|
|
84
|
+
rtpLaterPayment: [],
|
|
85
|
+
tokenization: [],
|
|
86
|
+
rtpEwalletPayment: ['EasyPaisa', 'JazzCash'],
|
|
87
|
+
bnpl: [],
|
|
88
|
+
unknown: []
|
|
89
|
+
};
|
|
90
|
+
const FROM_API = new Map([['paymentsession', 'paymentSession'], ['ewallet', 'ewallet'], ['biller', 'biller'], ['bankaccount', 'bankAccount'], ['visamastercardpayment', 'visaMasterCardPayment'], ['unionpaycardpayment', 'unionPayCardPayment'], ['dqrcpayment', 'dqrcPayment'], ['sqrcpayment', 'sqrcPayment'], ['rtpnowpayment', 'rtpNowPayment'], ['rtplaterpayment', 'rtpLaterPayment'], ['tokenization', 'tokenization'], ['rtpewalletpayment', 'rtpEwalletPayment'], ['bnpl', 'bnpl']]);
|
|
91
|
+
|
|
92
|
+
/** Parses a raw category id from the API, falling back to `unknown`. Exact match. */
|
|
93
|
+
function paymentCategoryFromApiValue(value) {
|
|
94
|
+
return typeof value === 'string' && FROM_API.get(value) || 'unknown';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The raw category id the API uses; empty for local-only categories. */
|
|
98
|
+
function paymentCategoryCode(category) {
|
|
99
|
+
return API_VALUES[category] ?? '';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Human-readable label for a button. */
|
|
103
|
+
function paymentCategoryLabel(category) {
|
|
104
|
+
return LABELS[category] ?? LABELS.unknown;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** `logos[].name` values that belong to this category. */
|
|
108
|
+
function paymentCategoryLogoNames(category) {
|
|
109
|
+
return LOGO_NAMES[category] ?? [];
|
|
110
|
+
}
|
|
111
|
+
function isPaymentCategory(value) {
|
|
112
|
+
return typeof value === 'string' && Object.prototype.hasOwnProperty.call(LABELS, value);
|
|
113
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.discountRequestToJson = discountRequestToJson;
|
|
7
|
+
exports.isDiscountUsableFor = isDiscountUsableFor;
|
|
8
|
+
exports.parseDiscountResult = parseDiscountResult;
|
|
9
|
+
var _json = require("../utils/json.js");
|
|
10
|
+
/** Request body for `POST /api/Discount/GetDiscount`. */
|
|
11
|
+
|
|
12
|
+
/** Wire body - note the API's own spelling `refrenceValue`. */
|
|
13
|
+
function discountRequestToJson(request) {
|
|
14
|
+
return {
|
|
15
|
+
amount: request.amount,
|
|
16
|
+
refrenceValue: request.referenceValue,
|
|
17
|
+
categoryId: request.categoryId ?? 'Ewallet',
|
|
18
|
+
merchantId: request.merchantId,
|
|
19
|
+
customerTransactionId: request.customerTransactionId,
|
|
20
|
+
ipAddress: request.ipAddress ?? '',
|
|
21
|
+
txnDate: (request.txnDate ?? new Date()).toISOString(),
|
|
22
|
+
discountableAmount: request.discountableAmount ?? request.amount,
|
|
23
|
+
msisdn: request.msisdn
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Response from `POST /api/Discount/GetDiscount`. */
|
|
28
|
+
|
|
29
|
+
function parseDiscountResult(json) {
|
|
30
|
+
return {
|
|
31
|
+
applied: json.applied === true,
|
|
32
|
+
transactionAmount: (0, _json.numOr)(json.transactionAmount, 0),
|
|
33
|
+
discountAmount: (0, _json.numOr)(json.discountAmount, 0),
|
|
34
|
+
finalAmount: (0, _json.numOr)(json.finalAmount, 0),
|
|
35
|
+
campaignMasterId: (0, _json.intOrNull)(json.campaignMasterId),
|
|
36
|
+
campaignDetailId: (0, _json.intOrNull)(json.campaignDetailId),
|
|
37
|
+
merchantId: (0, _json.intOrNull)(json.merchantId),
|
|
38
|
+
customerTransactionId: (0, _json.stringOrNull)(json.customerTransactionId),
|
|
39
|
+
ruleType: (0, _json.stringOrNull)(json.ruleType),
|
|
40
|
+
categoryId: (0, _json.str)(json.categoryId),
|
|
41
|
+
appliedOn: (0, _json.stringOrNull)(json.appliedOn)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Whether `result` is safe to apply against `requestedAmount` - guards against a stale or
|
|
47
|
+
* malformed response producing a zero, negative or amount-increasing total.
|
|
48
|
+
*/
|
|
49
|
+
function isDiscountUsableFor(result, requestedAmount) {
|
|
50
|
+
return result.applied && result.finalAmount > 0 && result.finalAmount <= requestedAmount && result.discountAmount >= 0;
|
|
51
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cancelledResult = cancelledResult;
|
|
7
|
+
exports.createPaymentResult = createPaymentResult;
|
|
8
|
+
exports.failedResult = failedResult;
|
|
9
|
+
exports.resolvePaymentDetails = resolvePaymentDetails;
|
|
10
|
+
var _errors = require("../errors.js");
|
|
11
|
+
/** Order, customer and redirect details for a single payment attempt. */
|
|
12
|
+
|
|
13
|
+
/** `PaymentDetails` with every default applied. */
|
|
14
|
+
|
|
15
|
+
const REQUIRED_STRING_FIELDS = ['orderNumber', 'customerTransactionId', 'billReferenceNo', 'merchantName', 'consumerName', 'currency', 'email', 'msisdn', 'cnic', 'item', 'successRedirectUrl', 'failedRedirectUrl'];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Applies the defaults and checks the required fields at runtime
|
|
19
|
+
* (`required` named parameters), so plain-JavaScript callers get the same contract.
|
|
20
|
+
*/
|
|
21
|
+
function resolvePaymentDetails(details) {
|
|
22
|
+
if (details == null || typeof details !== 'object') {
|
|
23
|
+
throw new _errors.SwichPayValidationException('Payment details are required.');
|
|
24
|
+
}
|
|
25
|
+
for (const field of REQUIRED_STRING_FIELDS) {
|
|
26
|
+
if (typeof details[field] !== 'string') {
|
|
27
|
+
throw new _errors.SwichPayValidationException(`PaymentDetails.${field} is required and must be a string.`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (typeof details.amount !== 'number' || !Number.isFinite(details.amount)) {
|
|
31
|
+
throw new _errors.SwichPayValidationException('PaymentDetails.amount must be a finite number.');
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
...details,
|
|
35
|
+
description: details.description ?? null,
|
|
36
|
+
date: details.date ?? null,
|
|
37
|
+
successRedirectParam: details.successRedirectParam ?? null,
|
|
38
|
+
discountAmount: details.discountAmount ?? 0,
|
|
39
|
+
isRecurringPayment: details.isRecurringPayment ?? false,
|
|
40
|
+
attempts: details.attempts ?? 10,
|
|
41
|
+
expiryMinutes: details.expiryMinutes ?? 10,
|
|
42
|
+
merchantCustomerToken: details.merchantCustomerToken ?? null,
|
|
43
|
+
doCapture: details.doCapture ?? false
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Raw card details - never logged or persisted. */
|
|
48
|
+
|
|
49
|
+
/** Outcome of a payment attempt. */
|
|
50
|
+
|
|
51
|
+
/** Builds a `PaymentResult` with every optional field defaulted. */
|
|
52
|
+
function createPaymentResult(init) {
|
|
53
|
+
return {
|
|
54
|
+
code: null,
|
|
55
|
+
message: null,
|
|
56
|
+
timestamp: null,
|
|
57
|
+
orderId: null,
|
|
58
|
+
redirectUrl: null,
|
|
59
|
+
isRedirectionRequired: false,
|
|
60
|
+
merchantRedirectionUrl: null,
|
|
61
|
+
remainingAttempts: null,
|
|
62
|
+
consumerNumber: null,
|
|
63
|
+
redirectFormFields: null,
|
|
64
|
+
postUrl: null,
|
|
65
|
+
continuation: null,
|
|
66
|
+
ddcCollectionUrl: null,
|
|
67
|
+
vendorTransactionId: null,
|
|
68
|
+
stepUpUrl: null,
|
|
69
|
+
qrString: null,
|
|
70
|
+
otpRequired: false,
|
|
71
|
+
bankTransactionId: null,
|
|
72
|
+
transactionReferenceNo: null,
|
|
73
|
+
retreivalReferenceNo: null,
|
|
74
|
+
retryable: false,
|
|
75
|
+
...init
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The result a checkout resolves with when the user closes it. */
|
|
80
|
+
function cancelledResult() {
|
|
81
|
+
return createPaymentResult({
|
|
82
|
+
isSuccess: false,
|
|
83
|
+
status: 'cancelled',
|
|
84
|
+
message: 'User closed the payment sheet'
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The failure a direct checkout hands back once its transaction id is used up. */
|
|
89
|
+
function failedResult(message) {
|
|
90
|
+
return createPaymentResult({
|
|
91
|
+
isSuccess: false,
|
|
92
|
+
status: 'failed',
|
|
93
|
+
message: message ?? 'Payment failed.'
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.maskedSavedCard = maskedSavedCard;
|
|
7
|
+
exports.maskedSavedWallet = maskedSavedWallet;
|
|
8
|
+
exports.parseDirectBank = parseDirectBank;
|
|
9
|
+
exports.parsePaymentBank = parsePaymentBank;
|
|
10
|
+
exports.parsePaymentChannel = parsePaymentChannel;
|
|
11
|
+
exports.parsePaymentSessionDetails = parsePaymentSessionDetails;
|
|
12
|
+
exports.parsePaymentSessionInquiryResult = parsePaymentSessionInquiryResult;
|
|
13
|
+
exports.parseSavedCard = parseSavedCard;
|
|
14
|
+
exports.parseSavedWallet = parseSavedWallet;
|
|
15
|
+
var _formatters = require("../utils/formatters.js");
|
|
16
|
+
var _json = require("../utils/json.js");
|
|
17
|
+
var _category = require("./category.js");
|
|
18
|
+
/** A wallet channel (e.g. EasyPaisa, JazzCash) enabled for a payment session. */
|
|
19
|
+
|
|
20
|
+
/** A bank enabled for a payment session, scoped per `channelCode` - the same `bankId` can repeat. */
|
|
21
|
+
|
|
22
|
+
/** A wallet account the customer previously saved. `channel` is a `channelId` as a string. */
|
|
23
|
+
|
|
24
|
+
/** A card previously saved via `doCardOnFile: true`. `id` is sent as `savedCardId`. */
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Details of a payment session (`paymentsession/get`'s `data`). Never carries the response's
|
|
28
|
+
* `clientSecret`.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** Result of `GET /gateway/paymentsession/inquire`. */
|
|
32
|
+
|
|
33
|
+
/** A bank from a direct (session-less) flow's bank-list endpoint. */
|
|
34
|
+
|
|
35
|
+
/** `mobileappinit`: enabled categories plus logo URLs keyed by logo name. */
|
|
36
|
+
|
|
37
|
+
function maskedSavedWallet(wallet) {
|
|
38
|
+
return (0, _formatters.maskForDisplay)(wallet.msisdn);
|
|
39
|
+
}
|
|
40
|
+
function maskedSavedCard(card) {
|
|
41
|
+
return (0, _formatters.maskForDisplay)(card.cardNumber);
|
|
42
|
+
}
|
|
43
|
+
function requiredString(json, key, fallback = '') {
|
|
44
|
+
const value = json[key];
|
|
45
|
+
return typeof value === 'string' ? value : fallback;
|
|
46
|
+
}
|
|
47
|
+
function parsePaymentChannel(json) {
|
|
48
|
+
return {
|
|
49
|
+
channelId: (0, _json.intOrNull)(json.channelId) ?? 0,
|
|
50
|
+
channelName: requiredString(json, 'channelName'),
|
|
51
|
+
channelCode: requiredString(json, 'channelCode')
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function parsePaymentBank(json) {
|
|
55
|
+
const bankCode = requiredString(json, 'bankCode');
|
|
56
|
+
return {
|
|
57
|
+
bankId: (0, _json.intOrNull)(json.bankId) ?? 0,
|
|
58
|
+
bankName: requiredString(json, 'bankName'),
|
|
59
|
+
bankCode,
|
|
60
|
+
swichBankCode: (0, _json.stringOrNull)(json.swich_BankCode) ?? bankCode,
|
|
61
|
+
channelId: (0, _json.intOrNull)(json.channelId) ?? 0,
|
|
62
|
+
channelCode: requiredString(json, 'channelCode')
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function parseSavedWallet(json) {
|
|
66
|
+
return {
|
|
67
|
+
id: (0, _json.intOrNull)(json.id) ?? 0,
|
|
68
|
+
msisdn: (0, _json.stringOrNull)(json.msisdn) ?? '',
|
|
69
|
+
channel: (0, _json.stringOrNull)(json.channel) ?? '',
|
|
70
|
+
customerToken: (0, _json.stringOrNull)(json.customerToken) ?? ''
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The id arrives under `savedCardId`, the PAN under `pan`; `id`/`cardNumber` are fallbacks. */
|
|
75
|
+
function parseSavedCard(json) {
|
|
76
|
+
return {
|
|
77
|
+
id: (0, _json.intOrNull)(json.savedCardId) ?? (0, _json.intOrNull)(json.id) ?? 0,
|
|
78
|
+
cardNumber: (0, _json.stringOrNull)(json.pan) ?? (0, _json.stringOrNull)(json.cardNumber) ?? '',
|
|
79
|
+
cardHolderName: (0, _json.stringOrNull)(json.cardHolderName) ?? '',
|
|
80
|
+
expiryDate: (0, _json.stringOrNull)(json.expiryDate) ?? '',
|
|
81
|
+
customerToken: (0, _json.stringOrNull)(json.customerToken) ?? '',
|
|
82
|
+
channel: (0, _json.stringOrNull)(json.channel) ?? ''
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Parses the `data` object of a `paymentsession/get` response. */
|
|
87
|
+
function parsePaymentSessionDetails(json) {
|
|
88
|
+
// Only entries explicitly marked `status: false` are dropped.
|
|
89
|
+
const categoryMaps = (0, _json.listOfMaps)(json.categories).filter(c => c.status !== false);
|
|
90
|
+
const categoryIds = {};
|
|
91
|
+
for (const c of categoryMaps) {
|
|
92
|
+
const id = c.categoryId ?? c.id;
|
|
93
|
+
if (typeof id === 'number' && Number.isInteger(id)) {
|
|
94
|
+
categoryIds[(0, _category.paymentCategoryFromApiValue)(c.categoryCode)] = id;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
paymentSessionGuid: requiredString(json, 'paymentSessionGuid'),
|
|
99
|
+
categories: categoryMaps.map(c => (0, _category.paymentCategoryFromApiValue)(c.categoryCode)),
|
|
100
|
+
categoryIds,
|
|
101
|
+
expiryMinutes: (0, _json.intOrNull)(json.expiry) ?? 15,
|
|
102
|
+
remainingAttempts: (0, _json.intOrNull)(json.remainingAttempts) ?? 3,
|
|
103
|
+
channels: (0, _json.listOfMaps)(json.channels).map(parsePaymentChannel),
|
|
104
|
+
banks: (0, _json.listOfMaps)(json.banks).map(parsePaymentBank),
|
|
105
|
+
savedWallets: (0, _json.listOfMaps)(json.savedWallets).map(parseSavedWallet),
|
|
106
|
+
savedCards: (0, _json.listOfMaps)(json.savedCards).map(parseSavedCard),
|
|
107
|
+
clientId: (0, _json.stringOrNull)(json.clientId)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function parsePaymentSessionInquiryResult(json) {
|
|
111
|
+
const code = (0, _json.normalizedCode)(json.code);
|
|
112
|
+
const status = (0, _json.stringOrNull)(json.status);
|
|
113
|
+
return {
|
|
114
|
+
transactionId: (0, _json.intOrNull)(json.transactionId) ?? 0,
|
|
115
|
+
orderId: (0, _json.stringOrNull)(json.orderId),
|
|
116
|
+
paymentSessionGuid: (0, _json.stringOrNull)(json.paymentSessionGuid),
|
|
117
|
+
status,
|
|
118
|
+
code,
|
|
119
|
+
message: (0, _json.stringOrNull)(json.message),
|
|
120
|
+
timestamp: (0, _json.stringOrNull)(json.timestamp),
|
|
121
|
+
amount: typeof json.amount === 'number' ? json.amount : 0,
|
|
122
|
+
isSuccess: code === '0000' || status?.toLowerCase() === 'success'
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function parseDirectBank(json) {
|
|
126
|
+
return {
|
|
127
|
+
name: (0, _json.stringOrNull)(json.name) ?? '',
|
|
128
|
+
code: (0, _json.stringOrNull)(json.code) ?? '',
|
|
129
|
+
bankProviderCode: (0, _json.stringOrNull)(json.bankProviderCode)
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "classifyInquiry", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _verify.classifyInquiry;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "createCheckoutSessionCreator", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _verify.createCheckoutSessionCreator;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "createNodeProxyMiddleware", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _node.createNodeProxyMiddleware;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "createPaymentVerifier", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _verify.createPaymentVerifier;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "createSwichPayProxy", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _proxy.createSwichPayProxy;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "evaluateInquiry", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _verify.evaluateInquiry;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "fetchClientCredentialsToken", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _apiClient.fetchClientCredentialsToken;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "generateTransactionCheckSum", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _crypto.generateTransactionCheckSum;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "lazyServerClient", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _verify.lazyServerClient;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
var _proxy = require("./proxy.js");
|
|
61
|
+
var _node = require("./node.js");
|
|
62
|
+
var _apiClient = require("../http/api-client.js");
|
|
63
|
+
var _crypto = require("../utils/crypto.js");
|
|
64
|
+
var _verify = require("./verify.js");
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createNodeProxyMiddleware = createNodeProxyMiddleware;
|
|
7
|
+
/** The parts of Node's `IncomingMessage` the adapter uses (no `node:http` import needed). */
|
|
8
|
+
|
|
9
|
+
/** The parts of Node's `ServerResponse` the adapter uses. */
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Adapts a proxy to Node/Express/Connect (`(req, res, next)`), mounted at `basePath`.
|
|
13
|
+
* Requests outside `basePath` go to `next()` when given, else 404.
|
|
14
|
+
*/
|
|
15
|
+
function createNodeProxyMiddleware(proxy, basePath) {
|
|
16
|
+
const base = `/${basePath.replace(/^\/+|\/+$/g, '')}`;
|
|
17
|
+
return async (req, res, next) => {
|
|
18
|
+
const rawUrl = req.url ?? '/';
|
|
19
|
+
const pathname = rawUrl.split('?')[0] ?? '/';
|
|
20
|
+
if (pathname !== base && !pathname.startsWith(`${base}/`)) {
|
|
21
|
+
if (next) return next();
|
|
22
|
+
res.statusCode = 404;
|
|
23
|
+
res.end();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const headers = new Headers();
|
|
28
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
29
|
+
if (typeof value === 'string') headers.set(key, value);else if (Array.isArray(value)) headers.set(key, value.join(', '));
|
|
30
|
+
}
|
|
31
|
+
const method = (req.method ?? 'GET').toUpperCase();
|
|
32
|
+
let body;
|
|
33
|
+
if (method !== 'GET' && method !== 'HEAD') {
|
|
34
|
+
let text = '';
|
|
35
|
+
const decoder = new TextDecoder();
|
|
36
|
+
for await (const chunk of req) text += typeof chunk === 'string' ? chunk : decoder.decode(chunk, {
|
|
37
|
+
stream: true
|
|
38
|
+
});
|
|
39
|
+
body = text + decoder.decode();
|
|
40
|
+
}
|
|
41
|
+
const host = headers.get('host') ?? 'localhost';
|
|
42
|
+
const request = new Request(`http://${host}${rawUrl}`, {
|
|
43
|
+
method,
|
|
44
|
+
headers,
|
|
45
|
+
body
|
|
46
|
+
});
|
|
47
|
+
const response = await proxy(request, pathname.slice(base.length));
|
|
48
|
+
res.statusCode = response.status;
|
|
49
|
+
res.setHeader('content-type', response.headers.get('content-type') ?? 'application/json');
|
|
50
|
+
res.setHeader('cache-control', 'no-store');
|
|
51
|
+
res.end(await response.text());
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (next) return next(error);
|
|
54
|
+
res.statusCode = 500;
|
|
55
|
+
res.end(JSON.stringify({
|
|
56
|
+
message: 'SwichPay proxy error.'
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|