purchases / com.revenuecat.purchases / Purchases

Purchases

class Purchases : PurchasesUpdatedListener, ActivityLifecycleCallbacks

Entry point for Purchases. It should be instantiated as soon as your app has a unique user id for your user. This can be when a user logs in if you have accounts or on launch if you can generate a random user identifier. Make sure you follow the quickstart guide to setup your RevenueCat account.

Warning
Only one instance of Purchases should be instantiated at a time! Set the Purchases.sharedInstance to let the SDK handle the singleton management for you.

Types

AliasHandler

interface AliasHandler

Used when creating an alias

AttributionNetwork

enum class AttributionNetwork

Different compatible attribution networks available

Builder

class Builder

Used to construct a Purchases object

ErrorDomains

enum class ErrorDomains

Different error domains

GetEntitlementsHandler

interface GetEntitlementsHandler

Used when retrieving entitlements

GetSkusResponseHandler

interface GetSkusResponseHandler

Used when retrieving subscriptions

PurchasesListener

interface PurchasesListener

Used to handle async updates from Purchases

Properties

allowSharingPlayStoreAccount

var allowSharingPlayStoreAccount: Boolean

If it should allow sharing Play Store accounts. False by default. If true treats all purchases as restores, aliasing together appUserIDs that share a Play Store account.

appUserID

var appUserID: String

The passed in or generated app user ID

listener

var listener: PurchasesListener?

Adds a PurchasesListener to handle async updates from Purchases. Remember to remove the listener when needed (i.e. Activity.onDestroy if it's an activity to avoid memory leaks)

Functions

addAttributionData

fun addAttributionData(data: JSONObject, network: AttributionNetwork): Unit
fun addAttributionData(data: Map<String, String>, network: AttributionNetwork): Unit

Add attribution data from a supported network

close

fun close(): Unit

Call close when you are done with this instance of Purchases

createAlias

fun createAlias(newAppUserID: String, handler: AliasHandler?): Unit

This function will alias two appUserIDs together.

getEntitlements

fun getEntitlements(handler: GetEntitlementsHandler): Unit

Fetch the configured entitlements for this user. Entitlements allows you to configure your in-app products via RevenueCat and greatly simplifies management. See the guide for more info.

getNonSubscriptionSkus

fun getNonSubscriptionSkus(skus: List<String>, handler: GetSkusResponseHandler): Unit

Gets the SKUDetails for the given list of non-subscription skus.

getSubscriptionSkus

fun getSubscriptionSkus(skus: List<String>, handler: GetSkusResponseHandler): Unit

Gets the SKUDetails for the given list of subscription skus.

identify

fun identify(appUserID: String): Unit

This function will change the current appUserID. Typically this would be used after a log out to identify a new user without calling configure

makePurchase

fun makePurchase(activity: Activity, sku: String, skuType: String, oldSkus: ArrayList<String> = ArrayList()): Unit

Make a purchase.

removeListener

fun removeListener(): Unit

Removes the PurchasesListener. You should call this to avoid memory leaks.

reset

fun reset(): Unit

Resets the Purchases client clearing the save appUserID. This will generate a random user id and save it in the cache.

restorePurchasesForPlayStoreAccount

fun restorePurchasesForPlayStoreAccount(): Unit

Restores purchases made with the current Play Store account for the current user. If you initialized Purchases with an appUserID any receipt tokens currently being used by other users of your app will not be restored. If you used an anonymous id, i.e. you initialized Purchases without an appUserID, any other anonymous users using the same purchases will be merged.

Companion Object Properties

frameworkVersion

val frameworkVersion: String

Current version of the Purchases SDK

sharedInstance

var sharedInstance: Purchases?

Singleton instance of Purchases