For Google Play

Google Play Billing Library: Integration Guide

Google Play Billing Library: Integration Guide

Android apps sell one-time products and subscriptions through the Google Play Billing Library, an API that connects the app to Google Play’s billing system. The setup itself is routine. The end of the flow is where sales get lost.

A purchase that stays unacknowledged for 3 days gets refunded automatically by Google, and the entitlement is revoked with it (Android Developers, 2026).

There’s a version cutoff to watch as well. As of November 2026, new apps and updates must use version 8 or later, and the extension window for version 7 closed on November 1, 2026 (Android Developers, 2026).

What does the Google Play Billing Library handle in an app?

It sits between the app and Google Play. Product listings and the purchase flow run through it, and the results come back to the app the same way.

It sells digital items only. Physical goods and services go through the Google Pay SDK, according to the Android Developers billing overview.

Core classes in an integration

How BillingClient, PurchasesUpdatedListener, ProductDetails, BillingFlowParams, Purchase and BillingResult fit together, plus INAPP and SUBS types

BillingClient is the main interface between the app and Google Play, and PurchasesUpdatedListener receives updates for all purchases in the app. A product query returns ProductDetails, which holds price and offer data. BillingFlowParams then takes the product and offer token for the purchase screen. Once someone buys, the Purchase object carries the purchase token and the purchase state, and BillingResult returns the response code for every call along the way.

Every step after this touches at least one of them.

One-time products and subscriptions

Products come in two types, passed as ProductType.INAPP for one-time products and ProductType.SUBS for subscriptions.

One-time products give permanent access, and consumable ones can be bought again once the purchase is consumed. Subscriptions give access only while active. They move through six states: active, cancelled, in grace period, on hold, paused and expired.

Version 8.0.0 renamed “in-app items” to “one-time products” in the release notes, so older tutorials use the former term.

Billing also reaches past regular Android development work. Google recommends a secure backend for purchase verification and real-time developer notifications.

Which Google Play Billing Library version must an app use in November 2026?

Version 8 or later, for new apps and updates alike. The current release is 9.1.0 (released 2026-06-18) in the Android Developers release notes.

Each version runs a two-year deprecation cycle, per Google’s deprecation FAQ.

VersionReleaseNew app and update deadlineExtension deadline
7.0.02024-05-14August 31, 2026November 1, 2026
8.0.02025-06-30August 31, 2027November 1, 2027
9.0.02026-05-19August 31, 2028November 1, 2028

Both version 7 dates have passed. An app still on 7.x cannot ship an update until it moves to 8 or 9.

An app nobody touches keeps working. The rule only bites on new apps and on updates of existing ones.

Warnings that survive an upgrade

Play Console shows a warning for unsupported versions, and the extension form sits on the warning’s details page under Policy status.

A deprecation warning can also persist after a correct upgrade. Manifest merging sometimes removes the com.google.android.play.billingclient.version entry, so check AndroidManifest.xml before filing an extension request.

How to set up BillingClient and connect to Google Play

YouTube player

Add the dependency

The artifact is com.android.billingclient:billing:9.1.0. Kotlin projects can add com.android.billingclient:billing-ktx at the same version for coroutine support.

Separately, AndroidX Core has to be version 1.9 or later, which the 9.0.0 release notes require for the new BILLING_UNAVAILABLE behavior.

After adding the line, sync the Gradle project in Android Studio and confirm the manifest entry mentioned above survives the merge.

Build the client

Create the client with BillingClient.newBuilder(context) and attach the listener with setListener. Then call enablePendingPurchases with PendingPurchasesParams. The one-argument form is the only one left, and enableOneTimeProducts() covers pending one-time purchases.

Keep one active connection only, since a second client produces duplicate PurchasesUpdatedListener callbacks. Start the connection at launch or when the app returns to the foreground, and end it when the app closes.

Google’s integration guide suggests registerActivityLifecycleCallbacks and onActivityResumed as the hook for the first connection.

Connect and reconnect

