@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,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repository contracts. `SwichPayClient` accepts implementations
|
|
3
|
+
* of these, so tests can replace a whole layer instead of the transport.
|
|
4
|
+
*/
|
|
5
|
+
import type { PaymentCategory } from '../models/category.js';
|
|
6
|
+
import type { DiscountRequest, DiscountResult } from '../models/discount.js';
|
|
7
|
+
import type { CardDetails, PaymentResult, ResolvedPaymentDetails } from '../models/payment.js';
|
|
8
|
+
import type { DirectBank, MobileAppInitResult, PaymentSessionDetails, PaymentSessionInquiryResult } from '../models/session.js';
|
|
9
|
+
import type { ConfirmDirectBankTransferInput, DirectCardPaymentInput, DirectRtpNowPaymentInput } from './direct-payment-api.js';
|
|
10
|
+
import type { ProcessBankAccountPaymentInput, ProcessBillerPaymentInput, ProcessCardPaymentInput, ProcessEwalletPaymentInput, ProcessQrPaymentInput, ProcessRtpNowPaymentInput, SubmitPaymentEnrollmentInput } from './gateway-api.js';
|
|
11
|
+
export interface PaymentsRepository {
|
|
12
|
+
init(sessionToken: string): Promise<void>;
|
|
13
|
+
pay(input: {
|
|
14
|
+
details: ResolvedPaymentDetails;
|
|
15
|
+
card: CardDetails;
|
|
16
|
+
clientId: string;
|
|
17
|
+
merchantId: number;
|
|
18
|
+
sessionToken: string;
|
|
19
|
+
}): Promise<PaymentResult>;
|
|
20
|
+
}
|
|
21
|
+
export interface GatewayRepository {
|
|
22
|
+
mobileAppInit(appId: string): Promise<MobileAppInitResult>;
|
|
23
|
+
createPaymentSession(details: ResolvedPaymentDetails, categories: readonly PaymentCategory[]): Promise<{
|
|
24
|
+
url: string;
|
|
25
|
+
guid: string;
|
|
26
|
+
}>;
|
|
27
|
+
getPaymentSessionDetails(paymentSessionGuid: string): Promise<PaymentSessionDetails>;
|
|
28
|
+
processCardPayment(input: ProcessCardPaymentInput): Promise<PaymentResult>;
|
|
29
|
+
processEwalletPayment(input: ProcessEwalletPaymentInput): Promise<PaymentResult>;
|
|
30
|
+
processBankAccountPayment(input: ProcessBankAccountPaymentInput): Promise<PaymentResult>;
|
|
31
|
+
processBillerPayment(input: ProcessBillerPaymentInput): Promise<PaymentResult>;
|
|
32
|
+
processQrPayment(input: ProcessQrPaymentInput): Promise<PaymentResult>;
|
|
33
|
+
processRtpNowPayment(input: ProcessRtpNowPaymentInput): Promise<PaymentResult>;
|
|
34
|
+
submitPaymentEnrollment(input: SubmitPaymentEnrollmentInput): Promise<PaymentResult>;
|
|
35
|
+
checkCardPaymentStatus(tracker: string, forceTimeout?: boolean): Promise<PaymentResult>;
|
|
36
|
+
cancelSession(paymentSessionGuid: string): Promise<void>;
|
|
37
|
+
inquirePaymentSession(paymentSessionGuid: string): Promise<PaymentSessionInquiryResult>;
|
|
38
|
+
}
|
|
39
|
+
export interface DirectPaymentRepository {
|
|
40
|
+
directEwalletPayment(input: {
|
|
41
|
+
details: ResolvedPaymentDetails;
|
|
42
|
+
channelId: number;
|
|
43
|
+
msisdn: string;
|
|
44
|
+
categoryId?: number;
|
|
45
|
+
}): Promise<PaymentResult>;
|
|
46
|
+
directBankTransfer(input: {
|
|
47
|
+
details: ResolvedPaymentDetails;
|
|
48
|
+
bankCode: string;
|
|
49
|
+
accountNo: string;
|
|
50
|
+
}): Promise<PaymentResult>;
|
|
51
|
+
confirmDirectBankTransfer(input: ConfirmDirectBankTransferInput): Promise<PaymentResult>;
|
|
52
|
+
fetchDirectBankList(): Promise<DirectBank[]>;
|
|
53
|
+
generateDirectOneBill(input: {
|
|
54
|
+
details: ResolvedPaymentDetails;
|
|
55
|
+
ucid?: string;
|
|
56
|
+
bankMnemonic?: string;
|
|
57
|
+
prefix?: string;
|
|
58
|
+
reserved?: string;
|
|
59
|
+
categoryId?: number;
|
|
60
|
+
channelId?: number;
|
|
61
|
+
}): Promise<PaymentResult>;
|
|
62
|
+
checkDirectOneBillStatus(customerTransactionId: string): Promise<PaymentResult>;
|
|
63
|
+
generateDirectQrPayment(details: ResolvedPaymentDetails): Promise<PaymentResult>;
|
|
64
|
+
checkDirectQrStatus(customerTransactionId: string): Promise<PaymentResult>;
|
|
65
|
+
fetchDirectRtpNowBanks(): Promise<DirectBank[]>;
|
|
66
|
+
directRtpNowPayment(input: DirectRtpNowPaymentInput): Promise<PaymentResult>;
|
|
67
|
+
fetchDirectRtpEwalletBanks(): Promise<DirectBank[]>;
|
|
68
|
+
directRtpEwalletPayment(input: {
|
|
69
|
+
details: ResolvedPaymentDetails;
|
|
70
|
+
bankCode: string;
|
|
71
|
+
msisdn?: string;
|
|
72
|
+
iban?: string;
|
|
73
|
+
}): Promise<PaymentResult>;
|
|
74
|
+
directCardPayment(input: DirectCardPaymentInput): Promise<PaymentResult>;
|
|
75
|
+
executeDirectCardTokenizedPayment(input: {
|
|
76
|
+
customerTransactionId: string;
|
|
77
|
+
billReferenceNo: string;
|
|
78
|
+
vendorTransactionId: string;
|
|
79
|
+
sessionId: string;
|
|
80
|
+
}): Promise<PaymentResult>;
|
|
81
|
+
checkDirectCardPaymentStatus(tracker: string): Promise<PaymentResult>;
|
|
82
|
+
}
|
|
83
|
+
export interface DiscountRepository {
|
|
84
|
+
getDiscount(request: DiscountRequest): Promise<DiscountResult>;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=repositories.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const LOGO_ONE_BILL: string;
|
|
2
|
+
export declare const LOGO_EASYPAISA: string;
|
|
3
|
+
export declare const LOGO_JAZZCASH: string;
|
|
4
|
+
export declare const LOGO_MASTERCARD: string;
|
|
5
|
+
export declare const LOGO_PAYPAK: string;
|
|
6
|
+
export declare const LOGO_PCI_DSS: string;
|
|
7
|
+
export declare const LOGO_BANK_TRANSFER: string;
|
|
8
|
+
export declare const LOGO_QR: string;
|
|
9
|
+
export declare const LOGO_RTP: string;
|
|
10
|
+
export declare const LOGO_SWICH: string;
|
|
11
|
+
export declare const LOGO_VISA: string;
|
|
12
|
+
//# sourceMappingURL=method-logos.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const PWA_SWICH_LOGO: string;
|
|
2
|
+
export declare const PWA_CARD_DEFAULT: string;
|
|
3
|
+
export declare const PWA_CARD_VISA: string;
|
|
4
|
+
export declare const PWA_CARD_MASTERCARD: string;
|
|
5
|
+
export declare const PWA_CARD_PAYPAK: string;
|
|
6
|
+
export declare const PWA_PCI_DSS_LOGO: string;
|
|
7
|
+
//# sourceMappingURL=pwa-images.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A unique, DOM-safe id. */
|
|
2
|
+
export declare function uniqueName(prefix: string): string;
|
|
3
|
+
/** A hidden `<form method="post">` targeting `target`, with one hidden input per field. */
|
|
4
|
+
export declare function createPostForm(action: string, fields: Record<string, string>, target: string): HTMLFormElement;
|
|
5
|
+
/** `event.data` as a JSON object when it is one (or a JSON string of one). */
|
|
6
|
+
export declare function messageDataAsObject(data: unknown): Record<string, unknown> | null;
|
|
7
|
+
/** `event.data` serialized as a string (`JSON.stringify(event.data)`). */
|
|
8
|
+
export declare function serializeMessageData(data: unknown): string;
|
|
9
|
+
/** The iframe's current URL when it's same-origin; `null` when the browser hides it. */
|
|
10
|
+
export declare function readFrameUrl(iframe: HTMLIFrameElement): URL | null;
|
|
11
|
+
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type PaymentDetails, type PaymentResult } from '../models/payment.js';
|
|
2
|
+
import { type MountedFrame } from './three-ds.js';
|
|
3
|
+
/**
|
|
4
|
+
* The hosted checkout's outcome for a URL it navigated to, or `null`
|
|
5
|
+
* when it isn't one of the redirect URLs.
|
|
6
|
+
*/
|
|
7
|
+
export declare function hostedCheckoutResultForUrl(url: string, details: Pick<PaymentDetails, 'successRedirectUrl' | 'failedRedirectUrl'>): PaymentResult | null;
|
|
8
|
+
export interface HostedCheckoutFrameOptions {
|
|
9
|
+
url: string;
|
|
10
|
+
details: Pick<PaymentDetails, 'successRedirectUrl' | 'failedRedirectUrl'>;
|
|
11
|
+
onResult: (result: PaymentResult) => void;
|
|
12
|
+
/** The checkout's own Close button (`closewindow`) - resolves `null`. */
|
|
13
|
+
onClose?: () => void;
|
|
14
|
+
onLoadingChange?: (loading: boolean) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Loads SwichPay's hosted checkout in an iframe (SwichPay sends `frame-ancestors *`). The checkout
|
|
18
|
+
* host's result page tells its parent what happened (Swich.CardPayment `_ResponseModal`):
|
|
19
|
+
* `{ command: "redirecttocustomer", url }` after its countdown and `{ command: "closewindow" }`
|
|
20
|
+
* on Close. A `redirecttocustomer` URL matching `successRedirectUrl`/`failedRedirectUrl` resolves
|
|
21
|
+
*; any other URL resolves with the last `TRANSACTION_COMPLETE` status and
|
|
22
|
+
* the URL in `redirectUrl`. Same-origin navigations to the redirect URLs are detected too.
|
|
23
|
+
*/
|
|
24
|
+
export declare function mountHostedCheckout(container: HTMLElement, options: HostedCheckoutFrameOptions): MountedFrame;
|
|
25
|
+
/** Sends the whole page to the hosted checkout; your redirect URLs receive the customer back. */
|
|
26
|
+
export declare function redirectToHostedCheckout(url: string): void;
|
|
27
|
+
//# sourceMappingURL=hosted-checkout.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@swichpay/core/browser` - DOM helpers used by the React and Nuxt components. Nothing here
|
|
3
|
+
* touches `window`/`document` at import time; each function checks for a browser when called.
|
|
4
|
+
*/
|
|
5
|
+
export { copyText } from './clipboard.js';
|
|
6
|
+
export { createPostForm, messageDataAsObject, readFrameUrl, serializeMessageData } from './dom.js';
|
|
7
|
+
export { hostedCheckoutResultForUrl, mountHostedCheckout, redirectToHostedCheckout, type HostedCheckoutFrameOptions, } from './hosted-checkout.js';
|
|
8
|
+
export { downloadQrCode, encodeQr, qrPngBlob, qrSvg, shareQrCode, type QrMatrix } from './qr.js';
|
|
9
|
+
export { mountStepUpChallenge, runDeviceDataCollection, stepUpRequest, TRANSACTION_COMPLETE, type MountedFrame, type StepUpChallengeOptions, } from './three-ds.js';
|
|
10
|
+
export { isBrowser } from '../utils/runtime.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface QrMatrix {
|
|
2
|
+
size: number;
|
|
3
|
+
isDark(row: number, col: number): boolean;
|
|
4
|
+
}
|
|
5
|
+
/** Encodes `text` as a QR matrix (error correction M, automatic version). Pure - SSR-safe. */
|
|
6
|
+
export declare function encodeQr(text: string): QrMatrix;
|
|
7
|
+
/** An SVG string for `text`, scalable to any size. Pure - safe to render on the server. */
|
|
8
|
+
export declare function qrSvg(text: string, options?: {
|
|
9
|
+
margin?: number;
|
|
10
|
+
title?: string;
|
|
11
|
+
}): string;
|
|
12
|
+
/** Rasterizes the QR to a PNG blob (for download/share). Browser only. */
|
|
13
|
+
export declare function qrPngBlob(text: string, pixels?: number): Promise<Blob>;
|
|
14
|
+
/** Saves the QR as a PNG file. */
|
|
15
|
+
export declare function downloadQrCode(text: string, fileName?: string): Promise<void>;
|
|
16
|
+
/** Shares the QR PNG with the Web Share API when it can share files; downloads it otherwise. */
|
|
17
|
+
export declare function shareQrCode(text: string): Promise<'shared' | 'downloaded'>;
|
|
18
|
+
//# sourceMappingURL=qr.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The checkout host's 3-D Secure return page (`CallBack.cshtml` in Swich.CardPayment) posts
|
|
3
|
+
* `{ type: "TRANSACTION_COMPLETE", status }` to `window.parent` once the issuer step is over.
|
|
4
|
+
*/
|
|
5
|
+
export declare const TRANSACTION_COMPLETE = "TRANSACTION_COMPLETE";
|
|
6
|
+
/**
|
|
7
|
+
* Runs Cardinal Cruise device-data-collection invisibly: POSTs `formFields` (the `JWT`) to `url`
|
|
8
|
+
* in a hidden iframe and resolves `true` on its `profile.complete` message, `false` after
|
|
9
|
+
* `timeoutMs`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function runDeviceDataCollection(input: {
|
|
12
|
+
url: string;
|
|
13
|
+
formFields: Record<string, string>;
|
|
14
|
+
timeoutMs: number;
|
|
15
|
+
}): Promise<boolean>;
|
|
16
|
+
export interface StepUpChallengeOptions {
|
|
17
|
+
/** The issuer's step-up URL. */
|
|
18
|
+
url: string;
|
|
19
|
+
/** Cardinal's JWT, POSTed as `JWT`. `null` (e.g. Meezan 3DS2): the URL's own query becomes the body. */
|
|
20
|
+
jwt: string | null;
|
|
21
|
+
/** Called once with the challenge's message (JSON), or `{"type":"redirect","url":...}`. */
|
|
22
|
+
onComplete: (eventData: string) => void;
|
|
23
|
+
/** Matches the URL the challenge returns to (only observable when same-origin). */
|
|
24
|
+
isCompletionUrl?: (url: URL) => boolean;
|
|
25
|
+
onLoadingChange?: (loading: boolean) => void;
|
|
26
|
+
}
|
|
27
|
+
export interface MountedFrame {
|
|
28
|
+
readonly iframe: HTMLIFrameElement;
|
|
29
|
+
destroy(): void;
|
|
30
|
+
}
|
|
31
|
+
/** The form a step-up challenge is POSTed with. */
|
|
32
|
+
export declare function stepUpRequest(url: string, jwt: string | null): {
|
|
33
|
+
action: string;
|
|
34
|
+
fields: Record<string, string>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Shows the issuer's 3-D Secure challenge in an iframe inside `container`. Completes on:
|
|
38
|
+
* - the first `postMessage` from the challenge frame -
|
|
39
|
+
* in practice SwichPay's return page's `{ type: "TRANSACTION_COMPLETE", status }`;
|
|
40
|
+
* - a `TRANSACTION_COMPLETE` message from a SwichPay/JazzCash origin posted by a nested frame;
|
|
41
|
+
* - a navigation to a completion URL we can read (same-origin only - browsers hide others).
|
|
42
|
+
* UIs also offer a manual "I've completed verification" action as a last resort.
|
|
43
|
+
*/
|
|
44
|
+
export declare function mountStepUpChallenge(container: HTMLElement, options: StepUpChallengeOptions): MountedFrame;
|
|
45
|
+
//# sourceMappingURL=three-ds.d.ts.map
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { type ConfirmDirectBankTransferInput } from './api/direct-payment-api.js';
|
|
2
|
+
import { type ProcessBankAccountPaymentInput, type ProcessBillerPaymentInput, type ProcessCardPaymentInput, type ProcessEwalletPaymentInput, type ProcessQrPaymentInput, type ProcessRtpNowPaymentInput, type SubmitPaymentEnrollmentInput } from './api/gateway-api.js';
|
|
3
|
+
import type { DirectPaymentRepository, DiscountRepository, GatewayRepository, PaymentsRepository } from './api/repositories.js';
|
|
4
|
+
import { type SwichPayConfig, type SwichPayOptions } from './config.js';
|
|
5
|
+
import { type Subscription } from './events.js';
|
|
6
|
+
import type { PaymentCategory } from './models/category.js';
|
|
7
|
+
import type { DiscountResult } from './models/discount.js';
|
|
8
|
+
import { type CardDetails, type PaymentDetails, type PaymentResult } from './models/payment.js';
|
|
9
|
+
import type { DirectBank, MobileAppInitResult, PaymentSessionDetails, PaymentSessionInquiryResult } from './models/session.js';
|
|
10
|
+
export interface SwichPayClientDependencies {
|
|
11
|
+
gatewayApi?: GatewayRepository;
|
|
12
|
+
paymentsApi?: PaymentsRepository;
|
|
13
|
+
directPaymentApi?: DirectPaymentRepository;
|
|
14
|
+
discountApi?: DiscountRepository;
|
|
15
|
+
}
|
|
16
|
+
/** Throws SwichPay's card validation errors. */
|
|
17
|
+
export declare function validateCard(card: CardDetails): void;
|
|
18
|
+
/**
|
|
19
|
+
* One live SDK session: config, API layers and the result stream behind `onResult`.
|
|
20
|
+
* Every completed payment attempt is emitted to that stream.
|
|
21
|
+
*/
|
|
22
|
+
export declare class SwichPayClient {
|
|
23
|
+
readonly config: SwichPayConfig;
|
|
24
|
+
private readonly gateway;
|
|
25
|
+
private readonly payments;
|
|
26
|
+
private readonly direct;
|
|
27
|
+
private readonly discount;
|
|
28
|
+
private readonly results;
|
|
29
|
+
private disposed;
|
|
30
|
+
constructor(options: SwichPayOptions, deps?: SwichPayClientDependencies);
|
|
31
|
+
get isDisposed(): boolean;
|
|
32
|
+
/** Listens for every payment result. */
|
|
33
|
+
onResult(listener: (result: PaymentResult) => void): Subscription;
|
|
34
|
+
private emit;
|
|
35
|
+
pay(input: {
|
|
36
|
+
details: PaymentDetails;
|
|
37
|
+
card: CardDetails;
|
|
38
|
+
}): Promise<PaymentResult>;
|
|
39
|
+
/** Runs `/init` and returns `clientId`, the token that authenticates it. */
|
|
40
|
+
startSession(): Promise<string>;
|
|
41
|
+
payWithSession(input: {
|
|
42
|
+
sessionToken: string;
|
|
43
|
+
details: PaymentDetails;
|
|
44
|
+
card: CardDetails;
|
|
45
|
+
}): Promise<PaymentResult>;
|
|
46
|
+
/** Categories and logos enabled for this merchant; fetched fresh each time. */
|
|
47
|
+
loadMobileAppInit(): Promise<MobileAppInitResult>;
|
|
48
|
+
availableCategories(): Promise<PaymentCategory[]>;
|
|
49
|
+
/**
|
|
50
|
+
* URL of SwichPay's hosted checkout page. The session always gets every enabled category
|
|
51
|
+
* (matches native); `categories` exists for API symmetry only.
|
|
52
|
+
*/
|
|
53
|
+
createHostedCheckoutUrl(input: {
|
|
54
|
+
details: PaymentDetails;
|
|
55
|
+
categories?: readonly PaymentCategory[] | null;
|
|
56
|
+
}): Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a session and fetches its details. `categories` only restricts what the returned
|
|
59
|
+
* details list (what a sheet displays), not what the session supports.
|
|
60
|
+
*/
|
|
61
|
+
startNativeCheckout(input: {
|
|
62
|
+
details: PaymentDetails;
|
|
63
|
+
categories?: readonly PaymentCategory[] | null;
|
|
64
|
+
}): Promise<PaymentSessionDetails>;
|
|
65
|
+
processCardPayment(input: ProcessCardPaymentInput): Promise<PaymentResult>;
|
|
66
|
+
/**
|
|
67
|
+
* Discount quote for a card payment (new card entry only - never for a saved card). Never
|
|
68
|
+
* emits. `ipAddress` defaults to `''` - a browser can't read the device IP.
|
|
69
|
+
*/
|
|
70
|
+
getCardDiscount(input: {
|
|
71
|
+
details: PaymentDetails;
|
|
72
|
+
cardNumber: string;
|
|
73
|
+
categoryId?: string;
|
|
74
|
+
ipAddress?: string | null;
|
|
75
|
+
}): Promise<DiscountResult>;
|
|
76
|
+
processEwalletPayment(input: ProcessEwalletPaymentInput): Promise<PaymentResult>;
|
|
77
|
+
/**
|
|
78
|
+
* Discount quote for an e-wallet payment; `channelId` is the wallet's channel (8 EasyPaisa,
|
|
79
|
+
* 10 JazzCash). Never emits. `ipAddress` defaults to `"127.0.0.1"`
|
|
80
|
+
*/
|
|
81
|
+
getEwalletDiscount(input: {
|
|
82
|
+
details: PaymentDetails;
|
|
83
|
+
msisdn: string;
|
|
84
|
+
channelId: number;
|
|
85
|
+
categoryId?: string;
|
|
86
|
+
ipAddress?: string | null;
|
|
87
|
+
}): Promise<DiscountResult>;
|
|
88
|
+
/** If the result has `otpRequired`, call again with `otp`. */
|
|
89
|
+
processBankAccountPayment(input: ProcessBankAccountPaymentInput): Promise<PaymentResult>;
|
|
90
|
+
/** Called twice: first with `msisdn` for the consumer number, then with `consumerNumber` to verify. */
|
|
91
|
+
processBillerPayment(input: ProcessBillerPaymentInput): Promise<PaymentResult>;
|
|
92
|
+
submitPaymentEnrollment(input: SubmitPaymentEnrollmentInput): Promise<PaymentResult>;
|
|
93
|
+
/**
|
|
94
|
+
* `tracker` is ProcessPayment's `vendorTransactionId`. With `orderId` and a payment-api host,
|
|
95
|
+
* asks `InquireV3` instead (resolves session card payments by `orderId`).
|
|
96
|
+
*/
|
|
97
|
+
checkCardPaymentStatus(input: {
|
|
98
|
+
tracker: string;
|
|
99
|
+
orderId?: string | null;
|
|
100
|
+
forceTimeout?: boolean;
|
|
101
|
+
}): Promise<PaymentResult>;
|
|
102
|
+
processQrPayment(input: ProcessQrPaymentInput): Promise<PaymentResult>;
|
|
103
|
+
processRtpNowPayment(input: ProcessRtpNowPaymentInput): Promise<PaymentResult>;
|
|
104
|
+
/** For when the user explicitly closes/cancels a payment sheet. */
|
|
105
|
+
cancelSession(input: {
|
|
106
|
+
paymentSessionGuid: string;
|
|
107
|
+
}): Promise<void>;
|
|
108
|
+
inquirePaymentSession(input: {
|
|
109
|
+
paymentSessionGuid: string;
|
|
110
|
+
}): Promise<PaymentSessionInquiryResult>;
|
|
111
|
+
directEwalletPayment(input: {
|
|
112
|
+
details: PaymentDetails;
|
|
113
|
+
channelId: number;
|
|
114
|
+
msisdn: string;
|
|
115
|
+
}): Promise<PaymentResult>;
|
|
116
|
+
/** Step 1 of a bank transfer; if `otpRequired`, call `confirmDirectBankTransfer`. Never emits. */
|
|
117
|
+
directBankTransfer(input: {
|
|
118
|
+
details: PaymentDetails;
|
|
119
|
+
bankCode: string;
|
|
120
|
+
accountNo: string;
|
|
121
|
+
}): Promise<PaymentResult>;
|
|
122
|
+
confirmDirectBankTransfer(input: ConfirmDirectBankTransferInput): Promise<PaymentResult>;
|
|
123
|
+
fetchDirectBankList(): Promise<DirectBank[]>;
|
|
124
|
+
/** The result's `consumerNumber` is what the customer pays against. Never emits. */
|
|
125
|
+
generateDirectOneBill(input: {
|
|
126
|
+
details: PaymentDetails;
|
|
127
|
+
}): Promise<PaymentResult>;
|
|
128
|
+
/** Emits on success only. */
|
|
129
|
+
checkDirectOneBillStatus(input: {
|
|
130
|
+
customerTransactionId: string;
|
|
131
|
+
}): Promise<PaymentResult>;
|
|
132
|
+
/** The result's `qrString` is the payload to render. Never emits. */
|
|
133
|
+
generateDirectQrPayment(input: {
|
|
134
|
+
details: PaymentDetails;
|
|
135
|
+
}): Promise<PaymentResult>;
|
|
136
|
+
/** Emits on success only. */
|
|
137
|
+
checkDirectQrStatus(input: {
|
|
138
|
+
customerTransactionId: string;
|
|
139
|
+
}): Promise<PaymentResult>;
|
|
140
|
+
fetchDirectRtpNowBanks(): Promise<DirectBank[]>;
|
|
141
|
+
directRtpNowPayment(input: {
|
|
142
|
+
details: PaymentDetails;
|
|
143
|
+
msisdn: string;
|
|
144
|
+
rtpId: string;
|
|
145
|
+
bankCode?: string | null;
|
|
146
|
+
accountTitle?: string | null;
|
|
147
|
+
accountNumber?: string | null;
|
|
148
|
+
accountNumberAlias?: string | null;
|
|
149
|
+
}): Promise<PaymentResult>;
|
|
150
|
+
fetchDirectRtpEwalletBanks(): Promise<DirectBank[]>;
|
|
151
|
+
directRtpEwalletPayment(input: {
|
|
152
|
+
details: PaymentDetails;
|
|
153
|
+
bankCode: string;
|
|
154
|
+
msisdn?: string;
|
|
155
|
+
iban?: string;
|
|
156
|
+
}): Promise<PaymentResult>;
|
|
157
|
+
/**
|
|
158
|
+
* Submits a direct card payment. Needs a checksum source: `secretHashKey`, `getChecksum`, or a
|
|
159
|
+
* proxy (which signs server-side). Emits unless a device-data-collection step follows.
|
|
160
|
+
*/
|
|
161
|
+
directCardPayment(input: {
|
|
162
|
+
details: PaymentDetails;
|
|
163
|
+
card: CardDetails;
|
|
164
|
+
doCardOnFile?: boolean;
|
|
165
|
+
}): Promise<PaymentResult>;
|
|
166
|
+
private checksumFor;
|
|
167
|
+
/** Completes a direct card payment after device-data-collection. Emits unless a step-up follows. */
|
|
168
|
+
executeDirectCardTokenizedPayment(input: {
|
|
169
|
+
customerTransactionId: string;
|
|
170
|
+
billReferenceNo: string;
|
|
171
|
+
tracker: string;
|
|
172
|
+
sessionId: string;
|
|
173
|
+
}): Promise<PaymentResult>;
|
|
174
|
+
/** `tracker` is `vendorTransactionId` from `directCardPayment`. Emits unless still pending. */
|
|
175
|
+
checkDirectCardPaymentStatus(input: {
|
|
176
|
+
tracker: string;
|
|
177
|
+
}): Promise<PaymentResult>;
|
|
178
|
+
/** Stops result delivery and drops every listener. */
|
|
179
|
+
dispose(): void;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type Environment, type SwichPayHosts } from './environment.js';
|
|
2
|
+
import { type SwichPayLogger } from './utils/log.js';
|
|
3
|
+
/** An access token returned by a merchant-hosted token endpoint. */
|
|
4
|
+
export interface AccessToken {
|
|
5
|
+
accessToken: string;
|
|
6
|
+
/** Seconds until expiry. Defaults to 3600, like the OAuth response. */
|
|
7
|
+
expiresIn?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ChecksumInput {
|
|
10
|
+
currency: string;
|
|
11
|
+
amount: number;
|
|
12
|
+
customerTransactionId: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Options for `SwichPay.initialize()` / `new SwichPayClient()`.
|
|
16
|
+
*
|
|
17
|
+
* The first six are the standard SwichPay merchant settings. The rest are optional,
|
|
18
|
+
* because a browser can't keep a secret and SwichPay's hosts don't send CORS headers to
|
|
19
|
+
* arbitrary origins - see docs/authentication.md.
|
|
20
|
+
*/
|
|
21
|
+
export interface SwichPayOptions {
|
|
22
|
+
/** Public client id from your SwichPay dashboard. */
|
|
23
|
+
clientId: string;
|
|
24
|
+
/** Must match what SwichPay has registered (sent as `Referer` on checkout-host calls). */
|
|
25
|
+
referrer: string;
|
|
26
|
+
merchantId: number;
|
|
27
|
+
/** Your app identifier as registered with SwichPay. */
|
|
28
|
+
appId: string;
|
|
29
|
+
environment: Environment;
|
|
30
|
+
/** Replaces the checkout host (`/init`, `/iframe/Payment`), e.g. for a local backend. */
|
|
31
|
+
baseUrlOverride?: string;
|
|
32
|
+
/** Replaces any other host. Takes precedence over `proxyUrl`. */
|
|
33
|
+
hosts?: Partial<SwichPayHosts>;
|
|
34
|
+
/**
|
|
35
|
+
* OAuth2 `client_credentials` secret. Safe on a server. In a browser it is readable by
|
|
36
|
+
* anyone, so it's refused unless `dangerouslyAllowBrowserSecrets` is set - prefer `proxyUrl`.
|
|
37
|
+
*/
|
|
38
|
+
clientSecret?: string;
|
|
39
|
+
/** HMAC key for the direct card payment checksum. A different secret than `clientSecret`. */
|
|
40
|
+
secretHashKey?: string;
|
|
41
|
+
/** Allows `clientSecret` / `secretHashKey` in a browser or React Native app. Only for local testing. */
|
|
42
|
+
dangerouslyAllowBrowserSecrets?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Base URL of a server proxy created with `createSwichPayProxy` (`@swichpay/core/server`).
|
|
45
|
+
* Every call goes through it; the proxy adds authentication, the `Referer` header and the
|
|
46
|
+
* card checksum, so no secret is needed in the browser. Recommended for web apps.
|
|
47
|
+
*/
|
|
48
|
+
proxyUrl?: string;
|
|
49
|
+
/** Returns a bearer token from your own backend (alternative to `clientSecret`). */
|
|
50
|
+
getAccessToken?: () => Promise<AccessToken | string>;
|
|
51
|
+
/** Returns the direct card checksum from your own backend (alternative to `secretHashKey`). */
|
|
52
|
+
getChecksum?: (input: ChecksumInput) => Promise<string>;
|
|
53
|
+
/** Custom `fetch` (tests, polyfills, instrumentation). Defaults to `globalThis.fetch`. */
|
|
54
|
+
fetch?: typeof fetch;
|
|
55
|
+
/** Receives redacted debug lines. The SDK is silent without it. */
|
|
56
|
+
logger?: SwichPayLogger;
|
|
57
|
+
/** Overrides request timeouts in milliseconds. */
|
|
58
|
+
timeouts?: Partial<SwichPayTimeouts>;
|
|
59
|
+
}
|
|
60
|
+
export interface SwichPayTimeouts {
|
|
61
|
+
/** Every call except discount lookups. */
|
|
62
|
+
request: number;
|
|
63
|
+
/** Discount lookups run while the user types. */
|
|
64
|
+
discount: number;
|
|
65
|
+
}
|
|
66
|
+
export declare const DEFAULT_TIMEOUTS: Readonly<SwichPayTimeouts>;
|
|
67
|
+
export type AuthMode = 'proxy' | 'token-provider' | 'client-secret' | 'public-key';
|
|
68
|
+
export interface SwichPayConfig {
|
|
69
|
+
readonly clientId: string;
|
|
70
|
+
readonly referrer: string;
|
|
71
|
+
readonly merchantId: number;
|
|
72
|
+
readonly appId: string;
|
|
73
|
+
readonly environment: Environment;
|
|
74
|
+
readonly hosts: Readonly<SwichPayHosts>;
|
|
75
|
+
readonly clientSecret: string | null;
|
|
76
|
+
readonly secretHashKey: string | null;
|
|
77
|
+
readonly authMode: AuthMode;
|
|
78
|
+
readonly getAccessToken: SwichPayOptions['getAccessToken'] | null;
|
|
79
|
+
readonly getChecksum: SwichPayOptions['getChecksum'] | null;
|
|
80
|
+
readonly fetch: typeof fetch;
|
|
81
|
+
readonly log: SwichPayLogger;
|
|
82
|
+
readonly timeouts: Readonly<SwichPayTimeouts>;
|
|
83
|
+
}
|
|
84
|
+
/** Validates options and resolves hosts, auth mode and defaults. */
|
|
85
|
+
export declare function resolveConfig(options: SwichPayOptions): SwichPayConfig;
|
|
86
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The backend environment a SwichPay client talks to. */
|
|
2
|
+
export type Environment = 'sandbox' | 'production';
|
|
3
|
+
export declare const Environment: {
|
|
4
|
+
readonly sandbox: "sandbox";
|
|
5
|
+
readonly production: "production";
|
|
6
|
+
};
|
|
7
|
+
export interface SwichPayHosts {
|
|
8
|
+
/** `/init` and `/iframe/Payment`. */
|
|
9
|
+
checkout: string;
|
|
10
|
+
/** `/gateway/...` - sessions, process payment, direct `payin` flows, bank lists. */
|
|
11
|
+
gateway: string;
|
|
12
|
+
/** `/connect/token` - OAuth2 `client_credentials`. */
|
|
13
|
+
auth: string;
|
|
14
|
+
/** `/api/Discount/GetDiscount`; `null` where the environment has none. */
|
|
15
|
+
discount: string | null;
|
|
16
|
+
/** `/api/Payment/...` - direct card flow; `null` where the environment has none. */
|
|
17
|
+
paymentApi: string | null;
|
|
18
|
+
}
|
|
19
|
+
/** SwichPay hosts per environment. */
|
|
20
|
+
export declare const ENVIRONMENT_HOSTS: Readonly<Record<Environment, Readonly<SwichPayHosts>>>;
|
|
21
|
+
export declare function isEnvironment(value: unknown): value is Environment;
|
|
22
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error hierarchy - every SDK error is a `SwichPayException`.
|
|
3
|
+
* Every SDK call rejects with one of these instead of a raw fetch/parse error.
|
|
4
|
+
*/
|
|
5
|
+
export type SwichPayErrorKind = 'not_initialized' | 'validation' | 'network' | 'api';
|
|
6
|
+
export declare abstract class SwichPayException extends Error {
|
|
7
|
+
/** Discriminator, handy where `instanceof` is awkward (e.g. across bundles). */
|
|
8
|
+
abstract readonly kind: SwichPayErrorKind;
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
/**
|
|
11
|
+
* Short, non-technical text safe to show to the paying user. `message` is technical detail
|
|
12
|
+
* (URLs, HTTP codes, field names) - log it, never show it.
|
|
13
|
+
*/
|
|
14
|
+
abstract get userMessage(): string;
|
|
15
|
+
toString(): string;
|
|
16
|
+
}
|
|
17
|
+
/** Thrown when a method is called before `SwichPay.initialize()`. */
|
|
18
|
+
export declare class SwichPayNotInitializedException extends SwichPayException {
|
|
19
|
+
readonly kind: "not_initialized";
|
|
20
|
+
constructor();
|
|
21
|
+
get userMessage(): string;
|
|
22
|
+
}
|
|
23
|
+
/** Thrown for malformed input (bad card number, missing fields, etc.) before any network call. */
|
|
24
|
+
export declare class SwichPayValidationException extends SwichPayException {
|
|
25
|
+
readonly kind: "validation";
|
|
26
|
+
get userMessage(): string;
|
|
27
|
+
}
|
|
28
|
+
/** Thrown when the SDK fails to reach the SwichPay API. */
|
|
29
|
+
export declare class SwichPayNetworkException extends SwichPayException {
|
|
30
|
+
readonly kind: "network";
|
|
31
|
+
readonly cause: unknown;
|
|
32
|
+
constructor(message: string, options?: {
|
|
33
|
+
cause?: unknown;
|
|
34
|
+
});
|
|
35
|
+
get userMessage(): string;
|
|
36
|
+
toString(): string;
|
|
37
|
+
}
|
|
38
|
+
export interface SwichPayApiExceptionInit {
|
|
39
|
+
statusCode: number;
|
|
40
|
+
code?: string | null;
|
|
41
|
+
serverMessage?: string | null;
|
|
42
|
+
serverStatus?: string | null;
|
|
43
|
+
orderId?: string | null;
|
|
44
|
+
}
|
|
45
|
+
/** Thrown when the SwichPay API returns an error response. */
|
|
46
|
+
export declare class SwichPayApiException extends SwichPayException {
|
|
47
|
+
readonly kind: "api";
|
|
48
|
+
readonly statusCode: number;
|
|
49
|
+
readonly code: string | null;
|
|
50
|
+
/** The response body's own `message` (e.g. "Invalid OTP."), when the server sent one. */
|
|
51
|
+
readonly serverMessage: string | null;
|
|
52
|
+
/**
|
|
53
|
+
* The response body's own `status` (e.g. `"failed"`, `"pending"`) - a 4xx isn't always a
|
|
54
|
+
* decline: direct card payments answer a vendor-side pending with HTTP 400 + `"pending"`.
|
|
55
|
+
*/
|
|
56
|
+
readonly serverStatus: string | null;
|
|
57
|
+
/** The response body's `orderId`, when the server created an order before erroring. */
|
|
58
|
+
readonly orderId: string | null;
|
|
59
|
+
constructor(message: string, init: SwichPayApiExceptionInit);
|
|
60
|
+
get isPending(): boolean;
|
|
61
|
+
get userMessage(): string;
|
|
62
|
+
toString(): string;
|
|
63
|
+
}
|
|
64
|
+
export declare function isSwichPayException(error: unknown): error is SwichPayException;
|
|
65
|
+
/** `userMessage` for SwichPay errors, a generic fallback for anything else. */
|
|
66
|
+
export declare function swichpayUserMessage(error: unknown): string;
|
|
67
|
+
/**
|
|
68
|
+
* User-facing text for `error`; `fallback` replaces the generic text for errors that aren't a
|
|
69
|
+
* `SwichPayException`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function swichpayUserError(error: unknown, fallback?: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Whether a failed attempt reached the gateway - and so used up the checkout's
|
|
74
|
+
* `customerTransactionId`, which the gateway refuses to see twice. Only a request that never
|
|
75
|
+
* left the device (network) or never got built (validation) is safe to resend.
|
|
76
|
+
*/
|
|
77
|
+
export declare function attemptUsedTransactionId(error: unknown): boolean;
|
|
78
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Returned by `onResult`: call it (or `.cancel()`) to stop listening. */
|
|
2
|
+
export interface Subscription {
|
|
3
|
+
(): void;
|
|
4
|
+
cancel(): void;
|
|
5
|
+
}
|
|
6
|
+
export declare function createSubscription(off: () => void): Subscription;
|
|
7
|
+
/**
|
|
8
|
+
* Minimal broadcast emitter. Like a Dart broadcast `StreamController`, events are delivered
|
|
9
|
+
* asynchronously (next microtask), and a throwing listener never affects the others.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Emitter<T> {
|
|
12
|
+
private readonly listeners;
|
|
13
|
+
private closed;
|
|
14
|
+
get listenerCount(): number;
|
|
15
|
+
on(listener: (value: T) => void): Subscription;
|
|
16
|
+
emit(value: T): void;
|
|
17
|
+
close(): void;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=events.d.ts.map
|