Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading