Entry point for Purchases SDK. It should be instantiated as soon as your app is started. Only one instance of Purchases should be instantiated at a time!

Methods

  • Change the current app user id. Returns the customer info for the new user id.

    Parameters

    • newAppUserId: string

      The user id to change to.

    Returns Promise<CustomerInfo>

  • Closes the Purchases instance. You should never have to do this normally.

    Returns void

  • Gets the current app user id.

    Returns string

  • Fetch the configured offerings for this user. You can configure these in the RevenueCat dashboard.

    Returns Promise<Offerings>

  • Convenience method to check whether a user is entitled to a specific entitlement. This will use Purchases.getCustomerInfo under the hood.

    Parameters

    • entitlementIdentifier: string

      The entitlement identifier you want to check.

    Returns Promise<boolean>

    Whether the user is entitled to the specified entitlement

    Throws

    PurchasesError if there is an error while fetching the customer info.

    See

    Purchases.getCustomerInfo

  • Returns boolean

    Whether the SDK is using a sandbox API Key.

  • Method to perform a purchase for a given package. You can obtain the package from Purchases.getOfferings. This method will present the purchase form on your site, using the given HTML element as the mount point, if provided, or as a modal if not.

    Parameters

    • rcPackage: Package

      The package you want to purchase. Obtained from Purchases.getOfferings.

    • Optional customerEmail: string

      The email of the user. If undefined, RevenueCat will ask the customer for their email.

    • Optional htmlTarget: HTMLElement

      The HTML element where the billing view should be added. If undefined, a new div will be created at the root of the page and appended to the body.

    Returns Promise<{
        customerInfo: CustomerInfo;
    }>

    a Promise for the customer info after the purchase is completed successfully.

    Deprecated

    • please use .purchase

    Throws

    PurchasesError if there is an error while performing the purchase. If the PurchasesError.errorCode is ErrorCode.UserCancelledError, the user cancelled the purchase.

  • Configures the Purchases SDK. This should be called as soon as your app has a unique user id for your user. You should only call this once, and keep the returned instance around for use throughout your application.

    Parameters

    • apiKey: string

      RevenueCat API Key. Can be obtained from the RevenueCat dashboard.

    • appUserId: string

      Your unique id for identifying the user.

    • httpConfig: HttpConfig = defaultHttpConfig

      Advanced http configuration to customise the SDK usage HttpConfig.

    Returns Purchases

    Throws

    PurchasesError if the API key or user id are invalid.

  • Returns whether the Purchases SDK is configured or not.

    Returns boolean

  • Set the log level. Logs of the given level and below will be printed in the console. Default is LogLevel.Silent so no logs will be printed in the console.

    Parameters

    Returns void