Question

Paywall in Fragment in Kotlin

  • 11 March 2024
  • 3 replies
  • 35 views

Badge +1

I feel stupid, but I don’t understand how to implement the Paywall in fragment in Kotlin.

Is there any tutorial or sample available ?

Thanks in advance


This post has been closed for comments

3 replies

Userlevel 2
Badge +3

Hi @fab-fd4ff0 ,

You can present the paywall as an activity using the provided PaywallActivityLauncher, as mentioned in the “Manually (Activity)” tab here: https://www.revenuecat.com/docs/tools/paywalls/displaying-paywalls#how-to-display-a-fullscreen-paywall-in-your-app-1

You will need to create the launcher in the `onCreate` of your activity:

@OptIn(ExperimentalPreviewRevenueCatUIPurchasesAPI::class)
class MainActivity : AppCompatActivity(), PaywallResultHandler {
private lateinit var paywallActivityLauncher: PaywallActivityLauncher

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

paywallActivityLauncher = PaywallActivityLauncher(this, this)
}

fun launchPaywallActivity() {
paywallActivityLauncher.launch()
// or
paywallActivityLauncher.launchIfNeeded(requiredEntitlementIdentifier = Constants.ENTITLEMENT_ID)
}

override fun onActivityResult(result: PaywallResult) {}
}

and then call the `launchPaywallActivity` method from your Fragment.

Please, let us know if you’re still running into issues and we would be glad to help!

Badge +1

Thanks for your anwser, that’s exactly what i was looking for.

It’s working now, i can open the Paywall.

But i can’t setup a listener ?

how do i know if the customer order or not a product ?

(in my case it’s a subscription to remove ads)

Thanks

Userlevel 2
Badge +3

Hi @fab-fd4ff0,

You can get whether the user purchased a product in the `onActivityResult` function implemented in the `PaywallResultHandler`.

Alternatively, you can also call the getCustomerInfo method after the paywall has been dismissed to obtain the latest version of the entitlements for that customer to unlock those entitlements.

Lmk if that works!