Android In-App purchases made easy

Mohammad Khakpaki
Appcent
Published in
3 min readAug 26, 2024

Recently, I had to implement in-app purchases for one of my Android apps. While Google Play offers in-app purchases natively, I discovered a service called RevenueCat during my research. Today, I’d like to share my experience with this service.

Pricing

Pricing is often the most important aspect of services like this. The good news is that RevenueCat offers a “Pro” plan where you can access all functionality for free if your monthly revenue is under $2,500. If you exceed that amount, the service charges only 1% of your revenue. There are also additional plans available for more flexibility.

Implementation

The easiest part of using this service is adding its dependency. First things first you should add gradle dependency into your application level build.gradle module.

implementation ‘com.revenuecat.purchases:purchases:7.0.0’

and add proguard rules

-keep class com.revenuecat.purchases.** { *; }

and that's it, after adding the dependencies you should be able to import its classes and use it inside your app.

import com.revenuecat.purchases.CustomerInfo;
import com.revenuecat.purchases.Entitlement;
import com.revenuecat.purchases.Offering;
import com.revenuecat.purchases.Purchases;
import com.revenuecat.purchases.models.Period;
import com.revenuecat.purchases.models.Price;
import com.revenuecat.purchases.models.StoreProduct;

Showing paywalls

One of the best features of RevenueCat is the ability to show dynamic paywalls directly from the service panel without needing to create and code them within your application.

After adding your subscription plans to the Google Play Console and connecting your console to RevenueCat (you can follow this well-documented guide here), your products will appear in the RevenueCat panel.

At this step, you should create an offering using any combination of your products. Once the offering is created, you can proceed to create your first paywall.

In the RevenueCat panel, go to Monetization Tools > Paywalls, then click Create Paywall next to your offering.

You can select a template and start adding content or create your paywall using the built-in options. Once satisfied with your paywall, save it and head back to your code.

At this level you can select any template and start to add your content, or even you can create your paywall using built-in options

after you are satisfied with your paywall save it and head back to your code.

You can check if a user has an active subscription using this simple code (assuming you have only one entitlement):

Purchases.sharedInstance.getCustomerInfo(object : ReceiveCustomerInfoCallback {
override fun onError(error: PurchasesError) {
// Handle error
}

override fun onReceived(customerInfo: CustomerInfo) {
val hasSubscription =
customerInfo.entitlements[Constants.ENTITLEMENT_ID]?.isActive == true
}
})

and after checking the user subscription status you can launch the paywall that you created from the web.

class MainActivity : AppCompatActivity(), PaywallResultHandler {
private lateinit var paywallActivityLauncher: PaywallActivityLauncher
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
paywallActivityLauncher = PaywallActivityLauncher(this, this)
paywallActivityLauncher.launchIfNeeded(requiredEntitlementIdentifier = Constants.ENTITLEMENT_ID)
}
override fun onActivityResult(result: PaywallResult) {

if (result is PaywallResult.Purchased) {

}
}
}

and that’s it in this simple code you just launched a paywall and if the user made any purchases you can see it from onActivityResult.

for more advanced documentation you can always read https://www.revenuecat.com/docs/welcome/overview

but in this article, I just wanted to share my experience with this beautiful service.

Hope you have a great day and see you at the next one.

--

--