Kotlin Multiplatform in-app purchases with RevenueCat

Learn how to implement in-app purchases and subscriptions in your Kotlin Multiplatform app using RevenueCat with our step-by-step guide.

Posted by

Kotlin Multiplatform in-app purchases with RevenueCat
TL;DR / Key Takeaways
  • Implement in-app purchases and subscriptions in Kotlin Multiplatform apps using RevenueCat.
  • Understand how to share purchase logic across both Android and iOS platforms.
  • Discover the step-by-step setup for Google Play Billing and StoreKit 2.
  • Learn to create a paywall UI with Compose Multiplatform.
  • KMPShip’s All-in tier includes fully configured RevenueCat integration.

How do you share purchase logic between Android and iOS?

You can share purchase logic between Android and iOS in your Kotlin Multiplatform app by using a common module that interfaces with RevenueCat. This allows you to maintain a single codebase for handling purchases, which simplifies the process and reduces code duplication.

What is the setup process for Google Play Billing and StoreKit 2?

To set up in-app purchases in your Kotlin Multiplatform app, you need to configure Google Play Billing for Android and StoreKit 2 for iOS. Below is a step-by-step guide to help you through the setup:

Step-by-Step Setup Guide

  1. Create a RevenueCat account: Visit RevenueCat and create an account.
  2. Set up products: In your RevenueCat dashboard, set up your in-app products and subscriptions.
  3. Integrate the RevenueCat SDK: Add the RevenueCat SDK to your project. For Kotlin Multiplatform, include the following dependencies in your common module:
    kotlin
    implementation("com.revenuecat.purchases:purchases:<latest-version>")
    Replace <latest-version> with the version available at the time of writing (check the official documentation).
  4. Configure Google Play Billing:
    • Enable in-app purchases in your Google Play Console.
    • Link your app to RevenueCat.
  5. Set up StoreKit 2 for iOS:
    • Enable in-app purchases in your App Store Connect account.
    • Link your app to RevenueCat.

How do you check entitlements in a Kotlin Multiplatform app?

Entitlement checking in a Kotlin Multiplatform app is done using the RevenueCat SDK, which provides a straightforward API for checking user entitlements. You can implement the following code snippet to verify whether a user has access to a subscription:
kotlin
val entitlements = Purchases.shared.getEntitlements() if (entitlements.active.isNotEmpty()) { // User has active entitlements }
This code checks if the user has any active entitlements and can be placed in your app’s logic to control access to premium features.

How can you restore purchases in a Kotlin Multiplatform app?

Restoring purchases is a crucial feature for any app with in-app purchases. The RevenueCat SDK makes this process simple. You can call the restore method as shown below:
kotlin
Purchases.shared.restorePurchases()
This method will automatically handle the restoration of purchases on both Android and iOS platforms, ensuring a seamless user experience.

What is the subscription lifecycle in a Kotlin Multiplatform app?

The subscription lifecycle in a Kotlin Multiplatform app involves several states: active, inactive, canceled, and expired. RevenueCat handles these states automatically and provides hooks to respond to changes. You can use the following code snippet to observe changes in subscription status:
kotlin
Purchases.shared.getPurchaserInfo { purchaserInfo, error -> // Handle changes in purchaser info }
This will allow your app to react appropriately based on the subscription status, enhancing user experience.

How do you create a paywall UI with Compose Multiplatform?

Creating a paywall UI in a Kotlin Multiplatform app can be effectively achieved using Compose Multiplatform. Below is an example of a simple paywall UI:
kotlin
@Composable fun PaywallScreen() { Column { Text(text = "Unlock Premium Features") Button(onClick = { purchaseProduct() }) { Text(text = "Subscribe Now") } } }
This UI can be customized further to include product details, pricing, and user testimonials to enhance conversion rates.

RevenueCat vs building billing from scratch

FeatureRevenueCatBuilding from Scratch
Ease of IntegrationHighLow
Cross-platform supportYesNo
MaintenanceMinimal (handled by RevenueCat)High
AnalyticsBuilt-inRequires custom implementation
CostSubscription-basedDevelopment and maintenance costs

Frequently Asked Questions

How do I implement subscriptions in Kotlin Multiplatform?

To implement subscriptions in Kotlin Multiplatform, you can use the RevenueCat SDK, which allows you to set up and manage subscriptions across both Android and iOS with shared logic.

What does KMPShip offer for in-app purchases?

KMPShip’s All-in tier includes fully configured RevenueCat integration, making it easy to implement in-app purchases and subscriptions without hassle.

Is RevenueCat free to use?

RevenueCat offers a free tier with limited features, but for full functionality, including analytics and advanced features, you may need to subscribe to their paid plans.

How do I test in-app purchases in my app?

You can test in-app purchases by using sandbox accounts provided by Google Play and Apple, allowing you to simulate purchases without actual transactions.

Can I use RevenueCat with Jetpack Compose?

Yes, RevenueCat can be used with Jetpack Compose, allowing you to create a modern UI for your in-app purchase flows seamlessly.

Conclusion

Implementing in-app purchases in your Kotlin Multiplatform app using RevenueCat streamlines the process significantly. By leveraging shared code for purchase logic, you can maintain a clean codebase while providing a seamless user experience across platforms. If you are looking for a hassle-free solution, consider KMPShip’s All-in tier, which offers fully configured RevenueCat integration. Start building your cross-platform in-app purchase system today!

Build your KMP app faster

Skip the setup and start shipping with a production-ready Kotlin Multiplatform starter kit.