Skip to main content
Question

Paywall in Fragment in Kotlin


Forum|alt.badge.img+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

Forum|alt.badge.img+3
  • RevenueCat Staff
  • 58 replies
  • March 11, 2024

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!


Forum|alt.badge.img+1
  • Author
  • New Member
  • 1 reply
  • March 11, 2024

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


Forum|alt.badge.img+3
  • RevenueCat Staff
  • 58 replies
  • March 11, 2024

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!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings