pa-sdk-react-native 3.0.0 → 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.
Files changed (42) hide show
  1. package/README.md +140 -73
  2. package/lib/api.d.ts +17 -8
  3. package/lib/api.js +35 -13
  4. package/lib/confirm.d.ts +32 -20
  5. package/lib/confirm.js +33 -22
  6. package/lib/errors.d.ts +9 -7
  7. package/lib/errors.generated.d.ts +2 -2
  8. package/lib/errors.generated.js +9 -2
  9. package/lib/errors.js +12 -19
  10. package/lib/index.d.ts +4 -4
  11. package/lib/index.js +11 -10
  12. package/lib/init.d.ts +8 -8
  13. package/lib/init.js +11 -8
  14. package/lib/locales.d.ts +20 -10
  15. package/lib/locales.generated.d.ts +3 -4
  16. package/lib/locales.generated.js +110 -27
  17. package/lib/locales.js +62 -14
  18. package/lib/poll.d.ts +3 -3
  19. package/lib/poll.js +4 -4
  20. package/lib/threeDs.d.ts +17 -6
  21. package/lib/threeDs.js +24 -2
  22. package/lib/threeDsHost.d.ts +2 -2
  23. package/lib/threeDsHost.js +3 -3
  24. package/lib/tokenize.d.ts +9 -4
  25. package/lib/tokenize.js +6 -4
  26. package/lib/types.d.ts +33 -26
  27. package/lib/types.js +4 -5
  28. package/lib/validator.d.ts +8 -8
  29. package/lib/validator.js +9 -10
  30. package/locales/en-US.json +21 -0
  31. package/locales/ms-MY.json +45 -24
  32. package/locales/zh-CN.json +21 -0
  33. package/locales/zh-TW.json +21 -0
  34. package/native/android/build.gradle +4 -4
  35. package/native/android/src/main/AndroidManifest.xml +12 -11
  36. package/native/android/src/main/java/com/pasdk/reactnative/PaSdk3dsActivity.kt +9 -16
  37. package/native/android/src/main/java/com/pasdk/reactnative/PaSdk3dsModule.kt +3 -3
  38. package/native/ios/PaSdk3ds.swift +64 -21
  39. package/native/ios/PaSdk3dsModule.m +16 -9
  40. package/package.json +3 -3
  41. package/scripts/generate-errors.js +2 -2
  42. package/scripts/generate-locales.js +24 -4
package/lib/confirm.js CHANGED
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  /**
3
- * Confirm orchestration (RN-14 / RN-16 / COM-05..COM-08 / COM-12).
3
+ * Confirm orchestration.
4
4
  *
5
5
  * Both mandatory forms are exported:
6
6
  * - confirmWithToken() — the two-step flow: tokenizeCard() first, then
7
- * confirm with the pa_token (RN-14 "the two-step form must exist").
7
+ * confirm with the pa_token.
8
8
  * - confirmWithCard() — combined convenience call: validates, tokenizes
9
9
  * and confirms in one await.
10
10
  *
11
- * Exactly one final result per confirm (COM-05): any 3DS runs inside the
12
- * call (SDK-presented WebView, RN-19); requires_action / processing are
11
+ * Exactly one final result per confirm: any 3DS runs inside the
12
+ * call (SDK-presented WebView); requires_action / processing are
13
13
  * polled until terminal; when the poll budget is exhausted the result is
14
- * `processing`, never `failed` (COM-06).
14
+ * `processing`, never `failed`.
15
15
  */
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.AlreadyFinalError = void 0;
@@ -27,19 +27,19 @@ const tokenize_1 = require("./tokenize");
27
27
  const init_1 = require("./init");
28
28
  const validator_1 = require("./validator");
29
29
  // ---------------------------------------------------------------------------
30
- // Client-side double-confirm guard (COM-13)
30
+ // Client-side double-confirm guard
31
31
  const inFlight = new Set();
32
32
  const finalResults = new Map();
33
33
  function guardStart(intentToken) {
34
34
  const previous = finalResults.get(intentToken);
35
35
  if (previous) {
36
36
  // Confirming an intent already final returns that state, without
37
- // charging again (COM-13, second half).
37
+ // charging again.
38
38
  throw new AlreadyFinalError(previous);
39
39
  }
40
40
  if (inFlight.has(intentToken)) {
41
41
  throw new errors_1.PaError('duplicate_confirm', {
42
- developerMessage: 'A confirm is already in progress for this intent (COM-13).',
42
+ developerMessage: 'A confirm is already in progress for this intent.',
43
43
  });
44
44
  }
45
45
  inFlight.add(intentToken);
@@ -53,7 +53,7 @@ function guardEnd(intentToken, result) {
53
53
  class AlreadyFinalError extends errors_1.PaError {
54
54
  constructor(result) {
55
55
  super('intent_already_final', {
56
- developerMessage: 'This intent already reached a final state (COM-13); the stored result is returned instead.',
56
+ developerMessage: 'This intent already reached a final state; the stored result is returned instead.',
57
57
  });
58
58
  this.name = 'AlreadyFinalError';
59
59
  this.result = result;
@@ -61,10 +61,10 @@ class AlreadyFinalError extends errors_1.PaError {
61
61
  }
62
62
  exports.AlreadyFinalError = AlreadyFinalError;
63
63
  // ---------------------------------------------------------------------------
64
- // Status mapping (A3)
64
+ // Status mapping
65
65
  const TERMINAL_STATUS = {
66
66
  succeeded: 'succeeded',
67
- requires_capture: 'authorized', // RN-16: authorized (pre-auth) is success
67
+ requires_capture: 'authorized', // authorized (pre-auth) is success
68
68
  failed: 'failed',
69
69
  cancelled: 'cancelled',
70
70
  };
@@ -88,7 +88,7 @@ function payloadToResult(status, payload, intentToken) {
88
88
  };
89
89
  }
90
90
  // ---------------------------------------------------------------------------
91
- // Billing pass-through (COM-23)
91
+ // Billing pass-through
92
92
  function billingToGateway(billing) {
93
93
  if (!billing) {
94
94
  return undefined;
@@ -136,7 +136,7 @@ async function handleThreeDs(api, options, threedsData) {
136
136
  fields.JWT = threedsData.jwt;
137
137
  }
138
138
  else if (threedsData.acs_url && threedsData.creq) {
139
- // 3DS1 / non-3DS2 ACS fallback (RN-18): POST the creq to the ACS.
139
+ // 3DS1 / non-3DS2 ACS fallback: POST the creq to the ACS.
140
140
  url = threedsData.acs_url;
141
141
  fields.creq = threedsData.creq;
142
142
  }
@@ -177,7 +177,7 @@ async function handleThreeDs(api, options, threedsData) {
177
177
  }, options.onThreeDsWillPresent);
178
178
  }
179
179
  catch (cause) {
180
- // Challenge UI failed to appear — not a payment result (COM-08). Keep
180
+ // Challenge UI failed to appear — not a payment result. Keep
181
181
  // polling the intent; worst case resolves `processing`.
182
182
  presentFailure = cause;
183
183
  }
@@ -185,7 +185,7 @@ async function handleThreeDs(api, options, threedsData) {
185
185
  options.onThreeDsEnded();
186
186
  }
187
187
  if (dismissal && dismissal.cancelled) {
188
- // User closed the challenge -> cancelled (A3 / WEB-49 analog). Tell the
188
+ // User closed the challenge -> cancelled. Tell the
189
189
  // gateway best-effort so the intent does not linger in requires_action.
190
190
  poller.stop();
191
191
  try {
@@ -223,7 +223,7 @@ async function handleThreeDs(api, options, threedsData) {
223
223
  });
224
224
  }
225
225
  // Budget exhausted with the challenge closed and no terminal state —
226
- // `processing`, never `failed` (COM-06 / RN-28).
226
+ // `processing`, never `failed`.
227
227
  return { result: null, cancelled: false };
228
228
  }
229
229
  // ---------------------------------------------------------------------------
@@ -243,7 +243,7 @@ function processingResult(intentToken) {
243
243
  };
244
244
  }
245
245
  /**
246
- * Confirm a payment intent with a tokenized card (RN-14, mandatory two-step:
246
+ * Confirm a payment intent with a tokenized card (mandatory two-step:
247
247
  * tokenizeCard() -> confirmWithToken()).
248
248
  */
249
249
  async function confirmWithToken(options) {
@@ -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);
@@ -269,11 +274,11 @@ async function confirmWithToken(options) {
269
274
  }
270
275
  }
271
276
  /**
272
- * Combined confirm: validate + tokenize + confirm in one call (RN-14,
273
- * "a single combined confirm with card details is welcome in addition").
274
- * Throws the COM-26 field codes before any network call when validation fails.
277
+ * Combined confirm: validate + tokenize + confirm in one call.
278
+ * Throws the shared field codes before any network call when validation fails.
275
279
  */
276
280
  async function confirmWithCard(options) {
281
+ var _a, _b;
277
282
  const sdk = (0, init_1.getSdk)();
278
283
  const account = sdk.accountFor(options.market);
279
284
  const validation = (0, validator_1.validateCard)(options.card, options.allowedBrands);
@@ -291,6 +296,8 @@ async function confirmWithCard(options) {
291
296
  const output = await (0, tokenize_1.tokenizeCard)(sdk.api, {
292
297
  card: options.card,
293
298
  merchantToken: account.merchantToken,
299
+ merchantReference: options.merchantReference,
300
+ metadata: options.metadata,
294
301
  });
295
302
  tokenized = output.result;
296
303
  }
@@ -298,7 +305,11 @@ async function confirmWithCard(options) {
298
305
  inFlight.delete(options.intentToken);
299
306
  throw error;
300
307
  }
301
- return confirmWithToken({ ...options, paToken: tokenized.paToken });
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 });
302
313
  }
303
314
  /** Drive a confirm payload to its single final result. */
304
315
  async function settle(api, options, payload, paToken) {
@@ -332,7 +343,7 @@ async function settle(api, options, payload, paToken) {
332
343
  });
333
344
  return polled || processingResult(options.intentToken);
334
345
  }
