OrderNext Webview

OrderNext Webview Integration

Any OrderNext mobile website can be integrated as a webview in iOS or Android. In order to supply extra data the host app can call a JavaScript function on the OrderNext page. This data is used to faciliate checkout and apply discounts.

JavaScript Function:

setExternalUserData(externalUserData)

Sets user data from an webview host.

Param Type Description
externalUserData object External Data supplied by webview host.
[externalUserData.email] string The email of the user.
[externalUserData.affiliation] string The affiliation of the user.
[externalUserData.locationType] string The locationType of the user either “room” or “seat”.
[externalUserData.location] Room | Seat The location of the user.

Room : Object

A room location defined by a name property

Properties

Name Type Description
name string The room name

Seat : Object

A seat location defined by section, row, and seat properties

Properties

Name Type Description
section string The section of the seat
row string The row of the seat
seat string The seat

Minimal iOS example

import UIKit
import WebKit

class ViewController: UIViewController, WKUIDelegate {
    var webView: WKWebView!

    override func loadView() {
        let contentController = WKUserContentController()
        let jsSource = """
            setExternalUserData({
                name:"Sam Jones",
                email:"sam@example.org",
                affiliation:"STH",
                locationType: "seat",
                location: {
                    section: "106C",
                    row: "H",
                    seat: "7",
                },
            });
        """
        let script = WKUserScript(source: jsSource, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
        contentController.addUserScript(script)

        let config = WKWebViewConfiguration()
        config.userContentController = contentController

        webView = WKWebView(frame: .zero, configuration: config)
        webView.uiDelegate = self
        view = webView
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let myURL = URL(string:"https://demo.ordernext.com")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }
}

Minimal Android example

class MainActivity : AppCompatActivity() {

    private val url = "https://demo.ordernext.com"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        webview.getSettings().setJavaScriptEnabled(true);
        webview.webViewClient = object : WebViewClient() {
            override fun onPageFinished(view: WebView, url: String) {
                val jsSource = """
                    setExternalUserData({
                        name:"Sam Jones",
                        email:"sam@example.org",
                        affiliation:"STH",
                        locationType: "seat",
                        location: {
                            section: "106C",
                            row: "H",
                            seat: "7",
                        },
                    });
                """.trimIndent()
                webview.evaluateJavascript(jsSource, null);
            }
        }
        webview.loadUrl(url);
    }
}