Call startConnection with a BillingClientStateListener, and wait for onBillingSetupFinished to return BillingResponseCode.OK before any other request.

Turn on enableAutoServiceReconnection(). Added in 8.0.0, it removes the manual startConnection call from onBillingServiceDisconnected, which then stays empty or logs state. I’d switch it on in every project.

Without it, the retry logic is yours to write, and a dropped service connection means failed purchase queries until it runs.

How to query product details for one-time products and subscriptions

queryProductDetailsAsync results split into fetched and unfetched lists, offer getters for INAPP and SUBS, and three checks before the paywall

Call queryProductDetailsAsync with a QueryProductDetailsParams listing the product IDs and one ProductType per query. The result splits into productDetailsList for fetched products and unfetchedProductList for failures.

The unfetched list arrived in 8.0.0, so a missing product no longer disappears silently.

Do not cache ProductDetails. Stale objects cause launchBillingFlow failures, per Google’s integration guide.

In Kotlin, the billing-ktx module adds a queryProductDetails() extension that suspends through Kotlin coroutines, which removes the separate listener.

What each product type returns

For ProductType.INAPP, offers come from getOneTimePurchaseOfferDetailsList(), and since 8.0.0 one product can carry multiple purchase options and offers. Subscriptions (ProductType.SUBS) work through getSubscriptionOfferDetails(), where each offer has its own offer token.

That token matters. Since 7.0.0, setOfferToken() throws an exception when the token is empty.

Checks before showing the paywall

Run isFeatureSupported() to confirm the device supports the product type, for example subscriptions on an older Play Store version. Then check ownership, so an owned item or active subscription is never offered again.

How to launch the billing flow

YouTube player

Launch from the main thread. Build BillingFlowParams, pass it to launchBillingFlow(Activity, params), and check that the returned BillingResult is OK.

  1. Query fresh ProductDetails for the product the user picked.
  2. Choose the offer: getOneTimePurchaseOfferDetailsList() for one-time products, getSubscriptionOfferDetails() for subscriptions.
  3. Build BillingFlowParams.ProductDetailsParams with setProductDetails() and setOfferToken().
  4. Call launchBillingFlow from the main thread.
  5. Read the returned BillingResult. The purchase outcome itself arrives later in onPurchasesUpdated.

setObfuscatedAccountId or setObfuscatedProfileId helps Google detect fraud and attribute purchases to users, so set one of them. There’s also setIsOfferPersonalized, which discloses personalized pricing to EU users and defaults to false.

Changing a subscription plan

Plan changes use ReplacementMode, an enum introduced in 6.0.0 to replace ProrationMode. Version 7.0.0 then removed ProrationMode, setReplaceProrationMode() and setOldSkuPurchaseToken(), leaving setOldPurchaseToken() as the way to name the purchase being replaced.

Code copied from a pre-7.0.0 tutorial fails to compile on the current library for that reason.

How to process a purchase after the billing flow

Entitlement goes out only once the state is PURCHASED, and the rest follows a fixed order.

  1. Receive the Purchase from onPurchasesUpdated or queryPurchasesAsync.
  2. Verify it on the secure backend.
  3. Grant entitlement if getPurchaseState() returns PURCHASED.
  4. Notify the user, and delay the message if it would interrupt gameplay or a cutscene.
  5. Acknowledge or consume the purchase.

Detecting purchases

onPurchasesUpdated fires for purchases made through launchBillingFlow and for ones made outside the app, plus pending purchases that complete while the connection is active.

It stays silent when the app is not running.

queryPurchasesAsync covers that gap. Call it after every successful connection and again on resume. It picks up network failures during checkout and purchases made on another device. Out-of-app purchases such as redeemed promo codes show up there too, and so do state changes that happened while the app was closed.

Suspended subscriptions come back only when includeSuspendedSubscriptions is set on QueryPurchasesParams.Builder.

Acknowledge or consume within 3 days

YouTube player

