pa-sdk-react-native 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +280 -2
- package/lib/api.d.ts +88 -0
- package/lib/api.js +163 -0
- package/lib/confirm.d.ts +65 -0
- package/lib/confirm.js +358 -0
- package/lib/errors.d.ts +38 -0
- package/lib/errors.generated.d.ts +13 -0
- package/lib/errors.generated.js +63 -0
- package/lib/errors.js +80 -0
- package/lib/index.d.ts +43 -0
- package/lib/index.js +94 -0
- package/lib/init.d.ts +47 -0
- package/lib/init.js +96 -0
- package/lib/locales.d.ts +36 -0
- package/lib/locales.generated.d.ts +22 -0
- package/lib/locales.generated.js +134 -0
- package/lib/locales.js +100 -0
- package/lib/poll.d.ts +61 -0
- package/lib/poll.js +172 -0
- package/lib/threeDs.d.ts +59 -0
- package/lib/threeDs.js +64 -0
- package/lib/threeDsHost.d.ts +17 -0
- package/lib/threeDsHost.js +159 -0
- package/lib/tokenize.d.ts +22 -0
- package/lib/tokenize.js +50 -0
- package/lib/types.d.ts +127 -0
- package/lib/types.js +16 -0
- package/lib/validator.d.ts +71 -0
- package/lib/validator.js +190 -0
- package/locales/en-US.json +30 -0
- package/locales/ms-MY.json +30 -0
- package/locales/zh-CN.json +30 -0
- package/locales/zh-TW.json +30 -0
- package/native/android/build.gradle +49 -0
- package/native/android/src/main/AndroidManifest.xml +42 -0
- package/native/android/src/main/java/com/pasdk/reactnative/PaSdk3dsActivity.kt +243 -0
- package/native/android/src/main/java/com/pasdk/reactnative/PaSdk3dsModule.kt +110 -0
- package/native/android/src/main/java/com/pasdk/reactnative/PaSdkReactNativePackage.kt +27 -0
- package/native/ios/PaSdk3ds.swift +311 -0
- package/native/ios/PaSdk3dsModule.m +47 -0
- package/pa-sdk-react-native.podspec +23 -0
- package/package.json +47 -4
- package/scripts/generate-errors.js +86 -0
- package/scripts/generate-locales.js +95 -0
package/lib/confirm.js
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Confirm orchestration.
|
|
4
|
+
*
|
|
5
|
+
* Both mandatory forms are exported:
|
|
6
|
+
* - confirmWithToken() — the two-step flow: tokenizeCard() first, then
|
|
7
|
+
* confirm with the pa_token.
|
|
8
|
+
* - confirmWithCard() — combined convenience call: validates, tokenizes
|
|
9
|
+
* and confirms in one await.
|
|
10
|
+
*
|
|
11
|
+
* Exactly one final result per confirm: any 3DS runs inside the
|
|
12
|
+
* call (SDK-presented WebView); requires_action / processing are
|
|
13
|
+
* polled until terminal; when the poll budget is exhausted the result is
|
|
14
|
+
* `processing`, never `failed`.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AlreadyFinalError = void 0;
|
|
18
|
+
exports.confirmWithToken = confirmWithToken;
|
|
19
|
+
exports.confirmWithCard = confirmWithCard;
|
|
20
|
+
exports.cancelIntent = cancelIntent;
|
|
21
|
+
exports.resetConfirmState = resetConfirmState;
|
|
22
|
+
const errors_1 = require("./errors");
|
|
23
|
+
const locales_1 = require("./locales");
|
|
24
|
+
const poll_1 = require("./poll");
|
|
25
|
+
const threeDs_1 = require("./threeDs");
|
|
26
|
+
const tokenize_1 = require("./tokenize");
|
|
27
|
+
const init_1 = require("./init");
|
|
28
|
+
const validator_1 = require("./validator");
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Client-side double-confirm guard
|
|
31
|
+
const inFlight = new Set();
|
|
32
|
+
const finalResults = new Map();
|
|
33
|
+
function guardStart(intentToken) {
|
|
34
|
+
const previous = finalResults.get(intentToken);
|
|
35
|
+
if (previous) {
|
|
36
|
+
// Confirming an intent already final returns that state, without
|
|
37
|
+
// charging again.
|
|
38
|
+
throw new AlreadyFinalError(previous);
|
|
39
|
+
}
|
|
40
|
+
if (inFlight.has(intentToken)) {
|
|
41
|
+
throw new errors_1.PaError('duplicate_confirm', {
|
|
42
|
+
developerMessage: 'A confirm is already in progress for this intent.',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
inFlight.add(intentToken);
|
|
46
|
+
}
|
|
47
|
+
function guardEnd(intentToken, result) {
|
|
48
|
+
inFlight.delete(intentToken);
|
|
49
|
+
if (result.status !== 'processing') {
|
|
50
|
+
finalResults.set(intentToken, result);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class AlreadyFinalError extends errors_1.PaError {
|
|
54
|
+
constructor(result) {
|
|
55
|
+
super('intent_already_final', {
|
|
56
|
+
developerMessage: 'This intent already reached a final state; the stored result is returned instead.',
|
|
57
|
+
});
|
|
58
|
+
this.name = 'AlreadyFinalError';
|
|
59
|
+
this.result = result;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.AlreadyFinalError = AlreadyFinalError;
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
// Status mapping
|
|
65
|
+
const TERMINAL_STATUS = {
|
|
66
|
+
succeeded: 'succeeded',
|
|
67
|
+
requires_capture: 'authorized', // authorized (pre-auth) is success
|
|
68
|
+
failed: 'failed',
|
|
69
|
+
cancelled: 'cancelled',
|
|
70
|
+
};
|
|
71
|
+
function isTerminalStatus(status) {
|
|
72
|
+
return Object.prototype.hasOwnProperty.call(TERMINAL_STATUS, status);
|
|
73
|
+
}
|
|
74
|
+
function payloadToResult(status, payload, intentToken) {
|
|
75
|
+
const mapped = TERMINAL_STATUS[status];
|
|
76
|
+
const errorCode = payload.error_code || null;
|
|
77
|
+
return {
|
|
78
|
+
status: mapped || 'processing',
|
|
79
|
+
intentToken,
|
|
80
|
+
requestReference: payload.request_reference || null,
|
|
81
|
+
merchantReference: payload.merchant_reference || null,
|
|
82
|
+
paToken: payload.pa_token || null,
|
|
83
|
+
brand: payload.brand || null,
|
|
84
|
+
last4: payload.last4 || null,
|
|
85
|
+
errorCode: mapped === 'failed' ? errorCode : null,
|
|
86
|
+
errorMessage: mapped === 'failed' ? payload.error_message || null : null,
|
|
87
|
+
userMessage: mapped === 'failed' ? (0, errors_1.userMessageForCode)(errorCode || 'internal_error') : null,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Billing pass-through
|
|
92
|
+
function billingToGateway(billing) {
|
|
93
|
+
if (!billing) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const out = {};
|
|
97
|
+
if (billing.cardholderName) {
|
|
98
|
+
out.cardholder_name = billing.cardholderName;
|
|
99
|
+
}
|
|
100
|
+
if (billing.firstName) {
|
|
101
|
+
out.first_name = billing.firstName;
|
|
102
|
+
}
|
|
103
|
+
if (billing.lastName) {
|
|
104
|
+
out.last_name = billing.lastName;
|
|
105
|
+
}
|
|
106
|
+
if (billing.email) {
|
|
107
|
+
out.email = billing.email;
|
|
108
|
+
}
|
|
109
|
+
if (billing.phone) {
|
|
110
|
+
out.phone =
|
|
111
|
+
billing.phoneDialCode && !billing.phone.startsWith('+')
|
|
112
|
+
? `${billing.phoneDialCode}${billing.phone}`
|
|
113
|
+
: billing.phone;
|
|
114
|
+
}
|
|
115
|
+
if (billing.address) {
|
|
116
|
+
const a = billing.address;
|
|
117
|
+
out.address = {
|
|
118
|
+
line1: a.line1,
|
|
119
|
+
line2: a.line2,
|
|
120
|
+
city: a.city,
|
|
121
|
+
state: a.state,
|
|
122
|
+
postal_code: a.postalCode,
|
|
123
|
+
country_code: a.countryCode,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
127
|
+
}
|
|
128
|
+
async function handleThreeDs(api, options, threedsData) {
|
|
129
|
+
const sdk = (0, init_1.getSdk)();
|
|
130
|
+
const strings = (0, locales_1.getLocaleStrings)().t;
|
|
131
|
+
const returnUrls = sdk.threeDsReturnUrls || {};
|
|
132
|
+
let url = '';
|
|
133
|
+
const fields = {};
|
|
134
|
+
if (threedsData.cardinal_url && threedsData.jwt) {
|
|
135
|
+
url = threedsData.cardinal_url;
|
|
136
|
+
fields.JWT = threedsData.jwt;
|
|
137
|
+
}
|
|
138
|
+
else if (threedsData.acs_url && threedsData.creq) {
|
|
139
|
+
// 3DS1 / non-3DS2 ACS fallback: POST the creq to the ACS.
|
|
140
|
+
url = threedsData.acs_url;
|
|
141
|
+
fields.creq = threedsData.creq;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
throw new errors_1.PaError('provider_error', {
|
|
145
|
+
developerMessage: 'requires_action without a usable threeds_data payload.',
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// Poll concurrently while the challenge is open; whichever side observes a
|
|
149
|
+
// terminal state first wins. The gateway posts the challenge result
|
|
150
|
+
// server-side, so /intent-status is the source of truth.
|
|
151
|
+
const poller = new poll_1.AppStateAwarePoller();
|
|
152
|
+
const pollPromise = poller.run(async () => {
|
|
153
|
+
const payload = await api.intentStatus({
|
|
154
|
+
clientToken: options.clientToken,
|
|
155
|
+
intentToken: options.intentToken,
|
|
156
|
+
});
|
|
157
|
+
if (payload && payload.status && isTerminalStatus(payload.status)) {
|
|
158
|
+
return { done: true, value: payloadToResult(payload.status, payload, options.intentToken) };
|
|
159
|
+
}
|
|
160
|
+
return { done: false };
|
|
161
|
+
});
|
|
162
|
+
let dismissal = null;
|
|
163
|
+
let presentFailure = null;
|
|
164
|
+
try {
|
|
165
|
+
dismissal = await (0, threeDs_1.presentThreeDs)({
|
|
166
|
+
url,
|
|
167
|
+
fields,
|
|
168
|
+
strings: {
|
|
169
|
+
title: strings('threeds.title'),
|
|
170
|
+
cancel: strings('threeds.cancel'),
|
|
171
|
+
close: strings('threeds.close'),
|
|
172
|
+
processing: strings('threeds.processing'),
|
|
173
|
+
redirecting: strings('threeds.redirecting'),
|
|
174
|
+
},
|
|
175
|
+
returnUrlScheme: returnUrls.scheme,
|
|
176
|
+
returnUrlUniversalHost: returnUrls.universalLinkHost,
|
|
177
|
+
}, options.onThreeDsWillPresent);
|
|
178
|
+
}
|
|
179
|
+
catch (cause) {
|
|
180
|
+
// Challenge UI failed to appear — not a payment result. Keep
|
|
181
|
+
// polling the intent; worst case resolves `processing`.
|
|
182
|
+
presentFailure = cause;
|
|
183
|
+
}
|
|
184
|
+
if (options.onThreeDsEnded) {
|
|
185
|
+
options.onThreeDsEnded();
|
|
186
|
+
}
|
|
187
|
+
if (dismissal && dismissal.cancelled) {
|
|
188
|
+
// User closed the challenge -> cancelled. Tell the
|
|
189
|
+
// gateway best-effort so the intent does not linger in requires_action.
|
|
190
|
+
poller.stop();
|
|
191
|
+
try {
|
|
192
|
+
await api.intentCancel({ clientToken: options.clientToken, intentToken: options.intentToken });
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
/* informational only */
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
result: {
|
|
199
|
+
status: 'cancelled',
|
|
200
|
+
intentToken: options.intentToken,
|
|
201
|
+
requestReference: null,
|
|
202
|
+
merchantReference: null,
|
|
203
|
+
paToken: null,
|
|
204
|
+
brand: null,
|
|
205
|
+
last4: null,
|
|
206
|
+
errorCode: null,
|
|
207
|
+
errorMessage: null,
|
|
208
|
+
userMessage: null,
|
|
209
|
+
},
|
|
210
|
+
cancelled: true,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const polled = await pollPromise;
|
|
214
|
+
if (polled) {
|
|
215
|
+
return { result: polled, cancelled: false };
|
|
216
|
+
}
|
|
217
|
+
if (presentFailure) {
|
|
218
|
+
throw presentFailure instanceof errors_1.PaError
|
|
219
|
+
? presentFailure
|
|
220
|
+
: new errors_1.PaError('internal_error', {
|
|
221
|
+
developerMessage: 'The 3DS challenge UI could not be presented.',
|
|
222
|
+
cause: presentFailure,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
// Budget exhausted with the challenge closed and no terminal state —
|
|
226
|
+
// `processing`, never `failed`.
|
|
227
|
+
return { result: null, cancelled: false };
|
|
228
|
+
}
|
|
229
|
+
// ---------------------------------------------------------------------------
|
|
230
|
+
// The two public confirms
|
|
231
|
+
function processingResult(intentToken) {
|
|
232
|
+
return {
|
|
233
|
+
status: 'processing',
|
|
234
|
+
intentToken,
|
|
235
|
+
requestReference: null,
|
|
236
|
+
merchantReference: null,
|
|
237
|
+
paToken: null,
|
|
238
|
+
brand: null,
|
|
239
|
+
last4: null,
|
|
240
|
+
errorCode: null,
|
|
241
|
+
errorMessage: null,
|
|
242
|
+
userMessage: null,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Confirm a payment intent with a tokenized card (mandatory two-step:
|
|
247
|
+
* tokenizeCard() -> confirmWithToken()).
|
|
248
|
+
*/
|
|
249
|
+
async function confirmWithToken(options) {
|
|
250
|
+
const sdk = (0, init_1.getSdk)();
|
|
251
|
+
const api = sdk.api;
|
|
252
|
+
guardStart(options.intentToken);
|
|
253
|
+
try {
|
|
254
|
+
const payload = await api.confirm({
|
|
255
|
+
clientToken: options.clientToken,
|
|
256
|
+
intentToken: options.intentToken,
|
|
257
|
+
paToken: options.paToken,
|
|
258
|
+
idempotencyKey: options.idempotencyKey,
|
|
259
|
+
saveCard: options.saveCard,
|
|
260
|
+
billing: billingToGateway(options.billing),
|
|
261
|
+
});
|
|
262
|
+
const result = await settle(api, options, payload, options.paToken);
|
|
263
|
+
guardEnd(options.intentToken, result);
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
inFlight.delete(options.intentToken);
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Combined confirm: validate + tokenize + confirm in one call.
|
|
273
|
+
* Throws the shared field codes before any network call when validation fails.
|
|
274
|
+
*/
|
|
275
|
+
async function confirmWithCard(options) {
|
|
276
|
+
const sdk = (0, init_1.getSdk)();
|
|
277
|
+
const account = sdk.accountFor(options.market);
|
|
278
|
+
const validation = (0, validator_1.validateCard)(options.card, options.allowedBrands);
|
|
279
|
+
if (!validation.complete) {
|
|
280
|
+
const firstKey = ['cardNumber', 'expiry', 'cvc'];
|
|
281
|
+
for (const key of firstKey) {
|
|
282
|
+
const code = validation.fields[key];
|
|
283
|
+
if (code) {
|
|
284
|
+
throw new errors_1.PaError(code);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
let tokenized;
|
|
289
|
+
try {
|
|
290
|
+
const output = await (0, tokenize_1.tokenizeCard)(sdk.api, {
|
|
291
|
+
card: options.card,
|
|
292
|
+
merchantToken: account.merchantToken,
|
|
293
|
+
});
|
|
294
|
+
tokenized = output.result;
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
inFlight.delete(options.intentToken);
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
return confirmWithToken({ ...options, paToken: tokenized.paToken });
|
|
301
|
+
}
|
|
302
|
+
/** Drive a confirm payload to its single final result. */
|
|
303
|
+
async function settle(api, options, payload, paToken) {
|
|
304
|
+
const status = payload && payload.status ? payload.status : 'processing';
|
|
305
|
+
if (isTerminalStatus(status)) {
|
|
306
|
+
return payloadToResult(status, { ...payload, pa_token: payload.pa_token || paToken }, options.intentToken);
|
|
307
|
+
}
|
|
308
|
+
if (status === 'requires_action' && payload.threeds_data && (0, threeDs_1.canPresentThreeDs)()) {
|
|
309
|
+
const outcome = await handleThreeDs(api, options, payload.threeds_data);
|
|
310
|
+
return outcome.result || processingResult(options.intentToken);
|
|
311
|
+
}
|
|
312
|
+
if (status === 'requires_action' && payload.threeds_data && !(0, threeDs_1.canPresentThreeDs)()) {
|
|
313
|
+
throw new errors_1.PaError('internal_error', {
|
|
314
|
+
developerMessage: 'The intent requires 3DS but no 3DS presenter is available. Install the native modules or mount <PaSdk3dsHost />.',
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
// processing (or unknown): poll /intent-status until terminal or budget end.
|
|
318
|
+
const poller = new poll_1.AppStateAwarePoller();
|
|
319
|
+
const polled = await poller.run(async () => {
|
|
320
|
+
const payload2 = await api.intentStatus({
|
|
321
|
+
clientToken: options.clientToken,
|
|
322
|
+
intentToken: options.intentToken,
|
|
323
|
+
});
|
|
324
|
+
if (payload2 && payload2.status && isTerminalStatus(payload2.status)) {
|
|
325
|
+
return {
|
|
326
|
+
done: true,
|
|
327
|
+
value: payloadToResult(payload2.status, { ...payload2, pa_token: payload2.pa_token || paToken }, options.intentToken),
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
return { done: false };
|
|
331
|
+
});
|
|
332
|
+
return polled || processingResult(options.intentToken);
|
|
333
|
+
}
|
|
334
|
+
/** Cancel an intent explicitly (resolves `cancelled` via intent-cancel). */
|
|
335
|
+
async function cancelIntent(options) {
|
|
336
|
+
const sdk = (0, init_1.getSdk)();
|
|
337
|
+
await sdk.api.intentCancel({
|
|
338
|
+
clientToken: options.clientToken,
|
|
339
|
+
intentToken: options.intentToken,
|
|
340
|
+
});
|
|
341
|
+
return {
|
|
342
|
+
status: 'cancelled',
|
|
343
|
+
intentToken: options.intentToken,
|
|
344
|
+
requestReference: null,
|
|
345
|
+
merchantReference: null,
|
|
346
|
+
paToken: null,
|
|
347
|
+
brand: null,
|
|
348
|
+
last4: null,
|
|
349
|
+
errorCode: null,
|
|
350
|
+
errorMessage: null,
|
|
351
|
+
userMessage: null,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/** Test/diagnostic helper: clear the in-process final-result cache. */
|
|
355
|
+
function resetConfirmState() {
|
|
356
|
+
inFlight.clear();
|
|
357
|
+
finalResults.clear();
|
|
358
|
+
}
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed errors.
|
|
3
|
+
*
|
|
4
|
+
* Every rejection is a PaError carrying:
|
|
5
|
+
* - `code` — a stable code from the shared table (src/errors.generated.ts)
|
|
6
|
+
* - `developerMessage`— the English developer message from the shared table
|
|
7
|
+
* - `userMessage` — a localized user message the app may show directly
|
|
8
|
+
*
|
|
9
|
+
* Technical failures (network, not initialised, 3DS UI unavailable) reject
|
|
10
|
+
* with a PaError too — they are never reported as payment results.
|
|
11
|
+
*/
|
|
12
|
+
/** Localized user message for a shared-table code. Falls back
|
|
13
|
+
* to `error.generic` when the code has no dedicated string. */
|
|
14
|
+
export declare function userMessageForCode(code: string, locale?: string | null): string;
|
|
15
|
+
export interface PaErrorOptions {
|
|
16
|
+
/** Override the developer message (e.g. transport detail). */
|
|
17
|
+
developerMessage?: string;
|
|
18
|
+
/** Locale used to build the user message; defaults to the runtime locale. */
|
|
19
|
+
locale?: string | null;
|
|
20
|
+
/** Underlying cause (kept for diagnostics). */
|
|
21
|
+
cause?: unknown;
|
|
22
|
+
}
|
|
23
|
+
export declare class PaError extends Error {
|
|
24
|
+
/** Shared-table code or a field code. */
|
|
25
|
+
readonly code: string;
|
|
26
|
+
/** English developer message from the shared table. */
|
|
27
|
+
readonly developerMessage: string;
|
|
28
|
+
/** Localized user message — the app shows this and logs `code`. */
|
|
29
|
+
readonly userMessage: string;
|
|
30
|
+
/** True when this is a field-validation error rather than a payment error. */
|
|
31
|
+
readonly isFieldError: boolean;
|
|
32
|
+
constructor(code: string, options?: PaErrorOptions);
|
|
33
|
+
}
|
|
34
|
+
export declare function isPaError(value: unknown): value is PaError;
|
|
35
|
+
/** Thrown when the SDK is used before init(). */
|
|
36
|
+
export declare class NotInitializedError extends PaError {
|
|
37
|
+
constructor();
|
|
38
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GENERATED FILE — do not edit by hand.
|
|
3
|
+
* Generated by scripts/generate-errors.js from: errors.json
|
|
4
|
+
* Table version: 1, generated_at: 2026-10-20T04:13:44+00:00.
|
|
5
|
+
*
|
|
6
|
+
* One code table shared by the server API, webhooks, the web SDK and this
|
|
7
|
+
* React Native SDK. Values are English developer
|
|
8
|
+
* messages; localized user messages live in the locale bundles.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ERROR_TABLE_VERSION: number;
|
|
11
|
+
export declare const ERROR_DEVELOPER_MESSAGES: {
|
|
12
|
+
readonly [code: string]: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* GENERATED FILE — do not edit by hand.
|
|
5
|
+
* Generated by scripts/generate-errors.js from: errors.json
|
|
6
|
+
* Table version: 1, generated_at: 2026-10-20T04:13:44+00:00.
|
|
7
|
+
*
|
|
8
|
+
* One code table shared by the server API, webhooks, the web SDK and this
|
|
9
|
+
* React Native SDK. Values are English developer
|
|
10
|
+
* messages; localized user messages live in the locale bundles.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.ERROR_DEVELOPER_MESSAGES = exports.ERROR_TABLE_VERSION = void 0;
|
|
14
|
+
exports.ERROR_TABLE_VERSION = 1;
|
|
15
|
+
exports.ERROR_DEVELOPER_MESSAGES = {
|
|
16
|
+
"acquirer_unavailable": "The payment acquirer is unavailable. Retry later.",
|
|
17
|
+
"amount_above_limit": "The amount exceeds the permitted limit.",
|
|
18
|
+
"amount_below_limit": "The amount is below the permitted minimum.",
|
|
19
|
+
"card_declined": "The card was declined. The customer should retry or contact the card-issuing bank.",
|
|
20
|
+
"customer_not_found": "The customer record does not exist.",
|
|
21
|
+
"duplicate_confirm": "A confirm is already in progress or the idempotency key conflicts.",
|
|
22
|
+
"expired_card": "The card has expired.",
|
|
23
|
+
"font_load_failed": "A merchant-supplied font failed to load; a system font is used instead.",
|
|
24
|
+
"frequency_limit": "Transaction frequency limit exceeded. Retry later.",
|
|
25
|
+
"incomplete_cvc": "The security code is incomplete.",
|
|
26
|
+
"incomplete_expiry": "The expiry date is incomplete.",
|
|
27
|
+
"incomplete_number": "The card number is incomplete.",
|
|
28
|
+
"insufficient_funds": "The card has insufficient funds.",
|
|
29
|
+
"intent_already_final": "The payment intent is already in a final state.",
|
|
30
|
+
"intent_expired": "The payment intent has expired.",
|
|
31
|
+
"internal_error": "An unexpected internal error occurred.",
|
|
32
|
+
"invalid_card_number": "The card number is invalid.",
|
|
33
|
+
"invalid_client_token": "The client token is invalid or expired.",
|
|
34
|
+
"invalid_cvc": "The card security code is incorrect.",
|
|
35
|
+
"invalid_expiry": "The expiry date is invalid or in the past.",
|
|
36
|
+
"invalid_number": "The card number is invalid.",
|
|
37
|
+
"invalid_publishable_key": "The publishable key is invalid.",
|
|
38
|
+
"issuer_unavailable": "The card issuer is unavailable. Retry later.",
|
|
39
|
+
"merchant_misconfigured": "The merchant account or channel setup is incomplete. Contact support.",
|
|
40
|
+
"method_not_allowed": "The payment method is not enabled for this merchant account.",
|
|
41
|
+
"network_error": "A network error occurred. The payment outcome may still succeed - never assume failure.",
|
|
42
|
+
"origin_not_allowed": "The calling origin is not registered for this merchant account.",
|
|
43
|
+
"processing_timeout": "The payment outcome is not yet known and remains in processing.",
|
|
44
|
+
"provider_error": "The payment provider returned an unexpected response.",
|
|
45
|
+
"rate_limited": "Too many requests. Retry later.",
|
|
46
|
+
"refund_exceeds_paid": "The refund amount exceeds the amount still refundable.",
|
|
47
|
+
"request_invalid": "The request failed validation.",
|
|
48
|
+
"risk_declined": "Blocked by fraud screening.",
|
|
49
|
+
"saved_card_disabled": "The saved card has been disabled.",
|
|
50
|
+
"saved_card_not_found": "The saved card does not exist.",
|
|
51
|
+
"sdk_load_failed": "The payment component failed to load.",
|
|
52
|
+
"session_already_used": "The element session has already been used.",
|
|
53
|
+
"session_expired": "The element session has expired. Re-mount the fields.",
|
|
54
|
+
"threeds_cancelled": "The customer cancelled the 3D Secure challenge.",
|
|
55
|
+
"threeds_failed": "3D Secure authentication failed.",
|
|
56
|
+
"threeds_no_liability_shift": "Authentication completed but liability did not shift to the issuer.",
|
|
57
|
+
"threeds_not_supported": "The card or issuer is not enrolled for 3D Secure.",
|
|
58
|
+
"token_not_chargeable": "The saved card cannot be charged without a previous successful verification.",
|
|
59
|
+
"token_not_found": "The card token does not exist.",
|
|
60
|
+
"transaction_not_permitted": "The issuer does not permit this transaction for this card.",
|
|
61
|
+
"unsupported_brand": "This card brand is not accepted.",
|
|
62
|
+
"unsupported_currency": "The currency is not supported for this payment method.",
|
|
63
|
+
};
|
package/lib/errors.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Typed errors.
|
|
4
|
+
*
|
|
5
|
+
* Every rejection is a PaError carrying:
|
|
6
|
+
* - `code` — a stable code from the shared table (src/errors.generated.ts)
|
|
7
|
+
* - `developerMessage`— the English developer message from the shared table
|
|
8
|
+
* - `userMessage` — a localized user message the app may show directly
|
|
9
|
+
*
|
|
10
|
+
* Technical failures (network, not initialised, 3DS UI unavailable) reject
|
|
11
|
+
* with a PaError too — they are never reported as payment results.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.NotInitializedError = exports.PaError = void 0;
|
|
15
|
+
exports.userMessageForCode = userMessageForCode;
|
|
16
|
+
exports.isPaError = isPaError;
|
|
17
|
+
const errors_generated_1 = require("./errors.generated");
|
|
18
|
+
const locales_1 = require("./locales");
|
|
19
|
+
/** Codes that are validation field codes — user message key `field.<code>`. */
|
|
20
|
+
const FIELD_CODE_PREFIX = 'field.';
|
|
21
|
+
const FIELD_CODES = new Set([
|
|
22
|
+
'incomplete_number',
|
|
23
|
+
'invalid_number',
|
|
24
|
+
'incomplete_expiry',
|
|
25
|
+
'invalid_expiry',
|
|
26
|
+
'incomplete_cvc',
|
|
27
|
+
'invalid_cvc',
|
|
28
|
+
'unsupported_brand',
|
|
29
|
+
]);
|
|
30
|
+
/** Localized-message keys the locale bundles actually ship. */
|
|
31
|
+
const LOCALIZED_ERROR_KEYS = new Set([
|
|
32
|
+
'rate_limited',
|
|
33
|
+
'processing_timeout',
|
|
34
|
+
'sdk_load_failed',
|
|
35
|
+
'invalid_publishable_key',
|
|
36
|
+
'invalid_client_token',
|
|
37
|
+
'origin_not_allowed',
|
|
38
|
+
'font_load_failed',
|
|
39
|
+
]);
|
|
40
|
+
/** Localized user message for a shared-table code. Falls back
|
|
41
|
+
* to `error.generic` when the code has no dedicated string. */
|
|
42
|
+
function userMessageForCode(code, locale) {
|
|
43
|
+
const strings = (0, locales_1.getLocaleStrings)(locale);
|
|
44
|
+
if (FIELD_CODES.has(code)) {
|
|
45
|
+
return strings.t((FIELD_CODE_PREFIX + code));
|
|
46
|
+
}
|
|
47
|
+
if (LOCALIZED_ERROR_KEYS.has(code)) {
|
|
48
|
+
return strings.t(('error.' + code));
|
|
49
|
+
}
|
|
50
|
+
return strings.t('error.generic');
|
|
51
|
+
}
|
|
52
|
+
class PaError extends Error {
|
|
53
|
+
constructor(code, options = {}) {
|
|
54
|
+
const known = errors_generated_1.ERROR_DEVELOPER_MESSAGES[code];
|
|
55
|
+
const developerMessage = options.developerMessage || known || 'An unexpected error occurred.';
|
|
56
|
+
super(developerMessage);
|
|
57
|
+
this.name = 'PaError';
|
|
58
|
+
this.code = code;
|
|
59
|
+
this.developerMessage = developerMessage;
|
|
60
|
+
this.isFieldError = FIELD_CODES.has(code);
|
|
61
|
+
this.userMessage = userMessageForCode(code, options.locale);
|
|
62
|
+
if (options.cause !== undefined) {
|
|
63
|
+
this.cause = options.cause;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.PaError = PaError;
|
|
68
|
+
function isPaError(value) {
|
|
69
|
+
return value instanceof PaError;
|
|
70
|
+
}
|
|
71
|
+
/** Thrown when the SDK is used before init(). */
|
|
72
|
+
class NotInitializedError extends PaError {
|
|
73
|
+
constructor() {
|
|
74
|
+
super('internal_error', {
|
|
75
|
+
developerMessage: 'PA SDK is not initialised. Call init() before any other call.',
|
|
76
|
+
});
|
|
77
|
+
this.name = 'NotInitializedError';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.NotInitializedError = NotInitializedError;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PA SDK React Native — public entry point.
|
|
3
|
+
*
|
|
4
|
+
* Headless card SDK for React Native: the app builds its own
|
|
5
|
+
* card UI; the SDK provides validation, tokenization, confirm with built-in
|
|
6
|
+
* 3DS, save-card and multi-market merchant accounts.
|
|
7
|
+
*
|
|
8
|
+
* Quickstart:
|
|
9
|
+
* import * as PaSdk from 'pa-sdk-react-native';
|
|
10
|
+
*
|
|
11
|
+
* PaSdk.init({
|
|
12
|
+
* environment: 'sandbox',
|
|
13
|
+
* accounts: { HK: 'mt_hk_live_or_sandbox', MY: 'mt_my_...' },
|
|
14
|
+
* defaultAccount: 'HK',
|
|
15
|
+
* locale: 'zh_HK',
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* const result = await PaSdk.confirmWithCard({
|
|
19
|
+
* card: { cardNumber: '4242...', expiryMonth: 12, expiryYear: 29, cvc: '123' },
|
|
20
|
+
* intentToken, clientToken, // from your server only
|
|
21
|
+
* idempotencyKey: myUuid,
|
|
22
|
+
* saveCard: saveChecked,
|
|
23
|
+
* onThreeDsWillPresent: () => hideLoadingOverlay(),
|
|
24
|
+
* });
|
|
25
|
+
* // result.status: 'succeeded' | 'authorized' | 'processing' | 'cancelled' | 'failed'
|
|
26
|
+
*/
|
|
27
|
+
export { init, getSdk, getSdkOrNull, updateLocale, deinitialize } from './init';
|
|
28
|
+
export type { PaAccount, PaSdkInstance } from './init';
|
|
29
|
+
export { detectBrand, luhnValid, sanitizeCardNumber, validateCard, validateCardNumber, validateCvc, validateExpiry, cvcLengthsForBrand, } from './validator';
|
|
30
|
+
export type { BrandInfo, CardValidation, CvcValidation, ExpiryValidation, NumberValidation } from './validator';
|
|
31
|
+
export { createElementSession, tokenizeCard } from './tokenize';
|
|
32
|
+
export { confirmWithToken, confirmWithCard, cancelIntent, resetConfirmState, AlreadyFinalError } from './confirm';
|
|
33
|
+
export type { ConfirmBaseOptions, ConfirmWithCardOptions, ConfirmWithTokenOptions } from './confirm';
|
|
34
|
+
export { AppStateAwarePoller, pollUntil, DEFAULT_POLLER_OPTIONS } from './poll';
|
|
35
|
+
export type { PollCheck, PollerOptions } from './poll';
|
|
36
|
+
export { PaError, isPaError, userMessageForCode, NotInitializedError } from './errors';
|
|
37
|
+
export { DEFAULT_LOCALE, SUPPORTED_LOCALES, getLocale, getLocaleStrings, normalizeLocale, resolveBundle, setLocale, } from './locales';
|
|
38
|
+
export { canPresentThreeDs, closeThreeDs, presentThreeDs, setThreeDsPresenter } from './threeDs';
|
|
39
|
+
export type { ThreeDsDismissal, ThreeDsParams, ThreeDsPresenter, ThreeDsStrings } from './threeDs';
|
|
40
|
+
export { PaSdk3dsHost } from './threeDsHost';
|
|
41
|
+
export { ApiClient, GATEWAY_BASE_URLS } from './api';
|
|
42
|
+
export type { BillingDetails, CardBrand, CardInput, ConfirmGatewayPayload, Environment, FieldErrorCode, InitOptions, PaymentResult, ResultStatus, TokenizeOutput, TokenizeResult, } from './types';
|
|
43
|
+
export { POLL_FAST_ATTEMPTS, POLL_FAST_INTERVAL_MS, POLL_SLOW_ATTEMPTS, POLL_SLOW_INTERVAL_MS, } from './types';
|