Skip to main content

Custom Scan Result

By default, after a successful scan the Web Video Authentication shows the landing page inside the WebView. If you want to display a native result screen with a different layout and product information instead, you can intercept the redirect and present your own activity or view controller.

When configured for native app integration, the authentication redirects to a URL that carries both the scan id and an API key, for example:

scantrust://scan-result?uid=<scan-id>&api_key=<api-key>

Intercept this URL in your WebView's navigation handler, extract the uid and api_key, and use them to fetch the scan data from the Scantrust Consumer API.

Note: The redirect target is configured in your campaign in the Scantrust Portal. It can be a custom scheme like the example above or a Scantrust-hosted URL, so read the uid and api_key from whichever form your campaign uses. If you need help, please contact Scantrust support.

Android

Set a WebViewClient on your WebView and override shouldOverrideUrlLoading to catch the redirect before the WebView attempts to navigate to it:

webView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(
view: WebView?, request: WebResourceRequest?
): Boolean {
val uri = request?.url ?: return false
// Match the redirect your campaign is configured to use. This example
// matches scantrust://scan-result. For an stc.scantrust.com redirect,
// check the https scheme and that host instead.
if (uri.scheme == "scantrust" && uri.host == "scan-result") {
val uid = uri.getQueryParameter("uid")
val apiKey = uri.getQueryParameter("api_key")
if (uid != null && apiKey != null) {
val intent = Intent(this@MainActivity, ScanResultActivity::class.java)
.putExtra("uid", uid)
.putExtra("api_key", apiKey)
startActivity(intent)
}
return true
}
return false
}
}

For the full pattern including a result activity that fetches and renders scan data, see the Android example app.

iOS

Conform to WKNavigationDelegate, assign it to your WebView's navigationDelegate, and implement decidePolicyFor:

func webView(_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
// Match the redirect your campaign is configured to use. This example
// matches scantrust://scan-result. For an stc.scantrust.com redirect,
// check the https scheme and that host instead.
if let url = navigationAction.request.url,
url.scheme == "scantrust", url.host == "scan-result",
let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let uid = components.queryItems?.first(where: { $0.name == "uid" })?.value,
let apiKey = components.queryItems?.first(where: { $0.name == "api_key" })?.value {
let resultVC = ScanResultViewController(uid: uid, apiKey: apiKey)
navigationController?.pushViewController(resultVC, animated: true)
decisionHandler(.cancel)
return
}
decisionHandler(.allow)
}

For the full pattern including a result view controller that fetches and renders scan data, see the iOS example app.

Fetching the Scan Details

Once you have the uid and api_key, fetch the scan data from the Consumer API:

GET https://api.scantrust.com/api/v2/consumer/scan/<uid>/combined-info/

Authenticate by passing the api_key you extracted from the redirect as the X-ScanTrust-Consumer-Api-Key header. The response contains the product, scan, and verification information needed to render your native result screen.

See the Scantrust Consumer API documentation for the full request and response shape.