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/README.md CHANGED
@@ -1,26 +1,27 @@
1
1
  # PA SDK React Native
2
2
 
3
3
  **Payment Asia card payment SDK for React Native** — headless card validation,
4
- direct tokenization, confirm with built-in 3D Secure, save-card and
5
- multi-market merchant accounts. The native-app counterpart of the PASDK web
6
- SDK, built to the Flow Travel unified requirements (deliverable D4).
4
+ direct tokenization, payment confirmation with built-in 3D Secure
5
+ (SDK-presented challenge), card saving, and multi-market merchant accounts.
6
+ Shares its error codes, locales and gateway contract with the PA SDK web
7
+ component.
7
8
 
8
9
  - Scope: **Visa and Mastercard** (other schemes are detected early so the app
9
10
  can block them).
10
- - Result states (exactly five, A3): `succeeded` · `authorized` · `processing`
11
- · `cancelled` · `failed`. `requires_action` is never resolved (COM-05);
12
- unknown outcomes resolve `processing`, never `failed` (COM-06).
11
+ - Result states (exactly five): `succeeded` · `authorized` · `processing`
12
+ · `cancelled` · `failed`. Unknown outcomes resolve `processing`, never
13
+ `failed`.
13
14
 
14
15
  ## Requirements
15
16
 
16
17
  | | |
17
18
  |---|---|
