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

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

finishTransactions

var finishTransactions: Boolean

Default to TRUE, set this to FALSE if you are consuming transactions outside of the Purchases SDK.

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: Purchases.AttributionNetwork): Unit
fun addAttributionData(data: Map<String, String>, network: Purchases.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, oldSkus: ArrayList<String>, listener: MakePurchaseListener): Unit
fun makePurchase(activity: Activity, sku: String, skuType: String, listener: PurchaseCompletedListener): Unit
fun makePurchase(activity: Activity, sku: String, skuType: String, listener: MakePurchaseListener): Unit
fun makePurchase(activity: Activity, skuDetails: SkuDetails, oldSku: String, listener: MakePurchaseListener): Unit
fun makePurchase(activity: Activity, skuDetails: SkuDetails, listener: MakePurchaseListener): 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.

syncPurchases

fun syncPurchases(): Unit

This method will send all the purchases to the RevenueCat backend. Call this when using your own implementation for subscriptions anytime a sync is needed, like after a successful purchase.

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

addAttributionData

fun addAttributionData(data: JSONObject, network: Purchases.AttributionNetwork, networkUserId: String? = null): Unit
fun addAttributionData(data: Map<String, String>, network: Purchases.AttributionNetwork, networkUserId: String? = null): Unit

Add attribution data from a supported network

configure

fun configure(context: Context, apiKey: String, appUserID: String? = null, observerMode: Boolean = false, 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

isBillingSupported

fun isBillingSupported(context: Context, callback: Callback<Boolean>): Unit

Check if billing is supported in the device. This method is asynchronous since it tries to connect the billing client and checks for the result of the connection. If billing is supported, IN-APP purchases are supported. If you want to check if SUBSCRIPTIONS or other type defined in BillingClient.FeatureType, call isFeatureSupported.

isFeatureSupported

fun isFeatureSupported(feature: String, context: Context, callback: Callback<Boolean>): Unit

Use this method if you want to check if Subscriptions or other type defined in com.android.billingclient.api.BillingClient.FeatureType is supported. This method is asynchronous since it requires a connected billing client.

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: MakePurchaseErrorFunction = onMakePurchaseErrorStub, onSuccess: MakePurchaseCompletedSuccessFunction): Unit
fun Purchases.makePurchaseWith(activity: Activity, skuDetails: SkuDetails, oldSku: String, onError: MakePurchaseErrorFunction = onMakePurchaseErrorStub, onSuccess: MakePurchaseCompletedSuccessFunction): Unit
fun Purchases.makePurchaseWith(activity: Activity, sku: String, skuType: String, onError: MakePurchaseErrorFunction = onMakePurchaseErrorStub, onSuccess: MakePurchaseCompletedSuccessFunction): Unit
fun Purchases.makePurchaseWith(activity: Activity, skuDetails: SkuDetails, onError: MakePurchaseErrorFunction = onMakePurchaseErrorStub, onSuccess: MakePurchaseCompletedSuccessFunction): 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.