Skip to content
Sumeet Rukeja edited this page Jun 11, 2021 · 7 revisions

EasyIAP

EasyIAP is an Android library backed with power of Kotlin coroutines to handle In-App purchases with minimal code.

Topics

Features

  • Written in Kotlin
  • No boilerplate code
  • Easy initialisation
  • Supports InApp & Subscription products
  • Simple configuration for consumable products
  • Leverages Kotlin coroutines & flow

Installation

Gradle Dependency

  • Add the JitPack repository to your project level build.gradle file.
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  • Add the library dependency in your app level build.gradle file.
dependencies {
    implementation 'com.github.smokelaboratory:easy-iap:2.0.0'
}

Usage

Establishing connection with Play console

val easyIapConnector = EasyIapConnector(context)
.enableAutoAcknowledge(
    consumableSkuList = listOf("<sku>"),
    subscriptionSkuList = listOf("<sku>")
)
/**
 * add base64 key to enable client-side purchase verification. for security reasons, it should be handled at server side
 */
.setEncodedBase64Key("<key>")
.connect()

Receiving events

easyIapConnector.getIapListener { iapErrorFlow, iapPurchaseResultFlow ->
    lifecycleScope.launch {
        iapErrorFlow.collect {
            Log.d(tag, "Error => ${it.responseCode} : ${it.debugMessage}")
        }
    }
    lifecycleScope.launch {
        iapPurchaseResultFlow.collect {
            if (it.first.responseCode == OK)
                Log.d(tag, "Purchase => ${it.second}")
            else
                Log.d(
                    tag,
                    "Acknowledgement error => ${it.first.responseCode} : ${it.first.debugMessage}"
                )
        }
    }
}

Fetching products

/**
 * in-app products
 */
easyIapConnector.getInAppProducts(listOf("<sku>"))

/**
 * subscriptions
 */
easyIapConnector.getSubscriptionProducts(listOf("<sku>"))

Making a purchase

easyIapConnector.purchaseProduct(activity, <sku>)

Acknowledging a purchase manually

easyIapConnector.acknowledgePurchase(purchase, <skuType>)

License

   Copyright © 2021 smokelaboratory

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.