Features • Development • Usage • License • Contribution
—
[](https://postimg.cc/Q9hGcs1f)
What is Google-IAP?
IAP is an Android library designed to streamline the process of handling In-App purchases, all with minimal code.
Features
- Written in Kotlin
- No boilerplate code
- Easy initialization
- Supports In-App Subscription products
- Simple configuration for consumable products
Gradle Dependency
To get started, you’ll need to add the JitPack repository and the required dependency in your project’s build.gradle file:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.akshaaatt:Google-IAP:1.7.0'
}
Development
Before diving into development, make sure you have the latest version of Android Studio along with the required SDKs installed on your machine.
- Clone this repository.
- Use the
gradlew buildcommand to build the project directly, or utilize the IDE to run it on your phone or emulator.
Usage
Establishing a connection with the Play Console requires a straightforward setup. Here’s a breakdown:
val iapConnector = IapConnector(
context = this, // Activity context
nonConsumableKeys = nonConsumablesList, // List of non-consumables
consumableKeys = consumablesList, // List of consumables
subscriptionKeys = subsList, // List of subscriptions
key = LICENSE_KEY, // Your app's license key
enableLogging = true // Enable or disable logging
)
Think of this as setting up a mail server. You’re establishing a connection with essential credentials (like a license key), and you’re ready to manage your purchasable items (like letters you send and receive).
Receiving Events
Here’s how you can listen for purchase events:
iapConnector.addPurchaseListener(object : PurchaseServiceListener {
override fun onPricesUpdated(iapKeyPrices: Map) {
// Update UI with prices if needed
}
override fun onProductPurchased(purchaseInfo: DataWrappers.PurchaseInfo) {
// Trigger when purchase succeeds
}
override fun onProductRestored(purchaseInfo: DataWrappers.PurchaseInfo) {
// Trigger fetching owned products
}
})
When you handle subscriptions, the process is quite similar:
iapConnector.addSubscriptionListener(object : SubscriptionServiceListener {
override fun onSubscriptionRestored(purchaseInfo: DataWrappers.PurchaseInfo) {
// Trigger fetching owned subscriptions
}
override fun onSubscriptionPurchased(purchaseInfo: DataWrappers.PurchaseInfo) {
// Trigger when subscription succeeds
}
override fun onPricesUpdated(iapKeyPrices: Map) {
// Update UI with prices if needed
}
})
Making a Purchase
Executing a purchase can be done easily, just pass the context and SKU to the purchase method:
iapConnector.purchase(this, sku)
Making a Subscription
Similarly, you can subscribe to a product with the following command:
iapConnector.subscribe(this, sku)
Removing a Subscription
To unsubscribe from a product, use the command:
iapConnector.unsubscribe(this, sku)
Sample App
To test the integration, add your products to the developer console and replace the license key with your actual App’s license key.
Apps Using this Library
License
This project is licensed under the GPL version 3 or later.
Contribution
Your contributions to this project are highly welcomed!
Troubleshooting
If you encounter issues while implementing Google-IAP, consider the following troubleshooting tips:
- Ensure your app’s license key is correctly configured.
- Verify that you have the needed permissions in your app’s manifest file.
- Check for any network connectivity issues if IAP calls are failing.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

