Purchases

actual class Purchases
expect class Purchases

Entry point for Purchases. This class can be instantiated using Purchases.configure. This should be done 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. Only one instance of Purchases should be instantiated at a time! Access the singleton instance with Purchases.sharedInstance.

actual class Purchases

Types

Link copied to clipboard
actual object Companion
expect object Companion
actual object Companion

Properties

Link copied to clipboard
actual val appUserID: String
expect val appUserID: String

The passed in or generated app user ID.

actual val appUserID: String
Link copied to clipboard

The delegate is responsible for handling promotional product purchases (App Store only) and changes to customer information.

Link copied to clipboard
actual val isAnonymous: Boolean
expect val isAnonymous: Boolean

If the appUserID has been generated by RevenueCat.

actual val isAnonymous: Boolean
Link copied to clipboard
actual val store: <Error class: unknown class>
expect val store: <Error class: unknown class>

The currently configured store

actual val store: <Error class: unknown class>

Functions

Link copied to clipboard
suspend fun Purchases.awaitCustomerInfo(fetchPolicy: <Error class: unknown class> = CacheFetchPolicy.default()): <Error class: unknown class>

Get the latest available customer info.

Link copied to clipboard
suspend fun Purchases.awaitGetProducts(productIds: List<String>): List<<Error class: unknown class>>

Gets the StoreProducts for the given list of product ids for all product types.

Link copied to clipboard
suspend fun Purchases.awaitLogIn(newAppUserID: String): SuccessfulLogin

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

Link copied to clipboard
suspend fun Purchases.awaitLogOut(): <Error class: unknown class>

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

Link copied to clipboard
suspend fun Purchases.awaitOfferings(): <Error class: unknown class>

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
suspend fun Purchases.awaitPromotionalOffer(discount: <Error class: unknown class>, storeProduct: <Error class: unknown class>): <Error class: unknown class>

App Store only. Use this method to fetch a PromotionalOffer to use with awaitPurchase.

Link copied to clipboard
suspend fun Purchases.awaitPurchase(packageToPurchase: <Error class: unknown class>, promotionalOffer: <Error class: unknown class>): SuccessfulPurchase

App Store only. Purchases packageToPurchase. Call this method when a user has decided to purchase a product with an applied discount. Only call this in direct response to user input. From here Purchases will handle the purchase with StoreKit.

suspend fun Purchases.awaitPurchase(storeProduct: <Error class: unknown class>, promotionalOffer: <Error class: unknown class>): SuccessfulPurchase

App Store only. Use this function if you are not using the Offerings system to purchase a StoreProduct with an applied PromotionalOffer. If you are using the Offerings system, use the overload with a Package parameter instead.

suspend fun Purchases.awaitPurchase(packageToPurchase: <Error class: unknown class>, isPersonalizedPrice: Boolean? = null, oldProductId: String? = null, replacementMode: <Error class: unknown class> = GoogleReplacementMode.WITHOUT_PRORATION): SuccessfulPurchase

Purchases packageToPurchase. On the Play Store, if packageToPurchase represents a subscription, upgrades from the subscription specified by oldProductId and chooses the default SubscriptionOption from packageToPurchase.

suspend fun Purchases.awaitPurchase(storeProduct: <Error class: unknown class>, isPersonalizedPrice: Boolean? = null, oldProductId: String? = null, replacementMode: <Error class: unknown class> = GoogleReplacementMode.WITHOUT_PRORATION): SuccessfulPurchase

Purchases storeProduct. On the Play Store, if storeProduct represents a subscription, upgrades from the subscription specified by oldProductId and chooses storeProduct's default SubscriptionOption.

suspend fun Purchases.awaitPurchase(subscriptionOption: <Error class: unknown class>, isPersonalizedPrice: Boolean? = null, oldProductId: String? = null, replacementMode: <Error class: unknown class> = GoogleReplacementMode.WITHOUT_PRORATION): SuccessfulPurchase

Play Store only. Purchases subscriptionOption.

