# PaywallBuilder

A builder class for creating custom PaywallView instances for advanced presentation.

> **Warning**

You're responsible for managing the lifecycle of the returned PaywallView. Do not use the same PaywallView instance in multiple places simultaneously.



> **Note**

The remotely configured presentation style is ignored when using this method. You must handle presentation styling programmatically.



Purpose [#purpose]

Creates a PaywallView that you can present however you want, bypassing Superwall's automatic presentation logic.

Signature [#signature]

```kotlin
class PaywallBuilder(private val placement: String) {
    fun params(params: Map<String, Any>?): PaywallBuilder
    fun overrides(overrides: PaywallOverrides?): PaywallBuilder
    fun delegate(delegate: PaywallViewCallback): PaywallBuilder
    fun activity(activity: Activity): PaywallBuilder
    
    suspend fun build(): Result<PaywallView>
    fun buildSync(): PaywallView
    fun build(onSuccess: (PaywallView) -> Unit, onError: (Throwable) -> Unit)
}
```

Parameters [#parameters]

<TypeTable
  type="{
  placement: {
    type: &#x22;String&#x22;,
    description: &#x22;The name of the placement as defined on the Superwall dashboard.&#x22;,
    required: true,
  },
  params: {
    type: &#x22;Map<String, Any>?&#x22;,
    description: &#x22;Optional parameters to pass with your placement for audience filters. Keys beginning with `$` are reserved and will be dropped.&#x22;,
  },
  overrides: {
    type: &#x22;PaywallOverrides?&#x22;,
    description: &#x22;Optional overrides for products and presentation style.&#x22;,
  },
  delegate: {
    type: &#x22;PaywallViewCallback&#x22;,
    description: &#x22;A delegate to handle user interactions with the retrieved PaywallView.&#x22;,
    required: true,
  },
  activity: {
    type: &#x22;Activity&#x22;,
    description: &#x22;The activity context required for the PaywallView.&#x22;,
    required: true,
  },
}"
/>

Returns / State [#returns--state]

Returns a `Result<PaywallView>` that you can add to your view hierarchy. If presentation should be skipped, returns a failure result.

Usage [#usage]

Using with coroutines:

```kotlin
lifecycleScope.launch {
    val result = PaywallBuilder("premium_feature")
        .params(mapOf("source" to "settings"))
        .delegate(object : PaywallViewCallback {
            override fun onFinished(
                paywall: PaywallView,
                result: PaywallResult,
                shouldDismiss: Boolean
            ) {
                // Handle paywall completion
            }
        })
        .activity(this@MainActivity)
        .build()
    
    result.fold(
        onSuccess = { paywallView ->
            binding.container.addView(paywallView)
        },
        onFailure = { error ->
            println("Error creating paywall: ${error.message}")
        }
    )
}
```

Jetpack Compose integration:

```kotlin
@Composable
fun PaywallScreen() {
    PaywallComposable(
        placement = "premium_feature",
        params = mapOf("source" to "settings"),
        delegate = object : PaywallViewCallback {
            override fun onFinished(
                paywall: PaywallView,
                result: PaywallResult,
                shouldDismiss: Boolean
            ) {
                // Handle completion
            }
        },
        errorComposable = { error ->
            Text("Failed to load paywall: ${error.message}")
        },
        loadingComposable = {
            CircularProgressIndicator()
        }
    )
}
```