These are the events of Platform Payments recommended to intercept. In the SDK, all payment flows are performed inside the bundled webview. These event listeners are intercepted to return control back to the Unity game from the webview.

Event Summary

Below are the events listeners the SDK implements

EventDescription
event OnPageStarted(UniWebView webview, string url)Raised when the webview in platform starts loading a url.
event OnPageFinished(UniWebView webview, int statusCode, string, url)Raised when the web view finished to load a url successfully.
event OnPageErrorReceived(UniWebView webView, int errorCode, string errorMessage)Raised when an error encountered during the loading process.
event bool OnShouldClose(UniWebView webView)Raised when the web view is about to close itself.

OnShouldClose

Add a listener to the event OnShouldClose which either Android or iOS will call when the Platform payments are about to be closed by a user action. Here we set the reference to platformPayments to null.

📘

Handling payment statuses

When performing payments, the webview should remain open to listen and intercept the callback URLs from the payment service. Closing it will close the session. These URLs will deliver the result of the payment status from the payment service. All payment statuses will be delivered displayed in the webview bundled inside the SDK.

_platformPayments.OnShouldClose += (view) =>
 {
    platformPayments = null;
    return true;
  };

OnPageErrorReceived

Add a listener to this event to intercept errors thrown when loading a webpage in Platform payments

_platformPayments.OnPageErrorReceived += (view, errorCode, errorMessage) =>
        {
            Debug.Log("OnPageErrorReceived :" + string.Format("errorCode:{0},errorMessage{1}", errorCode, errorMessage));
        };

OnPageStarted

Add a listener to the event OnPageStarted to intercept the payment success and payment failures callbacks from PlatformPayments

_platformPayments.OnPageStarted += (view, url) =>
        {
             Debug.Log("OnPageStarted " + url);

            if (url.Contains("payment-success"))
            { 
                Debug.Log("payment success " + url);
                platformPayments.CloseWebView();
                
            } else if (url.Contains("payment-failure"))
            {
                Debug.Log("payment failure " + url);
                platformPayments.CloseWebView();
            }
        };

OnPageFinished

Listen to events when the webpage has finished loading.

_platformPayments.OnPageFinished += (view, statusCode, url) => {
         // Handle event here 
   Debug.Log("OnPageFinished " + url + " statusCode: " + statusCode);
             
};