An unacknowledged purchase is refunded automatically after 3 days, and entitlement is revoked, per Google’s integration guide.

The window starts when the purchase moves from PENDING to PURCHASED, not at checkout.

For consumables, call consumeAsync with ConsumeParams and the purchase token. Consumption makes the item buyable again, so check your backend first to avoid granting the same purchase twice.

Non-consumables need an isAcknowledged() check, then acknowledgePurchase. Subscriptions work a little differently: acknowledge every initial purchase, and skip renewals, which need no acknowledgement.

Pending purchases

A pending purchase is not a sale yet.

Support for them is required for one-time products. While the state is PENDING, show the user that action is still needed, and never acknowledge. Call queryPurchasesAsync in onResume() so a completed pending purchase is caught even if the listener missed it.

Version 7.0.0 added prepaid plan support through PendingPurchasesParams.Builder.enablePrepaidPlans(), per the release notes.

One trap: since 6.0.0 the order ID is not created for PENDING purchases. It appears only after the purchase moves to PURCHASED, so a database keyed on order ID at checkout time fails.

How to verify purchases and revoke them on a backend

Backend decision flow for Play purchases: acknowledge or consume calls when verification passes, revoke calls when it fails, and the orders.refund trap

Verify every purchase on a secure backend before granting entitlement, using the Google Play Developer API as the source of truth.

Google’s billing overview recommends the same backend for subscription-specific features and for handling real-time developer notifications.

Backend calls for each product type

Consumables go through Purchases.products:consume, after checking consumptionState. Non-consumables use Purchases.products:acknowledge, and subscriptions use Purchases.subscriptions.acknowledge, each after checking acknowledgementState.

Each call has a client-side twin, so pick one side and keep it consistent. Doing both without a state check produces double grants.

Rejecting and revoking

A purchase that fails verification, eligibility checks, fraud checks or fulfillment gets no entitlement, no acknowledgement and no consumption. Do not wait for the 3-day window to expire either.

Revoke it explicitly. For subscriptions, that means purchases.subscriptionsv2.revoke with “fullRefund” in revocationContext. For one-time products, use orders.refund with revoke set to true, passing Purchase.getOrderId().

Calling orders.refund without revoke=true returns the money and keeps the entitlement. That is the quiet failure here.

Explicit revocations trigger notifications and are recorded in the Voided Purchases API.

Real-time developer notifications

Notifications arrive through a Cloud Pub/Sub topic, a server-to-server push that works like webhooks for purchase state changes.

Each message carries a base64-encoded DeveloperNotification with a packageName, an eventTimeMillis and exactly one typed field. Google’s reference recommends checking each messageId for uniqueness, so duplicates do not trigger redundant API calls.

One-time products send ONE_TIME_PRODUCT_PURCHASED and ONE_TIME_PRODUCT_CANCELED, and only if you opted in to one-time product events. Subscriptions have 19 types, including SUBSCRIPTION_PURCHASED, SUBSCRIPTION_RENEWED, SUBSCRIPTION_IN_GRACE_PERIOD, SUBSCRIPTION_ON_HOLD, SUBSCRIPTION_REVOKED and SUBSCRIPTION_EXPIRED.

The notification says only that state changed. Google’s reference requires a follow-up call to the Developer API for the full purchase status before updating backend records.

Which response codes break an integration, and how to handle them

Retry the transient codes (SERVICE_DISCONNECTED, SERVICE_UNAVAILABLE, NETWORK_ERROR, ERROR), with a simple retry while the user is in session and exponential backoff in the background, and fix the rest at the source.

Code (value)Documented causeHandling
SERVICE_DISCONNECTED (-1)App not connected to the Play Store serviceReconnect with backoff
SERVICE_UNAVAILABLE (2)Service currently unavailableRetry with backoff
BILLING_UNAVAILABLE (3)Outdated Play Store, unsupported country, admin block, charge failureRetry only if the condition changed
DEVELOPER_ERROR (5)Incorrect API usage, such as an empty product list or an unsigned appFix the code, no retry
ITEM_ALREADY_OWNED (7)Item already owned, often stale cached dataRefresh purchases

