Unity – Handling events

If you need to control or monitor the processes that take place on the purchase screen, you need to implement the AdaptyUIEventListener methods and register the observer before presenting any screen:

AdaptyUI.SetEventListener(this);

User generated events

Actions

If user has performed some action, this method will be invoked:

public void OnPerformAction(AdaptyUI.View view, AdaptyUI.Action action) {
  switch (action.Type) {
    case AdaptyUI.ActionType.Close:
      view.Dismiss(null);
      break;
    default:
      // handle other events
      break;
  }
}

At the moment there are four types of actions supported: Close, OpenUrl, Custom and AndroidSystemBack. For example, if user presses the close button, the action Close will occur and you are supposed to dismiss the paywall.
Note that AdaptyUI.Action has optional value property: look at this in case of OpenUrl and Custom

💡

Login Action

If you have configured Login Action in the dashboard, you should implement reaction for Custom action with value "login"

Product selection

If product was selected for purchase (by user or by system), this method will be invoked.

public void OnSelectProduct(AdaptyUI.View view, Adapty.PaywallProduct product) {
}

Started purchase

If user initiates the purchase process, this method will be invoked.

public void OnStartPurchase(AdaptyUI.View view, Adapty.PaywallProduct product) {
}

Canceled purchase

If the user initiates the purchase process but manually interrupts it, this function will be called. Basically, this event occurs when the Adapty.MakePurchase() function completes with a .paymentCancelled error:

public void OnCancelPurchase(AdaptyUI.View view, Adapty.PaywallProduct product) {
}

Successful purchase

If Adapty.MakePurchase() succeeds, this method will be invoked:

public void OnFinishPurchase(AdaptyUI.View view, 
                             Adapty.PaywallProduct product, 
                             Adapty.Profile profile) {
}

We recommend to dismiss the screen in that case.

Failed purchase

If Adapty.MakePurchase() fails, this method will be invoked:

public void OnFailPurchase(AdaptyUI.View view, 
                           Adapty.PaywallProduct product, 
                           Adapty.Error error) {
}

Successful restore

If Adapty.RestorePurchases() succeeds, this method will be invoked:

public void OnFinishRestore(AdaptyUI.View view, Adapty.Profile profile) {
}

We recommend to dismiss the screen if the user has the required accessLevel.

Failed restore

If Adapty.RestorePurchases() fails, this method will be invoked:

public void OnFailRestore(AdaptyUI.View view, Adapty.Error error) {
}

Data fetching and rendering

Products loading errors

If you didn't pass the product array during initialization, AdaptyUI will retrieve the necessary objects from the server by itself. In this case, this operation may fail, and AdaptyUI will report the error by invoking this method:

public void OnFailLoadingProducts(AdaptyUI.View view, Adapty.Error error) {
}

Rendering errors

If an error occurs during the interface rendering, it will be reported by calling this method:

public void OnFailRendering(AdaptyUI.View view, Adapty.Error error) {
}

In a normal situation such errors should not occur, so if you come across one, please let us know about it.