Skip to content

Android Library for easing Google Play Billing to your apps with support for Subscriptions, In App Purchases and Consumables with a beautiful sample app.

License

Notifications You must be signed in to change notification settings

MRZ07/Google-IAP

 
 

Repository files navigation

16113251508601.jpg ezgif-com-gif-maker-3.gif

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

Features

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

Gradle Dependency

  • Add the JitPack repository to your project's build.gradle file
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  • Add the dependency in your app's build.gradle file
dependencies {
    implementation 'com.github.akshaaatt:Google-IAP:1.0.8'
}

Usage

Add your In-App Products and Subscriptions to the Google Play Developer Console

Establishing connection with Play console

iapConnector = IapConnector(this, "...")
            .setNonConsumableInAppIds("id1", "id2", "id3")   /*pass the list of Non-Consumable Product IDs*/
            .setConsumableInAppIds("id4", "id5")  /*pass the list of Consumable Product IDs*/
            .setSubscriptionIds("subId1", "subId2")   /*pass the list of Subscription IDs*/
            .autoAcknowledge()  /*to enable auto acknowledgement*/
            .connect()

Receiving events

iapConnector.setOnInAppEventsListener(object : InAppEventsListener {

            override fun onSubscriptionsFetched(skuDetailsList: List<SkuInfo>) {
                /*provides list of product details of subs type*/
            }

            override fun onInAppProductsFetched(skuDetailsList: List<SkuInfo>) {
                /*provides list of product details of inapp type*/
            }

            override fun onPurchaseAcknowledged(purchase: PurchaseInfo) {
                /*callback after purchase being acknowledged*/
            }

            override fun onConsumed(purchase: PurchaseInfo) {
                /*callback after purchase being acknowledged*/
            }


            override fun onProductsPurchased(purchases: List<PurchaseInfo>) {
                  purchases.forEach {
        	  Log.d(tag, "A new product was purchaed : ${it.SkuId}")
			  when (it.skuId) {
		                "id1" -> {

		                }
		                "id2" -> {

		                }
		                "id3" -> {

		                }		          
		                "id4" -> {

		                }
		                "id5" -> {

		                }
		            }
		        }
            }

            override fun onError(inAppConnector: IapConnector, result: BillingResponse) {
                Log.d(tag, "Error : $result")

                when (result.errorType) {
                    CLIENT_NOT_READY -> TODO()
                    CLIENT_DISCONNECTED -> TODO()
                    ITEM_ALREADY_OWNED -> TODO()
                    CONSUME_ERROR -> TODO()
                    ACKNOWLEDGE_ERROR -> TODO()
                    FETCH_PURCHASED_PRODUCTS_ERROR -> TODO()
                    BILLING_ERROR -> TODO()
                }
            }
        })

Making a purchase

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

Sample App

  • Replace the key with your App's License Key
iapConnector = IapConnector(
                this, "key" // License Key
        )

Contribution

You are most welcome to contribute to this project!

About

Android Library for easing Google Play Billing to your apps with support for Subscriptions, In App Purchases and Consumables with a beautiful sample app.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%