pa-sdk-react-native 0.0.0-stage → 3.0.1
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/LICENSE +21 -0
- package/README.md +280 -2
- package/lib/api.d.ts +88 -0
- package/lib/api.js +163 -0
- package/lib/confirm.d.ts +65 -0
- package/lib/confirm.js +358 -0
- package/lib/errors.d.ts +38 -0
- package/lib/errors.generated.d.ts +13 -0
- package/lib/errors.generated.js +63 -0
- package/lib/errors.js +80 -0
- package/lib/index.d.ts +43 -0
- package/lib/index.js +94 -0
- package/lib/init.d.ts +47 -0
- package/lib/init.js +96 -0
- package/lib/locales.d.ts +36 -0
- package/lib/locales.generated.d.ts +22 -0
- package/lib/locales.generated.js +134 -0
- package/lib/locales.js +100 -0
- package/lib/poll.d.ts +61 -0
- package/lib/poll.js +172 -0
- package/lib/threeDs.d.ts +59 -0
- package/lib/threeDs.js +64 -0
- package/lib/threeDsHost.d.ts +17 -0
- package/lib/threeDsHost.js +159 -0
- package/lib/tokenize.d.ts +22 -0
- package/lib/tokenize.js +50 -0
- package/lib/types.d.ts +127 -0
- package/lib/types.js +16 -0
- package/lib/validator.d.ts +71 -0
- package/lib/validator.js +190 -0
- package/locales/en-US.json +30 -0
- package/locales/ms-MY.json +30 -0
- package/locales/zh-CN.json +30 -0
- package/locales/zh-TW.json +30 -0
- package/native/android/build.gradle +49 -0
- package/native/android/src/main/AndroidManifest.xml +42 -0
- package/native/android/src/main/java/com/pasdk/reactnative/PaSdk3dsActivity.kt +243 -0
- package/native/android/src/main/java/com/pasdk/reactnative/PaSdk3dsModule.kt +110 -0
- package/native/android/src/main/java/com/pasdk/reactnative/PaSdkReactNativePackage.kt +27 -0
- package/native/ios/PaSdk3ds.swift +311 -0
- package/native/ios/PaSdk3dsModule.m +47 -0
- package/pa-sdk-react-native.podspec +23 -0
- package/package.json +47 -4
- package/scripts/generate-errors.js +86 -0
- package/scripts/generate-locales.js +95 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PA SDK React Native — public entry point.
|
|
4
|
+
*
|
|
5
|
+
* Headless card SDK for React Native: the app builds its own
|
|
6
|
+
* card UI; the SDK provides validation, tokenization, confirm with built-in
|
|
7
|
+
* 3DS, save-card and multi-market merchant accounts.
|
|
8
|
+
*
|
|
9
|
+
* Quickstart:
|
|
10
|
+
* import * as PaSdk from 'pa-sdk-react-native';
|
|
11
|
+
*
|
|
12
|
+
* PaSdk.init({
|
|
13
|
+
* environment: 'sandbox',
|
|
14
|
+
* accounts: { HK: 'mt_hk_live_or_sandbox', MY: 'mt_my_...' },
|
|
15
|
+
* defaultAccount: 'HK',
|
|
16
|
+
* locale: 'zh_HK',
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* const result = await PaSdk.confirmWithCard({
|
|
20
|
+
* card: { cardNumber: '4242...', expiryMonth: 12, expiryYear: 29, cvc: '123' },
|
|
21
|
+
* intentToken, clientToken, // from your server only
|
|
22
|
+
* idempotencyKey: myUuid,
|
|
23
|
+
* saveCard: saveChecked,
|
|
24
|
+
* onThreeDsWillPresent: () => hideLoadingOverlay(),
|
|
25
|
+
* });
|
|
26
|
+
* // result.status: 'succeeded' | 'authorized' | 'processing' | 'cancelled' | 'failed'
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.POLL_SLOW_INTERVAL_MS = exports.POLL_SLOW_ATTEMPTS = exports.POLL_FAST_INTERVAL_MS = exports.POLL_FAST_ATTEMPTS = exports.GATEWAY_BASE_URLS = exports.ApiClient = exports.PaSdk3dsHost = exports.setThreeDsPresenter = exports.presentThreeDs = exports.closeThreeDs = exports.canPresentThreeDs = exports.setLocale = exports.resolveBundle = exports.normalizeLocale = exports.getLocaleStrings = exports.getLocale = exports.SUPPORTED_LOCALES = exports.DEFAULT_LOCALE = exports.NotInitializedError = exports.userMessageForCode = exports.isPaError = exports.PaError = exports.DEFAULT_POLLER_OPTIONS = exports.pollUntil = exports.AppStateAwarePoller = exports.AlreadyFinalError = exports.resetConfirmState = exports.cancelIntent = exports.confirmWithCard = exports.confirmWithToken = exports.tokenizeCard = exports.createElementSession = exports.cvcLengthsForBrand = exports.validateExpiry = exports.validateCvc = exports.validateCardNumber = exports.validateCard = exports.sanitizeCardNumber = exports.luhnValid = exports.detectBrand = exports.deinitialize = exports.updateLocale = exports.getSdkOrNull = exports.getSdk = exports.init = void 0;
|
|
30
|
+
// init / lifecycle
|
|
31
|
+
var init_1 = require("./init");
|
|
32
|
+
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_1.init; } });
|
|
33
|
+
Object.defineProperty(exports, "getSdk", { enumerable: true, get: function () { return init_1.getSdk; } });
|
|
34
|
+
Object.defineProperty(exports, "getSdkOrNull", { enumerable: true, get: function () { return init_1.getSdkOrNull; } });
|
|
35
|
+
Object.defineProperty(exports, "updateLocale", { enumerable: true, get: function () { return init_1.updateLocale; } });
|
|
36
|
+
Object.defineProperty(exports, "deinitialize", { enumerable: true, get: function () { return init_1.deinitialize; } });
|
|
37
|
+
// validation
|
|
38
|
+
var validator_1 = require("./validator");
|
|
39
|
+
Object.defineProperty(exports, "detectBrand", { enumerable: true, get: function () { return validator_1.detectBrand; } });
|
|
40
|
+
Object.defineProperty(exports, "luhnValid", { enumerable: true, get: function () { return validator_1.luhnValid; } });
|
|
41
|
+
Object.defineProperty(exports, "sanitizeCardNumber", { enumerable: true, get: function () { return validator_1.sanitizeCardNumber; } });
|
|
42
|
+
Object.defineProperty(exports, "validateCard", { enumerable: true, get: function () { return validator_1.validateCard; } });
|
|
43
|
+
Object.defineProperty(exports, "validateCardNumber", { enumerable: true, get: function () { return validator_1.validateCardNumber; } });
|
|
44
|
+
Object.defineProperty(exports, "validateCvc", { enumerable: true, get: function () { return validator_1.validateCvc; } });
|
|
45
|
+
Object.defineProperty(exports, "validateExpiry", { enumerable: true, get: function () { return validator_1.validateExpiry; } });
|
|
46
|
+
Object.defineProperty(exports, "cvcLengthsForBrand", { enumerable: true, get: function () { return validator_1.cvcLengthsForBrand; } });
|
|
47
|
+
// tokenization
|
|
48
|
+
var tokenize_1 = require("./tokenize");
|
|
49
|
+
Object.defineProperty(exports, "createElementSession", { enumerable: true, get: function () { return tokenize_1.createElementSession; } });
|
|
50
|
+
Object.defineProperty(exports, "tokenizeCard", { enumerable: true, get: function () { return tokenize_1.tokenizeCard; } });
|
|
51
|
+
// confirm — both forms
|
|
52
|
+
var confirm_1 = require("./confirm");
|
|
53
|
+
Object.defineProperty(exports, "confirmWithToken", { enumerable: true, get: function () { return confirm_1.confirmWithToken; } });
|
|
54
|
+
Object.defineProperty(exports, "confirmWithCard", { enumerable: true, get: function () { return confirm_1.confirmWithCard; } });
|
|
55
|
+
Object.defineProperty(exports, "cancelIntent", { enumerable: true, get: function () { return confirm_1.cancelIntent; } });
|
|
56
|
+
Object.defineProperty(exports, "resetConfirmState", { enumerable: true, get: function () { return confirm_1.resetConfirmState; } });
|
|
57
|
+
Object.defineProperty(exports, "AlreadyFinalError", { enumerable: true, get: function () { return confirm_1.AlreadyFinalError; } });
|
|
58
|
+
// polling (exposed for apps that want to drive their own reconciliation UI)
|
|
59
|
+
var poll_1 = require("./poll");
|
|
60
|
+
Object.defineProperty(exports, "AppStateAwarePoller", { enumerable: true, get: function () { return poll_1.AppStateAwarePoller; } });
|
|
61
|
+
Object.defineProperty(exports, "pollUntil", { enumerable: true, get: function () { return poll_1.pollUntil; } });
|
|
62
|
+
Object.defineProperty(exports, "DEFAULT_POLLER_OPTIONS", { enumerable: true, get: function () { return poll_1.DEFAULT_POLLER_OPTIONS; } });
|
|
63
|
+
// errors
|
|
64
|
+
var errors_1 = require("./errors");
|
|
65
|
+
Object.defineProperty(exports, "PaError", { enumerable: true, get: function () { return errors_1.PaError; } });
|
|
66
|
+
Object.defineProperty(exports, "isPaError", { enumerable: true, get: function () { return errors_1.isPaError; } });
|
|
67
|
+
Object.defineProperty(exports, "userMessageForCode", { enumerable: true, get: function () { return errors_1.userMessageForCode; } });
|
|
68
|
+
Object.defineProperty(exports, "NotInitializedError", { enumerable: true, get: function () { return errors_1.NotInitializedError; } });
|
|
69
|
+
// locales
|
|
70
|
+
var locales_1 = require("./locales");
|
|
71
|
+
Object.defineProperty(exports, "DEFAULT_LOCALE", { enumerable: true, get: function () { return locales_1.DEFAULT_LOCALE; } });
|
|
72
|
+
Object.defineProperty(exports, "SUPPORTED_LOCALES", { enumerable: true, get: function () { return locales_1.SUPPORTED_LOCALES; } });
|
|
73
|
+
Object.defineProperty(exports, "getLocale", { enumerable: true, get: function () { return locales_1.getLocale; } });
|
|
74
|
+
Object.defineProperty(exports, "getLocaleStrings", { enumerable: true, get: function () { return locales_1.getLocaleStrings; } });
|
|
75
|
+
Object.defineProperty(exports, "normalizeLocale", { enumerable: true, get: function () { return locales_1.normalizeLocale; } });
|
|
76
|
+
Object.defineProperty(exports, "resolveBundle", { enumerable: true, get: function () { return locales_1.resolveBundle; } });
|
|
77
|
+
Object.defineProperty(exports, "setLocale", { enumerable: true, get: function () { return locales_1.setLocale; } });
|
|
78
|
+
// 3DS bridge + fallback host
|
|
79
|
+
var threeDs_1 = require("./threeDs");
|
|
80
|
+
Object.defineProperty(exports, "canPresentThreeDs", { enumerable: true, get: function () { return threeDs_1.canPresentThreeDs; } });
|
|
81
|
+
Object.defineProperty(exports, "closeThreeDs", { enumerable: true, get: function () { return threeDs_1.closeThreeDs; } });
|
|
82
|
+
Object.defineProperty(exports, "presentThreeDs", { enumerable: true, get: function () { return threeDs_1.presentThreeDs; } });
|
|
83
|
+
Object.defineProperty(exports, "setThreeDsPresenter", { enumerable: true, get: function () { return threeDs_1.setThreeDsPresenter; } });
|
|
84
|
+
var threeDsHost_1 = require("./threeDsHost");
|
|
85
|
+
Object.defineProperty(exports, "PaSdk3dsHost", { enumerable: true, get: function () { return threeDsHost_1.PaSdk3dsHost; } });
|
|
86
|
+
// api client (advanced usage)
|
|
87
|
+
var api_1 = require("./api");
|
|
88
|
+
Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function () { return api_1.ApiClient; } });
|
|
89
|
+
Object.defineProperty(exports, "GATEWAY_BASE_URLS", { enumerable: true, get: function () { return api_1.GATEWAY_BASE_URLS; } });
|
|
90
|
+
var types_1 = require("./types");
|
|
91
|
+
Object.defineProperty(exports, "POLL_FAST_ATTEMPTS", { enumerable: true, get: function () { return types_1.POLL_FAST_ATTEMPTS; } });
|
|
92
|
+
Object.defineProperty(exports, "POLL_FAST_INTERVAL_MS", { enumerable: true, get: function () { return types_1.POLL_FAST_INTERVAL_MS; } });
|
|
93
|
+
Object.defineProperty(exports, "POLL_SLOW_ATTEMPTS", { enumerable: true, get: function () { return types_1.POLL_SLOW_ATTEMPTS; } });
|
|
94
|
+
Object.defineProperty(exports, "POLL_SLOW_INTERVAL_MS", { enumerable: true, get: function () { return types_1.POLL_SLOW_INTERVAL_MS; } });
|
package/lib/init.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK initialisation.
|
|
3
|
+
*
|
|
4
|
+
* One initialisation serves multiple merchant accounts: `accounts` maps a
|
|
5
|
+
* market key (e.g. "HK", "MY", "SG", "TW") to that market's publishable
|
|
6
|
+
* merchantToken. Currency and country are per intent — never per init.
|
|
7
|
+
* Environment is selected once, from the app's build config.
|
|
8
|
+
* No secret key is ever passed here — only publishable tokens.
|
|
9
|
+
*/
|
|
10
|
+
import { ApiClient } from './api';
|
|
11
|
+
import type { Environment, InitOptions } from './types';
|
|
12
|
+
export interface PaAccount {
|
|
13
|
+
market: string;
|
|
14
|
+
merchantToken: string;
|
|
15
|
+
}
|
|
16
|
+
export interface PaSdkInstance {
|
|
17
|
+
environment: Environment;
|
|
18
|
+
accounts: {
|
|
19
|
+
[market: string]: string;
|
|
20
|
+
};
|
|
21
|
+
defaultAccount: string;
|
|
22
|
+
/** Resolve the account for a market (or the default). */
|
|
23
|
+
accountFor(market?: string): PaAccount;
|
|
24
|
+
api: ApiClient;
|
|
25
|
+
/** 3DS return URL config. */
|
|
26
|
+
threeDsReturnUrls?: {
|
|
27
|
+
scheme?: string;
|
|
28
|
+
universalLinkHost?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Initialise the SDK. Call once, early (app start / payment screen mount).
|
|
33
|
+
* Re-initialising replaces the previous configuration (useful for
|
|
34
|
+
* locale changes via destroy-and-re-init).
|
|
35
|
+
*
|
|
36
|
+
* @throws PaError `request_invalid` when options are malformed (never a
|
|
37
|
+
* payment result).
|
|
38
|
+
*/
|
|
39
|
+
export declare function init(options: InitOptions): PaSdkInstance;
|
|
40
|
+
/** The current instance; throws NotInitializedError before init(). */
|
|
41
|
+
export declare function getSdk(): PaSdkInstance;
|
|
42
|
+
/** Like getSdk() but returns null instead of throwing. */
|
|
43
|
+
export declare function getSdkOrNull(): PaSdkInstance | null;
|
|
44
|
+
/** Change the locale at runtime without re-initialising. */
|
|
45
|
+
export declare function updateLocale(locale: string): void;
|
|
46
|
+
/** Drop the current configuration (e.g. logout). */
|
|
47
|
+
export declare function deinitialize(): void;
|
package/lib/init.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SDK initialisation.
|
|
4
|
+
*
|
|
5
|
+
* One initialisation serves multiple merchant accounts: `accounts` maps a
|
|
6
|
+
* market key (e.g. "HK", "MY", "SG", "TW") to that market's publishable
|
|
7
|
+
* merchantToken. Currency and country are per intent — never per init.
|
|
8
|
+
* Environment is selected once, from the app's build config.
|
|
9
|
+
* No secret key is ever passed here — only publishable tokens.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.init = init;
|
|
13
|
+
exports.getSdk = getSdk;
|
|
14
|
+
exports.getSdkOrNull = getSdkOrNull;
|
|
15
|
+
exports.updateLocale = updateLocale;
|
|
16
|
+
exports.deinitialize = deinitialize;
|
|
17
|
+
const api_1 = require("./api");
|
|
18
|
+
const errors_1 = require("./errors");
|
|
19
|
+
const locales_1 = require("./locales");
|
|
20
|
+
let instance = null;
|
|
21
|
+
/**
|
|
22
|
+
* Initialise the SDK. Call once, early (app start / payment screen mount).
|
|
23
|
+
* Re-initialising replaces the previous configuration (useful for
|
|
24
|
+
* locale changes via destroy-and-re-init).
|
|
25
|
+
*
|
|
26
|
+
* @throws PaError `request_invalid` when options are malformed (never a
|
|
27
|
+
* payment result).
|
|
28
|
+
*/
|
|
29
|
+
function init(options) {
|
|
30
|
+
if (!options || (options.environment !== 'production' && options.environment !== 'sandbox')) {
|
|
31
|
+
throw new errors_1.PaError('request_invalid', {
|
|
32
|
+
developerMessage: 'init(): environment must be "production" or "sandbox".',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (!options.accounts || typeof options.accounts !== 'object' || Object.keys(options.accounts).length === 0) {
|
|
36
|
+
throw new errors_1.PaError('request_invalid', {
|
|
37
|
+
developerMessage: 'init(): accounts must contain at least one { market: merchantToken } entry.',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const defaultAccount = options.defaultAccount || Object.keys(options.accounts)[0];
|
|
41
|
+
if (!options.accounts[defaultAccount]) {
|
|
42
|
+
throw new errors_1.PaError('request_invalid', {
|
|
43
|
+
developerMessage: `init(): defaultAccount "${defaultAccount}" is not a key of accounts.`,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
for (const market of Object.keys(options.accounts)) {
|
|
47
|
+
const token = options.accounts[market];
|
|
48
|
+
if (!token || typeof token !== 'string') {
|
|
49
|
+
throw new errors_1.PaError('invalid_publishable_key', {
|
|
50
|
+
developerMessage: `init(): accounts["${market}"] must be a merchant token string.`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (options.locale) {
|
|
55
|
+
(0, locales_1.setLocale)(options.locale); // accepted in any tag form
|
|
56
|
+
}
|
|
57
|
+
instance = {
|
|
58
|
+
environment: options.environment,
|
|
59
|
+
accounts: { ...options.accounts },
|
|
60
|
+
defaultAccount,
|
|
61
|
+
accountFor(market) {
|
|
62
|
+
const key = market || defaultAccount;
|
|
63
|
+
const merchantToken = instance && instance.accounts[key];
|
|
64
|
+
if (!merchantToken) {
|
|
65
|
+
throw new errors_1.PaError('request_invalid', {
|
|
66
|
+
developerMessage: `Unknown market "${key}". Registered markets: ${Object.keys(instance ? instance.accounts : {}).join(', ')}.`,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return { market: key, merchantToken };
|
|
70
|
+
},
|
|
71
|
+
api: new api_1.ApiClient(options.environment, options.origin),
|
|
72
|
+
threeDsReturnUrls: options.threeDsReturnUrls,
|
|
73
|
+
};
|
|
74
|
+
return instance;
|
|
75
|
+
}
|
|
76
|
+
/** The current instance; throws NotInitializedError before init(). */
|
|
77
|
+
function getSdk() {
|
|
78
|
+
if (!instance) {
|
|
79
|
+
throw new errors_1.PaError('internal_error', {
|
|
80
|
+
developerMessage: 'PA SDK is not initialised. Call init() before any other call.',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return instance;
|
|
84
|
+
}
|
|
85
|
+
/** Like getSdk() but returns null instead of throwing. */
|
|
86
|
+
function getSdkOrNull() {
|
|
87
|
+
return instance;
|
|
88
|
+
}
|
|
89
|
+
/** Change the locale at runtime without re-initialising. */
|
|
90
|
+
function updateLocale(locale) {
|
|
91
|
+
(0, locales_1.setLocale)(locale);
|
|
92
|
+
}
|
|
93
|
+
/** Drop the current configuration (e.g. logout). */
|
|
94
|
+
function deinitialize() {
|
|
95
|
+
instance = null;
|
|
96
|
+
}
|
package/lib/locales.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale resolution.
|
|
3
|
+
*
|
|
4
|
+
* - tags accepted in underscore or hyphen form, case-insensitively
|
|
5
|
+
* (`zh_HK`, `zh-HK`, `zh-hk`).
|
|
6
|
+
* - locale can be changed at runtime via setLocale() without reload.
|
|
7
|
+
* - unsupported / unknown locale never errors — fallback chain
|
|
8
|
+
* exact tag -> same language -> en-US.
|
|
9
|
+
* - zh_HK maps to zh-TW strings.
|
|
10
|
+
* - ms-MY (my_MY) ships incomplete and falls back to en-US per its _meta.
|
|
11
|
+
*/
|
|
12
|
+
import { type LocaleBundle, type LocaleKey, type LocaleMeta } from './locales.generated';
|
|
13
|
+
export type { LocaleBundle, LocaleKey, LocaleMeta };
|
|
14
|
+
export declare const DEFAULT_LOCALE = "en-US";
|
|
15
|
+
/** Canonical locales shipped in this SDK. */
|
|
16
|
+
export declare const SUPPORTED_LOCALES: readonly ["en-US", "zh-TW", "zh-CN", "ms-MY"];
|
|
17
|
+
export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number];
|
|
18
|
+
/** Normalize any accepted tag form; returns null when unknown (never throws). */
|
|
19
|
+
export declare function normalizeLocale(tag: string | null | undefined): SupportedLocale | null;
|
|
20
|
+
/** The bundle for a tag with the fallback chain applied: exact tag ->
|
|
21
|
+
* same language -> en-US. Unknown tags fall back to en-US silently.
|
|
22
|
+
* Incomplete bundles (ms-MY today) keep their non-empty strings and take the
|
|
23
|
+
* rest from the fallback, so no empty string ever reaches the UI. */
|
|
24
|
+
export declare function resolveBundle(tag: string | null | undefined): {
|
|
25
|
+
locale: SupportedLocale;
|
|
26
|
+
bundle: LocaleBundle;
|
|
27
|
+
};
|
|
28
|
+
export interface LocaleStrings {
|
|
29
|
+
t(key: LocaleKey): string;
|
|
30
|
+
locale: SupportedLocale;
|
|
31
|
+
}
|
|
32
|
+
export declare function setLocale(tag: string | null | undefined): void;
|
|
33
|
+
export declare function getLocale(): string;
|
|
34
|
+
/** Localized strings for a tag (or the current runtime locale when omitted).
|
|
35
|
+
* Falls back along the fallback chain; never throws for unknown tags. */
|
|
36
|
+
export declare function getLocaleStrings(tag?: string | null): LocaleStrings;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GENERATED FILE — do not edit by hand.
|
|
3
|
+
* Generated by scripts/generate-locales.js from locales/*.json.
|
|
4
|
+
*
|
|
5
|
+
* Locale coverage: en-US (complete), zh-TW (complete,
|
|
6
|
+
* serves zh_HK/zh-HK), zh-CN (complete), ms-MY (my_MY — complete,
|
|
7
|
+
* falls back to en-US at runtime until translations are supplied).
|
|
8
|
+
*/
|
|
9
|
+
export interface LocaleMeta {
|
|
10
|
+
name: string;
|
|
11
|
+
canonical: string;
|
|
12
|
+
fallback: string | null;
|
|
13
|
+
complete: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type LocaleKey = 'threeds.title' | 'threeds.cancel' | 'threeds.close' | 'threeds.processing' | 'threeds.redirecting' | 'payment.processing' | 'result.cancelled' | 'error.generic' | 'error.rate_limited' | 'error.processing_timeout' | 'error.sdk_load_failed' | 'error.invalid_publishable_key' | 'error.invalid_client_token' | 'error.origin_not_allowed' | 'error.font_load_failed' | 'field.incomplete_number' | 'field.invalid_number' | 'field.incomplete_expiry' | 'field.invalid_expiry' | 'field.incomplete_cvc' | 'field.invalid_cvc' | 'field.unsupported_brand';
|
|
16
|
+
export interface LocaleBundle {
|
|
17
|
+
_meta: LocaleMeta;
|
|
18
|
+
[key: string]: string | LocaleMeta;
|
|
19
|
+
}
|
|
20
|
+
export declare const LOCALE_BUNDLES: {
|
|
21
|
+
readonly [locale: string]: LocaleBundle;
|
|
22
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* GENERATED FILE — do not edit by hand.
|
|
5
|
+
* Generated by scripts/generate-locales.js from locales/*.json.
|
|
6
|
+
*
|
|
7
|
+
* Locale coverage: en-US (complete), zh-TW (complete,
|
|
8
|
+
* serves zh_HK/zh-HK), zh-CN (complete), ms-MY (my_MY — complete,
|
|
9
|
+
* falls back to en-US at runtime until translations are supplied).
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LOCALE_BUNDLES = void 0;
|
|
13
|
+
exports.LOCALE_BUNDLES = {
|
|
14
|
+
"en-US": {
|
|
15
|
+
"_meta": {
|
|
16
|
+
"name": "English",
|
|
17
|
+
"canonical": "en-US",
|
|
18
|
+
"fallback": null,
|
|
19
|
+
"complete": true
|
|
20
|
+
},
|
|
21
|
+
"threeds.title": "Secure Authentication",
|
|
22
|
+
"threeds.cancel": "Cancel",
|
|
23
|
+
"threeds.close": "Close",
|
|
24
|
+
"threeds.processing": "Processing, please wait...",
|
|
25
|
+
"threeds.redirecting": "Redirecting...",
|
|
26
|
+
"payment.processing": "Payment in progress...",
|
|
27
|
+
"result.cancelled": "Payment cancelled",
|
|
28
|
+
"error.generic": "Payment failed, please try again or use another card.",
|
|
29
|
+
"error.rate_limited": "Too many attempts, please wait a moment and try again.",
|
|
30
|
+
"error.processing_timeout": "Your payment is still being processed. We will confirm the result shortly.",
|
|
31
|
+
"error.sdk_load_failed": "Failed to load the payment component, please refresh the page.",
|
|
32
|
+
"error.invalid_publishable_key": "The merchant configuration is invalid.",
|
|
33
|
+
"error.invalid_client_token": "The payment session has expired. Please try again.",
|
|
34
|
+
"error.origin_not_allowed": "This website is not authorised to use the payment component.",
|
|
35
|
+
"error.font_load_failed": "Font failed to load, a system font is used instead.",
|
|
36
|
+
"field.incomplete_number": "Enter your full card number",
|
|
37
|
+
"field.invalid_number": "Check your card number",
|
|
38
|
+
"field.incomplete_expiry": "Enter the full expiry date",
|
|
39
|
+
"field.invalid_expiry": "Check the expiry date",
|
|
40
|
+
"field.incomplete_cvc": "Enter the security code",
|
|
41
|
+
"field.invalid_cvc": "Check the security code",
|
|
42
|
+
"field.unsupported_brand": "This card type is not accepted"
|
|
43
|
+
},
|
|
44
|
+
"ms-MY": {
|
|
45
|
+
"_meta": {
|
|
46
|
+
"name": "Bahasa Melayu",
|
|
47
|
+
"canonical": "ms-MY",
|
|
48
|
+
"fallback": "en-US",
|
|
49
|
+
"complete": true
|
|
50
|
+
},
|
|
51
|
+
"threeds.title": "Pengesahan Selamat",
|
|
52
|
+
"threeds.cancel": "Batal",
|
|
53
|
+
"threeds.close": "Tutup",
|
|
54
|
+
"threeds.processing": "Memproses, sila tunggu...",
|
|
55
|
+
"threeds.redirecting": "Mengalihkan...",
|
|
56
|
+
"payment.processing": "Pembayaran sedang diproses...",
|
|
57
|
+
"result.cancelled": "Pembayaran dibatalkan",
|
|
58
|
+
"error.generic": "Pembayaran gagal, sila cuba lagi atau gunakan kad lain.",
|
|
59
|
+
"error.rate_limited": "Terlalu banyak percubaan, sila tunggu sebentar dan cuba lagi.",
|
|
60
|
+
"error.processing_timeout": "Pembayaran anda masih diproses. Kami akan mengesahkan keputusan tidak lama lagi.",
|
|
61
|
+
"error.sdk_load_failed": "Komponen pembayaran gagal dimuatkan, sila muat semula halaman.",
|
|
62
|
+
"error.invalid_publishable_key": "Konfigurasi peniaga tidak sah.",
|
|
63
|
+
"error.invalid_client_token": "Sesi pembayaran telah tamat. Sila cuba lagi.",
|
|
64
|
+
"error.origin_not_allowed": "Laman web ini tidak dibenarkan menggunakan komponen pembayaran.",
|
|
65
|
+
"error.font_load_failed": "Fon gagal dimuatkan, fon sistem digunakan sebagai gantian.",
|
|
66
|
+
"field.incomplete_number": "Masukkan nombor kad penuh anda",
|
|
67
|
+
"field.invalid_number": "Semak nombor kad anda",
|
|
68
|
+
"field.incomplete_expiry": "Masukkan tarikh luput penuh",
|
|
69
|
+
"field.invalid_expiry": "Semak tarikh luput",
|
|
70
|
+
"field.incomplete_cvc": "Masukkan kod keselamatan",
|
|
71
|
+
"field.invalid_cvc": "Semak kod keselamatan",
|
|
72
|
+
"field.unsupported_brand": "Jenis kad ini tidak diterima"
|
|
73
|
+
},
|
|
74
|
+
"zh-CN": {
|
|
75
|
+
"_meta": {
|
|
76
|
+
"name": "Simplified Chinese",
|
|
77
|
+
"canonical": "zh-CN",
|
|
78
|
+
"fallback": "en-US",
|
|
79
|
+
"complete": true
|
|
80
|
+
},
|
|
81
|
+
"threeds.title": "安全验证",
|
|
82
|
+
"threeds.cancel": "取消",
|
|
83
|
+
"threeds.close": "关闭",
|
|
84
|
+
"threeds.processing": "处理中,请稍候...",
|
|
85
|
+
"threeds.redirecting": "正在跳转...",
|
|
86
|
+
"payment.processing": "付款处理中...",
|
|
87
|
+
"result.cancelled": "已取消付款",
|
|
88
|
+
"error.generic": "付款失败,请重试或改用其他银行卡。",
|
|
89
|
+
"error.rate_limited": "尝试次数过多,请稍后再试。",
|
|
90
|
+
"error.processing_timeout": "你的付款仍在处理中,结果将稍后确认。",
|
|
91
|
+
"error.sdk_load_failed": "付款组件加载失败,请刷新页面。",
|
|
92
|
+
"error.invalid_publishable_key": "商户设置无效。",
|
|
93
|
+
"error.invalid_client_token": "付款会话已过期,请重试。",
|
|
94
|
+
"error.origin_not_allowed": "此网站未获授权使用付款组件。",
|
|
95
|
+
"error.font_load_failed": "字体加载失败,已改用系统字体。",
|
|
96
|
+
"field.incomplete_number": "请输入完整卡号",
|
|
97
|
+
"field.invalid_number": "请检查卡号",
|
|
98
|
+
"field.incomplete_expiry": "请输入完整有效期",
|
|
99
|
+
"field.invalid_expiry": "请检查有效期",
|
|
100
|
+
"field.incomplete_cvc": "请输入安全码",
|
|
101
|
+
"field.invalid_cvc": "请检查安全码",
|
|
102
|
+
"field.unsupported_brand": "不支持此卡片类型"
|
|
103
|
+
},
|
|
104
|
+
"zh-TW": {
|
|
105
|
+
"_meta": {
|
|
106
|
+
"name": "Traditional Chinese (Hong Kong / Taiwan)",
|
|
107
|
+
"canonical": "zh-TW",
|
|
108
|
+
"fallback": "en-US",
|
|
109
|
+
"complete": true
|
|
110
|
+
},
|
|
111
|
+
"threeds.title": "安全驗證",
|
|
112
|
+
"threeds.cancel": "取消",
|
|
113
|
+
"threeds.close": "關閉",
|
|
114
|
+
"threeds.processing": "處理中,請稍候...",
|
|
115
|
+
"threeds.redirecting": "正在跳轉...",
|
|
116
|
+
"payment.processing": "付款處理中...",
|
|
117
|
+
"result.cancelled": "已取消付款",
|
|
118
|
+
"error.generic": "付款失敗,請重試或改用其他卡片。",
|
|
119
|
+
"error.rate_limited": "嘗試次數過多,請稍候再試。",
|
|
120
|
+
"error.processing_timeout": "你的付款仍在處理中,結果將稍後確認。",
|
|
121
|
+
"error.sdk_load_failed": "付款元件載入失敗,請重新整理頁面。",
|
|
122
|
+
"error.invalid_publishable_key": "商戶設定無效。",
|
|
123
|
+
"error.invalid_client_token": "付款工作階段已過期,請重試。",
|
|
124
|
+
"error.origin_not_allowed": "此網站未獲授權使用付款元件。",
|
|
125
|
+
"error.font_load_failed": "字體載入失敗,已改用系統字體。",
|
|
126
|
+
"field.incomplete_number": "請輸入完整卡號",
|
|
127
|
+
"field.invalid_number": "請檢查卡號",
|
|
128
|
+
"field.incomplete_expiry": "請輸入完整有效期",
|
|
129
|
+
"field.invalid_expiry": "請檢查有效期",
|
|
130
|
+
"field.incomplete_cvc": "請輸入安全碼",
|
|
131
|
+
"field.invalid_cvc": "請檢查安全碼",
|
|
132
|
+
"field.unsupported_brand": "不支援此卡片類型"
|
|
133
|
+
},
|
|
134
|
+
};
|
package/lib/locales.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Locale resolution.
|
|
4
|
+
*
|
|
5
|
+
* - tags accepted in underscore or hyphen form, case-insensitively
|
|
6
|
+
* (`zh_HK`, `zh-HK`, `zh-hk`).
|
|
7
|
+
* - locale can be changed at runtime via setLocale() without reload.
|
|
8
|
+
* - unsupported / unknown locale never errors — fallback chain
|
|
9
|
+
* exact tag -> same language -> en-US.
|
|
10
|
+
* - zh_HK maps to zh-TW strings.
|
|
11
|
+
* - ms-MY (my_MY) ships incomplete and falls back to en-US per its _meta.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.SUPPORTED_LOCALES = exports.DEFAULT_LOCALE = void 0;
|
|
15
|
+
exports.normalizeLocale = normalizeLocale;
|
|
16
|
+
exports.resolveBundle = resolveBundle;
|
|
17
|
+
exports.setLocale = setLocale;
|
|
18
|
+
exports.getLocale = getLocale;
|
|
19
|
+
exports.getLocaleStrings = getLocaleStrings;
|
|
20
|
+
const locales_generated_1 = require("./locales.generated");
|
|
21
|
+
exports.DEFAULT_LOCALE = 'en-US';
|
|
22
|
+
/** Canonical locales shipped in this SDK. */
|
|
23
|
+
exports.SUPPORTED_LOCALES = ['en-US', 'zh-TW', 'zh-CN', 'ms-MY'];
|
|
24
|
+
/** Alias table — normalized (lowercase, hyphen) tag -> canonical locale. */
|
|
25
|
+
const ALIASES = {
|
|
26
|
+
'en': 'en-US',
|
|
27
|
+
'en-us': 'en-US',
|
|
28
|
+
'en-hk': 'en-US',
|
|
29
|
+
'zh': 'zh-TW',
|
|
30
|
+
'zh-tw': 'zh-TW',
|
|
31
|
+
'zh-hk': 'zh-TW', // zh_HK maps to the zh-TW strings
|
|
32
|
+
'zh-cn': 'zh-CN',
|
|
33
|
+
'zh-hans': 'zh-CN',
|
|
34
|
+
'ms': 'ms-MY',
|
|
35
|
+
'ms-my': 'ms-MY',
|
|
36
|
+
'my-my': 'ms-MY', // Malay tag
|
|
37
|
+
};
|
|
38
|
+
/** Normalize any accepted tag form; returns null when unknown (never throws). */
|
|
39
|
+
function normalizeLocale(tag) {
|
|
40
|
+
if (!tag || typeof tag !== 'string') {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const norm = tag.trim().toLowerCase().replace(/_/g, '-');
|
|
44
|
+
const direct = exports.SUPPORTED_LOCALES.find((l) => l.toLowerCase() === norm);
|
|
45
|
+
if (direct) {
|
|
46
|
+
return direct;
|
|
47
|
+
}
|
|
48
|
+
return ALIASES[norm] || null;
|
|
49
|
+
}
|
|
50
|
+
/** The bundle for a tag with the fallback chain applied: exact tag ->
|
|
51
|
+
* same language -> en-US. Unknown tags fall back to en-US silently.
|
|
52
|
+
* Incomplete bundles (ms-MY today) keep their non-empty strings and take the
|
|
53
|
+
* rest from the fallback, so no empty string ever reaches the UI. */
|
|
54
|
+
function resolveBundle(tag) {
|
|
55
|
+
const fallback = locales_generated_1.LOCALE_BUNDLES[exports.DEFAULT_LOCALE];
|
|
56
|
+
const exact = normalizeLocale(tag);
|
|
57
|
+
if (!exact) {
|
|
58
|
+
return { locale: exports.DEFAULT_LOCALE, bundle: fallback };
|
|
59
|
+
}
|
|
60
|
+
const bundle = locales_generated_1.LOCALE_BUNDLES[exact];
|
|
61
|
+
if (!bundle || !bundle._meta) {
|
|
62
|
+
return { locale: exports.DEFAULT_LOCALE, bundle: fallback };
|
|
63
|
+
}
|
|
64
|
+
if (bundle._meta.complete) {
|
|
65
|
+
return { locale: exact, bundle };
|
|
66
|
+
}
|
|
67
|
+
const merged = { ...fallback, _meta: bundle._meta };
|
|
68
|
+
for (const key of Object.keys(bundle)) {
|
|
69
|
+
const value = bundle[key];
|
|
70
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
71
|
+
merged[key] = value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { locale: exact, bundle: merged };
|
|
75
|
+
}
|
|
76
|
+
/** Runtime locale for user messages. Changed via setLocale(). */
|
|
77
|
+
let currentLocale = exports.DEFAULT_LOCALE;
|
|
78
|
+
function setLocale(tag) {
|
|
79
|
+
currentLocale = normalizeLocale(tag) ? String(tag) : tag || exports.DEFAULT_LOCALE;
|
|
80
|
+
}
|
|
81
|
+
function getLocale() {
|
|
82
|
+
return currentLocale;
|
|
83
|
+
}
|
|
84
|
+
/** Localized strings for a tag (or the current runtime locale when omitted).
|
|
85
|
+
* Falls back along the fallback chain; never throws for unknown tags. */
|
|
86
|
+
function getLocaleStrings(tag) {
|
|
87
|
+
const effective = tag == null ? currentLocale : tag;
|
|
88
|
+
const { locale, bundle } = resolveBundle(effective);
|
|
89
|
+
return {
|
|
90
|
+
locale,
|
|
91
|
+
t(key) {
|
|
92
|
+
const value = bundle[key];
|
|
93
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
const fb = locales_generated_1.LOCALE_BUNDLES[exports.DEFAULT_LOCALE][key];
|
|
97
|
+
return typeof fb === 'string' ? fb : '';
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
package/lib/poll.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AppState-aware polling.
|
|
3
|
+
*
|
|
4
|
+
* Schedule: 2s x 15, then 5s x 12. While the app is
|
|
5
|
+
* backgrounded (user switched to a banking app during 3DS, screen off, etc.)
|
|
6
|
+
* the poll timer is suspended and suspended time does NOT consume the
|
|
7
|
+
* budget — the budget is a number of polls, not wall-clock time. On return
|
|
8
|
+
* to the foreground polling resumes where it stopped.
|
|
9
|
+
*
|
|
10
|
+
* On budget exhaustion the poller resolves undefined and the caller maps
|
|
11
|
+
* that to `processing` — never `failed`.
|
|
12
|
+
*/
|
|
13
|
+
export interface PollerOptions {
|
|
14
|
+
fastIntervalMs?: number;
|
|
15
|
+
fastAttempts?: number;
|
|
16
|
+
slowIntervalMs?: number;
|
|
17
|
+
slowAttempts?: number;
|
|
18
|
+
}
|
|
19
|
+
export type PollCheck<T> = {
|
|
20
|
+
done: true;
|
|
21
|
+
value: T;
|
|
22
|
+
} | {
|
|
23
|
+
done: false;
|
|
24
|
+
};
|
|
25
|
+
export declare const DEFAULT_POLLER_OPTIONS: Required<PollerOptions>;
|
|
26
|
+
export declare class AppStateAwarePoller<T> {
|
|
27
|
+
private options;
|
|
28
|
+
private check;
|
|
29
|
+
private timer;
|
|
30
|
+
private appStateSubscription;
|
|
31
|
+
private completed;
|
|
32
|
+
private stopped;
|
|
33
|
+
private inFlight;
|
|
34
|
+
private resolveRun;
|
|
35
|
+
private lastAppState;
|
|
36
|
+
constructor(options?: PollerOptions);
|
|
37
|
+
/** Total polls across the fast and slow phases. */
|
|
38
|
+
get budget(): number;
|
|
39
|
+
/** Polls completed so far in this run. */
|
|
40
|
+
get pollsCompleted(): number;
|
|
41
|
+
/** Interval (ms) for the next poll given the polls completed so far. */
|
|
42
|
+
private nextInterval;
|
|
43
|
+
/**
|
|
44
|
+
* Run `check` on the schedule until it reports done, the budget is
|
|
45
|
+
* exhausted, or stop() is called. Resolves the done value, or undefined
|
|
46
|
+
* when polling ended without a terminal answer (caller -> `processing`).
|
|
47
|
+
*/
|
|
48
|
+
run(check: () => Promise<PollCheck<T>>): Promise<T | undefined>;
|
|
49
|
+
/** Cancel polling; the pending run() resolves undefined immediately. */
|
|
50
|
+
stop(): void;
|
|
51
|
+
private teardown;
|
|
52
|
+
private deliver;
|
|
53
|
+
private handleAppStateChange;
|
|
54
|
+
private scheduleNext;
|
|
55
|
+
private tick;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Convenience wrapper: run a poller until done or budget exhaustion.
|
|
59
|
+
* Resolves the terminal value, or undefined (caller -> `processing`).
|
|
60
|
+
*/
|
|
61
|
+
export declare function pollUntil<T>(check: () => Promise<PollCheck<T>>, options?: PollerOptions): Promise<T | undefined>;
|