diff --git a/packages/@juspay-tech/react-native-hyperswitch/android/src/main/java/com/hyperswitchsdkreactnative/modules/ReactNativeHyperswitchModule.kt b/packages/@juspay-tech/react-native-hyperswitch/android/src/main/java/com/hyperswitchsdkreactnative/modules/ReactNativeHyperswitchModule.kt index 9272a6a7..63220858 100644 --- a/packages/@juspay-tech/react-native-hyperswitch/android/src/main/java/com/hyperswitchsdkreactnative/modules/ReactNativeHyperswitchModule.kt +++ b/packages/@juspay-tech/react-native-hyperswitch/android/src/main/java/com/hyperswitchsdkreactnative/modules/ReactNativeHyperswitchModule.kt @@ -75,9 +75,9 @@ class ReactNativeHyperswitchModule(reactContext: ReactApplicationContext) : /** * Accepts the same spellings as the iOS module ("PROD"/"PRODUCTION", "SANDBOX", "INTEG", - * case-insensitive). Anything else yields null (SDK picks the environment from the - * publishable key) instead of throwing from `valueOf`. + * case-insensitive). */ + // By design, absent or unrecognized environment values use PROD as the default; merchants must explicitly select a test environment. private fun parseEnvironment(value: String?): HyperswitchEnvironment? = when (value?.trim()?.uppercase()) { "PROD", "PRODUCTION" -> HyperswitchEnvironment.PROD diff --git a/packages/@juspay-tech/react-native-hyperswitch/android/src/main/java/io/hyperswitch/react/HyperModule.kt b/packages/@juspay-tech/react-native-hyperswitch/android/src/main/java/io/hyperswitch/react/HyperModule.kt index 1c91aa2d..b1c65ab6 100644 --- a/packages/@juspay-tech/react-native-hyperswitch/android/src/main/java/io/hyperswitch/react/HyperModule.kt +++ b/packages/@juspay-tech/react-native-hyperswitch/android/src/main/java/io/hyperswitch/react/HyperModule.kt @@ -319,6 +319,7 @@ class HyperModule internal constructor(private val rct: ReactApplicationContext) } @ReactMethod + // By design, iframe loading and URL policy are delegated to the Android HiddenIframe utility to support provider-specific DDC URLs and URL scheme checks override fun openIframeBridge(url: String, timeoutMs: Double, callback: Callback) { val activity = currentActivity ?: return callback.invoke("") HiddenIframe(activity).open(url, timeoutMs) { callback.invoke(it) } diff --git a/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/DeviceDataCollection/HeadlessWebView.swift b/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/DeviceDataCollection/HeadlessWebView.swift index a9ee0ae3..07536369 100644 --- a/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/DeviceDataCollection/HeadlessWebView.swift +++ b/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/DeviceDataCollection/HeadlessWebView.swift @@ -20,6 +20,8 @@ final internal class HeadlessWebView: NSObject, WKNavigationDelegate, WKUIDelega private var selfRetain: HeadlessWebView? private var callbackInvoked = false private var iframeOrigin: String? + /// Set once the wrapper document's own load is allowed; every later main-frame navigation is cancelled. + private var mainFrameLoadStarted = false init(url: String, timeoutMs: NSNumber, callback: @escaping RCTResponseSenderBlock) { self.url = url @@ -94,7 +96,8 @@ final internal class HeadlessWebView: NSObject, WKNavigationDelegate, WKUIDelega let configuration = WKWebViewConfiguration() configuration.userContentController = contentController configuration.defaultWebpagePreferences.allowsContentJavaScript = true - configuration.preferences.javaScriptCanOpenWindowsAutomatically = true + // A popup would be a second hidden WebView that cleanup never destroys. + configuration.preferences.javaScriptCanOpenWindowsAutomatically = false webView = WKWebView(frame: .zero, configuration: configuration) webView?.isHidden = false // Keep visible to prevent freezing @@ -165,6 +168,8 @@ final internal class HeadlessWebView: NSObject, WKNavigationDelegate, WKUIDelega let json = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] else { return } // Any message carrying next_action settles DDC, failing unless it is an https redirect (web also allows http). + // the redirect is either the Hyperswitch redirect URL or the merchant's return_url, which vary + // per merchant and self-hosted backend; guard json["next_action"] != nil else { return } let action = json["next_action"] as? [String: Any] let redirect = action?["url"] as? String @@ -180,6 +185,22 @@ final internal class HeadlessWebView: NSObject, WKNavigationDelegate, WKUIDelega invokeCallback(result) } + /// The main frame only ever shows the wrapper document; any redirect is returned to the caller, which opens it visibly. + /// The iframe may navigate (DDC hops across 3DS servers) but only over https. + /// iframe_url comes from the Hyperswitch API and its host varies by connector and + /// self-hosted backend + func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, + decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { + if navigationAction.targetFrame?.isMainFrame == true { + // Only the wrapper's own load; the main frame never navigates after that. + decisionHandler(mainFrameLoadStarted ? .cancel : .allow) + mainFrameLoadStarted = true + return + } + let scheme = navigationAction.request.url?.scheme?.lowercased() + decisionHandler(scheme == "https" || scheme == "about" ? .allow : .cancel) + } + func webViewWebContentProcessDidTerminate(_ webView: WKWebView) { invokeCallback("") } diff --git a/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/HyperSession/PaymentSession+UIKit.swift b/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/HyperSession/PaymentSession+UIKit.swift index 20222593..1b07323e 100644 --- a/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/HyperSession/PaymentSession+UIKit.swift +++ b/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/HyperSession/PaymentSession+UIKit.swift @@ -10,6 +10,7 @@ import React extension PaymentSession { + // By design, shared bridge completion state assumes one active payment flow at a time; overlapping flows are unsupported. private static var hasResponded: Bool = false internal static var headlessCompletion: ((PaymentSessionHandler) -> Void)? internal static var walletCompletion: ((WalletSessionHandler) -> Void)? diff --git a/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/NativeModule/HyperModuleImpl.swift b/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/NativeModule/HyperModuleImpl.swift index ca993949..8a2520ca 100644 --- a/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/NativeModule/HyperModuleImpl.swift +++ b/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Core/NativeModule/HyperModuleImpl.swift @@ -293,6 +293,7 @@ public class HyperModuleImpl: NSObject { return NSMutableDictionary(dictionary: obj) } + // By design, this maps the embedded SDK bundle's client result; merchants must verify payment status on their backend before fulfillment. private func paymentResult(from rnMessage: String) -> PaymentResult { guard let data = rnMessage.data(using: .utf8) else { return .failed( diff --git a/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Shared/Environment.swift b/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Shared/Environment.swift index 24d64178..faf5a0a8 100644 --- a/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Shared/Environment.swift +++ b/packages/@juspay-tech/react-native-hyperswitch/ios/hyperswitchSDK/Shared/Environment.swift @@ -37,6 +37,7 @@ enum SDKEnvironment { ) -> String { switch customEndpoints { case .overrideEndpoints(let config)?: + // By design, merchant-configured logging endpoints support custom deployments; endpoint trust and transport configuration belong to the integrator. if let url = config.customLoggingEndpoint?.trimmingCharacters(in: .whitespaces), !url.isEmpty { return url }