Google in app purchase in android app

07 Dec. 20
116 VIEWS

Before we start with app purchase, Let’s get a basic idea of what type of digital content we are selling to users.

Google’s Billing system gives us mainly two types of digital content to sell

  • Subscription
  • One Time product

One time product has two types of product

  • Consumable
  • Non Consumable

Consumable product is the one that is consumed in due time and you will purchase it again, Like a game currency in a gaming app, when the user consumes the product, your app dispenses associated content and the user can then purchase that item again.

Non Consumable Products is the one in which users can buy permanent benefits of purchase, without need of buying it again and again.

SubScription : it is a product that provides access on a recurring basis, subscription is not cancelled until the user does not cancel it, for example, music streaming services.

The google play console offers lot of flexibility when creating subscription products,

  • you can set billing period
  • offer free trial
  • offer introductory price
  • provides grace periods when payment fails
  • allow users to pause their subscription as an alternative to cancelling

Subscription has 6 states:

  • Active- When a new subscription is purchased.
  • Cancelled- Users can voluntarily cancel subscription, or subscription automatically cancelled if they don’t recover after being in account on hold.
  • In grace period- if grace period is enabled, then if there are payment issues at the end of billing cycle in subscription, then the subscription enters in grace period.
  • On hold- When a user’s payment fails and if the grace period is there, that also has ended without payment resolution then subscription enters into on hold period, and it lasts for 30 days.
  • Paused- All subscription paused by default, you have to change that setting from google play console, when pause feature is enable, user can pause their subscription for a period of time between one week to three months, depending on the recurring period of subscription, only annual subscription can not be paused.
  • Expired- once subscription enters into expiration state, users should lose access of their subscription.

Now steps for implementing in app purchase are

  • Set up a google merchant account.
  • Add billing library and billing permission to your in-app purchase demo app and upload that app to the internal publishing track.
  • Add your license key in your app in console and in your app and upload that version of app for publishing
  • Add products in that account
  • Handle in app purchase flow in app.

1. Adding a merchant account in Google play console.

Log in to your google developer account : with link https://play.google.com/apps/publish/

Click settings tab from the menu on left

Scroll down to the bottom of this page and you will see a link to activate your account, when your merchant account is activated, it will look like this

2. Now create simple app and add your billing library and billing permission to that app.

We are using this library from git repo :

Open android Manifest.xml and add billing permission in it

Upload this app in your developer account

3. Now add your billing License key in your uploaded app.

From Left menu in your developer account console, select all applications and select your app in which you are applied to in app purchase to.

From the menu on the left select services and APIs found under development tools

Copy the license key found under section titled “Your license key for this application”

Upload your license/Billing key to the commerce section of your app’s control panel

Now your merchant account is activated and your Licensing/Billing key is also uploaded, before adding products to your app, your app version must be uploaded that has a billing /license key included.

4. Add products in your app

Go to google developer console and select your app from all applications

if your app was already live on play store, you are now just including your in app purchases, in app products is found under “Store presence” tab in your app’s listing

Make sure subscription tab is selected for adding subscription, then click on “Create Subscription”

Add your product id : product id must be composed of lower letters(a-z), numbers(0-9), Underlies(_), or dots, without any spaces, and it should start with lower letters or numbers.

Input your title and description, then change status to active.

Set a price and billing period and save product

Now in your app’s control panel, step into the commerce section from the menu on the left. Copy and paste your product id into google play product id field,
And click add button to save it

5. Now handle in app purchase flow in your app.

As you already added billing library in gradle and billing permission in android manifest.xml,

Now create an instance of Billing Processor class and implement callback in your activity class, Constructor will take these three parameter
1, Context 2, Your licensing key from google developer console, 3, IBillingHandler interface implementation to handle purchase results and errors

Here billingProcessor. isIabServiceAvailable() is used to check if a google play store app is there in your device or not.

You will get four override methods for implemented interface

Override activity’s OnActivity method

Call purchase method for a billing processor instance to initiate purchase or subscribe method to initiate subscription

For subscribe or purchase method, you need your product id as a parameter needed to pass nad context

Don’t forget to release your billing processor instance in onDestroy method, once it’s work is done.

That’s it, if you have your purchase successful you will get your transaction details in onProductPurchased methods, from there you will get the State of your product also there, and depending on your product state you will update your app ui.

