Purchases

class Purchases : LifecycleDelegate

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.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun close()

Call close when you are done with this instance of Purchases

Link copied to clipboard
fun collectDeviceIdentifiers()

Automatically collect subscriber attributes associated with the device identifiers $gpsAdId, $androidId, $ip

Link copied to clipboard
fun getCustomerInfo(callback: ReceiveCustomerInfoCallback)
fun getCustomerInfo(fetchPolicy: CacheFetchPolicy, callback: ReceiveCustomerInfoCallback)

Get latest available purchaser info.

Link copied to clipboard
fun getNonSubscriptionSkus(skus: List<String>, callback: GetStoreProductsCallback)

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

Link copied to clipboard
fun getOfferings(listener: ReceiveOfferingsCallback)

Fetch the configured offerings for this users. Offerings allows you to configure your in-app products vis RevenueCat and greatly simplifies management. See the guide for more info.

Link copied to clipboard
fun getSubscriptionSkus(skus: List<String>, callback: GetStoreProductsCallback)

Gets the StoreProduct for the given list of subscription skus.

Link copied to clipboard
fun invalidateCustomerInfoCache()

Invalidates the cache for customer information.

Link copied to clipboard
fun logIn(newAppUserID: String, callback: LogInCallback? = null)

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

Link copied to clipboard
fun logOut(callback: ReceiveCustomerInfoCallback? = null)

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

Link copied to clipboard
fun purchasePackage(    activity: Activity,     packageToPurchase: Package,     listener: PurchaseCallback)

Make a purchase.

fun purchasePackage(    activity: Activity,     packageToPurchase: Package,     upgradeInfo: UpgradeInfo,     callback: ProductChangeCallback)

Make a purchase upgrading from a previous sku.

Link copied to clipboard
fun purchaseProduct(    activity: Activity,     storeProduct: StoreProduct,     callback: PurchaseCallback)

Make a purchase.

fun purchaseProduct(    activity: Activity,     storeProduct: StoreProduct,     upgradeInfo: UpgradeInfo,     listener: ProductChangeCallback)

Make a purchase upgrading from a previous sku.

Link copied to clipboard
fun removeUpdatedCustomerInfoListener()

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

Link copied to clipboard
fun restorePurchases(callback: ReceiveCustomerInfoCallback)

Restores purchases made with the current Play Store account for the current user. This method will post all purchases associated with the current Play Store account to RevenueCat and become associated with the current appUserID. If the receipt token is being used by an existing user, the current appUserID will be aliased together with the appUserID of the existing user. Going forward, either appUserID will be able to reference the same user.

Link copied to clipboard
fun setAd(ad: String?)

Subscriber attribute associated with the install ad for the user

Link copied to clipboard
fun setAdGroup(adGroup: String?)

Subscriber attribute associated with the install ad group for the user

Link copied to clipboard
fun setAdjustID(adjustID: String?)

Subscriber attribute associated with the Adjust Id for the user Required for the RevenueCat Adjust integration

Link copied to clipboard
fun setAirshipChannelID(airshipChannelID: String?)

Subscriber attribute associated with the Airship Channel ID Required for the RevenueCat Airship integration

Link copied to clipboard
fun setAppsflyerID(appsflyerID: String?)

Subscriber attribute associated with the AppsFlyer Id for the user Required for the RevenueCat AppsFlyer integration

Link copied to clipboard
fun setAttributes(attributes: Map<String, String?>)

Subscriber attributes are useful for storing additional, structured information on a user. Since attributes are writable using a public key they should not be used for managing secure or sensitive information such as subscription status, coins, etc.

Link copied to clipboard
fun setCampaign(campaign: String?)

Subscriber attribute associated with the install campaign for the user

Link copied to clipboard
fun setCleverTapID(cleverTapID: String?)

Subscriber attribute associated with the CleverTap ID for the user Required for the RevenueCat CleverTap integration

Link copied to clipboard
fun setCreative(creative: String?)

Subscriber attribute associated with the install ad creative for the user

Link copied to clipboard
fun setDisplayName(displayName: String?)

Subscriber attribute associated with the display name for the user

Link copied to clipboard
fun setEmail(email: String?)

Subscriber attribute associated with the Email address for the user

Link copied to clipboard
fun setFBAnonymousID(fbAnonymousID: String?)

Subscriber attribute associated with the Facebook SDK Anonymous Id for the user Recommended for the RevenueCat Facebook integration

Link copied to clipboard
fun setFirebaseAppInstanceID(firebaseAppInstanceID: String?)

Subscriber attribute associated with the Firebase App Instance ID for the user Required for the RevenueCat Firebase integration

Link copied to clipboard
fun setKeyword(keyword: String?)

Subscriber attribute associated with the install keyword for the user

Link copied to clipboard
fun setMediaSource(mediaSource: String?)

Subscriber attribute associated with the install media source for the user

Link copied to clipboard
fun setMixpanelDistinctID(mixpanelDistinctID: String?)