335
- /** Cancel an intent explicitly (A3 `cancelled` via intent-cancel). */
346
+ /** Cancel an intent explicitly (resolves `cancelled` via intent-cancel). */
336
347
  async function cancelIntent(options) {
337
348
  const sdk = (0, init_1.getSdk)();
338
349
  await sdk.api.intentCancel({
package/lib/errors.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Typed errors (COM-08 / COM-24 / COM-27 / RN-29).
2
+ * Typed errors.
3
3
  *
4
4
  * Every rejection is a PaError carrying:
5
5
  * - `code` — a stable code from the shared table (src/errors.generated.ts)
@@ -7,10 +7,12 @@
7
7
  * - `userMessage` — a localized user message the app may show directly
8
8
  *
9
9
  * Technical failures (network, not initialised, 3DS UI unavailable) reject
10
- * with a PaError too — they are never reported as payment results (COM-08).
10
+ * with a PaError too — they are never reported as payment results.
11
11
  */
12
- /** Localized user message for a shared-table code (COM-28, RN-29). Falls back
13
- * to `error.generic` when the code has no dedicated string. */
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). */
@@ -21,18 +23,18 @@ export interface PaErrorOptions {
21
23
  cause?: unknown;
22
24
  }
23
25
  export declare class PaError extends Error {
24
- /** Shared-table code (A8) or a field code (COM-26). */
26
+ /** Shared-table code or a field code. */
25
27
  readonly code: string;
26
28
  /** English developer message from the shared table. */
27
29
  readonly developerMessage: string;
28
- /** Localized user message — the app shows this and logs `code` (RN-29). */
30
+ /** Localized user message — the app shows this and logs `code`. */
29
31
  readonly userMessage: string;
30
32
  /** True when this is a field-validation error rather than a payment error. */
31
33
  readonly isFieldError: boolean;
32
34
  constructor(code: string, options?: PaErrorOptions);
33
35
  }
34
36
  export declare function isPaError(value: unknown): value is PaError;
35
- /** Thrown when the SDK is used before init() (COM-08). */
37
+ /** Thrown when the SDK is used before init(). */
36
38
  export declare class NotInitializedError extends PaError {
37
39
  constructor();
38
40
  }
@@ -1,10 +1,10 @@
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-10-20T04:13:44+00:00.
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
- * React Native SDK (requirement COM-24). Values are English developer
7
+ * React Native SDK. Values are English developer
8
8
  * messages; localized user messages live in the locale bundles.
9
9
  */
10
10
  export declare const ERROR_TABLE_VERSION: number;
@@ -3,10 +3,10 @@
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-10-20T04:13:44+00:00.
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
- * React Native SDK (requirement COM-24). Values are English developer
9
+ * React Native SDK. Values are English developer
10
10
  * messages; localized user messages live in the locale bundles.
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * Typed errors (COM-08 / COM-24 / COM-27 / RN-29).
3
+ * Typed errors.
4
4
  *
5
5
  * Every rejection is a PaError carrying:
6
6
  * - `code` — a stable code from the shared table (src/errors.generated.ts)
@@ -8,7 +8,7 @@
8
8
  * - `userMessage` — a localized user message the app may show directly
9
9
  *
10
10
  * Technical failures (network, not initialised, 3DS UI unavailable) reject
11
- * with a PaError too — they are never reported as payment results (COM-08).
11
+ * with a PaError too — they are never reported as payment results.
12
12
  */
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.NotInitializedError = exports.PaError = void 0;
@@ -16,7 +16,7 @@ exports.userMessageForCode = userMessageForCode;
16
16
  exports.isPaError = isPaError;
17
17
  const errors_generated_1 = require("./errors.generated");
18
18
  const locales_1 = require("./locales");
19
- /** Codes that are validation field codes (COM-26) — user message key `field.<code>`. */
19
+ /** Codes that are validation field codes — user message key `field.<code>`. */
20
20
  const FIELD_CODE_PREFIX = 'field.';
21
21
  const FIELD_CODES = new Set([
22
22
  'incomplete_number',
@@ -27,26 +27,19 @@ const FIELD_CODES = new Set([
27
27
  'invalid_cvc',
28
28
  'unsupported_brand',
29
29
  ]);
30
- /** Localized-message keys the locale bundles actually ship. */
31
- const LOCALIZED_ERROR_KEYS = new Set([
32
- 'rate_limited',
33
- 'processing_timeout',
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 (COM-28, RN-29). 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 {
@@ -68,7 +61,7 @@ exports.PaError = PaError;
68
61
  function isPaError(value) {
69
62
  return value instanceof PaError;
70
63
  }
71
- /** Thrown when the SDK is used before init() (COM-08). */
64
+ /** Thrown when the SDK is used before init(). */
72
65
  class NotInitializedError extends PaError {
73
66
  constructor() {
74
67
  super('internal_error', {
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * PA SDK React Native — public entry point.
3
3
  *
4
- * Headless card SDK for React Native (requirements D4): Flow builds its own
4
+ * Headless card SDK for React Native: the app builds its own
5
5
  * card UI; the SDK provides validation, tokenization, confirm with built-in
6
6
  * 3DS, save-card and multi-market merchant accounts.
7
7
  *
@@ -17,8 +17,8 @@
17
17
  *
18
18
  * const result = await PaSdk.confirmWithCard({
19
19
  * card: { cardNumber: '4242...', expiryMonth: 12, expiryYear: 29, cvc: '123' },
20
- * intentToken, clientToken, // from Flow's server only (COM-01)
21
- * idempotencyKey: myUuid, // COM-12
20
+ * intentToken, clientToken, // from your server only
21
+ * idempotencyKey: myUuid,
22
22
  * saveCard: saveChecked,
23
23
  * onThreeDsWillPresent: () => hideLoadingOverlay(),
24
24
  * });
@@ -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
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * PA SDK React Native — public entry point.
4
4
  *
5
- * Headless card SDK for React Native (requirements D4): Flow builds its own
5
+ * Headless card SDK for React Native: the app builds its own
6
6
  * card UI; the SDK provides validation, tokenization, confirm with built-in
7
7
  * 3DS, save-card and multi-market merchant accounts.
8
8
  *
@@ -18,15 +18,15 @@
18
18
  *
19
19
  * const result = await PaSdk.confirmWithCard({
20
20
  * card: { cardNumber: '4242...', expiryMonth: 12, expiryYear: 29, cvc: '123' },
21
- * intentToken, clientToken, // from Flow's server only (COM-01)
22
- * idempotencyKey: myUuid, // COM-12
21
+ * intentToken, clientToken, // from your server only
22
+ * idempotencyKey: myUuid,
23
23
  * saveCard: saveChecked,
24
24
  * onThreeDsWillPresent: () => hideLoadingOverlay(),
25
25
  * });
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; } });
@@ -34,7 +34,7 @@ Object.defineProperty(exports, "getSdk", { enumerable: true, get: function () {
34
34
  Object.defineProperty(exports, "getSdkOrNull", { enumerable: true, get: function () { return init_1.getSdkOrNull; } });
35
35
  Object.defineProperty(exports, "updateLocale", { enumerable: true, get: function () { return init_1.updateLocale; } });
36
36
  Object.defineProperty(exports, "deinitialize", { enumerable: true, get: function () { return init_1.deinitialize; } });
37
- // validation (RN-12)
37
+ // validation
38
38
  var validator_1 = require("./validator");
39
39
  Object.defineProperty(exports, "detectBrand", { enumerable: true, get: function () { return validator_1.detectBrand; } });
40
40
  Object.defineProperty(exports, "luhnValid", { enumerable: true, get: function () { return validator_1.luhnValid; } });
@@ -44,11 +44,11 @@ Object.defineProperty(exports, "validateCardNumber", { enumerable: true, get: fu
44
44
  Object.defineProperty(exports, "validateCvc", { enumerable: true, get: function () { return validator_1.validateCvc; } });
45
45
  Object.defineProperty(exports, "validateExpiry", { enumerable: true, get: function () { return validator_1.validateExpiry; } });
46
46
  Object.defineProperty(exports, "cvcLengthsForBrand", { enumerable: true, get: function () { return validator_1.cvcLengthsForBrand; } });
47
- // tokenization (RN-13)
47
+ // tokenization
48
48
  var tokenize_1 = require("./tokenize");
49
49
  Object.defineProperty(exports, "createElementSession", { enumerable: true, get: function () { return tokenize_1.createElementSession; } });
50
50
  Object.defineProperty(exports, "tokenizeCard", { enumerable: true, get: function () { return tokenize_1.tokenizeCard; } });
51
- // confirm (RN-14 / RN-16) — both forms
51
+ // confirm — both forms
52
52
  var confirm_1 = require("./confirm");
53
53
  Object.defineProperty(exports, "confirmWithToken", { enumerable: true, get: function () { return confirm_1.confirmWithToken; } });
54
54
  Object.defineProperty(exports, "confirmWithCard", { enumerable: true, get: function () { return confirm_1.confirmWithCard; } });
@@ -60,13 +60,13 @@ var poll_1 = require("./poll");
60
60
  Object.defineProperty(exports, "AppStateAwarePoller", { enumerable: true, get: function () { return poll_1.AppStateAwarePoller; } });
61
61
  Object.defineProperty(exports, "pollUntil", { enumerable: true, get: function () { return poll_1.pollUntil; } });
62
62
  Object.defineProperty(exports, "DEFAULT_POLLER_OPTIONS", { enumerable: true, get: function () { return poll_1.DEFAULT_POLLER_OPTIONS; } });
63
- // errors (RN-29)
63
+ // errors
64
64
  var errors_1 = require("./errors");
65
65
  Object.defineProperty(exports, "PaError", { enumerable: true, get: function () { return errors_1.PaError; } });
66
66
  Object.defineProperty(exports, "isPaError", { enumerable: true, get: function () { return errors_1.isPaError; } });
67
67
  Object.defineProperty(exports, "userMessageForCode", { enumerable: true, get: function () { return errors_1.userMessageForCode; } });
68
68
  Object.defineProperty(exports, "NotInitializedError", { enumerable: true, get: function () { return errors_1.NotInitializedError; } });
69
- // locales (A10 / COM-28)
69
+ // locales
70
70
  var locales_1 = require("./locales");
71
71
  Object.defineProperty(exports, "DEFAULT_LOCALE", { enumerable: true, get: function () { return locales_1.DEFAULT_LOCALE; } });
72
72
  Object.defineProperty(exports, "SUPPORTED_LOCALES", { enumerable: true, get: function () { return locales_1.SUPPORTED_LOCALES; } });
@@ -75,10 +75,11 @@ Object.defineProperty(exports, "getLocaleStrings", { enumerable: true, get: func
75
75
  Object.defineProperty(exports, "normalizeLocale", { enumerable: true, get: function () { return locales_1.normalizeLocale; } });
76
76
  Object.defineProperty(exports, "resolveBundle", { enumerable: true, get: function () { return locales_1.resolveBundle; } });
77
77
  Object.defineProperty(exports, "setLocale", { enumerable: true, get: function () { return locales_1.setLocale; } });
78
- // 3DS bridge + fallback host (RN-18..RN-20)
78
+ // 3DS bridge + fallback host
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.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * SDK initialisation (RN-08 / RN-09 / COM-03 / COM-40).
2
+ * SDK initialisation.
3
3
  *
4
4
  * One initialisation serves multiple merchant accounts: `accounts` maps a
5
5
  * market key (e.g. "HK", "MY", "SG", "TW") to that market's publishable
6
6
  * merchantToken. Currency and country are per intent — never per init.
7
- * Environment is selected once, from the app's build config (COM-03).
8
- * No secret key is ever passed here — only publishable tokens (COM-01).
7
+ * Environment is selected once, from the app's build config.
8
+ * No secret key is ever passed here — only publishable tokens.
9
9
  */
10
10
  import { ApiClient } from './api';
11
11
  import type { Environment, InitOptions } from './types';
@@ -22,7 +22,7 @@ export interface PaSdkInstance {
22
22
  /** Resolve the account for a market (or the default). */
23
23
  accountFor(market?: string): PaAccount;
24
24
  api: ApiClient;
25
- /** 3DS return URL config (RN-20). */
25
+ /** 3DS return URL config. */
26
26
  threeDsReturnUrls?: {
27
27
  scheme?: string;
28
28
  universalLinkHost?: string;
@@ -31,17 +31,17 @@ export interface PaSdkInstance {
31
31
  /**
32
32
  * Initialise the SDK. Call once, early (app start / payment screen mount).
33
33
  * Re-initialising replaces the previous configuration (useful for
34
- * locale changes via destroy-and-re-init, COM-35).
34
+ * locale changes via destroy-and-re-init).
35
35
  *
36
36
  * @throws PaError `request_invalid` when options are malformed (never a
37
- * payment result — COM-08).
37
+ * payment result).
38
38
  */
39
39
  export declare function init(options: InitOptions): PaSdkInstance;
40
- /** The current instance; throws NotInitializedError before init() (COM-08). */
40
+ /** The current instance; throws NotInitializedError before init(). */
41
41
  export declare function getSdk(): PaSdkInstance;
42
42
  /** Like getSdk() but returns null instead of throwing. */
43
43
  export declare function getSdkOrNull(): PaSdkInstance | null;
44
- /** Change the locale at runtime without re-initialising (COM-35). */
44
+ /** Change the locale at runtime without re-initialising. */
45
45
  export declare function updateLocale(locale: string): void;
46
46
  /** Drop the current configuration (e.g. logout). */
47
47
  export declare function deinitialize(): void;
package/lib/init.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  /**
3
- * SDK initialisation (RN-08 / RN-09 / COM-03 / COM-40).
3
+ * SDK initialisation.
4
4
  *
5
5
  * One initialisation serves multiple merchant accounts: `accounts` maps a
6
6
  * market key (e.g. "HK", "MY", "SG", "TW") to that market's publishable
7
7
  * merchantToken. Currency and country are per intent — never per init.
8
- * Environment is selected once, from the app's build config (COM-03).
9
- * No secret key is ever passed here — only publishable tokens (COM-01).
8
+ * Environment is selected once, from the app's build config.
9
+ * No secret key is ever passed here — only publishable tokens.
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.init = init;
@@ -21,10 +21,10 @@ let instance = null;
21
21
  /**
22
22
  * Initialise the SDK. Call once, early (app start / payment screen mount).
23
23
  * Re-initialising replaces the previous configuration (useful for
24
- * locale changes via destroy-and-re-init, COM-35).
24
+ * locale changes via destroy-and-re-init).
25
25
  *
26
26
  * @throws PaError `request_invalid` when options are malformed (never a
27
- * payment result — COM-08).
27
+ * payment result).
28
28
  */
29
29
  function init(options) {
30
30
  if (!options || (options.environment !== 'production' && options.environment !== 'sandbox')) {
@@ -52,8 +52,10 @@ function init(options) {
52
52
  }
53
53
  }
54
54
  if (options.locale) {
55
- (0, locales_1.setLocale)(options.locale); // COM-34/35 — accepted in any tag form
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 },
@@ -73,7 +75,7 @@ function init(options) {
73
75
  };
74
76
  return instance;
75
77
  }
76
- /** The current instance; throws NotInitializedError before init() (COM-08). */
78
+ /** The current instance; throws NotInitializedError before init(). */
77
79
  function getSdk() {
78
80
  if (!instance) {
79
81
  throw new errors_1.PaError('internal_error', {
@@ -86,11 +88,12 @@ function getSdk() {
86
88
  function getSdkOrNull() {
87
89
  return instance;
88
90
  }
89
- /** Change the locale at runtime without re-initialising (COM-35). */
91
+ /** Change the locale at runtime without re-initialising. */
90
92
  function updateLocale(locale) {
91
93
  (0, locales_1.setLocale)(locale);
92
94
  }
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
@@ -1,13 +1,16 @@
1
1
  /**
2
- * Locale resolution (A10).
2
+ * Locale resolution.
3
3
  *
4
- * - COM-34: tags accepted in underscore or hyphen form, case-insensitively
4
+ * - tags accepted in underscore or hyphen form, case-insensitively
5
5
  * (`zh_HK`, `zh-HK`, `zh-hk`).
6
- * - COM-35: locale can be changed at runtime via setLocale() without reload.
7
- * - COM-36: unsupported / unknown locale never errors — fallback chain
8
- * exact tag -> same language -> en-US.
9
- * - zh_HK maps to zh-TW strings (documented in A10 as acceptable).
10
- * - ms-MY (my_MY) ships incomplete and falls back to en-US per its _meta.
6
+ * - locale can be changed at runtime via setLocale() without reload.
7
+ * - unsupported / unknown locale never errors — fallback chain
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).
11
+ * - zh_HK maps to zh-TW strings.
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,9 +18,12 @@ 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
- /** The bundle for a tag with the COM-36 fallback chain applied: exact tag ->
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.
22
28
  * Incomplete bundles (ms-MY today) keep their non-empty strings and take the
23
29
  * rest from the fallback, so no empty string ever reaches the UI. */
@@ -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 COM-36 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;