Let’s Nurture, a top mobile app development company in India has got the expertise in providing many solutions based applications with E-Commerce, Social Networking, Health sector, IoT & Machine learning. Our team at LetsNurture provides best solutions for business (saving time), shopping experience, teaching experience and many more. If you want to know more about this technology in your existing mobile app, get a free consultation from our experts at Let’s Nurture.

Author

Lets Nurture
Posted by Lets Nurture

Blog A directory of wonderful things

AdMob Mediation in Android

We all know about Admob Ads very well. Here, I would like to explain what mediation features and how it will be useful for developers. Let’s take a simple one …

Laundry On-Demand services: A Successful App Service You Should Consider

With our hectic lifestyles and the need to physically distance due to the ongoing pandemic, on-demand app services are rising in popularity. One such category for this niche is on-demand …

How to Setup Twilio Package for SMS in Laravel

In your application workflow, you may need to pass important information to your users. Most services require your users to have an internet connection and unfortunately, this isn’t always the …

Firebase Dynamic Links

Deep links are a powerful and essential part of a market’s toolkit. They are connecting users to campaigns, streamlining user experience and exposing users to the right marking. Many developers …

Kotlin Coroutines in Android

Multithreading is a well known programming concept which all developers might have come across. The concept of multithreading is a vast subject and includes complex mechanisms in it, but in …

Augmented reality wayfinding

What is Augmented Reality? Augmented reality is made up of the word “augment” which means to make something great by adding something to it. Augmented reality is used to add …

COVID lockdown has brought the digital future forward

The Novel Coronavirus epidemic that has spread its tentacles worldwide almost brought business and the economy to its knees. With no way of attending office, how are employees supposed to …

The Impact of COVID 19 on Restaurant & Hospitality Industry

Coronavirus has literally crippled the economies of different countries catastrophically and has forced many industries to put down their shutters for long. Some have closed down temporarily abiding by the …

How AI might be the most effective weapon to detect COVID-19

The COVID-19 pandemic raises many problems in the domain of Artificial Intelligence (AI). The major challenges are often raised by way of so many pertinent questions such as, can AI …

AI for Pneumonia Detection

The risk of pneumonia is enormous for many, especially in the nations where billions face energy poverty and rely on polluting forms of energy. “The WHO estimates that over 4 …

How Outsourcing & Subcontracting help companies with Disaster Management

According to recent google reports, 114 countries have reported that 1,18,000 have contracted Covid-19, the disease caused by the virus, known as SARS-CoV2. Nearly 4,300 people have died. Introduction Where …

10 most extensively used Python libraries

Python, being one of the most sought after programming languages, has a huge collection of libraries. In fact, this expansive set of libraries can be considered as one of the …

AI for Food Detection

“Four simple ways to fight diabetes/Obesity: Go for regular medical check-ups; Exercise more; Watch your diet, and Cut down on soft drinks.” – Singapore PM Lee Hsien Loong (Nvidia Research …

Django vs Laravel vs Node js

Web Frameworks are basically software packages that ease the complexity of web development. They come with many inbuilt features that are common in web development, thus minimizing the development time, …

8 Chatbot Development Frameworks: Building a Better Bot for Your Business

There has been an explosion in the use of chatbots across both business websites and messaging applications, mainly because businesses want to cater to their customers and customers have a …

Personalization of advertising and marketing: Tools at a marketer’s disposal

According to Econsultancy, following the personalization of metasearch engine, 93 percent of organizations experienced an increase in transformation rates. Personalization depicts the system and strategies of conveying the content and …

Implementation of AI in Financial Planning

AI focuses on a future where machines not only do all of the manual labour, as they have done since the industrial revolution but also the work which requires Intelligence …

Importance of reliable IT outsourcing partner during a global pandemic

Though a bad reputation has developed over the years, outsourcing is on the rise and for good reason: it is a sound financial strategy for companies, of all sizes and …

BigCommerce Vs Shopify – Key Difference

According to google reports, current e-commerce statistics state that 40 percent of worldwide internet users have bought products or goods online via desktop, mobile, tablet or other online devices. This …

Tech in Prenatal Care-Empowering rural women with a mobile first avenue for information

In the era of wireless technology, where there are more mobile phones than people, mobile applications play an important role for rural women to improve their maternal health. Technology is …

CONTACT US

Have an !dea or need help with your current business?

loading...
We use cookies to give you tailored experiences on our website.
Okay