This guide walks you through the steps to integrate the Push Cash user experience into a mobile application. The example uses a Swift iOS application which displays the UX in a webview, but the same principles can be applied to other platforms.

Load the UX in a webview

First you will write a View to load the UX in a webview. This view will be presented when the user taps a button in your application.

import SwiftUI
import WebKit

struct ContentView: View {
    @State private var isWebViewPresented = false

    var body: some View {
       VStack {
            if isWebViewPresented {
                // replace with the URL returned from the create intent API
                let urlString = "{PLACEHOLDER}"
                WebView(urlString: urlString, isPresented: $isWebViewPresented ).edgesIgnoringSafeArea(.all)
            } else {
                Text("SportsBook")
                Button("Deposit/Withdraw") {
                    isWebViewPresented = true
                }
                .padding()
            }
        }
        .padding()
    }
}

struct WebView: UIViewRepresentable {
    let urlString: String
    @Binding var isPresented: Bool

    func makeUIView(context: Context) -> WKWebView {
        let webView = WKWebView()
        webView.navigationDelegate = context.coordinator
        return webView
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {
        if let url = URL(string: urlString) {
            let request = URLRequest(url: url)
            uiView.load(request)
        }
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    class Coordinator: NSObject, WKNavigationDelegate {
        var parent: WebView

        init(_ parent: WebView) {
            self.parent = parent
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Define the callbacks

Replace the Coordinator in the example above to incorporate listeners to events surfaced by the Push Cash UX. This allows you to dismiss the view controller on receiving any of the approved, declined and exit callbacks from the UX, and handle them with your custom logic.

class Coordinator: NSObject, WKNavigationDelegate {
    var parent: WebView

    init(_ parent: WebView) {
        self.parent = parent
    }

    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
        // Check if the URL scheme matches the desired custom schemes
        if let url = navigationAction.request.url, let scheme = url.scheme, let host = url.host {
            switch (scheme.lowercased(), host.lowercased()) {
            case ("pushcash", "approved"):
                handleApprovedEvent()
            case ("pushcash", "declined"):
                handleDeclinedEvent()
            case ("pushcash", "exit"):
                handleExitEvent()
            default:
                break
            }
        }

        // Continue with the default navigation behavior
        decisionHandler(.allow)
    }

    func handleApprovedEvent() {
        print("Received pushcash://approved event")
        // Perform actions for approved event
        parent.isPresented = false
    }

    func handleDeclinedEvent() {
        print("Received pushcash://declined event")
        // Perform actions for declined event
        parent.isPresented = false
    }

    func handleExitEvent() {
        print("Received pushcash://exit event")
        // Perform actions for exit event
        parent.isPresented = false
    }
}