Link copied to clipboard
suspend fun Purchases.awaitRestore(): <Error class: unknown class>

Restores purchases made with the current Store account for the current user. This method will post all purchases associated with the current 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
suspend fun Purchases.awaitSyncAttributesAndOfferingsIfNeeded(): <Error class: unknown class>

Syncs subscriber attributes and then fetches the configured offerings for this user. This method is intended to be called when using Targeting Rules with Custom Attributes. Any subscriber attributes should be set before calling this method to ensure the returned offerings are applied with the latest subscriber attributes.

Link copied to clipboard
suspend fun Purchases.awaitSyncPurchases(): <Error class: unknown class>

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, such as when migrating existing users to RevenueCat.

Link copied to clipboard
actual fun close()
expect fun close()

Call this when you are done with this instance of Purchases.

actual fun close()
Link copied to clipboard

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

Link copied to clipboard
expect fun getCustomerInfo(fetchPolicy: <Error class: unknown class> = CacheFetchPolicy.default(), onError: (<Error class: unknown class>) -> Unit, onSuccess: (<Error class: unknown class>) -> Unit)

Get the latest available customer info.

Link copied to clipboard
expect fun getOfferings(onError: (<Error class: unknown class>) -> Unit, onSuccess: (<Error class: unknown class>) -> 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
expect fun getProducts(productIds: List<String>, onError: (<Error class: unknown class>) -> Unit, onSuccess: (storeProducts: List<<Error class: unknown class>>) -> Unit)

Gets the StoreProducts for the given list of product ids for all product types.

Link copied to clipboard
expect fun getPromotionalOffer(discount: <Error class: unknown class>, storeProduct: <Error class: unknown class>, onError: (<Error class: unknown class>) -> Unit, onSuccess: (<Error class: unknown class>) -> Unit)

App Store only. Use this method to fetch a PromotionalOffer to use with purchase.

Link copied to clipboard

Invalidates the cache for customer information.

Link copied to clipboard
expect fun logIn(newAppUserID: String, onError: (<Error class: unknown class>) -> Unit, onSuccess: (<Error class: unknown class>, 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
expect fun logOut(onError: (<Error class: unknown class>) -> Unit, onSuccess: (<Error class: unknown class>) -> Unit)

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
expect fun purchase(storeProduct: <Error class: unknown class>, promotionalOffer: <Error class: unknown class>, onError: (<Error class: unknown class>, userCancelled: Boolean) -> Unit, onSuccess: (<Error class: unknown class>, <Error class: unknown class>) -> Unit)

App Store only. Use this function if you are not using the Offerings system to purchase a StoreProduct with an applied PromotionalOffer. If you are using the Offerings system, use the overload with a Package parameter instead.

expect fun purchase(packageToPurchase: <Error class: unknown class>, promotionalOffer: <Error class: unknown class>, onError: (<Error class: unknown class>, userCancelled: Boolean) -> Unit, onSuccess: (<Error class: unknown class>, <Error class: unknown class>) -> Unit)

App Store only. Purchases packageToPurchase. Call this method when a user has decided to purchase a product with an applied discount. Only call this in direct response to user input. From here Purchases will handle the purchase with StoreKit and call either onSuccess or onError.

expect fun purchase(storeProduct: <Error class: unknown class>, onError: (<Error class: unknown class>, userCancelled: Boolean) -> Unit, onSuccess: (<Error class: unknown class>, <Error class: unknown class>) -> Unit, isPersonalizedPrice: Boolean? = null, oldProductId: String? = null, replacementMode: <Error class: unknown class>? = null)

Purchases storeProduct. On the Play Store, if storeProduct represents a subscription, upgrades from the subscription specified by oldProductId and chooses storeProduct's default SubscriptionOption.

expect fun purchase(subscriptionOption: <Error class: unknown class>, onError: (<Error class: unknown class>, userCancelled: Boolean) -> Unit, onSuccess: (<Error class: unknown class>, <Error class: unknown class>) -> Unit, isPersonalizedPrice: Boolean? = null, oldProductId: String? = null, replacementMode: <Error class: unknown class>? = null)

Play Store only. Purchases subscriptionOption.

expect fun purchase(packageToPurchase: <Error class: unknown class>, onError: (<Error class: unknown class>, userCancelled: Boolean) -> Unit, onSuccess: (<Error class: unknown class>, <Error class: unknown class>) -> Unit, isPersonalizedPrice: Boolean? = null, oldProductId: String? = null, replacementMode: <Error class: unknown class>? = null)

Purchases packageToPurchase. On the Play Store, if packageToPurchase represents a subscription, upgrades from the subscription specified by oldProductId and chooses the default SubscriptionOption from packageToPurchase.

Link copied to clipboard
expect fun recordPurchase(productID: String, onError: (<Error class: unknown class>) -> Unit, onSuccess: (<Error class: unknown class>) -> Unit)

iOS only. Always returns an error on iOS < 15.

Link copied to clipboard
expect fun restorePurchases(onError: (<Error class: unknown class>) -> Unit, onSuccess: (<Error class: unknown class>) -> Unit)

Restores purchases made with the current Store account for the current user. This method will post all purchases associated with the current 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
actual fun setAd(ad: String?)
expect fun setAd(ad: String?)

Subscriber attribute associated with the install ad for the user

actual fun setAd(ad: String?)
Link copied to clipboard
actual fun setAdGroup(adGroup: String?)
expect fun setAdGroup(adGroup: String?)

Subscriber attribute associated with the install ad group for the user

actual fun setAdGroup(adGroup: String?)
Link copied to clipboard
actual fun setAdjustID(adjustID: String?)
expect fun setAdjustID(adjustID: String?)

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

actual fun setAdjustID(adjustID: String?)
Link copied to clipboard
actual fun setAirshipChannelID(airshipChannelID: String?)
expect fun setAirshipChannelID(airshipChannelID: String?)

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

actual fun setAirshipChannelID(airshipChannelID: String?)
Link copied to clipboard
actual fun setAppsflyerID(appsflyerID: String?)
expect fun setAppsflyerID(appsflyerID: String?)

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

actual fun setAppsflyerID(appsflyerID: String?)
Link copied to clipboard
actual fun setAttributes(attributes: Map<String, String?>)
expect 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.

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

Subscriber attribute associated with the install campaign for the user

actual fun setCampaign(campaign: String?)
Link copied to clipboard
actual fun setCleverTapID(cleverTapID: String?)
expect fun setCleverTapID(cleverTapID: String?)

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

actual fun setCleverTapID(cleverTapID: String?)
Link copied to clipboard
actual fun setCreative(creative: String?)
expect fun setCreative(creative: String?)

Subscriber attribute associated with the install ad creative for the user

actual fun setCreative(creative: String?)
Link copied to clipboard
actual fun setDisplayName(displayName: String?)
expect fun setDisplayName(displayName: String?)

Subscriber attribute associated with the display name for the user

actual fun setDisplayName(displayName: String?)
Link copied to clipboard
actual fun setEmail(email: String?)
expect fun setEmail(email: String?)

Subscriber attribute associated with the Email address for the user

actual fun setEmail(email: String?)
Link copied to clipboard
actual fun setFBAnonymousID(fbAnonymousID: String?)
expect fun setFBAnonymousID(fbAnonymousID: String?)

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

actual fun setFBAnonymousID(fbAnonymousID: String?)
Link copied to clipboard
actual fun setFirebaseAppInstanceID(firebaseAppInstanceID: String?)
expect fun setFirebaseAppInstanceID(firebaseAppInstanceID: String?)

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

actual fun setFirebaseAppInstanceID(firebaseAppInstanceID: String?)
Link copied to clipboard
actual fun setKeyword(keyword: String?)
expect fun setKeyword(keyword: String?)

Subscriber attribute associated with the install keyword for the user

actual fun setKeyword(keyword: String?)
Link copied to clipboard
actual fun setMediaSource(mediaSource: String?)
expect fun setMediaSource(mediaSource: String?)

Subscriber attribute associated with the install media source for the user

actual fun setMediaSource(mediaSource: String?)
Link copied to clipboard
actual fun setMixpanelDistinctID(mixpanelDistinctID: String?)
expect fun setMixpanelDistinctID(mixpanelDistinctID: String?)

Subscriber attribute associated with the Mixpanel Distinct ID for the user

actual fun setMixpanelDistinctID(mixpanelDistinctID: String?)
Link copied to clipboard
actual fun setMparticleID(mparticleID: String?)
expect fun setMparticleID(mparticleID: String?)

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

actual fun setMparticleID(mparticleID: String?)
Link copied to clipboard
actual fun setOnesignalID(onesignalID: String?)
expect fun setOnesignalID(onesignalID: String?)

Subscriber attribute associated with the OneSignal Player Id for the user Required for the RevenueCat OneSignal integration. Deprecated for OneSignal versions above v9.0.

actual fun setOnesignalID(onesignalID: String?)
Link copied to clipboard
actual fun setOnesignalUserID(onesignalUserID: String?)
expect fun setOnesignalUserID(onesignalUserID: String?)

Subscriber attribute associated with the OneSignal User ID for the user Required for the RevenueCat OneSignal integration with versions v11.0 and above.

actual fun setOnesignalUserID(onesignalUserID: String?)
Link copied to clipboard
actual fun setPhoneNumber(phoneNumber: String?)
expect fun setPhoneNumber(phoneNumber: String?)

Subscriber attribute associated with the phone number for the user

actual fun setPhoneNumber(phoneNumber: String?)
Link copied to clipboard
actual fun setPushToken(fcmToken: String?)
expect fun setPushToken(fcmToken: String?)

Subscriber attribute associated with the push token for the user

actual fun setPushToken(fcmToken: String?)
Link copied to clipboard
expect fun showInAppMessagesIfNeeded(messageTypes: List<<Error class: unknown class>> = listOf(StoreMessageType.BILLING_ISSUES))

Google Play and App Store only, no-op for Amazon. Displays the specified in-app message types to the user as a snackbar if there are any available to be shown. If PurchasesConfiguration.showInAppMessagesAutomatically is enabled, this will be done automatically.

actual fun showInAppMessagesIfNeeded(messageTypes: List<<Error class: unknown class>>)
Link copied to clipboard
actual fun syncAmazonPurchase(productID: String, receiptID: String, amazonUserID: String, isoCurrencyCode: String?, price: Double?)
expect fun syncAmazonPurchase(productID: String, receiptID: String, amazonUserID: String, isoCurrencyCode: String?, price: Double?)

This method will send an Amazon purchase to the RevenueCat backend. This function should only be called if you have set PurchasesAreCompletedBy to PurchasesAreCompletedBy.MyApp or when performing a client side migration of your current users to RevenueCat.

actual fun syncAmazonPurchase(productID: String, receiptID: String, amazonUserID: String, isoCurrencyCode: String?, price: Double?)
Link copied to clipboard
expect fun syncAttributesAndOfferingsIfNeeded(onError: (<Error class: unknown class>) -> Unit, onSuccess: (<Error class: unknown class>) -> Unit)

Syncs subscriber attributes and then fetches the configured offerings for this user. This method is intended to be called when using Targeting Rules with Custom Attributes. Any subscriber attributes should be set before calling this method to ensure the returned offerings are applied with the latest subscriber attributes.

Link copied to clipboard
expect fun syncPurchases(onError: (<Error class: unknown class>) -> Unit, onSuccess: (<Error class: unknown class>) -> 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, such as when migrating existing users to RevenueCat. The onSuccess callback will be called if all purchases have been synced successfully or there are no Otherwise, the onError callback will be called with a PurchasesError indicating the first error found.