purchases / com.revenuecat.purchases / Purchases

Purchases

class Purchases

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

AttributionNetwork

enum class AttributionNetwork

Different compatible attribution networks available

ErrorDomains

enum class ErrorDomains : Parcelable

Different error domains

PurchasesAPIError

enum class PurchasesAPIError

Different errors related to the Purchases SDK functions

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

lateinit var appUserID: String

The passed in or generated app user ID

updatedPurchaserInfoListener

var updatedPurchaserInfoListener: UpdatedPurchaserInfoListener?

The listener is responsible for handling changes to purchaser information. Make sure removeUpdatedPurchaserInfoListener is called when the listener needs to be destroyed.

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, listener: ReceivePurchaserInfoListener = receivePurchaserInfoListenerStub): Unit

This function will alias two appUserIDs together.

getEntitlements

fun getEntitlements(listener: ReceiveEntitlementsListener): 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>, listener: GetSkusResponseListener): Unit

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

getPurchaserInfo

fun getPurchaserInfo(listener: ReceivePurchaserInfoListener): Unit

Get latest available purchaser info.

getSubscriptionSkus

fun getSubscriptionSkus(skus: List<String>, listener: GetSkusResponseListener): Unit

Gets the SKUDetails for the given list of subscription skus.

identify

fun identify(appUserID: String, listener: ReceivePurchaserInfoListener? = null): 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>, listener: PurchaseCompletedListener): Unit
fun makePurchase(activity: Activity, sku: String, skuType: String, listener: PurchaseCompletedListener): Unit

Make a purchase.

removeUpdatedPurchaserInfoListener

fun removeUpdatedPurchaserInfoListener(): Unit

Call this when you are finished using the updatedPurchaserInfoListener. You should call this to avoid memory leaks.

reset

fun reset(listener: ReceivePurchaserInfoListener = receivePurchaserInfoListenerStub): Unit

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

restorePurchases

fun restorePurchases(listener: ReceivePurchaserInfoListener): 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

debugLogsEnabled

var debugLogsEnabled: Boolean

Enable debug logging. Useful for debugging issues with the lovely team @RevenueCat

frameworkVersion

val frameworkVersion: String

Current version of the Purchases SDK

sharedInstance

var sharedInstance: Purchases

Singleton instance of Purchases. configure will set this

Companion Object Functions

configure

fun configure(context: Context, apiKey: String, appUserID: String? = null, service: ExecutorService = createDefaultExecutor()): Purchases

Configures an instance of the Purchases SDK with a specified API key. The instance will be set as a singleton. You should access the singleton instance using Purchases.sharedInstance

Extension Functions

createAliasWith

fun Purchases.createAliasWith(newAppUserID: String, onError: ErrorFunction = onErrorStub, onSuccess: ReceivePurchaserInfoSuccessFunction): Unit

This function will alias two appUserIDs together.

getEntitlementsWith

fun Purchases.getEntitlementsWith(onError: ErrorFunction = onErrorStub, onSuccess: ReceiveEntitlementsSuccessFunction): 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.

getNonSubscriptionSkusWith

fun Purchases.getNonSubscriptionSkusWith(skus: List<String>, onError: ErrorFunction, onReceiveSkus: (skus: List<SkuDetails>) -> Unit): Unit

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

getPurchaserInfoWith

fun Purchases.getPurchaserInfoWith(onError: ErrorFunction = onErrorStub, onSuccess: ReceivePurchaserInfoSuccessFunction): Unit

Get latest available purchaser info.

getSubscriptionSkusWith

fun Purchases.getSubscriptionSkusWith(skus: List<String>, onError: ErrorFunction = onErrorStub, onReceiveSkus: (skus: List<SkuDetails>) -> Unit): Unit

Gets the SKUDetails for the given list of subscription skus.

identifyWith

fun Purchases.identifyWith(appUserID: String, onError: ErrorFunction = onErrorStub, onSuccess: ReceivePurchaserInfoSuccessFunction): 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

makePurchaseWith

fun Purchases.makePurchaseWith(activity: Activity, sku: String, skuType: String, oldSkus: ArrayList<String>, onError: ErrorFunction = onErrorStub, onSuccess: PurchaseCompletedSuccessFunction): Unit
fun Purchases.makePurchaseWith(activity: Activity, sku: String, skuType: String, onError: ErrorFunction = onErrorStub, onSuccess: PurchaseCompletedSuccessFunction): Unit

Make a purchase.

resetWith

fun Purchases.resetWith(onError: ErrorFunction = onErrorStub, onSuccess: ReceivePurchaserInfoSuccessFunction): Unit

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

restorePurchasesWith

fun Purchases.restorePurchasesWith(onError: ErrorFunction = onErrorStub, onSuccess: ReceivePurchaserInfoSuccessFunction): 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.