PA SDK React Native
Payment Asia card payment SDK for React Native — headless card validation,
direct tokenization, payment confirmation with built-in 3D Secure
(SDK-presented challenge), card saving, and multi-market merchant accounts.
Shares its error codes, locales and gateway contract with the PA SDK web
component.
- Scope: Visa and Mastercard (other schemes are detected early so the app
can block them).
- Result states (exactly five):
succeeded · authorized · processing
· cancelled · failed. Unknown outcomes resolve processing, never
failed.
Requirements
|
|
| React Native |
>= 0.79 (New Architecture + Hermes) |
| iOS |
13.0+ |
| Android |
API 24+ (Android 7.0) |
| Native dependency |
react-native-webview ^13 (used by the JS fallback presenter; the primary 3DS presenter is the SDK's own native WebView) |
No other native dependencies — no ads, analytics or billing SDKs.
Install
npm install pa-sdk-react-native
iOS
The podspec ships with the package (autolinked by RN 0.79+):
cd ios && pod install && cd ..
The native 3DS module is a classic NativeModules bridge
(native/ios/PaSdk3dsModule.m + PaSdk3ds.swift). It runs unchanged on the
New Architecture through React Native's interop layer — no codegen setup
needed.
Android
Autolinking picks up native/android — the only setup is the return-URL
placeholders. The library manifest registers a full-screen 3DS challenge
activity (PaSdk3dsActivity) whose intent-filters read two manifest
placeholders. Define your 3DS return URLs once in your app's
android/app/build.gradle:
android {
defaultConfig {
manifestPlaceholders = [
paSdk3dsReturnScheme: "yourapp", // custom scheme, no "://"
paSdk3dsReturnHost: "links.yourdomain.com" // universal-link host, no "https://"
]
}
}
The build fails if the placeholders are missing, so a missing configuration
is caught before release, not in production. The values must match the
threeDsReturnUrls you pass to init().
While a challenge is pending, the SDK consumes its own 3DS return URIs
(the custom scheme and universal-link host above); the app's own deep-link
handler never sees them. When no challenge is pending, matched URIs are
re-dispatched to the app's launch intent, so the app's normal link handling
proceeds. Do not declare overlapping intent-filters for those exact paths
unless you also want to handle them outside 3DS.
Quickstart
import { PaSdk3dsHost } from 'pa-sdk-react-native'; // optional JS 3DS fallback
// 1. Init — once, from your app's build config. One init, many merchant
// accounts. Publishable merchant tokens only — never a secret key.
import { init } from 'pa-sdk-react-native';
init({
environment: 'sandbox', // or 'production'
accounts: {
HK: 'mt_hk_...', // publishable merchantToken
MY: 'mt_my_...',
SG: 'mt_sg_...',
TW: 'mt_tw_...',
},
defaultAccount: 'HK',
locale: 'zh_HK', // en_US / zh_HK / zh_CN / my_MY
origin: 'https://app.yourdomain.com',
threeDsReturnUrls: { // consumed by the SDK
scheme: 'yourapp://',
universalLinkHost: 'https://links.yourdomain.com',
},
});
// Mount the fallback presenter once if the native module may be absent:
// <PaSdk3dsHost />
One-off payment (combined)
import { confirmWithCard } from 'pa-sdk-react-native';
const result = await confirmWithCard({
card: { cardNumber, expiryMonth, expiryYear, cvc, cardHolderName }, // from YOUR UI
intentToken, clientToken, // from your server only
idempotencyKey, // yours, unique per attempt
allowedBrands: ['visa', 'mastercard'], // from your server
onThreeDsWillPresent: () => hideLoadingOverlay(),
market: 'HK', // merchant account selection
});
// result.status: 'succeeded' | 'authorized' | 'processing' | 'cancelled' | 'failed'
Two-step payment (tokenize + confirm)
import { tokenizeCard, confirmWithToken } from 'pa-sdk-react-native';
// Step 1: card data goes straight to PA, never through your app's server
const { result: token } = await tokenizeCard(getSdk().api, {
card,
merchantToken: 'mt_hk_...', // per-market publishable token
});
// token = { paToken, last4, brand }
// Step 2: confirm the intent with the token
const result = await confirmWithToken({
paToken: token.paToken,
intentToken, clientToken, idempotencyKey,
onThreeDsWillPresent: () => hideLoadingOverlay(),
});
Save the card during payment
const result = await confirmWithCard({ card, intentToken, clientToken,
saveCard: true, idempotencyKey });
// result.paToken / result.brand / result.last4 arrive synchronously.
// The token is MIT-ready: your server charges it later via the Backend
// Recurring Payment API (/recurring/pay) or an intent-based server-side
// confirm.
Add a card without paying (verification intent)
Same call against a verification intent your server creates (zero amount,
or a minimal amount settable per request). saveCard: true, 3DS runs if the
issuer requires it; nothing is charged; pa_token returns synchronously.
3D Secure
Everything is inside confirm:
- The SDK presents the challenge (full-screen native WebView; Cardinal StepUp
JWT POST, or ACS
creq POST for the 3DS1 / non-frameable fallback).
onThreeDsWillPresent fires immediately before it appears (dismiss your
overlay there), onThreeDsEnded when it is gone (informational).
- The user can cancel the challenge →
cancelled (the SDK also cancels the
intent server-side, best effort).
- While the challenge is open the SDK polls
intent-status; the gateway
posts the result server-side, and the first observed terminal state wins.
- App-switch (banking app): polling is AppState-aware — the schedule is
2s x 15 then 5s x 12, suspended time while backgrounded does not count
against the budget, and polling resumes on return. Budget exhausted with
no answer →
processing, never failed.
- The challenge's return URLs (configured scheme + universal link) are
consumed by the SDK without surfacing to the app's link handler.
Multi-market
One init; pick the account per call with market. Currency and country are
per intent on your server.
Cancel an intent
import { cancelIntent } from 'pa-sdk-react-native';
await cancelIntent({ intentToken, clientToken }); // -> { status: 'cancelled' }
Validation helpers
import { validateCard, validateCardNumber, validateExpiry, validateCvc, detectBrand } from 'pa-sdk-react-native';
detectBrand('222100...').brand // 'mastercard' — 2-series 2221–2720 recognised
validateCardNumber('4242...', ['visa']) // Luhn, length, brand filter
validateCard(card, ['visa', 'mastercard'])
// -> { brand, complete, fields: { cardNumber?, expiry?, cvc? } }
// field codes: incomplete_number, invalid_number, incomplete_expiry,
// invalid_expiry, incomplete_cvc, invalid_cvc, unsupported_brand
Rules: Visa/Mastercard lengths, Luhn, current BIN ranges (Mastercard 2-series
2221–2720 included), 3-digit CVC, expiry not in the past — no valid Visa /
Mastercard is ever blocked.
Results and errors
interface PaymentResult {
status: 'succeeded' | 'authorized' | 'processing' | 'cancelled' | 'failed';
intentToken?: string;
requestReference?: string | null; // PA's reference for this attempt
merchantReference?: string | null;
paToken?: string | null; // set when a card was saved
brand?: string | null;
last4?: string | null;
errorCode?: string | null; // shared error-code table, for 'failed'
errorMessage?: string | null; // English developer message
userMessage?: string | null; // localized — show this, log the code
}
Every rejection is a PaError with code, developerMessage (English, from
the shared error table used across PA SDK components — API, webhooks, web and
this SDK) and userMessage (localized). Technical failures reject with typed
errors and are never payment results. Client-side, a second confirm on an
in-flight intent rejects with duplicate_confirm; confirming an
already-final intent returns its stored result.
Locales
en-US, zh-TW (serves zh_HK/zh-HK), zh-CN, ms-MY.
Accepts underscore/hyphen, case-insensitive (zh_HK, zh-hk, ms). Unknown
tags fall back along exact tag → same language → en-US, never error.
Change locale at runtime with updateLocale('zh_CN').
Gateway endpoints used
All POST JSON under https://gateway.pa-sys.com/pasdk/v1 (prod) /
https://gateway-sandbox.pa-sys.com/pasdk/v1 (sandbox), envelope
{request, response:{code,message}, payload}; business errors ride HTTP 200
with response.code != 200:
| Endpoint |
Used by |
/{merchantToken}/element-sessions |
createElementSession |
/tokenize |
tokenizeCard |
/confirm |
confirmWithToken / confirmWithCard |
/intent-cancel |
cancelIntent, 3DS user-cancel |
/intent-status |
polling (2s x 15, then 5s x 12) |
Error-code / locale generation (maintainers)
src/errors.generated.ts and src/locales.generated.ts ship pre-generated
in the package; merchants never need to run these. Regeneration is only
required when the shared PA SDK tables change:
node scripts/generate-errors.js [path/to/errors.json]
node scripts/generate-locales.js # mirrors locales/*.json into src/
Example app
See example/ — a runnable RN 0.79 (New Architecture) app covering one-off
payment, two-step payment, save during payment, manual save, 3DS
challenge/cancel and multi-market switching.
Technical notes
- The native 3DS modules use the classic
NativeModules bridge via
RCT_EXTERN_METHOD (iOS) and ReactPackage (Android). On the New
Architecture this runs through RN's interop layer — supported, but not a
codegen TurboModule spec yet.
- The JS fallback presenter (
<PaSdk3dsHost />, backed by
react-native-webview) is only used when the native module is missing;
its return-URL consumption happens via WebView navigation interception.
confirmWithCard validates with allowedBrands before any network call;
brand detection and allowedBrands filtering both live in validator.ts.
- Android: when no 3DS challenge is pending,
PaSdk3dsActivity re-dispatches
a matched URI to the app's launch intent so non-3DS deep links are not lost.