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.
- package/README.md +140 -73
- package/lib/api.d.ts +17 -8
- package/lib/api.js +35 -13
- package/lib/confirm.d.ts +32 -20
- package/lib/confirm.js +33 -22
- package/lib/errors.d.ts +9 -7
- package/lib/errors.generated.d.ts +2 -2
- package/lib/errors.generated.js +9 -2
- package/lib/errors.js +12 -19
- package/lib/index.d.ts +4 -4
- package/lib/index.js +11 -10
- package/lib/init.d.ts +8 -8
- package/lib/init.js +11 -8
- package/lib/locales.d.ts +20 -10
- package/lib/locales.generated.d.ts +3 -4
- package/lib/locales.generated.js +110 -27
- package/lib/locales.js +62 -14
- package/lib/poll.d.ts +3 -3
- package/lib/poll.js +4 -4
- package/lib/threeDs.d.ts +17 -6
- package/lib/threeDs.js +24 -2
- package/lib/threeDsHost.d.ts +2 -2
- package/lib/threeDsHost.js +3 -3
- package/lib/tokenize.d.ts +9 -4
- package/lib/tokenize.js +6 -4
- package/lib/types.d.ts +33 -26
- package/lib/types.js +4 -5
- package/lib/validator.d.ts +8 -8
- package/lib/validator.js +9 -10
- package/locales/en-US.json +21 -0
- package/locales/ms-MY.json +45 -24
- package/locales/zh-CN.json +21 -0
- package/locales/zh-TW.json +21 -0
- package/native/android/build.gradle +4 -4
- package/native/android/src/main/AndroidManifest.xml +12 -11
- package/native/android/src/main/java/com/pasdk/reactnative/PaSdk3dsActivity.kt +9 -16
- package/native/android/src/main/java/com/pasdk/reactnative/PaSdk3dsModule.kt +3 -3
- package/native/ios/PaSdk3ds.swift +64 -21
- package/native/ios/PaSdk3dsModule.m +16 -9
- package/package.json +3 -3
- package/scripts/generate-errors.js +2 -2
- 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,
|
|
5
|
-
multi-market merchant accounts.
|
|
6
|
-
|
|
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
|
|
11
|
-
· `cancelled` · `failed`.
|
|
12
|
-
|
|
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 (
|
|
19
|
-
| iOS | 13.0+
|
|
20
|
-
| Android | API 24+ (
|
|
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
|
|
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.
|
|
43
|
-
JS API.)
|
|
43
|
+
needed.
|
|
44
44
|
|
|
45
45
|
### Android
|
|
46
46
|
|
|
47
|
-
Autolinking picks up `native/android` —
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
52
|
-
|
|
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
|
|
55
|
-
the
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
intent-filters for
|
|
59
|
-
|
|
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
|
|
67
|
-
// accounts
|
|
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
|
|
81
|
-
origin: 'https://app.
|
|
82
|
-
threeDsReturnUrls: { // consumed by the SDK
|
|
83
|
-
scheme: '
|
|
84
|
-
universalLinkHost: 'https://
|
|
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
|
-
###
|
|
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
|
|
100
|
-
idempotencyKey, // yours, unique per attempt
|
|
101
|
-
allowedBrands: ['visa', 'mastercard'], // from your server
|
|
102
|
-
onThreeDsWillPresent: () => hideLoadingOverlay(),
|
|
103
|
-
market: 'HK', // merchant account selection
|
|
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
|
-
###
|
|
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
|
|
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
|
|
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
|
-
###
|
|
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
|
|
134
|
-
// The token is MIT-ready:
|
|
135
|
-
// Recurring Payment API (/recurring/pay
|
|
136
|
-
//
|
|
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
|
-
###
|
|
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
|
-
###
|
|
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
|
|
161
|
-
- The challenge's return URLs (
|
|
162
|
-
SDK
|
|
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
|
-
###
|
|
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
|
|
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
|
-
##
|
|
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
|
|
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
|
|
247
|
+
Mastercard is ever blocked.
|
|
192
248
|
|
|
193
|
-
## Results and errors
|
|
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
|
|
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
|
|
212
|
-
SDK
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
|
273
|
+
## Locales
|
|
218
274
|
|
|
219
|
-
`en-US`, `zh-TW` (serves `zh_HK`/`zh-HK`), `zh-CN`, `ms-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
|
|
222
|
-
(
|
|
223
|
-
|
|
224
|
-
|
|
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
|
|
307
|
+
## Error-code / locale generation (maintainers)
|
|
242
308
|
|
|
243
|
-
`src/errors.generated.ts`
|
|
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
|
-
##
|
|
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
|
|
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
|
|
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
|
|
9
|
-
* with `network_error` / `rate_limited` / `provider_error
|
|
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
|
|
16
|
+
/** Publishable merchantToken — used for per-account paths. */
|
|
17
17
|
merchantToken?: string;
|
|
18
|
-
/**
|
|
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
|
|
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
|
|
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
|
|
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
|
|
10
|
-
* with `network_error` / `rate_limited` / `provider_error
|
|
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
|
|
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
|
-
//
|
|
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
|
|
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
|
|
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
|
|
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). */
|
|
@@ -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;
|
|
145
|
+
body.idempotency_key = params.idempotencyKey;
|
|
139
146
|
}
|
|
140
147
|
if (params.saveCard != null) {
|
|
141
|
-
body.save_card = params.saveCard;
|
|
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; //
|
|
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
|
|
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
|
|
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
|
|
11
|
-
* call (SDK-presented WebView
|
|
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
|
|
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
|
|
20
|
+
/** Market key selecting the merchant account when it is not the default. */
|
|
21
21
|
market?: string;
|
|
22
|
-
/**
|
|
22
|
+
/** Caller-supplied idempotency key — repeated taps never double charge. */
|
|
23
23
|
idempotencyKey?: string;
|
|
24
|
-
/** Save the card during payment
|
|
24
|
+
/** Save the card during payment. */
|
|
25
25
|
saveCard?: boolean;
|
|
26
|
-
/**
|
|
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
|
|
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
|
|
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()
|
|
48
|
+
/** Token from tokenizeCard(). */
|
|
36
49
|
paToken: string;
|
|
37
50
|
}
|
|
38
51
|
export interface ConfirmWithCardOptions extends ConfirmBaseOptions {
|
|
39
|
-
/** Card from
|
|
52
|
+
/** Card from the app's own UI. */
|
|
40
53
|
card: CardInput;
|
|
41
|
-
/** Optional allowed-brands filter
|
|
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 (
|
|
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
|
|
56
|
-
*
|
|
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 (
|
|
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;
|