A very simple way to implement In App Purchases on Android.

Overview

The Google-developed Android In App Purchases library can seem quite confusing and too much code to do something as simple as making in-app purchases via Google Play. Whenever I needed to implement this in a new application, I wasted a lot of time reading their documentation with a lot of verbose code. So some time ago I had developed this library which makes this task much simpler and now I'm updating it and making it public for everyone. Any help is welcome! :D


MainActivityJava.java and MainActivityKotlin.kt examples here.

Download the demo

Dependencies

Step 1. Add the JitPack repository to your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependencies

dependencies {
	implementation 'com.github.maickonn:EasyInAppPurchases:1.0.0'
	implementation 'com.android.billingclient:billing:3.0.3'
}

Usage:

import com.maickonn.EasyInAppPurchases
import com.android.billingclient.api.Purchase
import com.android.billingclient.api.SkuDetails
import com.android.billingclient.api.BillingResult


val skuList: ArrayList<String> = ArrayList()  
skuList.add("item1")  
skuList.add("item2")  
skuList.add("item3")
skuList.add("subs1")  
skuList.add("subs2")  
skuList.add("subs3")

val easyInAppPurchases =  EasyInAppPurchases(this, skuList, object : EasyInAppPurchases.EasyInAppPurchasesCallback {  
    override fun onProductPurchased(purchase: Purchase) {
	if (purchase.purchaseState != Purchase.PurchaseState.PURCHASED)
	    return

	// TODO: Add your purchase control here
    }

    override fun onGetProductDetails(skuDetails: SkuDetails) {
	// SkuDetails usage example
	val price = skuDetails.price
	val sku = skuDetails.sku
    }

    override fun onProductRestored(purchase: Purchase) {
	// Example of use when you have an active purchase
	if (purchase.sku == "item1")
	    supportActionBar?.title = "Easy In-App Purchases (Premium)"
    }

    override fun onConsumeResponse(billingResult: BillingResult, purchaseToken: String) {

    }
})

How to test

  1. First, you need to submit your app to Google Play Console with the dependencies of that library. We recommend that you submit your app as Closed Alpha for testing.
  2. After submitting your app to the Google Play Console with dependencies from that library, the Products in App option must be enabled in your app's Products section in the Google Play Console.
  3. Go to Products in App option in the Google Play Console and add some products, remember that the SKUs must have the same name as the ones you entered in your app codes.
  4. Now go back to your Google Play Console home screen, go to the Settings section, then go to License Tests. On this screen, you'll add the emails that will be used as part of testing in-app purchases.
  5. Wait a few hours for the changes to take effect on Google's servers and then you'll be able to test all in-app purchase commands.

Please note: If you try to use in-app purchase commands without submitting your app to the store, nothing will work, no error messages or warnings will be displayed. Simply nothing will happen. You can find more details about this at this link.

Documentation

Public constructors

EasyInAppPurchases (
	activity: Activity,
	skuList: List<String>,
	easyInAppPurchasesCallback: EasyInAppPurchasesCallback?
)
Public methods Return types Callbacks
queryPurchases() void onProductRestored
launchPurchase(sku: String) void onProductPurchased
consumePurchase(sku: String) void onConsumeResponse
You might also like...
A sample project of implementing Liveness Detection and Identity OCR on Android app using Kredibel Vision SDK
A sample project of implementing Liveness Detection and Identity OCR on Android app using Kredibel Vision SDK

Vision Sample (Android) A sample project of implementing Liveness Detection and Identity OCR on Android app using Kredibel Vision SDK. You can checkou

Android SDK for eyeson video service incl. demo app

eyeson Android SDK Android SDK for eyeson video service incl. demo app Prerequisites A webservice to host and maintain eyeson meetings is required. Th

Free forever Marketing SDK with a dashboard for in-app SplashScreen banners with built-in analytics
Free forever Marketing SDK with a dashboard for in-app SplashScreen banners with built-in analytics

AdaptivePlus Android SDK AdaptivePlus is the control center for marketing campaigns in mobile applications Requirements minSdkVersion 16 Examples prov

Its measurement app made using kotlin with sceneform sdk by google

ARCORE MEASUREMENT This app is build using sceneform sdk for android using kotlin language It helps you measure the distance between multiple points i

Sdk-android - SnapOdds Android SDK

Documentation For the full API documentation go to https://snapodds.github.io/sd

AWS SDK for Android. For more information, see our web site:

AWS SDK for Android For new projects, we recommend interacting with AWS using the Amplify Framework. The AWS SDK for Android is a collection of low-le

Powerful custom Android Camera with granular control over the video quality and filesize, restricting recordings to landscape only.
Powerful custom Android Camera with granular control over the video quality and filesize, restricting recordings to landscape only.

LandscapeVideoCamera Highly flexible Android Camera which offers granular control over the video quality and filesize, while restricting recordings to

Countly Product Analytics Android SDK
Countly Product Analytics Android SDK

Countly Android SDK We're hiring: Countly is looking for Android SDK developers, full stack devs, devops and growth hackers (remote work). Click this

Android Real Time Chat & Messaging SDK
Android Real Time Chat & Messaging SDK

Android Chat SDK Overview Applozic brings real-time engagement with chat, video, and voice to your web, mobile, and conversational apps. We power emer

Owner
Maickonn Richard
Maickonn Richard
Qiscus provide everything you need to power up your app with chats. And it's now made simple.

Introduction Qiscus Chat SDK (Software Development Kit) is a product provided by Qiscus that enables you to embed an in-app chat/chat feature in your

Qiscus - Multichannel Conversational Platform 197 Dec 27, 2022
Amazon S3 multipart file upload for Android, made simple

Simpl3r Amazon S3 multipart file upload for Android, made simple This library provides a simple high level Android API for robust and resumable multip

Jeff Gilfelt 182 Nov 15, 2022
Simple Discord <-> Minecraft chat integration using webhooks

Minecraft Chat Simple Discord <-> Minecraft chat integration using webhooks Instalacja Plugin należy wrzucić do folderu plugins oraz ustawić URL webho

Oskar 10 Aug 31, 2022
CodingChallenge: A simple SDK. Which can provide you information related to Start Wars APi

CodingChallenge CodingChallenge is a simple SDK. Which can provide you informati

Wajahat Hussain 1 Feb 18, 2022
Android Weather Library: android weather lib to develop weather based app fast and easily

WeatherLib Android weather lib is an android weather aggregator. The lib helps you getting weather data from the most importat weather provider. It su

Surviving with android (by Francesco Azzola) 641 Dec 23, 2022
Accept PayPal and credit cards in your Android app

Important: PayPal Mobile SDKs are Deprecated. The APIs powering them will remain operational long enough for merchants to migrate, but the SDKs themse

PayPal 802 Dec 22, 2022
Library for Android In-App Billing (Version 3+)

Checkout (Android In-App Billing Library) Description Checkout is an implementation of Android In-App Billing API (v3+). Its main goal is to make inte

Sergey Solovyev 1k Nov 26, 2022
This App is sending Face capture data over network, built around the latest Android Arcore SDK.

AndroidArcoreFacesStreaming From any Android phone ArCore compatible, using this app will send over TCP 5680 bytes messages: The first 5616 bytes is a

Maxime Dupart 30 Nov 16, 2022
How to Integrate SAWO SDK to an Android app

How to Integrate SAWO SDK to an Android app Add following line to root build.gradle repositories block maven { url 'https://jitpack.io' } Add this to

Latiful Mousom 0 Nov 20, 2021
The client app for Android

handl-service-provider-application “Service Booking Platform ” is an advanced pl

null 0 Dec 20, 2021