Subscriber attribute associated with the Mixpanel Distinct ID for the user

Link copied to clipboard
fun setMparticleID(mparticleID: String?)

Subscriber attribute associated with the mParticle Id for the user Recommended for the RevenueCat mParticle integration

Link copied to clipboard
fun setOnesignalID(onesignalID: String?)

Subscriber attribute associated with the OneSignal Player Id for the user Required for the RevenueCat OneSignal integration

Link copied to clipboard
fun setPhoneNumber(phoneNumber: String?)

Subscriber attribute associated with the phone number for the user

Link copied to clipboard
fun setPushToken(fcmToken: String?)

Subscriber attribute associated with the push token for the user

Link copied to clipboard
fun syncObserverModeAmazonPurchase(    productID: String,     receiptID: String,     amazonUserID: String,     isoCurrencyCode: String?,     price: Double?)

This method will send a purchase to the RevenueCat backend. This function should only be called if you are in Amazon observer mode or performing a client side migration of your current users to RevenueCat.

Link copied to clipboard
fun syncPurchases()

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, or when migrating existing users to RevenueCat

Properties

Link copied to clipboard
val appUserID: String

The passed in or generated app user ID

Link copied to clipboard
var finishTransactions: Boolean

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

Link copied to clipboard
val isAnonymous: Boolean

If the appUserID has been generated by RevenueCat

Link copied to clipboard

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

Extensions

Link copied to clipboard
fun Purchases.getCustomerInfoWith(onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB, onSuccess: (customerInfo: CustomerInfo) -> Unit)

Get latest available customer info.

fun Purchases.getCustomerInfoWith(    fetchPolicy: CacheFetchPolicy,     onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB,     onSuccess: (customerInfo: CustomerInfo) -> Unit)

Get customer info from cache or network depending on fetch policy.

Link copied to clipboard
fun Purchases.getNonSubscriptionSkusWith(    skus: List<String>,     onError: (error: PurchasesError) -> Unit,     onReceiveSkus: (storeProducts: List<StoreProduct>) -> Unit)

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

Link copied to clipboard
fun Purchases.getOfferingsWith(onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB, onSuccess: (offerings: Offerings) -> Unit)

Fetch the configured offerings for this users. Offerings allows you to configure your in-app products vis RevenueCat and greatly simplifies management. See the guide for more info.

Link copied to clipboard
fun Purchases.getSubscriptionSkusWith(    skus: List<String>,     onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB,     onReceiveSkus: (storeProducts: List<StoreProduct>) -> Unit)

Gets the SKUDetails for the given list of subscription skus.

Link copied to clipboard
fun Purchases.logInWith(    appUserID: String,     onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB,     onSuccess: (customerInfo: CustomerInfo, created: Boolean) -> 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

Link copied to clipboard
fun Purchases.logOutWith(onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB, onSuccess: (customerInfo: CustomerInfo) -> Unit)

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

Link copied to clipboard
fun Purchases.purchasePackageWith(    activity: Activity,     packageToPurchase: Package,     upgradeInfo: UpgradeInfo,     onError: (error: PurchasesError, userCancelled: Boolean) -> Unit = ON_PURCHASE_ERROR_STUB,     onSuccess: (purchase: StoreTransaction?, customerInfo: CustomerInfo) -> Unit)

Make a purchase upgrading from a previous sku.

fun Purchases.purchasePackageWith(    activity: Activity,     packageToPurchase: Package,     onError: (error: PurchasesError, userCancelled: Boolean) -> Unit = ON_PURCHASE_ERROR_STUB,     onSuccess: (purchase: StoreTransaction, customerInfo: CustomerInfo) -> Unit)

Make a purchase.

Link copied to clipboard
fun Purchases.purchaseProductWith(    activity: Activity,     storeProduct: StoreProduct,     onError: (error: PurchasesError, userCancelled: Boolean) -> Unit = ON_PURCHASE_ERROR_STUB,     onSuccess: (purchase: StoreTransaction, customerInfo: CustomerInfo) -> Unit)

Purchase product.

fun Purchases.purchaseProductWith(    activity: Activity,     storeProduct: StoreProduct,     upgradeInfo: UpgradeInfo,     onError: (error: PurchasesError, userCancelled: Boolean) -> Unit = ON_PURCHASE_ERROR_STUB,     onSuccess: (purchase: StoreTransaction?, customerInfo: CustomerInfo) -> Unit)

Make a purchase upgrading from a previous sku.

Link copied to clipboard
fun Purchases.restorePurchasesWith(onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB, onSuccess: (customerInfo: CustomerInfo) -> Unit)

Restores purchases made with the current Play Store account for the current user. This method will post all purchases associated with the current Play Store account to RevenueCat and become associated with the current appUserID. If the receipt token is being used by an existing user, the current appUserID will be aliased together with the appUserID of the existing user. Going forward, either appUserID will be able to reference the same user.

Sources

Link copied to clipboard