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
|
@@ -3,13 +3,13 @@ import UIKit
|
|
|
3
3
|
import WebKit
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* PaSdk3ds — SDK-presented 3DS challenge for iOS
|
|
6
|
+
* PaSdk3ds — SDK-presented 3DS challenge for iOS.
|
|
7
7
|
*
|
|
8
8
|
* Presents a full-screen WKWebView view controller that auto-submits a POST
|
|
9
9
|
* form carrying the Cardinal JWT (3DS2 StepUp) or the ACS creq (3DS1
|
|
10
10
|
* fallback) to the challenge URL. The gateway posts the challenge result
|
|
11
11
|
* server-side; the JS layer observes it via /intent-status polling and calls
|
|
12
|
-
* `close`, or the user taps Cancel, which resolves `cancelled
|
|
12
|
+
* `close`, or the user taps Cancel, which resolves `cancelled`.
|
|
13
13
|
*
|
|
14
14
|
* Bridged by PaSdk3dsModule.m via RCT_EXTERN_METHOD (classic NativeModules
|
|
15
15
|
* bridge; runs on the New Architecture through the interop layer).
|
|
@@ -57,11 +57,11 @@ public final class PaSdk3ds: NSObject {
|
|
|
57
57
|
strings: strings,
|
|
58
58
|
returnUrlScheme: returnUrlScheme,
|
|
59
59
|
returnUrlUniversalHost: returnUrlUniversalHost
|
|
60
|
-
) {
|
|
60
|
+
) { cancelled, returnUrlConsumed in
|
|
61
61
|
PaSdk3ds.activeViewController = nil
|
|
62
62
|
PaSdk3ds.pendingResolve = nil
|
|
63
|
-
resolve(["cancelled":
|
|
64
|
-
"returnUrlConsumed":
|
|
63
|
+
resolve(["cancelled": cancelled,
|
|
64
|
+
"returnUrlConsumed": returnUrlConsumed])
|
|
65
65
|
}
|
|
66
66
|
PaSdk3ds.activeViewController = viewController
|
|
67
67
|
|
|
@@ -78,13 +78,41 @@ public final class PaSdk3ds: NSObject {
|
|
|
78
78
|
/// close() — dismiss the challenge after the JS poller observed a terminal
|
|
79
79
|
/// state; the present() promise resolves with cancelled: false.
|
|
80
80
|
@objc(close:)
|
|
81
|
-
public func close(_ resolve: (Any?) -> Void) {
|
|
81
|
+
public func close(_ resolve: @escaping (Any?) -> Void) {
|
|
82
82
|
DispatchQueue.main.async {
|
|
83
83
|
PaSdk3ds.dismissActive(animated: true)
|
|
84
84
|
resolve(nil)
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/// handleReturnUrl(url) — app-switch return hook for the app's own
|
|
89
|
+
/// AppDelegate/SceneDelegate link handler. A true app-switch return (e.g.
|
|
90
|
+
/// from a banking app) lands there instead of inside the challenge's own
|
|
91
|
+
/// WebView. Resolves true only when a challenge is pending AND the URL
|
|
92
|
+
/// matches its 3DS return URLs; the challenge is then consumed (dismissed,
|
|
93
|
+
/// present() resolves with returnUrlConsumed: true) and the app must ignore
|
|
94
|
+
/// the URL. Resolves false with no challenge pending or on a non-matching
|
|
95
|
+
/// URL — the app handles the URL as usual.
|
|
96
|
+
@objc(handleReturnUrl:resolver:rejecter:)
|
|
97
|
+
public func handleReturnUrl(_ url: String,
|
|
98
|
+
resolver resolve: @escaping (Any?) -> Void,
|
|
99
|
+
rejecter reject: @escaping (NSString?, NSString?, NSError?) -> Void) {
|
|
100
|
+
DispatchQueue.main.async {
|
|
101
|
+
guard let active = PaSdk3ds.activeViewController else {
|
|
102
|
+
resolve(false)
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
if active.matchesReturnUrl(url) {
|
|
106
|
+
active.consumeReturnUrl()
|
|
107
|
+
PaSdk3ds.activeViewController = nil
|
|
108
|
+
PaSdk3ds.pendingResolve = nil
|
|
109
|
+
resolve(true)
|
|
110
|
+
} else {
|
|
111
|
+
resolve(false)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
88
116
|
static func dismissActive(animated: Bool) {
|
|
89
117
|
if let active = activeViewController {
|
|
90
118
|
active.finishDismissal = nil // resolve via close, not as a cancel
|
|
@@ -262,25 +290,40 @@ public final class PaSdk3dsViewController: UIViewController, WKNavigationDelegat
|
|
|
262
290
|
}
|
|
263
291
|
}
|
|
264
292
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if let scheme = returnUrlScheme,
|
|
274
|
-
let url = url,
|
|
293
|
+
/// True when the URL matches this challenge's configured 3DS return
|
|
294
|
+
/// scheme or universal-link host — the same matcher used for the
|
|
295
|
+
/// in-WebView navigation consumption and for the app-switch
|
|
296
|
+
/// handleReturnUrl hook.
|
|
297
|
+
func matchesReturnUrl(_ urlString: String) -> Bool {
|
|
298
|
+
guard let url = URL(string: urlString) else {
|
|
299
|
+
return false
|
|
300
|
+
}
|
|
301
|
+
if let scheme = returnUrlScheme, !scheme.isEmpty,
|
|
275
302
|
url.absoluteString.lowercased().hasPrefix(scheme.lowercased()) {
|
|
276
|
-
|
|
277
|
-
finish(cancelled: false, returnUrlConsumed: true)
|
|
278
|
-
return
|
|
303
|
+
return true
|
|
279
304
|
}
|
|
280
|
-
if let host = returnUrlUniversalHost,
|
|
281
|
-
let url = url,
|
|
305
|
+
if let host = returnUrlUniversalHost, !host.isEmpty,
|
|
282
306
|
let hostComponent = URLComponents(url: url, resolvingAgainstBaseURL: false)?.host,
|
|
283
307
|
hostComponent.lowercased().hasSuffix(host.lowercased().replacingOccurrences(of: "https://", with: "")) {
|
|
308
|
+
return true
|
|
309
|
+
}
|
|
310
|
+
return false
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/// Consume a 3DS return that reached the app's own link handler
|
|
314
|
+
/// (app-switch flow): dismisses the challenge as a completed return.
|
|
315
|
+
func consumeReturnUrl() {
|
|
316
|
+
finish(cancelled: false, returnUrlConsumed: true)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// WKNavigationDelegate: when the ACS bounces through the 3DS
|
|
320
|
+
// return URLs (the configured scheme or the universal-link host), consume
|
|
321
|
+
// the navigation here so the app's own link handler never sees it, then
|
|
322
|
+
// let the JS poller observe the server-side result.
|
|
323
|
+
public func webView(_ webView: WKWebView,
|
|
324
|
+
decidePolicyFor navigationAction: WKNavigationAction,
|
|
325
|
+
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
|
|
326
|
+
if let url = navigationAction.request.url, matchesReturnUrl(url.absoluteString) {
|
|
284
327
|
decisionHandler(.cancel)
|
|
285
328
|
finish(cancelled: false, returnUrlConsumed: true)
|
|
286
329
|
return
|
|
@@ -11,13 +11,9 @@
|
|
|
11
11
|
#import <React/RCTBridgeModule.h>
|
|
12
12
|
#import <React/RCTLog.h>
|
|
13
13
|
|
|
14
|
-
#
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
#import "PaSdkReactNative-Swift.h"
|
|
18
|
-
#else
|
|
19
|
-
#import <pa_sdk_react_native/pa_sdk_react_native-Swift.h>
|
|
20
|
-
#endif
|
|
14
|
+
// No #import of the generated "pa_sdk_react_native-Swift.h" here: the
|
|
15
|
+
// RCT_EXTERN_REMAP_MODULE expansion declares @interface PaSdk3dsSwift itself,
|
|
16
|
+
// and importing the Swift header too is a duplicate class interface.
|
|
21
17
|
|
|
22
18
|
@interface RCT_EXTERN_REMAP_MODULE(PaSdk3ds, PaSdk3dsSwift, NSObject)
|
|
23
19
|
|
|
@@ -27,8 +23,8 @@
|
|
|
27
23
|
* url: NSString — Cardinal StepUp URL or issuer ACS URL
|
|
28
24
|
* fields: NSDictionary — form fields, e.g. {JWT: "..."} or {creq: "..."}
|
|
29
25
|
* strings: NSDictionary — {title, cancel, close, processing, redirecting}
|
|
30
|
-
* returnUrlScheme: NSString — e.g. "
|
|
31
|
-
* returnUrlUniversalHost: NSString — e.g. "https://
|
|
26
|
+
* returnUrlScheme: NSString — e.g. "yourapp://" (optional)
|
|
27
|
+
* returnUrlUniversalHost: NSString — e.g. "https://links.yourapp.com" (optional)
|
|
32
28
|
* }
|
|
33
29
|
* resolves: { cancelled: BOOL, returnUrlConsumed: BOOL }
|
|
34
30
|
*/
|
|
@@ -39,6 +35,17 @@ RCT_EXTERN_METHOD(present:(NSDictionary *)params
|
|
|
39
35
|
/** Dismiss the challenge after the JS poller observed a terminal state. */
|
|
40
36
|
RCT_EXTERN_METHOD(close:(RCTPromiseResolveBlock)resolve)
|
|
41
37
|
|
|
38
|
+
/**
|
|
39
|
+
* App-switch return hook. The app's AppDelegate/SceneDelegate must call this
|
|
40
|
+
* FIRST for every incoming URL and ignore the URL when it resolves YES:
|
|
41
|
+
* resolves YES when a 3DS challenge is pending and the URL matches its
|
|
42
|
+
* return URLs (the challenge is consumed); NO when no challenge is pending
|
|
43
|
+
* or the URL does not match.
|
|
44
|
+
*/
|
|
45
|
+
RCT_EXTERN_METHOD(handleReturnUrl:(NSString *)url
|
|
46
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
47
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
48
|
+
|
|
42
49
|
+ (BOOL)requiresMainQueueSetup
|
|
43
50
|
{
|
|
44
51
|
return NO;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pa-sdk-react-native",
|
|
3
|
-
"version": "3.0.
|
|
4
|
-
"description": "Payment Asia card payment SDK for React Native — headless validation, tokenization,
|
|
3
|
+
"version": "3.0.2",
|
|
4
|
+
"description": "Payment Asia card payment SDK for React Native — headless card validation, tokenization, payment confirmation with built-in 3D Secure, card saving and multi-market merchant accounts.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -46,4 +46,4 @@
|
|
|
46
46
|
"url": "git+https://git.prizm.digital/nelson.lin/security_component_rn.git"
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://git.prizm.digital/nelson.lin/security_component_rn#readme"
|
|
49
|
-
}
|
|
49
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Generates src/errors.generated.ts from the shared PA SDK error code table
|
|
4
4
|
* (errors.json, the single source of truth also used by the web SDK and the
|
|
5
|
-
* server API
|
|
5
|
+
* server API).
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
8
|
* node scripts/generate-errors.js [path/to/errors.json]
|
|
@@ -61,7 +61,7 @@ const header = [
|
|
|
61
61
|
', generated_at: ' + (table.generated_at || 'unknown') + '.',
|
|
62
62
|
' *',
|
|
63
63
|
' * One code table shared by the server API, webhooks, the web SDK and this',
|
|
64
|
-
' * React Native SDK
|
|
64
|
+
' * React Native SDK. Values are English developer',
|
|
65
65
|
' * messages; localized user messages live in the locale bundles.',
|
|
66
66
|
' */',
|
|
67
67
|
'',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* Generates src/locales.generated.ts from the canonical locale bundles in
|
|
4
|
-
* locales/*.json (
|
|
4
|
+
* locales/*.json (en-US, zh-TW, zh-CN, ms-MY).
|
|
5
5
|
*
|
|
6
6
|
* The JSON files in locales/ are the source of truth; this script mirrors
|
|
7
7
|
* them into src/ so the TypeScript build stays self-contained under rootDir.
|
|
@@ -38,9 +38,8 @@ const out = [
|
|
|
38
38
|
' * GENERATED FILE — do not edit by hand.',
|
|
39
39
|
' * Generated by scripts/generate-locales.js from locales/*.json.',
|
|
40
40
|
' *',
|
|
41
|
-
' * Locale coverage
|
|
42
|
-
' * serves zh_HK/zh-HK), zh-CN (complete), ms-MY (my_MY —
|
|
43
|
-
' * falls back to en-US at runtime until translations are supplied).',
|
|
41
|
+
' * Locale coverage: en-US (complete), zh-TW (complete,',
|
|
42
|
+
' * serves zh_HK/zh-HK), zh-CN (complete), ms-MY (my_MY — complete).',
|
|
44
43
|
' */',
|
|
45
44
|
'',
|
|
46
45
|
'export interface LocaleMeta {',
|
|
@@ -66,6 +65,27 @@ const out = [
|
|
|
66
65
|
" | 'error.invalid_client_token'",
|
|
67
66
|
" | 'error.origin_not_allowed'",
|
|
68
67
|
" | 'error.font_load_failed'",
|
|
68
|
+
" | 'error.card_declined'",
|
|
69
|
+
" | 'error.insufficient_funds'",
|
|
70
|
+
" | 'error.expired_card'",
|
|
71
|
+
" | 'error.invalid_cvc'",
|
|
72
|
+
" | 'error.invalid_number'",
|
|
73
|
+
" | 'error.unsupported_brand'",
|
|
74
|
+
" | 'error.unsupported_currency'",
|
|
75
|
+
" | 'error.threeds_failed'",
|
|
76
|
+
" | 'error.threeds_cancelled'",
|
|
77
|
+
" | 'error.threeds_not_supported'",
|
|
78
|
+
" | 'error.threeds_no_liability_shift'",
|
|
79
|
+
" | 'error.amount_above_limit'",
|
|
80
|
+
" | 'error.amount_below_limit'",
|
|
81
|
+
" | 'error.frequency_limit'",
|
|
82
|
+
" | 'error.risk_declined'",
|
|
83
|
+
" | 'error.issuer_unavailable'",
|
|
84
|
+
" | 'error.acquirer_unavailable'",
|
|
85
|
+
" | 'error.refund_exceeds_paid'",
|
|
86
|
+
" | 'error.duplicate_confirm'",
|
|
87
|
+
" | 'error.intent_expired'",
|
|
88
|
+
" | 'error.intent_already_final'",
|
|
69
89
|
" | 'field.incomplete_number'",
|
|
70
90
|
" | 'field.invalid_number'",
|
|
71
91
|
" | 'field.incomplete_expiry'",
|