pa-sdk-react-native 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -73
- package/lib/api.d.ts +7 -7
- package/lib/api.js +11 -11
- package/lib/confirm.d.ts +18 -19
- package/lib/confirm.js +20 -21
- package/lib/errors.d.ts +6 -6
- package/lib/errors.generated.d.ts +1 -1
- package/lib/errors.generated.js +1 -1
- package/lib/errors.js +5 -5
- package/lib/index.d.ts +3 -3
- package/lib/index.js +9 -9
- package/lib/init.d.ts +8 -8
- package/lib/init.js +8 -8
- package/lib/locales.d.ts +7 -7
- package/lib/locales.generated.d.ts +2 -2
- package/lib/locales.generated.js +26 -26
- package/lib/locales.js +10 -10
- package/lib/poll.d.ts +3 -3
- package/lib/poll.js +4 -4
- package/lib/threeDs.d.ts +6 -6
- package/lib/threeDs.js +2 -2
- package/lib/threeDsHost.d.ts +2 -2
- package/lib/threeDsHost.js +3 -3
- package/lib/tokenize.d.ts +4 -4
- package/lib/tokenize.js +4 -4
- package/lib/types.d.ts +25 -26
- package/lib/types.js +4 -5
- package/lib/validator.d.ts +8 -8
- package/lib/validator.js +9 -10
- package/locales/ms-MY.json +24 -24
- 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 +6 -6
- package/native/ios/PaSdk3dsModule.m +2 -2
- package/package.json +3 -3
- package/scripts/generate-errors.js +2 -2
- package/scripts/generate-locales.js +3 -3
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,14 @@ 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 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 without surfacing to the app's link handler.
|
|
163
176
|
|
|
164
|
-
###
|
|
177
|
+
### Multi-market
|
|
165
178
|
|
|
166
179
|
One init; pick the account per call with `market`. Currency and country are
|
|
167
|
-
per intent on your server
|
|
180
|
+
per intent on your server.
|
|
168
181
|
|
|
169
182
|
### Cancel an intent
|
|
170
183
|
|
|
@@ -173,7 +186,7 @@ import { cancelIntent } from 'pa-sdk-react-native';
|
|
|
173
186
|
await cancelIntent({ intentToken, clientToken }); // -> { status: 'cancelled' }
|
|
174
187
|
```
|
|
175
188
|
|
|
176
|
-
## Validation helpers
|
|
189
|
+
## Validation helpers
|
|
177
190
|
|
|
178
191
|
```tsx
|
|
179
192
|
import { validateCard, validateCardNumber, validateExpiry, validateCvc, detectBrand } from 'pa-sdk-react-native';
|
|
@@ -182,15 +195,15 @@ detectBrand('222100...').brand // 'mastercard' — 2-series 2221–2720 recogn
|
|
|
182
195
|
validateCardNumber('4242...', ['visa']) // Luhn, length, brand filter
|
|
183
196
|
validateCard(card, ['visa', 'mastercard'])
|
|
184
197
|
// -> { brand, complete, fields: { cardNumber?, expiry?, cvc? } }
|
|
185
|
-
// field codes
|
|
198
|
+
// field codes: incomplete_number, invalid_number, incomplete_expiry,
|
|
186
199
|
// invalid_expiry, incomplete_cvc, invalid_cvc, unsupported_brand
|
|
187
200
|
```
|
|
188
201
|
|
|
189
202
|
Rules: Visa/Mastercard lengths, Luhn, current BIN ranges (Mastercard 2-series
|
|
190
203
|
2221–2720 included), 3-digit CVC, expiry not in the past — no valid Visa /
|
|
191
|
-
Mastercard is ever blocked
|
|
204
|
+
Mastercard is ever blocked.
|
|
192
205
|
|
|
193
|
-
## Results and errors
|
|
206
|
+
## Results and errors
|
|
194
207
|
|
|
195
208
|
```ts
|
|
196
209
|
interface PaymentResult {
|
|
@@ -201,27 +214,25 @@ interface PaymentResult {
|
|
|
201
214
|
paToken?: string | null; // set when a card was saved
|
|
202
215
|
brand?: string | null;
|
|
203
216
|
last4?: string | null;
|
|
204
|
-
errorCode?: string | null; // shared table
|
|
217
|
+
errorCode?: string | null; // shared error-code table, for 'failed'
|
|
205
218
|
errorMessage?: string | null; // English developer message
|
|
206
219
|
userMessage?: string | null; // localized — show this, log the code
|
|
207
220
|
}
|
|
208
221
|
```
|
|
209
222
|
|
|
210
223
|
Every rejection is a `PaError` with `code`, `developerMessage` (English, from
|
|
211
|
-
the shared
|
|
212
|
-
SDK
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
224
|
+
the shared error table used across PA SDK components — API, webhooks, web and
|
|
225
|
+
this SDK) and `userMessage` (localized). Technical failures reject with typed
|
|
226
|
+
errors and are never payment results. Client-side, a second confirm on an
|
|
227
|
+
in-flight intent rejects with `duplicate_confirm`; confirming an
|
|
228
|
+
already-final intent returns its stored result.
|
|
216
229
|
|
|
217
|
-
## Locales
|
|
230
|
+
## Locales
|
|
218
231
|
|
|
219
|
-
`en-US`, `zh-TW` (serves `zh_HK`/`zh-HK`), `zh-CN`, `ms-MY
|
|
232
|
+
`en-US`, `zh-TW` (serves `zh_HK`/`zh-HK`), `zh-CN`, `ms-MY`.
|
|
220
233
|
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
|
-
|
|
223
|
-
renders English until translations land. Change locale at runtime with
|
|
224
|
-
`updateLocale('zh_CN')` (COM-35).
|
|
234
|
+
tags fall back along exact tag → same language → `en-US`, never error.
|
|
235
|
+
Change locale at runtime with `updateLocale('zh_CN')`.
|
|
225
236
|
|
|
226
237
|
## Gateway endpoints used
|
|
227
238
|
|
|
@@ -238,13 +249,14 @@ with `response.code != 200`:
|
|
|
238
249
|
| `/intent-cancel` | `cancelIntent`, 3DS user-cancel |
|
|
239
250
|
| `/intent-status` | polling (2s x 15, then 5s x 12) |
|
|
240
251
|
|
|
241
|
-
## Error-code
|
|
252
|
+
## Error-code / locale generation (maintainers)
|
|
242
253
|
|
|
243
|
-
`src/errors.generated.ts`
|
|
254
|
+
`src/errors.generated.ts` and `src/locales.generated.ts` ship pre-generated
|
|
255
|
+
in the package; merchants never need to run these. Regeneration is only
|
|
256
|
+
required when the shared PA SDK tables change:
|
|
244
257
|
|
|
245
258
|
```bash
|
|
246
259
|
node scripts/generate-errors.js [path/to/errors.json]
|
|
247
|
-
# default input: ../system-v3/public_html/pasdk/v3/errors.json
|
|
248
260
|
node scripts/generate-locales.js # mirrors locales/*.json into src/
|
|
249
261
|
```
|
|
250
262
|
|
|
@@ -254,12 +266,12 @@ See `example/` — a runnable RN 0.79 (New Architecture) app covering one-off
|
|
|
254
266
|
payment, two-step payment, save during payment, manual save, 3DS
|
|
255
267
|
challenge/cancel and multi-market switching.
|
|
256
268
|
|
|
257
|
-
##
|
|
269
|
+
## Technical notes
|
|
258
270
|
|
|
259
271
|
- The native 3DS modules use the classic `NativeModules` bridge via
|
|
260
272
|
`RCT_EXTERN_METHOD` (iOS) and `ReactPackage` (Android). On the New
|
|
261
273
|
Architecture this runs through RN's interop layer — supported, but not a
|
|
262
|
-
codegen TurboModule spec yet
|
|
274
|
+
codegen TurboModule spec yet.
|
|
263
275
|
- The JS fallback presenter (`<PaSdk3dsHost />`, backed by
|
|
264
276
|
`react-native-webview`) is only used when the native module is missing;
|
|
265
277
|
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
11
|
import type { ConfirmGatewayPayload, Environment } 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;
|
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,14 +101,14 @@ 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
|
return this.post('/tokenize', {
|
|
114
114
|
session_token: params.sessionToken,
|
|
@@ -135,13 +135,13 @@ class ApiClient {
|
|
|
135
135
|
body.pa_token = params.paToken;
|
|
136
136
|
}
|
|
137
137
|
if (params.idempotencyKey) {
|
|
138
|
-
body.idempotency_key = params.idempotencyKey;
|
|
138
|
+
body.idempotency_key = params.idempotencyKey;
|
|
139
139
|
}
|
|
140
140
|
if (params.saveCard != null) {
|
|
141
|
-
body.save_card = params.saveCard;
|
|
141
|
+
body.save_card = params.saveCard;
|
|
142
142
|
}
|
|
143
143
|
if (params.billing) {
|
|
144
|
-
body.billing = params.billing; //
|
|
144
|
+
body.billing = params.billing; // pass-through
|
|
145
145
|
}
|
|
146
146
|
return this.post('/confirm', body);
|
|
147
147
|
}
|
package/lib/confirm.d.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
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
16
|
import type { BillingDetails, CardInput, PaymentResult } 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
|
-
/** Optional pass-through billing details
|
|
26
|
+
/** Optional pass-through billing details. */
|
|
27
27
|
billing?: BillingDetails;
|
|
28
|
-
/** Fires immediately before the 3DS challenge appears
|
|
28
|
+
/** Fires immediately before the 3DS challenge appears — dismiss
|
|
29
29
|
* your loading overlay here. */
|
|
30
30
|
onThreeDsWillPresent?: () => void;
|
|
31
|
-
/** Fires when the 3DS challenge UI is gone (informational
|
|
31
|
+
/** Fires when the 3DS challenge UI is gone (informational). */
|
|
32
32
|
onThreeDsEnded?: () => void;
|
|
33
33
|
}
|
|
34
34
|
export interface ConfirmWithTokenOptions extends ConfirmBaseOptions {
|
|
35
|
-
/** Token from tokenizeCard()
|
|
35
|
+
/** Token from tokenizeCard(). */
|
|
36
36
|
paToken: string;
|
|
37
37
|
}
|
|
38
38
|
export interface ConfirmWithCardOptions extends ConfirmBaseOptions {
|
|
39
|
-
/** Card from
|
|
39
|
+
/** Card from the app's own UI. */
|
|
40
40
|
card: CardInput;
|
|
41
|
-
/** Optional allowed-brands filter
|
|
41
|
+
/** Optional allowed-brands filter; rejects other brands with
|
|
42
42
|
* `unsupported_brand` before any network call. */
|
|
43
43
|
allowedBrands?: readonly string[];
|
|
44
44
|
}
|
|
@@ -47,17 +47,16 @@ export declare class AlreadyFinalError extends PaError {
|
|
|
47
47
|
constructor(result: PaymentResult);
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
* Confirm a payment intent with a tokenized card (
|
|
50
|
+
* Confirm a payment intent with a tokenized card (mandatory two-step:
|
|
51
51
|
* tokenizeCard() -> confirmWithToken()).
|
|
52
52
|
*/
|
|
53
53
|
export declare function confirmWithToken(options: ConfirmWithTokenOptions): Promise<PaymentResult>;
|
|
54
54
|
/**
|
|
55
|
-
* Combined confirm: validate + tokenize + confirm in one call
|
|
56
|
-
*
|
|
57
|
-
* Throws the COM-26 field codes before any network call when validation fails.
|
|
55
|
+
* Combined confirm: validate + tokenize + confirm in one call.
|
|
56
|
+
* Throws the shared field codes before any network call when validation fails.
|
|
58
57
|
*/
|
|
59
58
|
export declare function confirmWithCard(options: ConfirmWithCardOptions): Promise<PaymentResult>;
|
|
60
|
-
/** Cancel an intent explicitly (
|
|
59
|
+
/** Cancel an intent explicitly (resolves `cancelled` via intent-cancel). */
|
|
61
60
|
export declare function cancelIntent(options: {
|
|
62
61
|
intentToken: string;
|
|
63
62
|
clientToken: string;
|
package/lib/confirm.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Confirm orchestration
|
|
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
|
|
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
|
|
12
|
-
* call (SDK-presented WebView
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
64
|
+
// Status mapping
|
|
65
65
|
const TERMINAL_STATUS = {
|
|
66
66
|
succeeded: 'succeeded',
|
|
67
|
-
requires_capture: 'authorized', //
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 (
|
|
246
|
+
* Confirm a payment intent with a tokenized card (mandatory two-step:
|
|
247
247
|
* tokenizeCard() -> confirmWithToken()).
|
|
248
248
|
*/
|
|
249
249
|
async function confirmWithToken(options) {
|
|
@@ -269,9 +269,8 @@ async function confirmWithToken(options) {
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
/**
|
|
272
|
-
* Combined confirm: validate + tokenize + confirm in one call
|
|
273
|
-
*
|
|
274
|
-
* Throws the COM-26 field codes before any network call when validation fails.
|
|
272
|
+
* Combined confirm: validate + tokenize + confirm in one call.
|
|
273
|
+
* Throws the shared field codes before any network call when validation fails.
|
|
275
274
|
*/
|
|
276
275
|
async function confirmWithCard(options) {
|
|
277
276
|
const sdk = (0, init_1.getSdk)();
|
|
@@ -332,7 +331,7 @@ async function settle(api, options, payload, paToken) {
|
|
|
332
331
|
});
|
|
333
332
|
return polled || processingResult(options.intentToken);
|
|
334
333
|
}
|
|
335
|
-
/** Cancel an intent explicitly (
|
|
334
|
+
/** Cancel an intent explicitly (resolves `cancelled` via intent-cancel). */
|
|
336
335
|
async function cancelIntent(options) {
|
|
337
336
|
const sdk = (0, init_1.getSdk)();
|
|
338
337
|
await sdk.api.intentCancel({
|