akshaaatt / Google-IAP

Android Library for easing Google Play Billing to your apps with support for Subscriptions, Non-Consumable and Consumable Purchases with a beautiful sample app.
https://play.google.com/store/apps/details?id=com.redalck.gameone
GNU General Public License v3.0
245 stars 57 forks source link
2021 android android-library billing consumables google gradle hacktoberfest iap inapppurchase java kotlin library purchase subscription subscriptions v4

Google-IAP (Play Billing Library Version 7.0.0)

GitHub issues GitHub last commit GitHub issues GitHub pull requests

FeaturesDevelopmentUsageLicenseContribution


Google-IAP


ezgif-com-gif-maker-3.gif

IAP is an Android library to handle In-App purchases with minimal code.

Features

Gradle Dependency

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.akshaaatt:Google-IAP:1.7.0'
}

Development

Usage

Establishing connection with Play console

val iapConnector = IapConnector(
    context = this, // activity / context
    nonConsumableKeys = nonConsumablesList, // pass the list of non-consumables
    consumableKeys = consumablesList, // pass the list of consumables
    subscriptionKeys = subsList, // pass the list of subscriptions
    key = "LICENSE KEY", // pass your app's license key
    enableLogging = true // to enable / disable logging
)

Receiving events

iapConnector.addPurchaseListener(object : PurchaseServiceListener {
    override fun onPricesUpdated(iapKeyPrices: Map<String, DataWrappers.SkuDetails>) {
        // list of available products will be received here, so you can update UI with prices if needed
    }

    override fun onProductPurchased(purchaseInfo: DataWrappers.PurchaseInfo) {
        // will be triggered whenever purchase succeeded
    }

    override fun onProductRestored(purchaseInfo: DataWrappers.PurchaseInfo) {
        // will be triggered fetching owned products using IapConnector
    }
})

iapConnector.addSubscriptionListener(object : SubscriptionServiceListener {
    override fun onSubscriptionRestored(purchaseInfo: DataWrappers.PurchaseInfo) {
        // will be triggered upon fetching owned subscription upon initialization
    }

    override fun onSubscriptionPurchased(purchaseInfo: DataWrappers.PurchaseInfo) {
        // will be triggered whenever subscription succeeded
    }

    override fun onPricesUpdated(iapKeyPrices: Map<String, DataWrappers.SkuDetails>) {
        // list of available products will be received here, so you can update UI with prices if needed
    }
})

Making a purchase

iapConnector.purchase(this, "<sku>")

Making a subscription

iapConnector.subscribe(this, "<sku>")

Removing a subscription

iapConnector.unsubscribe(this, "<sku>")

Sample App

Apps Using this Library

License

This Project is licensed under the GPL version 3 or later.

Contribution

You are most welcome to contribute to this project!