In-App Purchase / Subscription — Verification(Android)

Karthik Ponnam
Nov 11, 2017 · 3 min read

In-app purchase is the easiest way to make a purchase of some products or make a subscriptions

Here’s how you can do it.

Google Play :

In order to test or implement InApp Purchase / Subscription, you need a developer account and your app need to be published either in alpha/beta/production level

After creating application go to Development Tools > Services & APIs

Inside Services & APIs, you will find Licensing & in-app billing Section where you find a Base64 encoded Licence Key

Upload your signed APK under release Management > App releases > Manage Alpha > Upload your first APK

Google play will take some time to approve your APK ( 2–3 hours )

Create Subscription / Products

Once the APK is published you can now able to create Subscription / Product

In Developer console go to Store Presence > In-app products

Now create a product or a subscription

fill the details and click on save.

now your in app product is ready to purchase

Now Lets get out hands dirty

Open your android app code in android studio

include google play billing library in your build.gradle file

compile 'com.android.billingclient:billing:1.0'

Initialise billing client

https://gist.github.com/PonnamKarthik/828f8ff63d48a1f474fc62552010d999

Once the Billing client is initialised you can get the list of products or can start purchasing product / subscription

Purchase In-app Product / Subscription

List all the Items available for purchase

In below code product_1 and product_2 are the product ids which we mentioned during the creation of In-app products

If you want to get the available subscriptions inthe place of product_id’s add subscription_id and change BillingClient.SkuType.INAPP to BillingClient.SkuType.SUBS

Purchased Items List

Inorder to get the user purchased items list use the below code

Consuming a purchase

For consuming a purchase

That is Now you can perform In-app purchase very easily.


Verify your purchase

Now we verify the purchase we got in the above process.

Create a file named Security.java and copy paste the below code

Now to implement the verification process we do the process in onPurchaseUpdated method which is triggered when a new purchase is made

Hurry!!! Now are able to validate your purchase.

Thanks for your time.

Need any help or have a freelance job contact me at ponnamkarthik3@gmail.com

If you find it useful Please like and share, Don’t forget to clap

Karthik Ponnam

Written by

❤️ to Code. Full Stack Developer, Flutter, Android Developer, Web Development, Known Languages Java, Python so on.,