class="nav-up">

Google in app purchase in android app

07

Dec. 20

1.85 K

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

6 Business Models That Online Marketplaces Use to Earn Money

As the ongoing pandemic continues to push consumers to shop online and get delivery directly to their homes in a bid to stay safe from the spread of Covid-19, online …

Store sensitive data using KeyChain

There is always some sensitive data that our App holds for instance, Passwords, Touch Id, Certificates, Tokens or Biometric information. In general, React Native does not come bundled with any …

How to Tackle & Manage SKUs as an Ecommerce Business in 2021

If you are just starting to build up your eCommerce business, you may have started thinking about the size of your inventory but not necessarily, how you are going to …

How to setup Contact form 7 plugin In WordPress

Contact Form 7 is the most popular and oldest WordPress contact form plugin. It is easy to integrate and equally easy to deploy. For setup contact form 7 follow the …

Setting up a multi-platform SwiftUI project

What is SwiftUI? Before SwiftUI, we were designing iOS applications User Interface into storyboards. Storyboards are an imperative user interface. From June 2020, Apple released SwiftUI for design applications in …

Steps to Create Apple Enterprise Developer Account

The Apple Developer Enterprise Program allows large organizations to develop and deploy proprietary, internal-use apps to their employees. This program is for specific use cases that require private distribution directly …

React Native: First Demo

Let us start to build our first React Native application on Windows as a development operating system and Android as a target operating system. If you are looking to set …

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

Augmented Reality (AR) is a technology that superimposes virtual objects on a user’s real-world view, creating an enhanced mixed reality experience. AR blends real and virtual objects into a single …

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 …

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