The codes above come from the BillingResponseCode reference.

The ownership codes

ITEM_ALREADY_OWNED and ITEM_NOT_OWNED usually point to stale purchase data. Refresh with queryPurchasesAsync, and if the refreshed state shows the item already consumed, ignore the error.

Codes people misread

USER_CANCELED (1) is a normal outcome, not a failure. Log it and move on.

FEATURE_NOT_SUPPORTED (-2) is preventable. Call isFeatureSupported() before offering the feature.

Where two Google pages disagree

The 8.0.0 release notes list the launchBillingFlow sub-response codes PAYMENT_DECLINED_DUE_TO_INSUFFICIENT_FUNDS, USER_INELIGIBLE and NO_APPLICABLE_SUB_RESPONSE_CODE as new in 8.0.0. The version 9 migration guide presents the same three as new behavior to handle when moving to 9.

Handle all three on either version. An unhandled USER_INELIGIBLE leaves the user looking at a failed purchase with no explanation.

How to test Play Billing before release

Five license tester payment methods with expected outcomes, and production versus test timings for acknowledgement, renewals, grace period and hold

Testing runs through license testers and five test payment instruments, with the Response Simulator in Play Billing Lab for error paths. Real money never moves, and every state transition runs on a shortened clock.

License testers and test cards

Test purchases go through the normal purchase flow but charge nothing, and no taxes are computed. The dialog shows a test notice.

The Always approves card gives a successful purchase or renewal, while Always declines fails the payment, so no item should be granted. Slow decline creates a pending purchase that fails after a few minutes. Slow approve is the pending one that completes after a few minutes, which means you grant the item only at PURCHASED. Approve then charge back simulates a user-initiated chargeback and sends a PendingRefundReviewNotification.

Publish to a test track first, such as Google Play internal testing, and have each tester opt in. The app can take a few hours to appear.

Shortened timings

Test timing differs from production, and Google’s testing guide documents it.

A license tester purchase that goes unacknowledged is refunded after 3 minutes, against 3 days in production. Code that acknowledges late passes on a real account and fails in the test, which is the useful direction to fail in.

Weekly and monthly subscriptions renew every 5 minutes, at most 6 times. Grace period lasts 5 minutes and account hold lasts 10 minutes.

Test with non-tester accounts too. License testers behave differently, since resubscribe and pause are always available to them.

Simulating response codes

The Response Simulator forces specific BillingResponseCode values per API, which covers error paths the real Play Store rarely produces. It needs library version 7.1.1 or later and a license tester signed in to Play Billing Lab.

Add the enableBillingOverridesTesting meta-data tag with value true to AndroidManifest.xml, and add the NONPRODUCTION release-audience tag too. Google recommends the second one as protection against shipping with overrides on. Open Play Billing Lab first and the app second, since the reverse order may cause connection problems.

Production builds use a manifest without these tags.

How to migrate the Google Play Billing Library from version 7 or 8 to 9

If the app is on 7.x, migrate now, since updates are already blocked. Apps on 8.x can schedule the move, and it touches fewer lines than a jump from 7.

The reason is in the migration page: the queryProductDetailsAsync and onProductDetailsResponse update applies only to upgrades from 7, since 8.0.0 already changed that signature.

Removed APIs and their replacements

Removed APIReplacementNote
queryPurchaseHistoryAsyncqueryPurchasesAsyncTrack consumed purchases on the backend, and use the Voided Purchases API for canceled ones
SkuDetails, SkuDetailsParams, querySkuDetailsAsyncProductDetails, QueryProductDetailsParams, queryProductDetailsAsyncListener becomes ProductDetailsResponseListener
BillingClient.SkuTypeBillingClient.ProductTypeINAPP and SUBS
enablePendingPurchases() with no parametersenablePendingPurchases(PendingPurchasesParams)Old call equals enableOneTimeProducts()
queryPurchasesAsync(String skuType, …)queryPurchasesAsync(QueryPurchasesParams, …)Signature change

