Enable purchases by using paywalls in Unity SDK

To enable in-app purchases, you need to understand three key concepts:

  • Products – anything users can buy (subscriptions, consumables, lifetime access)
  • Paywalls are configurations that define which products to offer. In Adapty, paywalls are the only way to retrieve products, but this design lets you modify offerings, pricing, and product combinations without touching your app code.
  • Placements – where and when you show paywalls in your app (like main, onboarding, settings). You set up paywalls for placements in the dashboard, then request them by placement ID in your code. This makes it easy to run A/B tests and show different paywalls to different users.

Adapty offers you three ways to enable purchases in your app. Select one of them depending on your app requirements:

ImplementationComplexityWhen to use
Adapty Paywall Builder✅ EasyYou create a complete, purchase-ready paywall in the no-code builder. Adapty automatically renders it and handles all the complex purchase flow, receipt validation, and subscription management behind the scenes.
Manually created paywalls🟡 MediumYou implement your paywall UI in your app code, but still get the paywall object from Adapty to maintain flexibility in product offerings. See the guide.
Observer mode🔴 HardYou already have your own purchase handling infrastructure and want to keep using it. Note that the observer mode has its limitations in Adapty. See the article.

The steps below show how to implement a paywall created in the Adapty paywall builder.

If you don’t want to use the paywall builder, see the guide for handling purchases in manually created paywalls.

To display a paywall created in the Adapty paywall builder, in your app code, you only need to:

  1. Get the paywall: Get the paywall from Adapty.
  2. Display the paywall and Adapty will handle purchases for you: Show the paywall container you’ve got in your app.
  3. Handle button actions: Associate user interactions with the paywall with your app’s response to them. For example, open links or close the paywall when users click buttons.

1. Get the paywall

Your paywalls are associated with placements configured in the dashboard. Placements allow you to run different paywalls for different audiences or to run A/B tests.

To get a paywall created in the Adapty paywall builder, you need to:

  1. Get the paywall object by the placement ID using the GetPaywall method and check whether it is a paywall created in the builder using the HasViewConfiguration property.

  2. Create the paywall view using the CreatePaywallView method. The view contains the UI elements and styling needed to display the paywall.

To get the view configuration, you must switch on the Show on device toggle in the Paywall Builder. Otherwise, you will get an empty view configuration, and the paywall won’t be displayed.

Adapty.GetPaywall("YOUR_PLACEMENT_ID", (paywall, error) => {
    if(error != null) {
        // handle the error
        return;
    }
    
    // Create paywall view parameters
    var parameters = new AdaptyUICreatePaywallViewParameters();
    
    // Create the paywall view
    AdaptyUI.CreatePaywallView(paywall, parameters, (view, error) => {
        if(error != null) {
            // handle the error
            return;
        }
        
        // view - the paywall view ready to be presented
    });
});

This quickstart provides the minimum configuration required to display a paywall. For advanced configuration details, see our guide on getting paywalls.

2. Display the paywall

Now, when you have the paywall configuration, it’s enough to add a few lines to display your paywall.

To display the paywall, use the view.Present() method on the view created by the CreatePaywallView method. Each view can only be used once. If you need to display the paywall again, call CreatePaywallView one more to create a new view instance.

view.Present((error) => {
  // handle the error
});

For more details on how to display a paywall, see our guide.

3. Handle button actions

When users click buttons in the paywall, the Unity SDK automatically handles purchases and restoration. However, other buttons have custom or pre-defined IDs and require handling actions in your code.

For example, your paywall probably has a close button and URLs to open (e.g., terms of use and privacy policy). To handle these actions, your class needs to implement the AdaptyPaywallsEventsListener interface and register as a listener.

Read our guides on how to handle button actions and events.

public class YourClass : MonoBehaviour, AdaptyPaywallsEventsListener
{
    void Start()
    {
        // Register this class as the paywall events listener
        Adapty.SetPaywallsEventsListener(this);
    }

    // AdaptyPaywallsEventsListener method - handles button actions
    public void PaywallViewDidPerformAction(
        AdaptyUIPaywallView view,
        AdaptyUIUserAction action
    ) {
        switch (action.Type) {
            case AdaptyUIUserActionType.Close:
                view.Dismiss(null);
                break;
            case AdaptyUIUserActionType.OpenUrl:
                Application.OpenURL(action.Value);
                break;
            default:
                break;
        }
    }
}

