pa-sdk-react-native 3.0.1 → 3.0.2
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/README.md +57 -2
- package/lib/api.d.ts +10 -1
- package/lib/api.js +24 -2
- package/lib/confirm.d.ts +14 -1
- package/lib/confirm.js +13 -1
- package/lib/errors.d.ts +4 -2
- package/lib/errors.generated.d.ts +1 -1
- package/lib/errors.generated.js +8 -1
- package/lib/errors.js +8 -15
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/init.js +3 -0
- package/lib/locales.d.ts +14 -4
- package/lib/locales.generated.d.ts +2 -3
- package/lib/locales.generated.js +85 -2
- package/lib/locales.js +53 -5
- package/lib/threeDs.d.ts +11 -0
- package/lib/threeDs.js +22 -0
- package/lib/tokenize.d.ts +5 -0
- package/lib/tokenize.js +2 -0
- package/lib/types.d.ts +8 -0
- package/locales/en-US.json +21 -0
- package/locales/ms-MY.json +21 -0
- package/locales/zh-CN.json +21 -0
- package/locales/zh-TW.json +21 -0
- package/native/ios/PaSdk3ds.swift +59 -16
- package/native/ios/PaSdk3dsModule.m +14 -7
- package/package.json +1 -1
- package/scripts/generate-locales.js +22 -2
package/README.md
CHANGED
|
@@ -172,7 +172,31 @@ Everything is inside confirm:
|
|
|
172
172
|
against the budget, and polling resumes on return. Budget exhausted with
|
|
173
173
|
no answer → `processing`, never `failed`.
|
|
174
174
|
- The challenge's return URLs (configured scheme + universal link) are
|
|
175
|
-
consumed by the SDK
|
|
175
|
+
consumed by the SDK — inside the challenge WebView, at the OS level on
|
|
176
|
+
Android, and via the app-switch hook on iOS (below).
|
|
177
|
+
|
|
178
|
+
#### iOS app-switch returns
|
|
179
|
+
|
|
180
|
+
On iOS a return from a banking app / issuer portal lands in your own link
|
|
181
|
+
handler (`AppDelegate.openURL` / `SceneDelegate.openURLContexts`, or
|
|
182
|
+
`continueUserActivity` for universal links). Call
|
|
183
|
+
`handleReturnUrl(url)` first and ignore the URL when it resolves `true` —
|
|
184
|
+
it matched the pending 3DS challenge and the SDK consumed it:
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
import { handleReturnUrl } from 'pa-sdk-react-native';
|
|
188
|
+
|
|
189
|
+
// AppDelegate / SceneDelegate link handling:
|
|
190
|
+
const consumed = await handleReturnUrl(url);
|
|
191
|
+
if (consumed) {
|
|
192
|
+
return true; // 3DS return — the SDK consumed it; do not route it
|
|
193
|
+
}
|
|
194
|
+
// ... your normal deep-link handling
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
When no challenge is pending (or the URL does not match), it resolves
|
|
198
|
+
`false` and your normal link handling proceeds. Android needs no hook —
|
|
199
|
+
its returns are consumed at the OS level.
|
|
176
200
|
|
|
177
201
|
### Multi-market
|
|
178
202
|
|
|
@@ -186,6 +210,25 @@ import { cancelIntent } from 'pa-sdk-react-native';
|
|
|
186
210
|
await cancelIntent({ intentToken, clientToken }); // -> { status: 'cancelled' }
|
|
187
211
|
```
|
|
188
212
|
|
|
213
|
+
## Sandbox test cards
|
|
214
|
+
|
|
215
|
+
Sandbox only — never real cards. Pass `threeDsAction: 'force'` in the confirm
|
|
216
|
+
options to run an interactive 3DS challenge on any sandbox card.
|
|
217
|
+
|
|
218
|
+
| Scenario | Card number |
|
|
219
|
+
|---|---|
|
|
220
|
+
| Success | 4000 0000 0000 0069 |
|
|
221
|
+
| Insufficient funds | 4000 0000 0000 9995 |
|
|
222
|
+
| Expired card | 4000 0000 0000 0120 |
|
|
223
|
+
| Generic decline | 4111 1111 1111 1111 |
|
|
224
|
+
| 3DS challenge — pass | 4000 0000 0000 3220 |
|
|
225
|
+
| 3DS challenge — fail | 4000 0000 0000 3221 |
|
|
226
|
+
| 3DS challenge — cancel | 4000 0000 0000 3222 |
|
|
227
|
+
| Redirect fallback | 4000 0000 0000 0044 |
|
|
228
|
+
| Delayed / processing | 4000 0000 0000 9976 |
|
|
229
|
+
| Mastercard | 5100 0000 0000 0008 |
|
|
230
|
+
| Mastercard 2-series | 2221 0000 0000 0009 |
|
|
231
|
+
|
|
189
232
|
## Validation helpers
|
|
190
233
|
|
|
191
234
|
```tsx
|
|
@@ -231,9 +274,21 @@ already-final intent returns its stored result.
|
|
|
231
274
|
|
|
232
275
|
`en-US`, `zh-TW` (serves `zh_HK`/`zh-HK`), `zh-CN`, `ms-MY`.
|
|
233
276
|
Accepts underscore/hyphen, case-insensitive (`zh_HK`, `zh-hk`, `ms`). Unknown
|
|
234
|
-
tags fall back along exact tag → same language → `en-US
|
|
277
|
+
tags fall back along exact tag → alias → same primary language → `en-US`
|
|
278
|
+
(zh-SG → `zh-CN`, en-AU → `en-US`, fr-CA → `en-US`), never error.
|
|
235
279
|
Change locale at runtime with `updateLocale('zh_CN')`.
|
|
236
280
|
|
|
281
|
+
Common payment outcomes (`card_declined`, `insufficient_funds`,
|
|
282
|
+
`threeds_failed`, ...) ship localized user messages in all four locales;
|
|
283
|
+
`PaymentResult.userMessage` and `PaError.userMessage` resolve them
|
|
284
|
+
automatically. To override any string for your flow, pass `messages` at
|
|
285
|
+
init — keys are the bundle keys (`'error.card_declined'`,
|
|
286
|
+
`'threeds.title'`, ...), merged over the resolved locale at lookup time:
|
|
287
|
+
|
|
288
|
+
```tsx
|
|
289
|
+
init({ ..., messages: { 'error.card_declined': 'Please try a different card.' } });
|
|
290
|
+
```
|
|
291
|
+
|
|
237
292
|
## Gateway endpoints used
|
|
238
293
|
|
|
239
294
|
All POST JSON under `https://gateway.pa-sys.com/pasdk/v1` (prod) /
|
package/lib/api.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* to PaError with a shared-table code. Transport failures reject
|
|
9
9
|
* with `network_error` / `rate_limited` / `provider_error`.
|
|
10
10
|
*/
|
|
11
|
-
import type { ConfirmGatewayPayload, Environment } from './types';
|
|
11
|
+
import type { ConfirmGatewayPayload, Environment, ThreeDsAction } from './types';
|
|
12
12
|
export declare const GATEWAY_BASE_URLS: {
|
|
13
13
|
[env in Environment]: string;
|
|
14
14
|
};
|
|
@@ -62,6 +62,10 @@ export declare class ApiClient {
|
|
|
62
62
|
expiryYear: number | string;
|
|
63
63
|
cvc: string;
|
|
64
64
|
cardHolderName?: string;
|
|
65
|
+
/** The app's own reference, stored with the token. */
|
|
66
|
+
merchantReference?: string;
|
|
67
|
+
/** Arbitrary key-value data stored with the token; sent as token_metadata. */
|
|
68
|
+
metadata?: Record<string, unknown>;
|
|
65
69
|
}): Promise<TokenizePayload>;
|
|
66
70
|
/** POST /confirm — one confirm per attempt; while status is
|
|
67
71
|
* requires_action / processing the app keeps polling (see poll.ts). */
|
|
@@ -71,6 +75,11 @@ export declare class ApiClient {
|
|
|
71
75
|
paToken?: string;
|
|
72
76
|
idempotencyKey?: string;
|
|
73
77
|
saveCard?: boolean;
|
|
78
|
+
threeDsAction?: ThreeDsAction;
|
|
79
|
+
cardExpiryMonth?: string;
|
|
80
|
+
cardExpiryYear?: string;
|
|
81
|
+
merchantReference?: string;
|
|
82
|
+
metadata?: Record<string, unknown>;
|
|
74
83
|
billing?: Record<string, unknown>;
|
|
75
84
|
}): Promise<ConfirmPayload>;
|
|
76
85
|
/** POST /intent-cancel. */
|
package/lib/api.js
CHANGED
|
@@ -110,14 +110,21 @@ class ApiClient {
|
|
|
110
110
|
}
|
|
111
111
|
/** POST /tokenize — card data goes straight from the app to PA. */
|
|
112
112
|
tokenize(params) {
|
|
113
|
-
|
|
113
|
+
const body = {
|
|
114
114
|
session_token: params.sessionToken,
|
|
115
115
|
card_number: params.cardNumber,
|
|
116
116
|
card_expiry_month: String(params.expiryMonth).padStart(2, '0'),
|
|
117
117
|
card_expiry_year: String(params.expiryYear),
|
|
118
118
|
card_cvv: params.cvc,
|
|
119
119
|
card_holder_name: params.cardHolderName,
|
|
120
|
-
}
|
|
120
|
+
};
|
|
121
|
+
if (params.merchantReference) {
|
|
122
|
+
body.merchant_reference = params.merchantReference;
|
|
123
|
+
}
|
|
124
|
+
if (params.metadata && typeof params.metadata === 'object') {
|
|
125
|
+
body.token_metadata = JSON.stringify(params.metadata);
|
|
126
|
+
}
|
|
127
|
+
return this.post('/tokenize', body);
|
|
121
128
|
}
|
|
122
129
|
/** POST /confirm — one confirm per attempt; while status is
|
|
123
130
|
* requires_action / processing the app keeps polling (see poll.ts). */
|
|
@@ -140,6 +147,21 @@ class ApiClient {
|
|
|
140
147
|
if (params.saveCard != null) {
|
|
141
148
|
body.save_card = params.saveCard;
|
|
142
149
|
}
|
|
150
|
+
if (params.threeDsAction) {
|
|
151
|
+
body.three_ds_action = params.threeDsAction;
|
|
152
|
+
}
|
|
153
|
+
if (params.cardExpiryMonth) {
|
|
154
|
+
body.card_expiry_month = params.cardExpiryMonth;
|
|
155
|
+
}
|
|
156
|
+
if (params.cardExpiryYear) {
|
|
157
|
+
body.card_expiry_year = params.cardExpiryYear;
|
|
158
|
+
}
|
|
159
|
+
if (params.merchantReference) {
|
|
160
|
+
body.merchant_reference = params.merchantReference;
|
|
161
|
+
}
|
|
162
|
+
if (params.metadata && typeof params.metadata === 'object') {
|
|
163
|
+
body.token_metadata = JSON.stringify(params.metadata);
|
|
164
|
+
}
|
|
143
165
|
if (params.billing) {
|
|
144
166
|
body.billing = params.billing; // pass-through
|
|
145
167
|
}
|
package/lib/confirm.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* `processing`, never `failed`.
|
|
14
14
|
*/
|
|
15
15
|
import { PaError } from './errors';
|
|
16
|
-
import type { BillingDetails, CardInput, PaymentResult } from './types';
|
|
16
|
+
import type { BillingDetails, CardInput, PaymentResult, ThreeDsAction } from './types';
|
|
17
17
|
export interface ConfirmBaseOptions {
|
|
18
18
|
intentToken: string;
|
|
19
19
|
clientToken: string;
|
|
@@ -23,6 +23,19 @@ export interface ConfirmBaseOptions {
|
|
|
23
23
|
idempotencyKey?: string;
|
|
24
24
|
/** Save the card during payment. */
|
|
25
25
|
saveCard?: boolean;
|
|
26
|
+
/** three_ds_action — 'force' always runs an interactive 3DS challenge,
|
|
27
|
+
* 'skip' requests no challenge. Unsupported on a route -> 400 with a
|
|
28
|
+
* stable error code (e.g. threeds_action_force_not_supported). */
|
|
29
|
+
threeDsAction?: ThreeDsAction;
|
|
30
|
+
/** Expiry sent in the confirm body (used for SavedCard fingerprinting
|
|
31
|
+
* when saveCard creates the card). confirmWithCard defaults these from
|
|
32
|
+
* the card input. */
|
|
33
|
+
cardExpiryMonth?: string;
|
|
34
|
+
cardExpiryYear?: string;
|
|
35
|
+
/** The app's own order number, echoed back on the result. */
|
|
36
|
+
merchantReference?: string;
|
|
37
|
+
/** Arbitrary key-value data stored with the token; sent as token_metadata. */
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
26
39
|
/** Optional pass-through billing details. */
|
|
27
40
|
billing?: BillingDetails;
|
|
28
41
|
/** Fires immediately before the 3DS challenge appears — dismiss
|
package/lib/confirm.js
CHANGED
|
@@ -257,6 +257,11 @@ async function confirmWithToken(options) {
|
|
|
257
257
|
paToken: options.paToken,
|
|
258
258
|
idempotencyKey: options.idempotencyKey,
|
|
259
259
|
saveCard: options.saveCard,
|
|
260
|
+
threeDsAction: options.threeDsAction,
|
|
261
|
+
cardExpiryMonth: options.cardExpiryMonth,
|
|
262
|
+
cardExpiryYear: options.cardExpiryYear,
|
|
263
|
+
merchantReference: options.merchantReference,
|
|
264
|
+
metadata: options.metadata,
|
|
260
265
|
billing: billingToGateway(options.billing),
|
|
261
266
|
});
|
|
262
267
|
const result = await settle(api, options, payload, options.paToken);
|
|
@@ -273,6 +278,7 @@ async function confirmWithToken(options) {
|
|
|
273
278
|
* Throws the shared field codes before any network call when validation fails.
|
|
274
279
|
*/
|
|
275
280
|
async function confirmWithCard(options) {
|
|
281
|
+
var _a, _b;
|
|
276
282
|
const sdk = (0, init_1.getSdk)();
|
|
277
283
|
const account = sdk.accountFor(options.market);
|
|
278
284
|
const validation = (0, validator_1.validateCard)(options.card, options.allowedBrands);
|
|
@@ -290,6 +296,8 @@ async function confirmWithCard(options) {
|
|
|
290
296
|
const output = await (0, tokenize_1.tokenizeCard)(sdk.api, {
|
|
291
297
|
card: options.card,
|
|
292
298
|
merchantToken: account.merchantToken,
|
|
299
|
+
merchantReference: options.merchantReference,
|
|
300
|
+
metadata: options.metadata,
|
|
293
301
|
});
|
|
294
302
|
tokenized = output.result;
|
|
295
303
|
}
|
|
@@ -297,7 +305,11 @@ async function confirmWithCard(options) {
|
|
|
297
305
|
inFlight.delete(options.intentToken);
|
|
298
306
|
throw error;
|
|
299
307
|
}
|
|
300
|
-
|
|
308
|
+
// The combined flow knows the card expiry — default the confirm body's
|
|
309
|
+
// fingerprinting fields from it when the caller did not override them.
|
|
310
|
+
const expiryMonth = (_a = options.cardExpiryMonth) !== null && _a !== void 0 ? _a : String(options.card.expiryMonth).padStart(2, '0');
|
|
311
|
+
const expiryYear = (_b = options.cardExpiryYear) !== null && _b !== void 0 ? _b : String(options.card.expiryYear);
|
|
312
|
+
return confirmWithToken({ ...options, paToken: tokenized.paToken, cardExpiryMonth: expiryMonth, cardExpiryYear: expiryYear });
|
|
301
313
|
}
|
|
302
314
|
/** Drive a confirm payload to its single final result. */
|
|
303
315
|
async function settle(api, options, payload, paToken) {
|
package/lib/errors.d.ts
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
* Technical failures (network, not initialised, 3DS UI unavailable) reject
|
|
10
10
|
* with a PaError too — they are never reported as payment results.
|
|
11
11
|
*/
|
|
12
|
-
/** Localized user message for a shared-table code.
|
|
13
|
-
*
|
|
12
|
+
/** Localized user message for a shared-table code. Resolves
|
|
13
|
+
* `error.<code>` from the locale bundle (all common payment outcomes ship
|
|
14
|
+
* one), falls back to `field.<code>` for validation codes, then to
|
|
15
|
+
* `error.generic`. */
|
|
14
16
|
export declare function userMessageForCode(code: string, locale?: string | null): string;
|
|
15
17
|
export interface PaErrorOptions {
|
|
16
18
|
/** Override the developer message (e.g. transport detail). */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* GENERATED FILE — do not edit by hand.
|
|
3
3
|
* Generated by scripts/generate-errors.js from: errors.json
|
|
4
|
-
* Table version: 1, generated_at: 2026-
|
|
4
|
+
* Table version: 1, generated_at: 2026-11-24T05:47:16+00:00.
|
|
5
5
|
*
|
|
6
6
|
* One code table shared by the server API, webhooks, the web SDK and this
|
|
7
7
|
* React Native SDK. Values are English developer
|
package/lib/errors.generated.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* GENERATED FILE — do not edit by hand.
|
|
5
5
|
* Generated by scripts/generate-errors.js from: errors.json
|
|
6
|
-
* Table version: 1, generated_at: 2026-
|
|
6
|
+
* Table version: 1, generated_at: 2026-11-24T05:47:16+00:00.
|
|
7
7
|
*
|
|
8
8
|
* One code table shared by the server API, webhooks, the web SDK and this
|
|
9
9
|
* React Native SDK. Values are English developer
|
|
@@ -19,6 +19,7 @@ exports.ERROR_DEVELOPER_MESSAGES = {
|
|
|
19
19
|
"card_declined": "The card was declined. The customer should retry or contact the card-issuing bank.",
|
|
20
20
|
"customer_not_found": "The customer record does not exist.",
|
|
21
21
|
"duplicate_confirm": "A confirm is already in progress or the idempotency key conflicts.",
|
|
22
|
+
"exemption_request_not_supported": "exemption_request is not supported on this acquiring route.",
|
|
22
23
|
"expired_card": "The card has expired.",
|
|
23
24
|
"font_load_failed": "A merchant-supplied font failed to load; a system font is used instead.",
|
|
24
25
|
"frequency_limit": "Transaction frequency limit exceeded. Retry later.",
|
|
@@ -28,6 +29,7 @@ exports.ERROR_DEVELOPER_MESSAGES = {
|
|
|
28
29
|
"insufficient_funds": "The card has insufficient funds.",
|
|
29
30
|
"intent_already_final": "The payment intent is already in a final state.",
|
|
30
31
|
"intent_expired": "The payment intent has expired.",
|
|
32
|
+
"intent_not_awaiting_action": "The intent has not been confirmed yet; there is no 3DS result to continue.",
|
|
31
33
|
"internal_error": "An unexpected internal error occurred.",
|
|
32
34
|
"invalid_card_number": "The card number is invalid.",
|
|
33
35
|
"invalid_client_token": "The client token is invalid or expired.",
|
|
@@ -35,6 +37,7 @@ exports.ERROR_DEVELOPER_MESSAGES = {
|
|
|
35
37
|
"invalid_expiry": "The expiry date is invalid or in the past.",
|
|
36
38
|
"invalid_number": "The card number is invalid.",
|
|
37
39
|
"invalid_publishable_key": "The publishable key is invalid.",
|
|
40
|
+
"invalid_threeds_result": "three_ds_result is invalid: three_ds_version, ds_transaction_id, cavv and eci (02 or 05) are required.",
|
|
38
41
|
"issuer_unavailable": "The card issuer is unavailable. Retry later.",
|
|
39
42
|
"merchant_misconfigured": "The merchant account or channel setup is incomplete. Contact support.",
|
|
40
43
|
"method_not_allowed": "The payment method is not enabled for this merchant account.",
|
|
@@ -44,6 +47,7 @@ exports.ERROR_DEVELOPER_MESSAGES = {
|
|
|
44
47
|
"provider_error": "The payment provider returned an unexpected response.",
|
|
45
48
|
"rate_limited": "Too many requests. Retry later.",
|
|
46
49
|
"refund_exceeds_paid": "The refund amount exceeds the amount still refundable.",
|
|
50
|
+
"refund_failed": "The refund could not be completed. No funds have been moved.",
|
|
47
51
|
"request_invalid": "The request failed validation.",
|
|
48
52
|
"risk_declined": "Blocked by fraud screening.",
|
|
49
53
|
"saved_card_disabled": "The saved card has been disabled.",
|
|
@@ -51,10 +55,13 @@ exports.ERROR_DEVELOPER_MESSAGES = {
|
|
|
51
55
|
"sdk_load_failed": "The payment component failed to load.",
|
|
52
56
|
"session_already_used": "The element session has already been used.",
|
|
53
57
|
"session_expired": "The element session has expired. Re-mount the fields.",
|
|
58
|
+
"threeds_action_external_not_supported_for_setup": "three_ds_action=external is not supported for $0 card verification.",
|
|
59
|
+
"threeds_action_force_not_supported": "three_ds_action=force is not supported on this acquiring route.",
|
|
54
60
|
"threeds_cancelled": "The customer cancelled the 3D Secure challenge.",
|
|
55
61
|
"threeds_failed": "3D Secure authentication failed.",
|
|
56
62
|
"threeds_no_liability_shift": "Authentication completed but liability did not shift to the issuer.",
|
|
57
63
|
"threeds_not_supported": "The card or issuer is not enrolled for 3D Secure.",
|
|
64
|
+
"threeds_result_required": "three_ds_action=external requires a three_ds_result object in the confirm request.",
|
|
58
65
|
"token_not_chargeable": "The saved card cannot be charged without a previous successful verification.",
|
|
59
66
|
"token_not_found": "The card token does not exist.",
|
|
60
67
|
"transaction_not_permitted": "The issuer does not permit this transaction for this card.",
|
package/lib/errors.js
CHANGED
|
@@ -27,26 +27,19 @@ const FIELD_CODES = new Set([
|
|
|
27
27
|
'invalid_cvc',
|
|
28
28
|
'unsupported_brand',
|
|
29
29
|
]);
|
|
30
|
-
/** Localized
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
'sdk_load_failed',
|
|
35
|
-
'invalid_publishable_key',
|
|
36
|
-
'invalid_client_token',
|
|
37
|
-
'origin_not_allowed',
|
|
38
|
-
'font_load_failed',
|
|
39
|
-
]);
|
|
40
|
-
/** Localized user message for a shared-table code. Falls back
|
|
41
|
-
* to `error.generic` when the code has no dedicated string. */
|
|
30
|
+
/** Localized user message for a shared-table code. Resolves
|
|
31
|
+
* `error.<code>` from the locale bundle (all common payment outcomes ship
|
|
32
|
+
* one), falls back to `field.<code>` for validation codes, then to
|
|
33
|
+
* `error.generic`. */
|
|
42
34
|
function userMessageForCode(code, locale) {
|
|
43
35
|
const strings = (0, locales_1.getLocaleStrings)(locale);
|
|
36
|
+
const direct = strings.t(('error.' + code));
|
|
37
|
+
if (direct) {
|
|
38
|
+
return direct;
|
|
39
|
+
}
|
|
44
40
|
if (FIELD_CODES.has(code)) {
|
|
45
41
|
return strings.t((FIELD_CODE_PREFIX + code));
|
|
46
42
|
}
|
|
47
|
-
if (LOCALIZED_ERROR_KEYS.has(code)) {
|
|
48
|
-
return strings.t(('error.' + code));
|
|
49
|
-
}
|
|
50
43
|
return strings.t('error.generic');
|
|
51
44
|
}
|
|
52
45
|
class PaError extends Error {
|
package/lib/index.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export { AppStateAwarePoller, pollUntil, DEFAULT_POLLER_OPTIONS } from './poll';
|
|
|
35
35
|
export type { PollCheck, PollerOptions } from './poll';
|
|
36
36
|
export { PaError, isPaError, userMessageForCode, NotInitializedError } from './errors';
|
|
37
37
|
export { DEFAULT_LOCALE, SUPPORTED_LOCALES, getLocale, getLocaleStrings, normalizeLocale, resolveBundle, setLocale, } from './locales';
|
|
38
|
-
export { canPresentThreeDs, closeThreeDs, presentThreeDs, setThreeDsPresenter } from './threeDs';
|
|
38
|
+
export { canPresentThreeDs, closeThreeDs, handleReturnUrl, presentThreeDs, setThreeDsPresenter } from './threeDs';
|
|
39
39
|
export type { ThreeDsDismissal, ThreeDsParams, ThreeDsPresenter, ThreeDsStrings } from './threeDs';
|
|
40
40
|
export { PaSdk3dsHost } from './threeDsHost';
|
|
41
41
|
export { ApiClient, GATEWAY_BASE_URLS } from './api';
|
package/lib/index.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* // result.status: 'succeeded' | 'authorized' | 'processing' | 'cancelled' | 'failed'
|
|
27
27
|
*/
|
|
28
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;
|
|
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.handleReturnUrl = 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
30
|
// init / lifecycle
|
|
31
31
|
var init_1 = require("./init");
|
|
32
32
|
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_1.init; } });
|
|
@@ -79,6 +79,7 @@ Object.defineProperty(exports, "setLocale", { enumerable: true, get: function ()
|
|
|
79
79
|
var threeDs_1 = require("./threeDs");
|
|
80
80
|
Object.defineProperty(exports, "canPresentThreeDs", { enumerable: true, get: function () { return threeDs_1.canPresentThreeDs; } });
|
|
81
81
|
Object.defineProperty(exports, "closeThreeDs", { enumerable: true, get: function () { return threeDs_1.closeThreeDs; } });
|
|
82
|
+
Object.defineProperty(exports, "handleReturnUrl", { enumerable: true, get: function () { return threeDs_1.handleReturnUrl; } });
|
|
82
83
|
Object.defineProperty(exports, "presentThreeDs", { enumerable: true, get: function () { return threeDs_1.presentThreeDs; } });
|
|
83
84
|
Object.defineProperty(exports, "setThreeDsPresenter", { enumerable: true, get: function () { return threeDs_1.setThreeDsPresenter; } });
|
|
84
85
|
var threeDsHost_1 = require("./threeDsHost");
|
package/lib/init.js
CHANGED
|
@@ -54,6 +54,8 @@ function init(options) {
|
|
|
54
54
|
if (options.locale) {
|
|
55
55
|
(0, locales_1.setLocale)(options.locale); // accepted in any tag form
|
|
56
56
|
}
|
|
57
|
+
// Flow-supplied strings overlay the resolved bundle at lookup time.
|
|
58
|
+
(0, locales_1.setCustomMessages)(options.messages);
|
|
57
59
|
instance = {
|
|
58
60
|
environment: options.environment,
|
|
59
61
|
accounts: { ...options.accounts },
|
|
@@ -93,4 +95,5 @@ function updateLocale(locale) {
|
|
|
93
95
|
/** Drop the current configuration (e.g. logout). */
|
|
94
96
|
function deinitialize() {
|
|
95
97
|
instance = null;
|
|
98
|
+
(0, locales_1.setCustomMessages)(null);
|
|
96
99
|
}
|
package/lib/locales.d.ts
CHANGED
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
* (`zh_HK`, `zh-HK`, `zh-hk`).
|
|
6
6
|
* - locale can be changed at runtime via setLocale() without reload.
|
|
7
7
|
* - unsupported / unknown locale never errors — fallback chain
|
|
8
|
-
* exact tag -> same language -> en-US
|
|
8
|
+
* exact tag -> alias -> same primary language -> en-US
|
|
9
|
+
* (zh picks zh-TW for Traditional/HK variants and zh-CN for
|
|
10
|
+
* Simplified/SG variants; en picks en-US; ms picks ms-MY).
|
|
9
11
|
* - zh_HK maps to zh-TW strings.
|
|
10
|
-
* -
|
|
12
|
+
* - flow-supplied init() messages overlay the resolved bundle at lookup
|
|
13
|
+
* time (setCustomMessages).
|
|
11
14
|
*/
|
|
12
15
|
import { type LocaleBundle, type LocaleKey, type LocaleMeta } from './locales.generated';
|
|
13
16
|
export type { LocaleBundle, LocaleKey, LocaleMeta };
|
|
@@ -15,7 +18,10 @@ export declare const DEFAULT_LOCALE = "en-US";
|
|
|
15
18
|
/** Canonical locales shipped in this SDK. */
|
|
16
19
|
export declare const SUPPORTED_LOCALES: readonly ["en-US", "zh-TW", "zh-CN", "ms-MY"];
|
|
17
20
|
export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number];
|
|
18
|
-
/** Normalize any accepted tag form; returns null when unknown (never throws).
|
|
21
|
+
/** Normalize any accepted tag form; returns null when unknown (never throws).
|
|
22
|
+
* Unlisted regional variants of a shipped language resolve to that
|
|
23
|
+
* language's bundle (en-AU -> en-US, zh-SG -> zh-CN, zh-Hant-HK -> zh-TW,
|
|
24
|
+
* fr-CA -> null -> en-US via resolveBundle). */
|
|
19
25
|
export declare function normalizeLocale(tag: string | null | undefined): SupportedLocale | null;
|
|
20
26
|
/** The bundle for a tag with the fallback chain applied: exact tag ->
|
|
21
27
|
* same language -> en-US. Unknown tags fall back to en-US silently.
|
|
@@ -29,8 +35,12 @@ export interface LocaleStrings {
|
|
|
29
35
|
t(key: LocaleKey): string;
|
|
30
36
|
locale: SupportedLocale;
|
|
31
37
|
}
|
|
38
|
+
/** Install (or clear) flow-supplied message overrides, keyed like the
|
|
39
|
+
* locale bundles ("error.card_declined", "threeds.title", ...). */
|
|
40
|
+
export declare function setCustomMessages(messages: Record<string, string> | null | undefined): void;
|
|
32
41
|
export declare function setLocale(tag: string | null | undefined): void;
|
|
33
42
|
export declare function getLocale(): string;
|
|
34
43
|
/** Localized strings for a tag (or the current runtime locale when omitted).
|
|
35
|
-
* Falls back along the fallback chain; never throws for unknown tags.
|
|
44
|
+
* Falls back along the fallback chain; never throws for unknown tags.
|
|
45
|
+
* Custom messages (init) win over the resolved bundle. */
|
|
36
46
|
export declare function getLocaleStrings(tag?: string | null): LocaleStrings;
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* Generated by scripts/generate-locales.js from locales/*.json.
|
|
4
4
|
*
|
|
5
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).
|
|
6
|
+
* serves zh_HK/zh-HK), zh-CN (complete), ms-MY (my_MY — complete).
|
|
8
7
|
*/
|
|
9
8
|
export interface LocaleMeta {
|
|
10
9
|
name: string;
|
|
@@ -12,7 +11,7 @@ export interface LocaleMeta {
|
|
|
12
11
|
fallback: string | null;
|
|
13
12
|
complete: boolean;
|
|
14
13
|
}
|
|
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';
|
|
14
|
+
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' | 'error.card_declined' | 'error.insufficient_funds' | 'error.expired_card' | 'error.invalid_cvc' | 'error.invalid_number' | 'error.unsupported_brand' | 'error.unsupported_currency' | 'error.threeds_failed' | 'error.threeds_cancelled' | 'error.threeds_not_supported' | 'error.threeds_no_liability_shift' | 'error.amount_above_limit' | 'error.amount_below_limit' | 'error.frequency_limit' | 'error.risk_declined' | 'error.issuer_unavailable' | 'error.acquirer_unavailable' | 'error.refund_exceeds_paid' | 'error.duplicate_confirm' | 'error.intent_expired' | 'error.intent_already_final' | 'field.incomplete_number' | 'field.invalid_number' | 'field.incomplete_expiry' | 'field.invalid_expiry' | 'field.incomplete_cvc' | 'field.invalid_cvc' | 'field.unsupported_brand';
|
|
16
15
|
export interface LocaleBundle {
|
|
17
16
|
_meta: LocaleMeta;
|
|
18
17
|
[key: string]: string | LocaleMeta;
|
package/lib/locales.generated.js
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* Generated by scripts/generate-locales.js from locales/*.json.
|
|
6
6
|
*
|
|
7
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).
|
|
8
|
+
* serves zh_HK/zh-HK), zh-CN (complete), ms-MY (my_MY — complete).
|
|
10
9
|
*/
|
|
11
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
11
|
exports.LOCALE_BUNDLES = void 0;
|
|
@@ -33,6 +32,27 @@ exports.LOCALE_BUNDLES = {
|
|
|
33
32
|
"error.invalid_client_token": "The payment session has expired. Please try again.",
|
|
34
33
|
"error.origin_not_allowed": "This website is not authorised to use the payment component.",
|
|
35
34
|
"error.font_load_failed": "Font failed to load, a system font is used instead.",
|
|
35
|
+
"error.card_declined": "Your card was declined. Please try another card.",
|
|
36
|
+
"error.insufficient_funds": "Insufficient funds on this card.",
|
|
37
|
+
"error.expired_card": "This card has expired.",
|
|
38
|
+
"error.invalid_cvc": "The card security code is incorrect.",
|
|
39
|
+
"error.invalid_number": "The card number is incorrect.",
|
|
40
|
+
"error.unsupported_brand": "This card type is not accepted.",
|
|
41
|
+
"error.unsupported_currency": "This currency is not supported for this card.",
|
|
42
|
+
"error.threeds_failed": "Card authentication failed. Please try another card.",
|
|
43
|
+
"error.threeds_cancelled": "Card authentication was cancelled.",
|
|
44
|
+
"error.threeds_not_supported": "This card does not support 3D Secure authentication.",
|
|
45
|
+
"error.threeds_no_liability_shift": "Card authentication could not be completed.",
|
|
46
|
+
"error.amount_above_limit": "The amount exceeds the limit for this card.",
|
|
47
|
+
"error.amount_below_limit": "The amount is below the minimum allowed.",
|
|
48
|
+
"error.frequency_limit": "Too many attempts, please try again later.",
|
|
49
|
+
"error.risk_declined": "The payment was blocked. Please contact your bank or try another card.",
|
|
50
|
+
"error.issuer_unavailable": "Your card issuer is unavailable. Please try again later.",
|
|
51
|
+
"error.acquirer_unavailable": "Payment processing is temporarily unavailable. Please try again later.",
|
|
52
|
+
"error.refund_exceeds_paid": "The refund amount exceeds the amount paid.",
|
|
53
|
+
"error.duplicate_confirm": "This payment is already being processed.",
|
|
54
|
+
"error.intent_expired": "The payment session has expired. Please start again.",
|
|
55
|
+
"error.intent_already_final": "This payment has already been processed.",
|
|
36
56
|
"field.incomplete_number": "Enter your full card number",
|
|
37
57
|
"field.invalid_number": "Check your card number",
|
|
38
58
|
"field.incomplete_expiry": "Enter the full expiry date",
|
|
@@ -63,6 +83,27 @@ exports.LOCALE_BUNDLES = {
|
|
|
63
83
|
"error.invalid_client_token": "Sesi pembayaran telah tamat. Sila cuba lagi.",
|
|
64
84
|
"error.origin_not_allowed": "Laman web ini tidak dibenarkan menggunakan komponen pembayaran.",
|
|
65
85
|
"error.font_load_failed": "Fon gagal dimuatkan, fon sistem digunakan sebagai gantian.",
|
|
86
|
+
"error.card_declined": "Kad anda ditolak. Sila gunakan kad lain.",
|
|
87
|
+
"error.insufficient_funds": "Baki kad tidak mencukupi.",
|
|
88
|
+
"error.expired_card": "Kad telah luput.",
|
|
89
|
+
"error.invalid_cvc": "Kod keselamatan tidak betul.",
|
|
90
|
+
"error.invalid_number": "Nombor kad tidak betul.",
|
|
91
|
+
"error.unsupported_brand": "Jenis kad ini tidak diterima.",
|
|
92
|
+
"error.unsupported_currency": "Mata wang ini tidak disokong untuk kad ini.",
|
|
93
|
+
"error.threeds_failed": "Pengesahan kad gagal. Sila gunakan kad lain.",
|
|
94
|
+
"error.threeds_cancelled": "Pengesahan telah dibatalkan.",
|
|
95
|
+
"error.threeds_not_supported": "Kad ini tidak menyokong pengesahan 3DS.",
|
|
96
|
+
"error.threeds_no_liability_shift": "Pengesahan kad tidak dapat diselesaikan.",
|
|
97
|
+
"error.amount_above_limit": "Amaun melebihi had untuk kad ini.",
|
|
98
|
+
"error.amount_below_limit": "Amaun kurang daripada jumlah minimum.",
|
|
99
|
+
"error.frequency_limit": "Terlalu banyak percubaan, sila cuba lagi kemudian.",
|
|
100
|
+
"error.risk_declined": "Pembayaran disekat. Sila hubungi bank anda atau gunakan kad lain.",
|
|
101
|
+
"error.issuer_unavailable": "Bank penerbit kad tidak tersedia. Sila cuba lagi kemudian.",
|
|
102
|
+
"error.acquirer_unavailable": "Perkhidmatan pembayaran tidak tersedia buat sementara waktu. Sila cuba lagi kemudian.",
|
|
103
|
+
"error.refund_exceeds_paid": "Amaun bayaran balik melebihi jumlah yang dibayar.",
|
|
104
|
+
"error.duplicate_confirm": "Pembayaran ini sedang diproses.",
|
|
105
|
+
"error.intent_expired": "Sesi pembayaran telah tamat. Sila mula semula.",
|
|
106
|
+
"error.intent_already_final": "Pembayaran ini telah selesai.",
|
|
66
107
|
"field.incomplete_number": "Masukkan nombor kad penuh anda",
|
|
67
108
|
"field.invalid_number": "Semak nombor kad anda",
|
|
68
109
|
"field.incomplete_expiry": "Masukkan tarikh luput penuh",
|
|
@@ -93,6 +134,27 @@ exports.LOCALE_BUNDLES = {
|
|
|
93
134
|
"error.invalid_client_token": "付款会话已过期,请重试。",
|
|
94
135
|
"error.origin_not_allowed": "此网站未获授权使用付款组件。",
|
|
95
136
|
"error.font_load_failed": "字体加载失败,已改用系统字体。",
|
|
137
|
+
"error.card_declined": "银行卡被拒绝,请更换银行卡重试。",
|
|
138
|
+
"error.insufficient_funds": "银行卡余额不足。",
|
|
139
|
+
"error.expired_card": "银行卡已过期。",
|
|
140
|
+
"error.invalid_cvc": "安全码不正确。",
|
|
141
|
+
"error.invalid_number": "卡号不正确。",
|
|
142
|
+
"error.unsupported_brand": "不支持此银行卡类型。",
|
|
143
|
+
"error.unsupported_currency": "该银行卡不支持此币种。",
|
|
144
|
+
"error.threeds_failed": "安全验证失败,请更换银行卡重试。",
|
|
145
|
+
"error.threeds_cancelled": "你已取消安全验证。",
|
|
146
|
+
"error.threeds_not_supported": "该银行卡不支持 3DS 验证。",
|
|
147
|
+
"error.threeds_no_liability_shift": "安全验证未能完成。",
|
|
148
|
+
"error.amount_above_limit": "金额超过该银行卡的限额。",
|
|
149
|
+
"error.amount_below_limit": "金额低于最低要求。",
|
|
150
|
+
"error.frequency_limit": "操作过于频繁,请稍后再试。",
|
|
151
|
+
"error.risk_declined": "交易被拦截,请联系发卡银行或更换银行卡。",
|
|
152
|
+
"error.issuer_unavailable": "发卡银行暂时无法连接,请稍后再试。",
|
|
153
|
+
"error.acquirer_unavailable": "收单服务暂时不可用,请稍后再试。",
|
|
154
|
+
"error.refund_exceeds_paid": "退款金额超过可退款金额。",
|
|
155
|
+
"error.duplicate_confirm": "该笔付款正在处理中。",
|
|
156
|
+
"error.intent_expired": "付款已过期,请重新发起付款。",
|
|
157
|
+
"error.intent_already_final": "该笔付款已完成。",
|
|
96
158
|
"field.incomplete_number": "请输入完整卡号",
|
|
97
159
|
"field.invalid_number": "请检查卡号",
|
|
98
160
|
"field.incomplete_expiry": "请输入完整有效期",
|
|
@@ -123,6 +185,27 @@ exports.LOCALE_BUNDLES = {
|
|
|
123
185
|
"error.invalid_client_token": "付款工作階段已過期,請重試。",
|
|
124
186
|
"error.origin_not_allowed": "此網站未獲授權使用付款元件。",
|
|
125
187
|
"error.font_load_failed": "字體載入失敗,已改用系統字體。",
|
|
188
|
+
"error.card_declined": "你的卡片被拒絕,請改用其他卡片。",
|
|
189
|
+
"error.insufficient_funds": "卡片餘額不足。",
|
|
190
|
+
"error.expired_card": "卡片已過期。",
|
|
191
|
+
"error.invalid_cvc": "安全碼不正確。",
|
|
192
|
+
"error.invalid_number": "卡號不正確。",
|
|
193
|
+
"error.unsupported_brand": "不接受此卡片類型。",
|
|
194
|
+
"error.unsupported_currency": "此卡片不支援該貨幣。",
|
|
195
|
+
"error.threeds_failed": "安全驗證失敗,請改用其他卡片。",
|
|
196
|
+
"error.threeds_cancelled": "你已取消安全驗證。",
|
|
197
|
+
"error.threeds_not_supported": "此卡片不支援 3DS 驗證。",
|
|
198
|
+
"error.threeds_no_liability_shift": "安全驗證未能完成。",
|
|
199
|
+
"error.amount_above_limit": "金額超過此卡片的限額。",
|
|
200
|
+
"error.amount_below_limit": "金額低於最低要求。",
|
|
201
|
+
"error.frequency_limit": "嘗試次數過多,請稍後再試。",
|
|
202
|
+
"error.risk_declined": "付款被攔截,請聯絡發卡銀行或改用其他卡片。",
|
|
203
|
+
"error.issuer_unavailable": "發卡銀行暫時無法連線,請稍後再試。",
|
|
204
|
+
"error.acquirer_unavailable": "收款服務暫時無法使用,請稍後再試。",
|
|
205
|
+
"error.refund_exceeds_paid": "退款金額超過可退款金額。",
|
|
206
|
+
"error.duplicate_confirm": "此付款正在處理中。",
|
|
207
|
+
"error.intent_expired": "付款已逾時,請重新發起付款。",
|
|
208
|
+
"error.intent_already_final": "此付款已完成。",
|
|
126
209
|
"field.incomplete_number": "請輸入完整卡號",
|
|
127
210
|
"field.invalid_number": "請檢查卡號",
|
|
128
211
|
"field.incomplete_expiry": "請輸入完整有效期",
|
package/lib/locales.js
CHANGED
|
@@ -6,14 +6,18 @@
|
|
|
6
6
|
* (`zh_HK`, `zh-HK`, `zh-hk`).
|
|
7
7
|
* - locale can be changed at runtime via setLocale() without reload.
|
|
8
8
|
* - unsupported / unknown locale never errors — fallback chain
|
|
9
|
-
* exact tag -> same language -> en-US
|
|
9
|
+
* exact tag -> alias -> same primary language -> en-US
|
|
10
|
+
* (zh picks zh-TW for Traditional/HK variants and zh-CN for
|
|
11
|
+
* Simplified/SG variants; en picks en-US; ms picks ms-MY).
|
|
10
12
|
* - zh_HK maps to zh-TW strings.
|
|
11
|
-
* -
|
|
13
|
+
* - flow-supplied init() messages overlay the resolved bundle at lookup
|
|
14
|
+
* time (setCustomMessages).
|
|
12
15
|
*/
|
|
13
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
17
|
exports.SUPPORTED_LOCALES = exports.DEFAULT_LOCALE = void 0;
|
|
15
18
|
exports.normalizeLocale = normalizeLocale;
|
|
16
19
|
exports.resolveBundle = resolveBundle;
|
|
20
|
+
exports.setCustomMessages = setCustomMessages;
|
|
17
21
|
exports.setLocale = setLocale;
|
|
18
22
|
exports.getLocale = getLocale;
|
|
19
23
|
exports.getLocaleStrings = getLocaleStrings;
|
|
@@ -35,7 +39,10 @@ const ALIASES = {
|
|
|
35
39
|
'ms-my': 'ms-MY',
|
|
36
40
|
'my-my': 'ms-MY', // Malay tag
|
|
37
41
|
};
|
|
38
|
-
/** Normalize any accepted tag form; returns null when unknown (never throws).
|
|
42
|
+
/** Normalize any accepted tag form; returns null when unknown (never throws).
|
|
43
|
+
* Unlisted regional variants of a shipped language resolve to that
|
|
44
|
+
* language's bundle (en-AU -> en-US, zh-SG -> zh-CN, zh-Hant-HK -> zh-TW,
|
|
45
|
+
* fr-CA -> null -> en-US via resolveBundle). */
|
|
39
46
|
function normalizeLocale(tag) {
|
|
40
47
|
if (!tag || typeof tag !== 'string') {
|
|
41
48
|
return null;
|
|
@@ -45,7 +52,24 @@ function normalizeLocale(tag) {
|
|
|
45
52
|
if (direct) {
|
|
46
53
|
return direct;
|
|
47
54
|
}
|
|
48
|
-
|
|
55
|
+
const alias = ALIASES[norm];
|
|
56
|
+
if (alias) {
|
|
57
|
+
return alias;
|
|
58
|
+
}
|
|
59
|
+
// Same-language fallback for unlisted regional variants.
|
|
60
|
+
const primary = norm.split('-')[0];
|
|
61
|
+
if (primary === 'zh') {
|
|
62
|
+
// Simplified variants -> zh-CN; Traditional / HK / MO / TW -> zh-TW.
|
|
63
|
+
const simplified = norm.includes('hans') || norm.endsWith('-sg') || norm.endsWith('-my') || norm.endsWith('-cn');
|
|
64
|
+
return simplified ? 'zh-CN' : 'zh-TW';
|
|
65
|
+
}
|
|
66
|
+
if (primary === 'en') {
|
|
67
|
+
return 'en-US';
|
|
68
|
+
}
|
|
69
|
+
if (primary === 'ms') {
|
|
70
|
+
return 'ms-MY';
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
49
73
|
}
|
|
50
74
|
/** The bundle for a tag with the fallback chain applied: exact tag ->
|
|
51
75
|
* same language -> en-US. Unknown tags fall back to en-US silently.
|
|
@@ -75,6 +99,25 @@ function resolveBundle(tag) {
|
|
|
75
99
|
}
|
|
76
100
|
/** Runtime locale for user messages. Changed via setLocale(). */
|
|
77
101
|
let currentLocale = exports.DEFAULT_LOCALE;
|
|
102
|
+
/** Flow-supplied message overrides, merged over the resolved bundle at
|
|
103
|
+
* lookup time (set at init). */
|
|
104
|
+
let customMessages = null;
|
|
105
|
+
/** Install (or clear) flow-supplied message overrides, keyed like the
|
|
106
|
+
* locale bundles ("error.card_declined", "threeds.title", ...). */
|
|
107
|
+
function setCustomMessages(messages) {
|
|
108
|
+
if (messages && typeof messages === 'object') {
|
|
109
|
+
const copy = {};
|
|
110
|
+
for (const key of Object.keys(messages)) {
|
|
111
|
+
if (typeof messages[key] === 'string') {
|
|
112
|
+
copy[key] = messages[key];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
customMessages = copy;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
customMessages = null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
78
121
|
function setLocale(tag) {
|
|
79
122
|
currentLocale = normalizeLocale(tag) ? String(tag) : tag || exports.DEFAULT_LOCALE;
|
|
80
123
|
}
|
|
@@ -82,13 +125,18 @@ function getLocale() {
|
|
|
82
125
|
return currentLocale;
|
|
83
126
|
}
|
|
84
127
|
/** Localized strings for a tag (or the current runtime locale when omitted).
|
|
85
|
-
* Falls back along the fallback chain; never throws for unknown tags.
|
|
128
|
+
* Falls back along the fallback chain; never throws for unknown tags.
|
|
129
|
+
* Custom messages (init) win over the resolved bundle. */
|
|
86
130
|
function getLocaleStrings(tag) {
|
|
87
131
|
const effective = tag == null ? currentLocale : tag;
|
|
88
132
|
const { locale, bundle } = resolveBundle(effective);
|
|
89
133
|
return {
|
|
90
134
|
locale,
|
|
91
135
|
t(key) {
|
|
136
|
+
const custom = customMessages && customMessages[key];
|
|
137
|
+
if (typeof custom === 'string' && custom.length > 0) {
|
|
138
|
+
return custom;
|
|
139
|
+
}
|
|
92
140
|
const value = bundle[key];
|
|
93
141
|
if (typeof value === 'string' && value.length > 0) {
|
|
94
142
|
return value;
|
package/lib/threeDs.d.ts
CHANGED
|
@@ -57,3 +57,14 @@ export declare function presentThreeDs(params: ThreeDsParams, onWillPresent?: ()
|
|
|
57
57
|
/** Close a presented challenge (called once polling observed a terminal
|
|
58
58
|
* state; the native side dismisses the WebView and resolves present()). */
|
|
59
59
|
export declare function closeThreeDs(): void;
|
|
60
|
+
/**
|
|
61
|
+
* App-switch return hook (iOS). An app-switch return from the issuer's app
|
|
62
|
+
* (or bank portal) lands in the app's own link handler, not inside the
|
|
63
|
+
* challenge WebView — call this FIRST from AppDelegate/SceneDelegate
|
|
64
|
+
* (openURL / continueUserActivity) and ignore the URL when it resolves
|
|
65
|
+
* true: the URL matched the pending 3DS challenge's return URLs and the
|
|
66
|
+
* challenge has been consumed. Resolves false when no challenge is pending
|
|
67
|
+
* or the URL does not match — handle the URL as usual then. Android needs
|
|
68
|
+
* no hook: the SDK consumes its returns at the OS level.
|
|
69
|
+
*/
|
|
70
|
+
export declare function handleReturnUrl(url: string): Promise<boolean>;
|
package/lib/threeDs.js
CHANGED
|
@@ -21,6 +21,7 @@ exports.setThreeDsPresenter = setThreeDsPresenter;
|
|
|
21
21
|
exports.canPresentThreeDs = canPresentThreeDs;
|
|
22
22
|
exports.presentThreeDs = presentThreeDs;
|
|
23
23
|
exports.closeThreeDs = closeThreeDs;
|
|
24
|
+
exports.handleReturnUrl = handleReturnUrl;
|
|
24
25
|
const react_native_1 = require("react-native");
|
|
25
26
|
const errors_1 = require("./errors");
|
|
26
27
|
const nativeModule = react_native_1.NativeModules.PaSdk3ds;
|
|
@@ -62,3 +63,24 @@ function closeThreeDs() {
|
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* App-switch return hook (iOS). An app-switch return from the issuer's app
|
|
68
|
+
* (or bank portal) lands in the app's own link handler, not inside the
|
|
69
|
+
* challenge WebView — call this FIRST from AppDelegate/SceneDelegate
|
|
70
|
+
* (openURL / continueUserActivity) and ignore the URL when it resolves
|
|
71
|
+
* true: the URL matched the pending 3DS challenge's return URLs and the
|
|
72
|
+
* challenge has been consumed. Resolves false when no challenge is pending
|
|
73
|
+
* or the URL does not match — handle the URL as usual then. Android needs
|
|
74
|
+
* no hook: the SDK consumes its returns at the OS level.
|
|
75
|
+
*/
|
|
76
|
+
async function handleReturnUrl(url) {
|
|
77
|
+
if (nativeModule && typeof nativeModule.handleReturnUrl === 'function') {
|
|
78
|
+
try {
|
|
79
|
+
return (await nativeModule.handleReturnUrl(url)) === true;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
package/lib/tokenize.d.ts
CHANGED
|
@@ -19,4 +19,9 @@ export declare function tokenizeCard(api: ApiClient, params: {
|
|
|
19
19
|
sessionToken?: string;
|
|
20
20
|
/** Publishable merchantToken of the market account to tokenize under. */
|
|
21
21
|
merchantToken: string;
|
|
22
|
+
/** The app's own reference, stored with the token (merchant_reference). */
|
|
23
|
+
merchantReference?: string;
|
|
24
|
+
/** Arbitrary key-value data stored with the token, sent as
|
|
25
|
+
* token_metadata (JSON string). */
|
|
26
|
+
metadata?: Record<string, unknown>;
|
|
22
27
|
}): Promise<TokenizeOutput>;
|
package/lib/tokenize.js
CHANGED
|
@@ -34,6 +34,8 @@ async function tokenizeCard(api, params) {
|
|
|
34
34
|
expiryYear: params.card.expiryYear,
|
|
35
35
|
cvc: params.card.cvc,
|
|
36
36
|
cardHolderName: params.card.cardHolderName,
|
|
37
|
+
merchantReference: params.merchantReference,
|
|
38
|
+
metadata: params.metadata,
|
|
37
39
|
});
|
|
38
40
|
if (!payload || !payload.pa_token) {
|
|
39
41
|
throw new errors_1.PaError('provider_error', {
|
package/lib/types.d.ts
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
export type Environment = 'production' | 'sandbox';
|
|
10
10
|
/** SDK result states. */
|
|
11
11
|
export type ResultStatus = 'succeeded' | 'authorized' | 'processing' | 'cancelled' | 'failed';
|
|
12
|
+
/** three_ds_action values accepted at confirm. */
|
|
13
|
+
export type ThreeDsAction = 'force' | 'skip';
|
|
12
14
|
/** Field codes reported by validation. */
|
|
13
15
|
export type FieldErrorCode = 'incomplete_number' | 'invalid_number' | 'incomplete_expiry' | 'invalid_expiry' | 'incomplete_cvc' | 'invalid_cvc' | 'unsupported_brand';
|
|
14
16
|
/** Published brand vocabulary. Scope is Visa + Mastercard; the
|
|
@@ -27,6 +29,9 @@ export interface CardInput {
|
|
|
27
29
|
/** Optional; never required. */
|
|
28
30
|
cardHolderName?: string;
|
|
29
31
|
}
|
|
32
|
+
/** Flow-supplied message overrides, keyed like the locale bundles
|
|
33
|
+
* ("error.card_declined", "threeds.title", "field.invalid_number", ...). */
|
|
34
|
+
export type SdkMessages = Record<string, string>;
|
|
30
35
|
/** Optional pass-through billing details.
|
|
31
36
|
* Postal address is optional and never required. */
|
|
32
37
|
export interface BillingDetails {
|
|
@@ -60,6 +65,9 @@ export interface InitOptions {
|
|
|
60
65
|
defaultAccount: string;
|
|
61
66
|
/** Locale tag; underscore/hyphen and case-insensitive. */
|
|
62
67
|
locale?: string;
|
|
68
|
+
/** Flow-supplied message overrides merged over the resolved locale bundle
|
|
69
|
+
* at lookup time, keyed like the bundles ("error.card_declined", ...). */
|
|
70
|
+
messages?: SdkMessages;
|
|
63
71
|
/** App origin sent with API calls where the gateway recommends one,
|
|
64
72
|
* e.g. "https://links.yourapp.com". */
|
|
65
73
|
origin?: string;
|
package/locales/en-US.json
CHANGED
|
@@ -20,6 +20,27 @@
|
|
|
20
20
|
"error.invalid_client_token": "The payment session has expired. Please try again.",
|
|
21
21
|
"error.origin_not_allowed": "This website is not authorised to use the payment component.",
|
|
22
22
|
"error.font_load_failed": "Font failed to load, a system font is used instead.",
|
|
23
|
+
"error.card_declined": "Your card was declined. Please try another card.",
|
|
24
|
+
"error.insufficient_funds": "Insufficient funds on this card.",
|
|
25
|
+
"error.expired_card": "This card has expired.",
|
|
26
|
+
"error.invalid_cvc": "The card security code is incorrect.",
|
|
27
|
+
"error.invalid_number": "The card number is incorrect.",
|
|
28
|
+
"error.unsupported_brand": "This card type is not accepted.",
|
|
29
|
+
"error.unsupported_currency": "This currency is not supported for this card.",
|
|
30
|
+
"error.threeds_failed": "Card authentication failed. Please try another card.",
|
|
31
|
+
"error.threeds_cancelled": "Card authentication was cancelled.",
|
|
32
|
+
"error.threeds_not_supported": "This card does not support 3D Secure authentication.",
|
|
33
|
+
"error.threeds_no_liability_shift": "Card authentication could not be completed.",
|
|
34
|
+
"error.amount_above_limit": "The amount exceeds the limit for this card.",
|
|
35
|
+
"error.amount_below_limit": "The amount is below the minimum allowed.",
|
|
36
|
+
"error.frequency_limit": "Too many attempts, please try again later.",
|
|
37
|
+
"error.risk_declined": "The payment was blocked. Please contact your bank or try another card.",
|
|
38
|
+
"error.issuer_unavailable": "Your card issuer is unavailable. Please try again later.",
|
|
39
|
+
"error.acquirer_unavailable": "Payment processing is temporarily unavailable. Please try again later.",
|
|
40
|
+
"error.refund_exceeds_paid": "The refund amount exceeds the amount paid.",
|
|
41
|
+
"error.duplicate_confirm": "This payment is already being processed.",
|
|
42
|
+
"error.intent_expired": "The payment session has expired. Please start again.",
|
|
43
|
+
"error.intent_already_final": "This payment has already been processed.",
|
|
23
44
|
"field.incomplete_number": "Enter your full card number",
|
|
24
45
|
"field.invalid_number": "Check your card number",
|
|
25
46
|
"field.incomplete_expiry": "Enter the full expiry date",
|
package/locales/ms-MY.json
CHANGED
|
@@ -20,6 +20,27 @@
|
|
|
20
20
|
"error.invalid_client_token": "Sesi pembayaran telah tamat. Sila cuba lagi.",
|
|
21
21
|
"error.origin_not_allowed": "Laman web ini tidak dibenarkan menggunakan komponen pembayaran.",
|
|
22
22
|
"error.font_load_failed": "Fon gagal dimuatkan, fon sistem digunakan sebagai gantian.",
|
|
23
|
+
"error.card_declined": "Kad anda ditolak. Sila gunakan kad lain.",
|
|
24
|
+
"error.insufficient_funds": "Baki kad tidak mencukupi.",
|
|
25
|
+
"error.expired_card": "Kad telah luput.",
|
|
26
|
+
"error.invalid_cvc": "Kod keselamatan tidak betul.",
|
|
27
|
+
"error.invalid_number": "Nombor kad tidak betul.",
|
|
28
|
+
"error.unsupported_brand": "Jenis kad ini tidak diterima.",
|
|
29
|
+
"error.unsupported_currency": "Mata wang ini tidak disokong untuk kad ini.",
|
|
30
|
+
"error.threeds_failed": "Pengesahan kad gagal. Sila gunakan kad lain.",
|
|
31
|
+
"error.threeds_cancelled": "Pengesahan telah dibatalkan.",
|
|
32
|
+
"error.threeds_not_supported": "Kad ini tidak menyokong pengesahan 3DS.",
|
|
33
|
+
"error.threeds_no_liability_shift": "Pengesahan kad tidak dapat diselesaikan.",
|
|
34
|
+
"error.amount_above_limit": "Amaun melebihi had untuk kad ini.",
|
|
35
|
+
"error.amount_below_limit": "Amaun kurang daripada jumlah minimum.",
|
|
36
|
+
"error.frequency_limit": "Terlalu banyak percubaan, sila cuba lagi kemudian.",
|
|
37
|
+
"error.risk_declined": "Pembayaran disekat. Sila hubungi bank anda atau gunakan kad lain.",
|
|
38
|
+
"error.issuer_unavailable": "Bank penerbit kad tidak tersedia. Sila cuba lagi kemudian.",
|
|
39
|
+
"error.acquirer_unavailable": "Perkhidmatan pembayaran tidak tersedia buat sementara waktu. Sila cuba lagi kemudian.",
|
|
40
|
+
"error.refund_exceeds_paid": "Amaun bayaran balik melebihi jumlah yang dibayar.",
|
|
41
|
+
"error.duplicate_confirm": "Pembayaran ini sedang diproses.",
|
|
42
|
+
"error.intent_expired": "Sesi pembayaran telah tamat. Sila mula semula.",
|
|
43
|
+
"error.intent_already_final": "Pembayaran ini telah selesai.",
|
|
23
44
|
"field.incomplete_number": "Masukkan nombor kad penuh anda",
|
|
24
45
|
"field.invalid_number": "Semak nombor kad anda",
|
|
25
46
|
"field.incomplete_expiry": "Masukkan tarikh luput penuh",
|
package/locales/zh-CN.json
CHANGED
|
@@ -20,6 +20,27 @@
|
|
|
20
20
|
"error.invalid_client_token": "付款会话已过期,请重试。",
|
|
21
21
|
"error.origin_not_allowed": "此网站未获授权使用付款组件。",
|
|
22
22
|
"error.font_load_failed": "字体加载失败,已改用系统字体。",
|
|
23
|
+
"error.card_declined": "银行卡被拒绝,请更换银行卡重试。",
|
|
24
|
+
"error.insufficient_funds": "银行卡余额不足。",
|
|
25
|
+
"error.expired_card": "银行卡已过期。",
|
|
26
|
+
"error.invalid_cvc": "安全码不正确。",
|
|
27
|
+
"error.invalid_number": "卡号不正确。",
|
|
28
|
+
"error.unsupported_brand": "不支持此银行卡类型。",
|
|
29
|
+
"error.unsupported_currency": "该银行卡不支持此币种。",
|
|
30
|
+
"error.threeds_failed": "安全验证失败,请更换银行卡重试。",
|
|
31
|
+
"error.threeds_cancelled": "你已取消安全验证。",
|
|
32
|
+
"error.threeds_not_supported": "该银行卡不支持 3DS 验证。",
|
|
33
|
+
"error.threeds_no_liability_shift": "安全验证未能完成。",
|
|
34
|
+
"error.amount_above_limit": "金额超过该银行卡的限额。",
|
|
35
|
+
"error.amount_below_limit": "金额低于最低要求。",
|
|
36
|
+
"error.frequency_limit": "操作过于频繁,请稍后再试。",
|
|
37
|
+
"error.risk_declined": "交易被拦截,请联系发卡银行或更换银行卡。",
|
|
38
|
+
"error.issuer_unavailable": "发卡银行暂时无法连接,请稍后再试。",
|
|
39
|
+
"error.acquirer_unavailable": "收单服务暂时不可用,请稍后再试。",
|
|
40
|
+
"error.refund_exceeds_paid": "退款金额超过可退款金额。",
|
|
41
|
+
"error.duplicate_confirm": "该笔付款正在处理中。",
|
|
42
|
+
"error.intent_expired": "付款已过期,请重新发起付款。",
|
|
43
|
+
"error.intent_already_final": "该笔付款已完成。",
|
|
23
44
|
"field.incomplete_number": "请输入完整卡号",
|
|
24
45
|
"field.invalid_number": "请检查卡号",
|
|
25
46
|
"field.incomplete_expiry": "请输入完整有效期",
|
package/locales/zh-TW.json
CHANGED
|
@@ -20,6 +20,27 @@
|
|
|
20
20
|
"error.invalid_client_token": "付款工作階段已過期,請重試。",
|
|
21
21
|
"error.origin_not_allowed": "此網站未獲授權使用付款元件。",
|
|
22
22
|
"error.font_load_failed": "字體載入失敗,已改用系統字體。",
|
|
23
|
+
"error.card_declined": "你的卡片被拒絕,請改用其他卡片。",
|
|
24
|
+
"error.insufficient_funds": "卡片餘額不足。",
|
|
25
|
+
"error.expired_card": "卡片已過期。",
|
|
26
|
+
"error.invalid_cvc": "安全碼不正確。",
|
|
27
|
+
"error.invalid_number": "卡號不正確。",
|
|
28
|
+
"error.unsupported_brand": "不接受此卡片類型。",
|
|
29
|
+
"error.unsupported_currency": "此卡片不支援該貨幣。",
|
|
30
|
+
"error.threeds_failed": "安全驗證失敗,請改用其他卡片。",
|
|
31
|
+
"error.threeds_cancelled": "你已取消安全驗證。",
|
|
32
|
+
"error.threeds_not_supported": "此卡片不支援 3DS 驗證。",
|
|
33
|
+
"error.threeds_no_liability_shift": "安全驗證未能完成。",
|
|
34
|
+
"error.amount_above_limit": "金額超過此卡片的限額。",
|
|
35
|
+
"error.amount_below_limit": "金額低於最低要求。",
|
|
36
|
+
"error.frequency_limit": "嘗試次數過多,請稍後再試。",
|
|
37
|
+
"error.risk_declined": "付款被攔截,請聯絡發卡銀行或改用其他卡片。",
|
|
38
|
+
"error.issuer_unavailable": "發卡銀行暫時無法連線,請稍後再試。",
|
|
39
|
+
"error.acquirer_unavailable": "收款服務暫時無法使用,請稍後再試。",
|
|
40
|
+
"error.refund_exceeds_paid": "退款金額超過可退款金額。",
|
|
41
|
+
"error.duplicate_confirm": "此付款正在處理中。",
|
|
42
|
+
"error.intent_expired": "付款已逾時,請重新發起付款。",
|
|
43
|
+
"error.intent_already_final": "此付款已完成。",
|
|
23
44
|
"field.incomplete_number": "請輸入完整卡號",
|
|
24
45
|
"field.invalid_number": "請檢查卡號",
|
|
25
46
|
"field.incomplete_expiry": "請輸入完整有效期",
|
|
@@ -57,11 +57,11 @@ public final class PaSdk3ds: NSObject {
|
|
|
57
57
|
strings: strings,
|
|
58
58
|
returnUrlScheme: returnUrlScheme,
|
|
59
59
|
returnUrlUniversalHost: returnUrlUniversalHost
|
|
60
|
-
) {
|
|
60
|
+
) { cancelled, returnUrlConsumed in
|
|
61
61
|
PaSdk3ds.activeViewController = nil
|
|
62
62
|
PaSdk3ds.pendingResolve = nil
|
|
63
|
-
resolve(["cancelled":
|
|
64
|
-
"returnUrlConsumed":
|
|
63
|
+
resolve(["cancelled": cancelled,
|
|
64
|
+
"returnUrlConsumed": returnUrlConsumed])
|
|
65
65
|
}
|
|
66
66
|
PaSdk3ds.activeViewController = viewController
|
|
67
67
|
|
|
@@ -78,13 +78,41 @@ public final class PaSdk3ds: NSObject {
|
|
|
78
78
|
/// close() — dismiss the challenge after the JS poller observed a terminal
|
|
79
79
|
/// state; the present() promise resolves with cancelled: false.
|
|
80
80
|
@objc(close:)
|
|
81
|
-
public func close(_ resolve: (Any?) -> Void) {
|
|
81
|
+
public func close(_ resolve: @escaping (Any?) -> Void) {
|
|
82
82
|
DispatchQueue.main.async {
|
|
83
83
|
PaSdk3ds.dismissActive(animated: true)
|
|
84
84
|
resolve(nil)
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/// handleReturnUrl(url) — app-switch return hook for the app's own
|
|
89
|
+
/// AppDelegate/SceneDelegate link handler. A true app-switch return (e.g.
|
|
90
|
+
/// from a banking app) lands there instead of inside the challenge's own
|
|
91
|
+
/// WebView. Resolves true only when a challenge is pending AND the URL
|
|
92
|
+
/// matches its 3DS return URLs; the challenge is then consumed (dismissed,
|
|
93
|
+
/// present() resolves with returnUrlConsumed: true) and the app must ignore
|
|
94
|
+
/// the URL. Resolves false with no challenge pending or on a non-matching
|
|
95
|
+
/// URL — the app handles the URL as usual.
|
|
96
|
+
@objc(handleReturnUrl:resolver:rejecter:)
|
|
97
|
+
public func handleReturnUrl(_ url: String,
|
|
98
|
+
resolver resolve: @escaping (Any?) -> Void,
|
|
99
|
+
rejecter reject: @escaping (NSString?, NSString?, NSError?) -> Void) {
|
|
100
|
+
DispatchQueue.main.async {
|
|
101
|
+
guard let active = PaSdk3ds.activeViewController else {
|
|
102
|
+
resolve(false)
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
if active.matchesReturnUrl(url) {
|
|
106
|
+
active.consumeReturnUrl()
|
|
107
|
+
PaSdk3ds.activeViewController = nil
|
|
108
|
+
PaSdk3ds.pendingResolve = nil
|
|
109
|
+
resolve(true)
|
|
110
|
+
} else {
|
|
111
|
+
resolve(false)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
88
116
|
static func dismissActive(animated: Bool) {
|
|
89
117
|
if let active = activeViewController {
|
|
90
118
|
active.finishDismissal = nil // resolve via close, not as a cancel
|
|
@@ -262,6 +290,32 @@ public final class PaSdk3dsViewController: UIViewController, WKNavigationDelegat
|
|
|
262
290
|
}
|
|
263
291
|
}
|
|
264
292
|
|
|
293
|
+
/// True when the URL matches this challenge's configured 3DS return
|
|
294
|
+
/// scheme or universal-link host — the same matcher used for the
|
|
295
|
+
/// in-WebView navigation consumption and for the app-switch
|
|
296
|
+
/// handleReturnUrl hook.
|
|
297
|
+
func matchesReturnUrl(_ urlString: String) -> Bool {
|
|
298
|
+
guard let url = URL(string: urlString) else {
|
|
299
|
+
return false
|
|
300
|
+
}
|
|
301
|
+
if let scheme = returnUrlScheme, !scheme.isEmpty,
|
|
302
|
+
url.absoluteString.lowercased().hasPrefix(scheme.lowercased()) {
|
|
303
|
+
return true
|
|
304
|
+
}
|
|
305
|
+
if let host = returnUrlUniversalHost, !host.isEmpty,
|
|
306
|
+
let hostComponent = URLComponents(url: url, resolvingAgainstBaseURL: false)?.host,
|
|
307
|
+
hostComponent.lowercased().hasSuffix(host.lowercased().replacingOccurrences(of: "https://", with: "")) {
|
|
308
|
+
return true
|
|
309
|
+
}
|
|
310
|
+
return false
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/// Consume a 3DS return that reached the app's own link handler
|
|
314
|
+
/// (app-switch flow): dismisses the challenge as a completed return.
|
|
315
|
+
func consumeReturnUrl() {
|
|
316
|
+
finish(cancelled: false, returnUrlConsumed: true)
|
|
317
|
+
}
|
|
318
|
+
|
|
265
319
|
// WKNavigationDelegate: when the ACS bounces through the 3DS
|
|
266
320
|
// return URLs (the configured scheme or the universal-link host), consume
|
|
267
321
|
// the navigation here so the app's own link handler never sees it, then
|
|
@@ -269,18 +323,7 @@ public final class PaSdk3dsViewController: UIViewController, WKNavigationDelegat
|
|
|
269
323
|
public func webView(_ webView: WKWebView,
|
|
270
324
|
decidePolicyFor navigationAction: WKNavigationAction,
|
|
271
325
|
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
|
|
272
|
-
let url = navigationAction.request.url
|
|
273
|
-
if let scheme = returnUrlScheme,
|
|
274
|
-
let url = url,
|
|
275
|
-
url.absoluteString.lowercased().hasPrefix(scheme.lowercased()) {
|
|
276
|
-
decisionHandler(.cancel)
|
|
277
|
-
finish(cancelled: false, returnUrlConsumed: true)
|
|
278
|
-
return
|
|
279
|
-
}
|
|
280
|
-
if let host = returnUrlUniversalHost,
|
|
281
|
-
let url = url,
|
|
282
|
-
let hostComponent = URLComponents(url: url, resolvingAgainstBaseURL: false)?.host,
|
|
283
|
-
hostComponent.lowercased().hasSuffix(host.lowercased().replacingOccurrences(of: "https://", with: "")) {
|
|
326
|
+
if let url = navigationAction.request.url, matchesReturnUrl(url.absoluteString) {
|
|
284
327
|
decisionHandler(.cancel)
|
|
285
328
|
finish(cancelled: false, returnUrlConsumed: true)
|
|
286
329
|
return
|
|
@@ -11,13 +11,9 @@
|
|
|
11
11
|
#import <React/RCTBridgeModule.h>
|
|
12
12
|
#import <React/RCTLog.h>
|
|
13
13
|
|
|
14
|
-
#
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
#import "PaSdkReactNative-Swift.h"
|
|
18
|
-
#else
|
|
19
|
-
#import <pa_sdk_react_native/pa_sdk_react_native-Swift.h>
|
|
20
|
-
#endif
|
|
14
|
+
// No #import of the generated "pa_sdk_react_native-Swift.h" here: the
|
|
15
|
+
// RCT_EXTERN_REMAP_MODULE expansion declares @interface PaSdk3dsSwift itself,
|
|
16
|
+
// and importing the Swift header too is a duplicate class interface.
|
|
21
17
|
|
|
22
18
|
@interface RCT_EXTERN_REMAP_MODULE(PaSdk3ds, PaSdk3dsSwift, NSObject)
|
|
23
19
|
|
|
@@ -39,6 +35,17 @@ RCT_EXTERN_METHOD(present:(NSDictionary *)params
|
|
|
39
35
|
/** Dismiss the challenge after the JS poller observed a terminal state. */
|
|
40
36
|
RCT_EXTERN_METHOD(close:(RCTPromiseResolveBlock)resolve)
|
|
41
37
|
|
|
38
|
+
/**
|
|
39
|
+
* App-switch return hook. The app's AppDelegate/SceneDelegate must call this
|
|
40
|
+
* FIRST for every incoming URL and ignore the URL when it resolves YES:
|
|
41
|
+
* resolves YES when a 3DS challenge is pending and the URL matches its
|
|
42
|
+
* return URLs (the challenge is consumed); NO when no challenge is pending
|
|
43
|
+
* or the URL does not match.
|
|
44
|
+
*/
|
|
45
|
+
RCT_EXTERN_METHOD(handleReturnUrl:(NSString *)url
|
|
46
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
47
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
48
|
+
|
|
42
49
|
+ (BOOL)requiresMainQueueSetup
|
|
43
50
|
{
|
|
44
51
|
return NO;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pa-sdk-react-native",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Payment Asia card payment SDK for React Native — headless card validation, tokenization, payment confirmation with built-in 3D Secure, card saving and multi-market merchant accounts.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -39,8 +39,7 @@ const out = [
|
|
|
39
39
|
' * Generated by scripts/generate-locales.js from locales/*.json.',
|
|
40
40
|
' *',
|
|
41
41
|
' * Locale coverage: en-US (complete), zh-TW (complete,',
|
|
42
|
-
' * serves zh_HK/zh-HK), zh-CN (complete), ms-MY (my_MY — complete
|
|
43
|
-
' * falls back to en-US at runtime until translations are supplied).',
|
|
42
|
+
' * serves zh_HK/zh-HK), zh-CN (complete), ms-MY (my_MY — complete).',
|
|
44
43
|
' */',
|
|
45
44
|
'',
|
|
46
45
|
'export interface LocaleMeta {',
|
|
@@ -66,6 +65,27 @@ const out = [
|
|
|
66
65
|
" | 'error.invalid_client_token'",
|
|
67
66
|
" | 'error.origin_not_allowed'",
|
|
68
67
|
" | 'error.font_load_failed'",
|
|
68
|
+
" | 'error.card_declined'",
|
|
69
|
+
" | 'error.insufficient_funds'",
|
|
70
|
+
" | 'error.expired_card'",
|
|
71
|
+
" | 'error.invalid_cvc'",
|
|
72
|
+
" | 'error.invalid_number'",
|
|
73
|
+
" | 'error.unsupported_brand'",
|
|
74
|
+
" | 'error.unsupported_currency'",
|
|
75
|
+
" | 'error.threeds_failed'",
|
|
76
|
+
" | 'error.threeds_cancelled'",
|
|
77
|
+
" | 'error.threeds_not_supported'",
|
|
78
|
+
" | 'error.threeds_no_liability_shift'",
|
|
79
|
+
" | 'error.amount_above_limit'",
|
|
80
|
+
" | 'error.amount_below_limit'",
|
|
81
|
+
" | 'error.frequency_limit'",
|
|
82
|
+
" | 'error.risk_declined'",
|
|
83
|
+
" | 'error.issuer_unavailable'",
|
|
84
|
+
" | 'error.acquirer_unavailable'",
|
|
85
|
+
" | 'error.refund_exceeds_paid'",
|
|
86
|
+
" | 'error.duplicate_confirm'",
|
|
87
|
+
" | 'error.intent_expired'",
|
|
88
|
+
" | 'error.intent_already_final'",
|
|
69
89
|
" | 'field.incomplete_number'",
|
|
70
90
|
" | 'field.invalid_number'",
|
|
71
91
|
" | 'field.incomplete_expiry'",
|