A conflict between two Google pages

The 8.0.0 release notes list queryPurchaseHistory(), querySkuDetailsAsync(), the no-argument enablePendingPurchases() and the String-based queryPurchasesAsync as removed in 8.0.0. The version 9 migration guide, which covers upgrades from both 7 and 8, lists the same group as APIs that version 9 no longer supports.

Neither page explains the difference. Code that still calls any of them has to change before it compiles against 9.1.0, so treat the compiler as the authority.

Migration steps

  1. Raise the billing and billing-ktx versions to 9.1.0.
  2. Replace every removed API with the replacement above.
  3. Turn on enableAutoServiceReconnection() if it is still off.
  4. Handle the three launchBillingFlow sub-response codes covered in the response codes section.
  5. Handle BILLING_UNAVAILABLE where code still assumes a generic ERROR, and update AndroidX Core to 1.9 or later.
  6. Check for null and empty values from DeveloperProvidedBillingDetails.getLinkUri() if the app uses external payments.
  7. Optionally, support pending purchases for prepaid plans and virtual installment subscriptions.

Run regression testing on every purchase path after each API swap, using the slow-approve and always-decline test cards. The removed query methods fail at compile time, but the behavior changes do not.

Google Play Billing Library FAQ

Does the library add the BILLING permission automatically?

Yes, since version 1.0. The Android Developers blog (2017) announced that the library adds the com.android.vending.BILLING permission to the APK on its own, so no manual manifest entry is needed.

Check the merged manifest after each build to confirm the permission is present.

Is billing-ktx required for Kotlin?

No. The KTX module is optional and adds Kotlin extensions with coroutine support.

The base artifact covers every integration step, and Google’s integration guide shows Java and Kotlin samples for each one.

How do multi-quantity purchases work?

Since version 4.0, a customer can buy several units of one consumable one-time product in a single transaction. The app reads the amount from Purchase.getQuantity() and grants that many units.

Switch the feature on in Play Console only after the app honors quantity. Older app versions may need a forced update first.

What does getBillingConfigAsync return, and can the data be stored?

It returns the user’s Google Play country as an ISO-3166-1 alpha-2 code in BillingConfig.getCountryCode().

Do not store the result. Google states the data is meant for one use and can change at any time, and it cannot feed user profiling or advertising.

Does the standard billing flow cover external payments?

No. Version 8.3.0 (2025-12-23) added separate APIs for them, including the enableBillingProgram(EnableBillingProgramParams) overload and BillingFlowParams.Builder.enableDeveloperBillingOption.

Version 9.1.0 (2026-06-18) then added Billing Choice APIs such as getBillingChoiceInfoAsync.

Is a third-party wrapper such as RevenueCat required?

No. Google documents a direct path: the app uses the library, and a secure backend verifies purchases.

Wrappers like RevenueCat publish their own Play Billing guides, but they sit on top of that path and do not replace it.

Keeping a Google Play Billing Library Integration Current

A Google Play Billing Library integration stays compliant when the team adopts each major version within its first 12 months.

Combining the release notes with the deprecation FAQ shows the margin: a team that adopts version 8.0.0 (2025-06-30) within a year keeps at least 14 months before its deadline, and version 9.0.0 (2026-05-19) leaves at least 15 (Android Developers, 2026).

Order the recurring work by cost of failure. Run the test cards before every release and watch notifications on the backend. Version migration before the deadline comes third on that list, because it gives you the longest warning.

A tester’s acknowledgement window runs 1,440 times shorter than production’s 3 days, so a late acknowledgement fails in minutes during testing and in days after launch.

The cost is one migration roughly every year. Once the final test cycle passes, the remaining step is to publish the app on Google Play with the current library.

This schedule was verified on November 26, 2026. A new major release restarts the two-year cycle and moves the dates.

Bogdan Sandu

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.