Skip to main content

A Developer's Guide to verify In-App purchase

 

Disclaimer: Helpful document for the coder
This document is providing the API calls needed from the mobile device to verify the purchase from the respective stores. The RESTful API will connect with the respective store and verify the purchase, update the user data and will provide the necessary response to the user call.

We are going to verify the receipt data from the Apple Store and the purchase token from the Google Play Store. Both stores provide steps to verify/get details of the transaction but this document comes in handy and provides action plans for the mobile app developer and the backend team.

Objective

Verify In-App purchase/subscription from Google Play Store and Apple Store

Requirements

RESTful APIs

Purchase subscription/product

This will be the first API call from the mobile app to send the purchase details to the backend.
Parameters
item_idstring
Subscription package or Product package.
receiptstring
iPhone should pass the receipt_data and the Android should pass the purchase_token
platformstring
Either “google” or “apple”
is_renewableint
Optional parameter for Android only. iPhone devices can skip this parameter.
1 = True, 0 = False
- 1 indicates that it’s a subscription package
- 0 indicates that it’s a product package

Sequence diagrams



Verify Purchase

This will be another API call from the mobile app to verify the purchase period and the Backend is checking this on daily basis with the CRON (The CRON is a software utility, offered by a Linux-like operating system that automates the scheduled task at a predetermined time.)

Sequence diagram

Verify on Google

When the “platform” is “google”, the backend needs to verify the purchase token stored in the key “receipt”. To do so, the backend team needs the Service Account JSON file to communicate with the Google Play Developer API. To get the purchased details and to verify it, you have to check, if you are checking for product purchase or subscription purchase.

Requirements: 

purchases.products

Checks the purchase and consumption status of an in-app item.
purchases.subscriptions

Checks whether a user's subscription purchase is valid and returns its expiry time. 
Parameters
packageNamestring
The package name of the application the in-app product was sold in (for example, 'com.devdigital.app').
productIdstring
The package name of the application the in-app product was sold in (e.g., 'com.devdigital.app.tier1.package1').
subscriptionIdstring
The purchase subscription id (e.g., 'com.devdigital.app.tier1.monthly')
purchaseTokenstring
The purchase token stored in the database by the user
accessTokenstring
The access token generated with
OAuth Steps

Sample Response


Verify on Apple

When the “platform” is “apple”, the backend needs to verify the receipt-data stored in the key “receipt”.

Requirements:

verifyReceipt

Send a receipt to the App Store for verification HTTP requests.

References

Apple IAP verification

  1. Sandbox API endpoint: https://sandbox.itunes.apple.com/verifyReceipt
  2. Production API endpoint: https://buy.itunes.apple.com/verifyReceipt 

Google IAP verification

General

Comments

Popular posts from this blog

Google Play Developer API: How to Create a Service Account

Why am I reading this? Mobile applications are surrounded by so many modules in addition to that, the IN-APP Purchase and Subscriptions play a good amount of role, where you as an owner of the app, can generate revenue by selling consumable and non-consumable goods such as Coins for Games, Subscription plans for your app many things. Now, as you are selling some goods on your app, there must be a way to validate that purchase or get the details. But obviously, you can do it from the app itself as Google does provide SDK for the same. (SDK – Software Development Kit). But, we are living in a world where Android and iOS exist and in a very competitive market! Google Play Developer API gives us the power to check the user’s transaction from the RESTful APIs which leads you to read this blog. With the RESTful API, we can do this call from the BACKEND and leave the app standalone and do other stuff Offering Google Play Developer API lets you manage the two main components in your project Th...

ADB - The Android Developer's Swiss Army Knife

Introduction: In the world of Android app development, having the right tools can make a significant difference. One such indispensable tool is ADB (Android Debug Bridge), a versatile command-line tool that empowers developers and Android enthusiasts to interact with Android devices from their computers. In this blog, we'll explore what ADB is, its key functionalities, how to install it on Windows and Mac, and how it simplifies the app development and testing process. What is ADB? ADB, short for Android Debug Bridge, is a critical component of the Android Software Development Kit (SDK) or the standalone Android Platform Tools package. It serves as a bridge between a computer and Android devices, enabling seamless communication and control over connected devices. How to Install ADB on Windows? Installing ADB on Windows is a straightforward process: Download Android SDK Platform Tools : Go to the official Android Developer website and download the SDK Platform Tools package from this...