Back to the RevenueCat homepage
RevenueCat SDKGoogle Play Billing

Preface

Who This Book Is For

This book is for Android developers who want to sell digital goods and services through the Google Play Store. You already know how to build Android apps with Kotlin. You know your way around Activities, ViewModels, Gradle, and the Android SDK. What you do not know, or know only partially, is how to integrate Google Play Billing into your app.

Maybe you have tried before. You read a few pages of documentation, got a basic purchase working, and then discovered that subscriptions have seven different states, grace periods, account holds, and a notification system that requires Cloud Pub/Sub. You realized this is not a weekend project.

This book takes you from zero billing knowledge to production readiness. It covers everything: the client library, the server API, the Play Console configuration, subscription lifecycle management, testing, security, and the edge cases that only surface in production.

What You Will Learn

By the end of this book, you will be able to:

  • Set up a complete billing environment from scratch (developer account, products, API access, notifications)
  • Sell one time products (consumable and non consumable) with proper verification and acknowledgement
  • Implement subscriptions with free trials, introductory pricing, and multiple plan options
  • Handle subscription upgrades, downgrades, and plan changes correctly
  • Build a backend that verifies purchases, processes notifications, and maintains accurate entitlement state
  • Manage the full subscription lifecycle: renewals, grace periods, account holds, pauses, cancellations, and recovery
  • Change subscription prices for existing subscribers without losing them
  • Test every billing scenario before shipping to production
  • Manage a product catalog at scale using the catalog management APIs
  • Protect your revenue with server side verification and fraud detection
  • Implement alternative billing where regional regulations require it

How to Read This Book

This book is organized in seven parts that build on each other:

Part I: Foundations (Chapters 1-2) gives you the big picture and walks you through environment setup. Start here if you are new to Google Play Billing.

Part II: Products (Chapters 3-4) covers the two product types: one time products and subscriptions. You will understand how each works and how to configure them.

Part III: Client Side Integration (Chapters 5-8) is where you start writing code. You will learn to integrate the Play Billing Library, build purchase flows, handle plan changes, and implement error handling.

Part IV: Server Side Integration (Chapters 9-10) covers your backend: purchase verification, the Google Play Developer API, and Real Time Developer Notifications.

Part V: The Subscription Lifecycle (Chapters 11-14) is the deepest part of the book. It covers the subscription state machine, payment recovery, cancellations, pauses, winback strategies, and price changes.

Part VI: Production Readiness (Chapters 15-17) prepares you for launch: security, testing, and catalog management at scale.

Part VII: Beyond Standard Billing (Chapter 18) covers alternative billing and external offers for apps operating in regions with special regulations.

The appendices provide reference material: a complete RTDN reference table, response code reference, API endpoint reference, a PBL 7 to PBL 8 migration guide, and a pull out subscription state diagram.

If you are experienced with billing but upgrading to PBL 8, start with Appendix D (Migration Guide) and then read the chapters that cover your knowledge gaps.

If you are building a new integration from scratch, read Parts I through IV in order. Then read Part V as you prepare for production, and Part VI before launch.

Prerequisites

This book assumes you have:

  • Working knowledge of Android development with Kotlin
  • Familiarity with coroutines (the code examples use suspend functions and Flows)
  • Basic understanding of REST APIs and JSON
  • Access to a backend server (for purchase verification and notifications)
  • A Google Play Developer Account (or the ability to create one)

You do not need prior experience with billing, payments, or the Google Play Console.

Play Billing Library 8 Focus

This book targets Play Billing Library (PBL) version 8.x, specifically versions 8.0.0 through 8.3.0. PBL 8 introduced several important changes from PBL 7, including auto service reconnection, pending purchase parameter changes, the UnfetchedProduct API, sub response codes, and new replacement mode APIs.

If you are currently on PBL 7, Appendix D provides a complete migration guide. Note that Google has announced PBL 7 will reach end of support on August 31, 2026. Migrating to PBL 8 is not optional.

All code examples in this book use Kotlin and the billing-ktx artifact, which provides coroutine extensions for the billing library's async operations.

Conventions Used in This Book

Code blocks show Kotlin code targeting PBL 8.x. Client side code runs on Android. Server side code runs on your backend (also shown in Kotlin for consistency).

Diagrams illustrate architecture, state machines, and flows. They follow a consistent visual style and are available as both inline images and full page reference cards in the appendices.

Bold terms indicate first use of important vocabulary or emphasis. Terms defined in Chapter 1 are used consistently throughout.

Tables summarize reference information that you will want to look up later. The appendices contain comprehensive reference tables.

Acknowledgments

This book would not exist without the Google Play Billing documentation team, whose work across dozens of pages formed the foundation for this consolidated guide. The Android developer community's questions, bug reports, and Stack Overflow answers also shaped the practical focus of every chapter.

Want a simpler approach?

The RevenueCat SDK Handbook covers the same topics — with less code and a managed backend.

Related chapters

  • Chapter 1: Understanding Google Play's Billing System

    The big picture: key actors, core vocabulary, product types, and the three pillars of Google Play Billing.

    Learn more
  • Chapter 2: Setting Up Your Environment

    Developer account, Play Console, service account keys, Pub/Sub for RTDNs — everything before a single line of code.

    Learn more
  • Chapter 6: The Purchase Flow

    End-to-end from launchBillingFlow() to acknowledgement: payment dialog, callbacks, pending purchases, and multi-quantity.

    Learn more
Preface | RevenueCat