RevenueCat Purchases KMP

repository·main·Indexed 43 days ago

https://github.com/revenuecat/purchases-kmp

A Kotlin Multiplatform (KMP) wrapper for RevenueCat that unifies StoreKit and Google Play Billing under a single API for subscription management across Android, iOS, and watchOS. Key features include cross-platform subscription tracking, server-side validation, remote configuration, and analytics.

Tokens
5.2K
Snippets
13
Records
33
Agent score
55%

What's inside RevenueCat KMP

  1. Overview of Purchases KMP

    main

    Purchases is a Kotlin Multiplatform (KMP) client for the RevenueCat subscription and purchase tracking system. It acts as a wrapper around BillingClient (Android) and StoreKit (iOS/watchOS) to simplify implementing in-app purchases and subscriptions.

    Key capabilities include:

    • Cross-platform support: Android, iOS, and watchOS.
    • Subscription tracking: Unified status tracking across different platforms.
    • Server-side validation: Automatic receipt validation via the RevenueCat backend.
    • Remote configuration: Manage products and offerings remotely from the RevenueCat dashboard.
    • Analytics & Webhooks: Automatic metric calculation (MRR, churn, etc.) and real-time event notifications.
  2. Use launch arguments to navigate to specific test cases

    main

    The app supports a launchApp argument called e2e_test_flow.

    • With argument: When Maestro passes e2e_test_flow as a launch argument, the app navigates directly to the screen associated with that specific test case, bypassing the main Test Cases list. On Android, this is read from intent extras; on iOS, it is read from UserDefaults.
    • Without argument: If no argument is provided (e.g., when running the app manually), the app displays the manual Test Cases list.
  3. Migrate from versions before 3.0.0: Remove native iOS SDK dependencies

    main

    When upgrading to version 3.0.0 or later, you must remove the native iOS dependencies PurchasesHybridCommon and/or PurchasesHybridCommonUI from your iOS project, as they are no longer required for the KMP integration.

    Remove from Swift Package Manager

    1. Open Xcode and select your project in the Project navigator.
    2. Click Package Dependencies.
    3. Select PurchasesHybridCommon and/or PurchasesHybridCommonUI and click the '-' (minus) button to remove them.

    Remove from CocoaPods

    Ensure these dependencies are removed from both your Podfile and your build.gradle[.kts] file.

    In your Podfile: Remove lines such as:

    pod 'PurchasesHybridCommon', '17.21.2'
    pod 'PurchasesHybridCommonUI', '17.21.2'

    In your build.gradle[.kts]: Remove sections such as:

    pod("PurchasesHybridCommon") {
        version = "17.21.2"
        extraOpts += listOf("-compiler-option", "-fmodules")
    }
    pod("PurchasesHybridCommonUI") {
        version = "17.21.2"
        extraOpts += listOf("-compiler-option", "-fmodules")
    }
  4. Configure the RevenueCat API Key for Maestro tests

    main

    The app uses the placeholder MAESTRO_TESTS_REVENUECAT_API_KEY for the RevenueCat API key. To run the app locally with a real key, you have two options:

    1. Manual replacement: Replace the placeholder string directly in src/commonMain/kotlin/.../App.kt with a valid API key.
    2. Fastlane: Set the environment variable and run the Fastlane lane to automate the replacement:
      bundle exec fastlane change_maestro_test_app_api_key

    Warning: Do not commit real API keys to version control.

    bundle exec fastlane change_maestro_test_app_api_key
  5. Update Maven coordinates for KobanKat migration

    main

    The Maven coordinates have changed from io.shortway.kobankat to com.revenuecat.purchases. Update your dependency declarations as follows:

    Old coordinateNew coordinate
    io.shortway.kobankat:kobankat-corecom.revenuecat.purchases:purchases-kmp-core
    io.shortway.kobankat:kobankat-datetimecom.revenuecat.purchases:purchases-kmp-datetime
    io.shortway.kobankat:kobankat-eithercom.revenuecat.purchases:purchases-kmp-either
    io.shortway.kobankat:kobankat-resultcom.revenuecat.purchases:purchases-kmp-result
    N/Acom.revenuecat.purchases:purchases-kmp-ui (for Paywalls)
    // Example: migrating core
    // Old:
    // io.shortway.kobankat:kobankat-core:<version>
    
    // New:
    com.revenuecat.purchases:purchases-kmp-core:<version>
  6. Add Amazon Appstore support to Android

    main

    If you are using the Amazon Appstore, you must now explicitly add the Amazon module to your project.

    1. Add the coordinates to your libs.versions.toml file:
    purchases-amazon = { module = "com.revenuecat.purchases:purchases-store-amazon", version = "x.y.z"}
    1. Add the dependency to your build.gradle[.kts] file:
    kotlin {
      sourceSets {
        androidMain.dependencies {
          implementation(libs.purchases.amazon)
        }
      }
    }
  7. Update linked iOS framework for KobanKat migration

    main

    The linked iOS framework name has changed. Update your iOS project (e.g., in your Podfile). If using CocoaPods, run pod install --repo-update after making the change.

    If using Paywalls: Replace RevenueCat with PurchasesHybridCommonUI.

    If NOT using Paywalls: Replace RevenueCat with PurchasesHybridCommon.