Next steps

Have questions or running into issues? Check out our support forum where you can find answers to common questions or ask your own. Our team and community are here to help!

Your paywall is ready to be displayed in the app.

Now, you need to check the users’ access level to ensure you display a paywall or give access to paid features to right users.

Full example

Here is how all those steps can be integrated in your app together.

using System;
using UnityEngine;
using AdaptySDK;

public class PaywallManager : MonoBehaviour, AdaptyPaywallsEventsListener
{
    [SerializeField] private string placementId = "YOUR_PLACEMENT_ID";
    
    private AdaptyUIPaywallView currentPaywallView;
    
    void Start()
    {
        // Register for paywall events
        Adapty.SetPaywallsEventsListener(this);
        GetAndDisplayPaywall();
    }
    
    private void GetAndDisplayPaywall()
    {
        Adapty.GetPaywall(placementId, (paywall, error) => {
            if (error != null) {
                Debug.LogError("Error getting paywall: " + error.Message);
                return;
            }
            
            if (paywall.HasViewConfiguration) {
                CreateAndPresentPaywallView(paywall);
            } else {
                Debug.LogWarning("Paywall was not created using the builder");
            }
        });
    }
    
    private void CreateAndPresentPaywallView(AdaptyPaywall paywall)
    {
        var parameters = new AdaptyUICreatePaywallViewParameters();
        
        AdaptyUI.CreatePaywallView(paywall, parameters, (view, error) => {
            if (error != null) {
                Debug.LogError("Error creating paywall view: " + error.Message);
                return;
            }
            
            currentPaywallView = view;
            
            view.Present((presentError) => {
                if (presentError != null) {
                    Debug.LogError("Error presenting paywall: " + presentError.Message);
                    return;
                }
                
                Debug.Log("Paywall presented successfully");
            });
        });
    }
    
    // AdaptyPaywallsEventsListener implementation
    public void PaywallViewDidPerformAction(
        AdaptyUIPaywallView view, 
        AdaptyUIUserAction action
    ) {
        switch (action.Type) {
            case AdaptyUIUserActionType.Close:
                Debug.Log("Close button pressed");
                view.Dismiss(null);
                break;
            case AdaptyUIUserActionType.OpenUrl:
                Application.OpenURL(action.Value);
                break;
            default:
                break;
        }
    }
    
    // Required interface methods (implement as needed)
    public void PaywallViewDidAppear(AdaptyUIPaywallView view) { }
    public void PaywallViewDidDisappear(AdaptyUIPaywallView view) { }
    public void PaywallViewDidSelectProduct(AdaptyUIPaywallView view, string productId) { }
    public void PaywallViewDidStartPurchase(AdaptyUIPaywallView view, AdaptyPaywallProduct product) { }
    public void PaywallViewDidFinishPurchase(AdaptyUIPaywallView view, AdaptyPaywallProduct product, AdaptyPurchaseResult purchasedResult) { }
    public void PaywallViewDidFailPurchase(AdaptyUIPaywallView view, AdaptyPaywallProduct product, AdaptyError error) { }
    public void PaywallViewDidStartRestore(AdaptyUIPaywallView view) { }
    public void PaywallViewDidFinishRestore(AdaptyUIPaywallView view, AdaptyProfile profile) { }
    public void PaywallViewDidFailRestore(AdaptyUIPaywallView view, AdaptyError error) { }
    public void PaywallViewDidFailRendering(AdaptyUIPaywallView view, AdaptyError error) { }
    public void PaywallViewDidFailLoadingProducts(AdaptyUIPaywallView view, AdaptyError error) { }
    public void PaywallViewDidFinishWebPaymentNavigation(AdaptyUIPaywallView view, AdaptyPaywallProduct product, AdaptyError error) { }
    
    public void ShowPaywall()
    {
        GetAndDisplayPaywall();
    }
    
    void OnDestroy()
    {
        if (currentPaywallView != null) {
            currentPaywallView.Dismiss(null);
        }
    }
}