---
title: "Enable purchases with Flow Builder in Kotlin Multiplatform SDK"
description: "Quickstart guide to enabling in-app purchases with Adapty Flow Builder."
---

This guide uses Adapty Kotlin Multiplatform SDK v4 (beta) APIs. If you're on v3, see the [migration guide](migration-to-kmp-sdk-v4) for the corresponding method names.

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

- [**Products**](product) – anything users can buy (subscriptions, consumables, lifetime access)
- [**Flows**](adapty-flow-builder) – screen sequences that present products to users, built in the no-code Flow Builder. The SDK retrieves them via `getFlow`. If you'd rather build the UI in your own code, use a paywall instead — see [Implement paywalls manually](kmp-quickstart-manual).
- [**Placements**](placements) – where and when you show flows in your app (like `main`, `onboarding`, `settings`). You attach flows to 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 flows to different users.

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

| Implementation | Complexity | When to use |
|---|---|---|
| Adapty Flow Builder | ✅ Easy | You [create a complete, purchase-ready flow in the no-code builder](quickstart-paywalls). Adapty automatically renders it and handles all the complex purchase flow, receipt validation, and subscription management behind the scenes. |
| Manually created paywalls | 🟡 Medium | You implement your paywall UI in your app code, but still get the flow object from Adapty to maintain flexibility in product offerings. See the [guide](kmp-quickstart-manual). |
| Observer mode | 🔴 Hard | You 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](observer-vs-full-mode). |

:::important
**The steps below show how to implement a flow created in the Adapty Flow Builder.**

If you'd rather build the paywall UI yourself, see [Implement paywalls manually](kmp-quickstart-manual).
:::

To display a flow created in the Adapty Flow Builder, in your app code, you only need to:

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

## Before you start

Before you start, complete these steps:

1. Connect your app to the [App Store](initial_ios) and/or [Google Play](initial-android) in the Adapty Dashboard.
2. [Create your products](create-product) in Adapty.
3. [Create a flow and add products to it](create-paywall).
4. [Create a placement and add your flow to it](create-placement).
5. [Install and activate the Adapty SDK](sdk-installation-kotlin-multiplatform) in your app code.

:::tip
The fastest way to complete these steps is to follow the [quickstart guide](quickstart) or create flows and placements using the [Developer CLI](developer-cli-quickstart).
:::

## 1. Get the flow

Your flows are associated with placements configured in the dashboard. Placements allow you to run different flows for different audiences or to run [A/B tests](ab-tests).

To get a flow created in the Adapty Flow Builder, you need to:

1. Get the `flow` object by the [placement](placements) ID using the `getFlow` method.

2. Create the flow view using the `createFlowView` method. The view contains the UI elements and styling needed to display the flow. If the flow has no view configured, `createFlowView` returns an error — handle it in `onError`.

:::important
To get the view, you must switch on the **Show on device** toggle in the Flow Builder. Otherwise, `createFlowView` will return an error, and the flow won't be displayed.
:::

```kotlin showLineNumbers
Adapty.getFlow("YOUR_PLACEMENT_ID")
    .onSuccess { flow ->
        AdaptyUI.createFlowView(flow)
            .onSuccess { view ->
                view.present()
            }
            .onError { error ->
                // the flow has no view configured, or view creation failed
            }
    }
    .onError { error ->
        // handle the error
    }
```

## 2. Display the flow

Now, when you have the flow, it's enough to add a few lines to display it.

In order to display the visual flow on the device screen, you must first create the view. To do this, call the method `AdaptyUI.createFlowView()`:

```kotlin showLineNumbers
AdaptyUI.createFlowView(flow)
    .onSuccess { view ->
        view.present()
    }
    .onError { error ->
        // handle the error
    }
```

After the view has been successfully created, you can present it on the screen of the device. Each view can only be used once: after you call `dismiss()`, call `createFlowView` again to display the flow one more time.

:::tip
For more details on how to display a flow, see our [guide](kmp-present-paywalls).
:::

## 3. Handle button actions

When users click buttons in the flow, the Kotlin Multiplatform SDK automatically handles purchases, restoration, closing the flow, and opening links.

However, other buttons have custom or pre-defined IDs and require handling actions in your code. Or, you may want to override their default behavior.

For example, here is the default behavior for the close button. You don't need to add it in the code, but here, you can see how it is done if needed.

Note that, by default, the flow stays open after a successful purchase. If you want to close it once the purchase finishes, dismiss the view in the `flowViewDidFinishPurchase` callback.

:::tip
Read our guides on how to handle button [actions](kmp-handle-paywall-actions) and [events](kmp-handling-events).
:::

```kotlin showLineNumbers
AdaptyUI.setFlowsEventsObserver(object : AdaptyUIFlowsEventsObserver {
    override fun flowViewDidPerformAction(view: AdaptyUIFlowView, action: AdaptyUIAction) {
        when (action) {
            is AdaptyUIAction.CloseAction -> mainUiScope.launch { view.dismiss() }
            else -> Unit
        }
    }

    override fun flowViewDidFinishPurchase(
        view: AdaptyUIFlowView,
        product: AdaptyPaywallProduct,
        purchaseResult: AdaptyPurchaseResult
    ) {
        if (purchaseResult !is AdaptyPurchaseResult.UserCanceled) {
            mainUiScope.launch { view.dismiss() }
        }
    }
})
```

## Next steps

Your flow is ready to be displayed in the app. Test your purchases in the [App Store sandbox](test-purchases-in-sandbox) or in [Google Play Store](testing-on-android) to make sure you can complete a test purchase from the flow.

Now, you need to [check the users' access level](kmp-check-subscription-status) to ensure you display a flow or give access to paid features to right users.

## Full example

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

```kotlin showLineNumbers
// Set up the observer for handling flow events
AdaptyUI.setFlowsEventsObserver(object : AdaptyUIFlowsEventsObserver {
    override fun flowViewDidPerformAction(view: AdaptyUIFlowView, action: AdaptyUIAction) {
        when (action) {
            is AdaptyUIAction.CloseAction -> mainUiScope.launch { view.dismiss() }
            else -> Unit
        }
    }

    override fun flowViewDidFinishPurchase(
        view: AdaptyUIFlowView,
        product: AdaptyPaywallProduct,
        purchaseResult: AdaptyPurchaseResult
    ) {
        if (purchaseResult !is AdaptyPurchaseResult.UserCanceled) {
            mainUiScope.launch { view.dismiss() }
        }
    }
})

// Get and display the flow
Adapty.getFlow("YOUR_PLACEMENT_ID")
    .onSuccess { flow ->
        AdaptyUI.createFlowView(flow)
            .onSuccess { view ->
                view.present()
            }
            .onError { error ->
                // the flow has no view configured — use custom logic
            }
    }
    .onError { error ->
        // handle the error
    }
```