18
- | React Native | >= 0.79 (developed against 0.79; New Architecture + Hermes, RN-01/RN-02) |
19
- | iOS | 13.0+ (Flow floor 15 — RN-03) |
20
- | Android | API 24+ (RN-03) |
19
+ | React Native | >= 0.79 (New Architecture + Hermes) |
20
+ | iOS | 13.0+ |
21
+ | Android | API 24+ (Android 7.0) |
21
22
  | Native dependency | `react-native-webview` ^13 (used by the JS fallback presenter; the primary 3DS presenter is the SDK's own native WebView) |
22
23
 
23
- No other native dependencies — no ads, analytics or billing SDKs (RN-05).
24
+ No other native dependencies — no ads, analytics or billing SDKs.
24
25
 
25
26
  ## Install
26
27
 
@@ -39,33 +40,45 @@ cd ios && pod install && cd ..
39
40
  The native 3DS module is a classic NativeModules bridge
40
41
  (`native/ios/PaSdk3dsModule.m` + `PaSdk3ds.swift`). It runs unchanged on the
41
42
  New Architecture through React Native's interop layer — no codegen setup
42
- needed. (A TurboModule codegen spec can be added later without changing the
43
- JS API.)
43
+ needed.
44
44
 
45
45
  ### Android
46
46
 
47
- Autolinking picks up `native/android` — no manual gradle edits. The manifest
48
- of the library registers `PaSdk3dsActivity` with intent-filters for the 3DS
49
- return URLs:
47
+ Autolinking picks up `native/android` — the only setup is the return-URL
48
+ placeholders. The library manifest registers a full-screen 3DS challenge
49
+ activity (`PaSdk3dsActivity`) whose intent-filters read two manifest
50
+ placeholders. Define your 3DS return URLs once in your app's
51
+ `android/app/build.gradle`:
52
+
53
+ ```gradle
54
+ android {
55
+ defaultConfig {
56
+ manifestPlaceholders = [
57
+ paSdk3dsReturnScheme: "yourapp", // custom scheme, no "://"
58
+ paSdk3dsReturnHost: "links.yourdomain.com" // universal-link host, no "https://"
59
+ ]
60
+ }
61
+ }
62
+ ```
50
63
 
51
- - custom scheme `flow://`
52
- - universal-link host `https://app.flowtheroom.com`
64
+ The build fails if the placeholders are missing, so a missing configuration
65
+ is caught before release, not in production. The values must match the
66
+ `threeDsReturnUrls` you pass to `init()`.
53
67
 
54
- While a challenge is pending, the SDK **consumes** its own 3DS returns there;
55
- the app's own deep-link handler never sees them (RN-20). When no challenge is
56
- pending, the activity re-dispatches the URI to the app's launch intent, so
57
- Flow's normal link handling proceeds. Do not declare overlapping
58
- intent-filters for these exact paths if you also want to handle them yourself
59
- in production beyond 3DS.
68
+ While a challenge is pending, the SDK **consumes** its own 3DS return URIs
69
+ (the custom scheme and universal-link host above); the app's own deep-link
70
+ handler never sees them. When no challenge is pending, matched URIs are
71
+ re-dispatched to the app's launch intent, so the app's normal link handling
72
+ proceeds. Do not declare overlapping intent-filters for those exact paths
73
+ unless you also want to handle them outside 3DS.
60
74
 
61
75
  ## Quickstart
62
76
 
63
77
  ```tsx
64
78
  import { PaSdk3dsHost } from 'pa-sdk-react-native'; // optional JS 3DS fallback
65
79
 
66
- // 1. Init — once, from build config (COM-03). One init, many merchant
67
- // accounts (COM-40). Publishable merchant tokens only — never a secret
68
- // key (COM-01).
80
+ // 1. Init — once, from your app's build config. One init, many merchant
81
+ // accounts. Publishable merchant tokens only — never a secret key.
69
82
  import { init } from 'pa-sdk-react-native';
70
83
 
71
84
  init({
@@ -77,11 +90,11 @@ init({
77
90
  TW: 'mt_tw_...',
78
91
  },
79
92
  defaultAccount: 'HK',
80
- locale: 'zh_HK', // en_US / zh_HK / zh_CN / my_MY (A10)
81
- origin: 'https://app.flowtheroom.com',
82
- threeDsReturnUrls: { // consumed by the SDK (RN-20)
83
- scheme: 'flow://',
84
- universalLinkHost: 'https://app.flowtheroom.com',
93
+ locale: 'zh_HK', // en_US / zh_HK / zh_CN / my_MY
94
+ origin: 'https://app.yourdomain.com',
95
+ threeDsReturnUrls: { // consumed by the SDK
96
+ scheme: 'yourapp://',
97
+ universalLinkHost: 'https://links.yourdomain.com',
85
98
  },
86
99
  });
87
100
 
@@ -89,31 +102,31 @@ init({
89
102
  // <PaSdk3dsHost />
90
103
  ```
91
104
 
92
- ### Flow 1 — one-off payment (combined, RN-14)
105
+ ### One-off payment (combined)
93
106
 
94
107
  ```tsx
95
108
  import { confirmWithCard } from 'pa-sdk-react-native';
96
109
 
97
110
  const result = await confirmWithCard({
98
111
  card: { cardNumber, expiryMonth, expiryYear, cvc, cardHolderName }, // from YOUR UI
99
- intentToken, clientToken, // from Flow's server only (COM-01)
100
- idempotencyKey, // yours, unique per attempt (COM-12 / RN-30)
101
- allowedBrands: ['visa', 'mastercard'], // from your server (RN-12)
102
- onThreeDsWillPresent: () => hideLoadingOverlay(), // RN-19
103
- market: 'HK', // merchant account selection (COM-40)
112
+ intentToken, clientToken, // from your server only
113
+ idempotencyKey, // yours, unique per attempt
114
+ allowedBrands: ['visa', 'mastercard'], // from your server
115
+ onThreeDsWillPresent: () => hideLoadingOverlay(),
116
+ market: 'HK', // merchant account selection
104
117
  });
105
118
  // result.status: 'succeeded' | 'authorized' | 'processing' | 'cancelled' | 'failed'
106
119
  ```
107
120
 
108
- ### Flow 2 — two-step (mandatory form, RN-14)
121
+ ### Two-step payment (tokenize + confirm)
109
122
 
110
123
  ```tsx
111
124
  import { tokenizeCard, confirmWithToken } from 'pa-sdk-react-native';
112
125
 
113
- // Step 1: card data goes straight to PA (COM-02)
126
+ // Step 1: card data goes straight to PA, never through your app's server
114
127
  const { result: token } = await tokenizeCard(getSdk().api, {
115
128
  card,
116
- merchantToken: 'mt_hk_...', // per-market publishable token (COM-41)
129
+ merchantToken: 'mt_hk_...', // per-market publishable token
117
130
  });
118
131
  // token = { paToken, last4, brand }
119
132
 
@@ -125,24 +138,24 @@ const result = await confirmWithToken({
125
138
  });
126
139
  ```
127
140
 
128
- ### Flow 3 — save during payment (COM-14 / RN-23)
141
+ ### Save the card during payment
129
142
 
130
143
  ```tsx
131
144
  const result = await confirmWithCard({ card, intentToken, clientToken,
132
145
  saveCard: true, idempotencyKey });
133
- // result.paToken / result.brand / result.last4 arrive synchronously (COM-16).
134
- // The token is MIT-ready: Flow's server charges it later via the Backend
135
- // Recurring Payment API (/recurring/pay, COM-18) or an intent-based
136
- // server-side confirm — PASDK's /charge endpoint was disabled on 2026-11-13.
146
+ // result.paToken / result.brand / result.last4 arrive synchronously.
147
+ // The token is MIT-ready: your server charges it later via the Backend
148
+ // Recurring Payment API (/recurring/pay) or an intent-based server-side
149
+ // confirm.
137
150
  ```
138
151
 
139
- ### Flow 4 — manual save / add card (COM-15 / RN-24)
152
+ ### Add a card without paying (verification intent)
140
153
 
141
154
  Same call against a **verification intent** your server creates (zero amount,
142
155
  or a minimal amount settable per request). `saveCard: true`, 3DS runs if the
143
156
  issuer requires it; nothing is charged; `pa_token` returns synchronously.
144
157
 
145
- ### Flow 5 — 3DS (RN-18..RN-20)
158
+ ### 3D Secure
146
159
 
147
160
  Everything is inside confirm:
148
161
 
@@ -157,14 +170,38 @@ Everything is inside confirm:
157
170
  - App-switch (banking app): polling is **AppState-aware** — the schedule is
158
171
  2s x 15 then 5s x 12, suspended time while backgrounded does not count
159
172
  against the budget, and polling resumes on return. Budget exhausted with
160
- no answer → `processing` (COM-06), never `failed`.
161
- - The challenge's return URLs (`flow://`, universal link) are consumed by the
162
- SDK without surfacing to the app's link handler.
173
+ no answer → `processing`, never `failed`.
174
+ - The challenge's return URLs (configured scheme + universal link) are
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.
163
200
 
164
- ### Flow 6 — multi-market (COM-40)
201
+ ### Multi-market
165
202
 
166
203
  One init; pick the account per call with `market`. Currency and country are
167
- per intent on your server (COM-39).
204
+ per intent on your server.
168
205
 
169
206
  ### Cancel an intent
170
207
 
@@ -173,7 +210,26 @@ import { cancelIntent } from 'pa-sdk-react-native';
173
210
  await cancelIntent({ intentToken, clientToken }); // -> { status: 'cancelled' }
174
211
  ```
175
212
 
176
- ## Validation helpers (RN-12)
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
+
232
+ ## Validation helpers
177
233
 
178
234
  ```tsx
179
235
  import { validateCard, validateCardNumber, validateExpiry, validateCvc, detectBrand } from 'pa-sdk-react-native';
@@ -182,15 +238,15 @@ detectBrand('222100...').brand // 'mastercard' — 2-series 2221–2720 recogn
182
238
  validateCardNumber('4242...', ['visa']) // Luhn, length, brand filter
183
239
  validateCard(card, ['visa', 'mastercard'])
184
240
  // -> { brand, complete, fields: { cardNumber?, expiry?, cvc? } }
185
- // field codes (COM-26): incomplete_number, invalid_number, incomplete_expiry,
241
+ // field codes: incomplete_number, invalid_number, incomplete_expiry,
186
242
  // invalid_expiry, incomplete_cvc, invalid_cvc, unsupported_brand
187
243
  ```
188
244
 
189
245
  Rules: Visa/Mastercard lengths, Luhn, current BIN ranges (Mastercard 2-series
190
246
  2221–2720 included), 3-digit CVC, expiry not in the past — no valid Visa /
191
- Mastercard is ever blocked (COM-31).
247
+ Mastercard is ever blocked.
192
248
 
193
- ## Results and errors (RN-28 / RN-29)
249
+ ## Results and errors
194
250
 
195
251
  ```ts
196
252
  interface PaymentResult {
@@ -201,27 +257,37 @@ interface PaymentResult {
201
257
  paToken?: string | null; // set when a card was saved
202
258
  brand?: string | null;
203
259
  last4?: string | null;
204
- errorCode?: string | null; // shared table (A8) for 'failed'
260
+ errorCode?: string | null; // shared error-code table, for 'failed'
205
261
  errorMessage?: string | null; // English developer message
206
262
  userMessage?: string | null; // localized — show this, log the code
207
263
  }
208
264
  ```
209
265
 
210
266
  Every rejection is a `PaError` with `code`, `developerMessage` (English, from
211
- the shared `errors.json` table — one table for API, webhooks, web and this
212
- SDK, COM-24) and `userMessage` (localized). Technical failures reject with
213
- typed errors and are never payment results (COM-08). Client-side, a second
214
- confirm on an in-flight intent rejects with `duplicate_confirm`; confirming
215
- an already-final intent returns its stored result (COM-13).
267
+ the shared error table used across PA SDK components — API, webhooks, web and
268
+ this SDK) and `userMessage` (localized). Technical failures reject with typed
269
+ errors and are never payment results. Client-side, a second confirm on an
270
+ in-flight intent rejects with `duplicate_confirm`; confirming an
271
+ already-final intent returns its stored result.
216
272
 
217
- ## Locales (A10)
273
+ ## Locales
218
274
 
219
- `en-US`, `zh-TW` (serves `zh_HK`/`zh-HK`), `zh-CN`, `ms-MY` (Flow's `my_MY`).
275
+ `en-US`, `zh-TW` (serves `zh_HK`/`zh-HK`), `zh-CN`, `ms-MY`.
220
276
  Accepts underscore/hyphen, case-insensitive (`zh_HK`, `zh-hk`, `ms`). Unknown
221
- tags fall back along exact tag → same language → `en-US`, never error
222
- (COM-36). `ms-MY` currently ships empty with `_meta.fallback = 'en-US'` and
223
- renders English until translations land. Change locale at runtime with
224
- `updateLocale('zh_CN')` (COM-35).
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.
279
+ Change locale at runtime with `updateLocale('zh_CN')`.
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
+ ```
225
291
 
226
292
  ## Gateway endpoints used
227
293
 
@@ -238,13 +304,14 @@ with `response.code != 200`:
238
304
  | `/intent-cancel` | `cancelIntent`, 3DS user-cancel |
239
305
  | `/intent-status` | polling (2s x 15, then 5s x 12) |
240
306
 
241
- ## Error-code sharing
307
+ ## Error-code / locale generation (maintainers)
242
308
 
243
- `src/errors.generated.ts` is generated from the shared table:
309
+ `src/errors.generated.ts` and `src/locales.generated.ts` ship pre-generated
310
+ in the package; merchants never need to run these. Regeneration is only
311
+ required when the shared PA SDK tables change:
244
312
 
245
313
  ```bash
246
314
  node scripts/generate-errors.js [path/to/errors.json]
247
- # default input: ../system-v3/public_html/pasdk/v3/errors.json
248
315
  node scripts/generate-locales.js # mirrors locales/*.json into src/
249
316
  ```
250
317
 
@@ -254,12 +321,12 @@ See `example/` — a runnable RN 0.79 (New Architecture) app covering one-off
254
321
  payment, two-step payment, save during payment, manual save, 3DS
255
322
  challenge/cancel and multi-market switching.
256
323
 
257
- ## Known deviations / notes
324
+ ## Technical notes
258
325
 
259
326
  - The native 3DS modules use the classic `NativeModules` bridge via
260
327
  `RCT_EXTERN_METHOD` (iOS) and `ReactPackage` (Android). On the New
261
328
  Architecture this runs through RN's interop layer — supported, but not a
262
- codegen TurboModule spec yet (documented per deliverable note).
329
+ codegen TurboModule spec yet.
263
330
  - The JS fallback presenter (`<PaSdk3dsHost />`, backed by
264
331
  `react-native-webview`) is only used when the native module is missing;
265
332
  its return-URL consumption happens via WebView navigation interception.
package/lib/api.d.ts CHANGED
@@ -1,21 +1,21 @@
1
1
  /**
2
- * Gateway API client (RN-13/14 back end).
2
+ * Gateway API client.
3
3
  *
4
4
  * All endpoints are POST JSON on the pasdk/v1 base URL. Responses use the
5
5
  * PA envelope:
6
6
  * { request, response: { code, message }, payload }
7
7
  * Business errors ride HTTP 200 with response.code != 200 and are converted
8
- * to PaError with a shared-table code (COM-24). Transport failures reject
9
- * with `network_error` / `rate_limited` / `provider_error` (COM-08).
8
+ * to PaError with a shared-table code. Transport failures reject
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
  };
15
15
  export interface ApiCallOptions {
16
- /** Publishable merchantToken — used for per-account paths (COM-41). */
16
+ /** Publishable merchantToken — used for per-account paths. */
17
17
  merchantToken?: string;
18
- /** Flow-supplied idempotency key (COM-12 / RN-30), sent as a body field. */
18
+ /** Caller-supplied idempotency key, sent as a body field. */
19
19
  idempotencyKey?: string;
20
20
  }
21
21
  export interface ElementSessionPayload {
@@ -52,9 +52,9 @@ export declare class ApiClient {
52
52
  private static codeForHttpStatus;
53
53
  private post;
54
54
  /** POST /{merchantToken}/element-sessions — public app session (publishable
55
- * credential is the merchantToken, never a secret key; COM-01). */
55
+ * credential is the merchantToken, never a secret key). */
56
56
  createElementSession(merchantToken: string): Promise<ElementSessionPayload>;
57
- /** POST /tokenize — card data goes straight from the app to PA (COM-02). */
57
+ /** POST /tokenize — card data goes straight from the app to PA. */
58
58
  tokenize(params: {
59
59
  sessionToken: string;
60
60
  cardNumber: string;
@@ -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
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
  /**
3
- * Gateway API client (RN-13/14 back end).
3
+ * Gateway API client.
4
4
  *
5
5
  * All endpoints are POST JSON on the pasdk/v1 base URL. Responses use the
6
6
  * PA envelope:
7
7
  * { request, response: { code, message }, payload }
8
8
  * Business errors ride HTTP 200 with response.code != 200 and are converted
9
- * to PaError with a shared-table code (COM-24). Transport failures reject
10
- * with `network_error` / `rate_limited` / `provider_error` (COM-08).
9
+ * to PaError with a shared-table code. Transport failures reject
10
+ * with `network_error` / `rate_limited` / `provider_error`.
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.ApiClient = exports.GATEWAY_BASE_URLS = void 0;
14
14
  const errors_1 = require("./errors");
15
15
  const errors_generated_1 = require("./errors.generated");
16
- /** Whether a code exists in the shared table (COM-24). */
16
+ /** Whether a code exists in the shared table. */
17
17
  function ERROR_TABLE_HAS(code) {
18
18
  return Object.prototype.hasOwnProperty.call(errors_generated_1.ERROR_DEVELOPER_MESSAGES, code);
19
19
  }
@@ -66,7 +66,7 @@ class ApiClient {
66
66
  });
67
67
  }
68
68
  catch (cause) {
69
- // COM-08: technical failure -> typed error, never a payment result.
69
+ // Technical failure -> typed error, never a payment result.
70
70
  throw new errors_1.PaError('network_error', {
71
71
  developerMessage: `Network error calling ${path}.`,
72
72
  cause,
@@ -89,7 +89,7 @@ class ApiClient {
89
89
  }
90
90
  const responseCode = envelope.response && typeof envelope.response.code === 'number' ? envelope.response.code : HTTP_OK;
91
91
  if (responseCode !== HTTP_OK) {
92
- // Business error riding HTTP 200 — map to the shared table (COM-24).
92
+ // Business error riding HTTP 200 — map to the shared table.
93
93
  const payload = (envelope.payload || {});
94
94
  const code = payload.error_code && ERROR_TABLE_HAS(payload.error_code)
95
95
  ? payload.error_code
@@ -101,23 +101,30 @@ class ApiClient {
101
101
  return envelope.payload;
102
102
  }
103
103
  /** POST /{merchantToken}/element-sessions — public app session (publishable
104
- * credential is the merchantToken, never a secret key; COM-01). */
104
+ * credential is the merchantToken, never a secret key). */
105
105
  createElementSession(merchantToken) {
106
106
  return this.post('/element-sessions', {
107
107
  origin: this.origin,
108
108
  element_type: 'card',
109
109
  }, { merchantToken });
110
110
  }
111
- /** POST /tokenize — card data goes straight from the app to PA (COM-02). */
111
+ /** POST /tokenize — card data goes straight from the app to PA. */
112
112
  tokenize(params) {
113
- return this.post('/tokenize', {
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). */
@@ -135,13 +142,28 @@ class ApiClient {
135
142
  body.pa_token = params.paToken;
136
143
  }
137
144
  if (params.idempotencyKey) {
138
- body.idempotency_key = params.idempotencyKey; // COM-12 / RN-30
145
+ body.idempotency_key = params.idempotencyKey;
139
146
  }
140
147
  if (params.saveCard != null) {
141
- body.save_card = params.saveCard; // COM-14 / RN-23
148
+ body.save_card = params.saveCard;
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);
142
164
  }
143
165
  if (params.billing) {
144
- body.billing = params.billing; // COM-23 pass-through
166
+ body.billing = params.billing; // pass-through
145
167
  }
146
168
  return this.post('/confirm', body);
147
169
  }
package/lib/confirm.d.ts CHANGED
@@ -1,44 +1,57 @@
1
1
  /**
2
- * Confirm orchestration (RN-14 / RN-16 / COM-05..COM-08 / COM-12).
2
+ * Confirm orchestration.
3
3
  *
4
4
  * Both mandatory forms are exported:
5
5
  * - confirmWithToken() — the two-step flow: tokenizeCard() first, then
6
- * confirm with the pa_token (RN-14 "the two-step form must exist").
6
+ * confirm with the pa_token.
7
7
  * - confirmWithCard() — combined convenience call: validates, tokenizes
8
8
  * and confirms in one await.
9
9
  *
10
- * Exactly one final result per confirm (COM-05): any 3DS runs inside the
11
- * call (SDK-presented WebView, RN-19); requires_action / processing are
10
+ * Exactly one final result per confirm: any 3DS runs inside the
11
+ * call (SDK-presented WebView); requires_action / processing are
12
12
  * polled until terminal; when the poll budget is exhausted the result is
13
- * `processing`, never `failed` (COM-06).
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;
20
- /** Market key selecting the merchant account when it is not the default (COM-40). */
20
+ /** Market key selecting the merchant account when it is not the default. */
21
21
  market?: string;
22
- /** Flow-supplied idempotency key — repeated taps never double charge (COM-12 / RN-30). */
22
+ /** Caller-supplied idempotency key — repeated taps never double charge. */
23
23
  idempotencyKey?: string;
24
- /** Save the card during payment (COM-14 / RN-23). */
24
+ /** Save the card during payment. */
25
25
  saveCard?: boolean;
26
- /** Optional pass-through billing details (COM-22 / COM-23 / RN-15). */
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>;
39
+ /** Optional pass-through billing details. */
27
40
  billing?: BillingDetails;
28
- /** Fires immediately before the 3DS challenge appears (RN-19) — dismiss
41
+ /** Fires immediately before the 3DS challenge appears — dismiss
29
42
  * your loading overlay here. */
30
43
  onThreeDsWillPresent?: () => void;
31
- /** Fires when the 3DS challenge UI is gone (informational, WEB-48 analog). */
44
+ /** Fires when the 3DS challenge UI is gone (informational). */
32
45
  onThreeDsEnded?: () => void;
33
46
  }
34
47
  export interface ConfirmWithTokenOptions extends ConfirmBaseOptions {
35
- /** Token from tokenizeCard() (RN-14). */
48
+ /** Token from tokenizeCard(). */
36
49
  paToken: string;
37
50
  }
38
51
  export interface ConfirmWithCardOptions extends ConfirmBaseOptions {
39
- /** Card from Flow's own UI (RN-13). */
52
+ /** Card from the app's own UI. */
40
53
  card: CardInput;
41
- /** Optional allowed-brands filter (RN-12); rejects other brands with
54
+ /** Optional allowed-brands filter; rejects other brands with
42
55
  * `unsupported_brand` before any network call. */
43
56
  allowedBrands?: readonly string[];
44
57
  }
@@ -47,17 +60,16 @@ export declare class AlreadyFinalError extends PaError {
47
60
  constructor(result: PaymentResult);
48
61
  }
49
62
  /**
50
- * Confirm a payment intent with a tokenized card (RN-14, mandatory two-step:
63
+ * Confirm a payment intent with a tokenized card (mandatory two-step:
51
64
  * tokenizeCard() -> confirmWithToken()).
52
65
  */
53
66
  export declare function confirmWithToken(options: ConfirmWithTokenOptions): Promise<PaymentResult>;
54
67
  /**
55
- * Combined confirm: validate + tokenize + confirm in one call (RN-14,
56
- * "a single combined confirm with card details is welcome in addition").
57
- * Throws the COM-26 field codes before any network call when validation fails.
68
+ * Combined confirm: validate + tokenize + confirm in one call.
69
+ * Throws the shared field codes before any network call when validation fails.
58
70
  */
59
71
  export declare function confirmWithCard(options: ConfirmWithCardOptions): Promise<PaymentResult>;
60
- /** Cancel an intent explicitly (A3 `cancelled` via intent-cancel). */
72
+ /** Cancel an intent explicitly (resolves `cancelled` via intent-cancel). */
61
73
  export declare function cancelIntent(options: {
62
74
  intentToken: string;
63
75
  clientToken: string;