---
updatedAt: 2026-08-24T11:05:42.000Z
agentTools:
  projectIndex: https://developers.cleeng.com/llms.txt
---

# Google Play Billing

This tutorial will help you integrate Google Play in-app purchases using the **Google Play Billing** connector for Android devices, including phones, tablets, and Android TV.

<Callout icon="🚧" theme="warn">
  ### **Important**

  Android in-app purchase integration with the new Google Play Billing connector supports **auto-renewable subscriptions&#x20;**&#x61;nd **one-time products**. Subscriptions correspond to Cleeng subscription offers and one-time-products - to Cleeng passes.
</Callout>

<Callout icon="👍" theme="okay">
  ### **Pro Tip**

  Get guidance on this setup using your favorite tool, like <Anchor target="_blank" href="https://chatgpt.com/?prompt=Hi+ChatGPT%21+Can+you+please+read+%5Bthis+page%5D%28https%3A%2F%2Fdevelopers.cleeng.com%2Fdocs%2Fgoogle-play-billing.md%29+and+prepare+to+answer+questions+about+it%3F">Chat GPT</Anchor> or <Anchor target="_blank" href="https://claude.ai/login?from=logout&returnTo=%2Fnew%3Fq%3DHi%2520Claude!%2520Can%2520you%2520please%2520read%2520%255Bthis%2520page%255D(https%253A%252F%252Fdevelopers.cleeng.com%252Fdocs%252Fgoogle-play-billing.md)%2520and%2520prepare%2520to%2520answer%2520questions%2520about%2520it%253F">Claude</Anchor>.
</Callout>

## Overview

The Google Play Billing connector lets you offer in-app subscriptions and one-time products in your Android applications (phones, tablets, Android TV) and have Cleeng manage the full subscriber lifecycle - entitlement, renewals, grace periods, account holds, pauses, and revocations.

Cleeng acts as an observer: Google handles the payment, and Cleeng records the purchase, keeps it in sync with Google's authoritative state, and controls access rights on your behalf.

The integration lives under **Admin & Tools > Integration Hub > Google Play Billing V2** in the Cleeng Dashboard, and exposes a small REST API surface that your app or backend calls when a purchase happens.

It solves three publisher problems:

* end-to-end visibility into the subscription lifecycle (instead of only seeing the initial payment),

* consolidated cross-platform reporting, and

* a reliable mechanism for re-assigning subscription ownership between customers.

## Availability

|                      |                                                      |
| -------------------- | ---------------------------------------------------- |
| **Plan**             | Cleeng Pro / Enterprise                              |
| **Integration type** | In Apps (native Android)                             |
| **Offer types**      | Auto-renewable subscriptions and one-time products   |
| **Platforms**        | Android phones, tablets, Android TV                  |
| **MoR**              | Google is the Merchant of Record for in-app payments |

## Main Benefits

* **Full subscription lifecycle coverage** - 18+ Google notification types processed automatically (vs. 4 in the legacy integration), including grace period, account hold, pause/resume, and revocation.

* **Real-time entitlement sync** - purchases are verified and reflected in Cleeng without polling Google manually; lifecycle changes propagate via Real-Time Developer Notifications.

* **Cross-platform reporting parity** - same level of analytics and tracking as Apple StoreKit 2.

* **Subscription ownership transfer** - re-assign an active subscription from one customer to another via a dedicated endpoint.

## How It Works

1. The user buys a subscription or a one-time product in your Android app via Google Play Billing Library.

2. Your app calls Cleeng's <Anchor target="_blank" href="https://developers.cleeng.com/reference/register-google-play-purchase">`POST /purchases`</Anchor>  endpoint with the Google purchase token.

3. Cleeng verifies the purchase against Google's V2 API, creates the subscription record, and grants entitlement asynchronously. Your app polls a status endpoint, listens to a webhook, or both.

4. From there, Cleeng listens to Google's Real-Time Developer Notifications (RTDN) and keeps the subscription in sync - no further action required from your app for renewals or lifecycle events.

5. If a subscription needs to move to a different customer, your backend calls <Anchor target="_blank" href="https://developers.cleeng.com/reference/transfer-google-play-purchase">`POST /purchases/transfers`</Anchor> .

## Prerequisites

Before you start, make sure you have:

* A Google Play developer account and a published (or test-track) Android app - see <Anchor target="_blank" href="https://developer.android.com/google/play/billing/getting-ready">Google Docs</Anchor>.

* Subscription products and/or one-time products defined in Play Console (**Subscription > Base Plan > Offer** **hierarchy**; **One-time product > Purchase Option > Offer hierarchy**).

* A Google Cloud service account with Google Play Android Developer API access and the following Play Console permissions: **View financial data, orders, and cancellation survey responses** and **Manage orders and subscriptions**.

* A Google Cloud Pub/Sub topic for Real-Time Developer Notifications.

* A Cleeng publisher account on the Pro or Enterprise plan.

<Callout icon="📘" theme="info">
  **Note**

  Google credentials can take up to 24 hours to become valid. If you added in-app products before granting the service account permission, you may need to make a change to those products (for example, create and activate a new product) for receipt validation to start working.
</Callout>

### How to create a Google service account key

Cleeng requires a **service account key** in JSON format to validate Google Play purchases and keep subscription state synchronized between Google Play and Cleeng. The Google Cloud service account must have permission to call the Google Play Android Developer API on behalf of your Play Console account.

Follow the steps below to create the service account and download the JSON key.

1. In the **Google Cloud Console**, select the correct project and confirm that access to the <Anchor target="_blank" href="https://console.cloud.google.com/apis/library/androidpublisher.googleapis.com">Google Play Android Developer API</Anchor>  is enabled (the button reads **Enable** when disabled and **Manage** when already enabled).
2. Open <Anchor target="_blank" href="https://console.cloud.google.com/iam-admin/serviceaccounts">Service Accounts</Anchor> and click **Create service account**. Walk through the wizard:

   **2.1** Copy the generated **Service account ID** (email address) - you will need it in step 2.5.<br />**2.2** Under **Grant this service account access to project**, select **Basic > Owner**.

   <Image src="https://files.readme.io/92f092c96aa66e56c4e1ffff2cc1b488c426b7753d9ec8baaa543215e8887279-cleeng_iap_android_service_account_roles.png" align="center" caption="Google Cloud Console: Grant this service account access to project" border={true} />

   The service account now exists in Google Cloud. Next, grant it access to your Google Play Console.

   **2.3** Open the <Anchor target="_blank" href="https://play.google.com/console/users-and-permissions">Users & Permissions</Anchor> page in the **Google Play Console**.<br />**2.4** Click **Invite new users**.<br />**2.5** Enter the service account email from step 2.1 and grant the following Play Console permissions:<br />a. *View app information and download bulk reports (read-only)*<br />b. *View financial data, orders, and cancellation survey responses*<br />c. *Manage orders and subscriptions*

   <Image src="https://files.readme.io/5e499dc84cdef0d4ff66dd99be1f55428c888f32eab9cb1cd4c46a74f4c36069-cleeng_iap_android_granting_permissions.png" align="center" caption="Google Play Console: Granting permissions" border={true} />

   **2.6** Click **Invite user** to finish. The service account can now access the Google Play Developer API. To use it, generate a JSON key.<br />**2.7** Back in the Google Cloud Console, open <Anchor target="_blank" href="https://console.cloud.google.com/iam-admin/serviceaccounts">Service Accounts</Anchor> again.<br />**2.8** Click the service account email, then:<br />a.  Open the **Keys** tab.<br />b.  Click **Add Key**.

   **2.9** Choose **Create new key** from the drop-down.<br />**2.10** Pick **JSON** as the **Key type** and click **Create**. The JSON key downloads automatically - **store it securely; it cannot be downloaded again**. Paste its contents into the **Service account JSON key** field in the Cleeng Dashboard (see [Configure the connector](https://developers.cleeng.com/docs/google-play-billing#1-configure-the-connector-in-the-cleeng-dashboard)).

   <Image src="https://files.readme.io/8dea51a1dda53259c7cccf5964266a327ffadd50e471061637777e8699de7a15-cleeng_iap_android_create_service_key.png" align="center" caption="Google Cloud Console: Creating a service account key" border={true} />

   For background reading, see <Anchor target="_blank" href="https://developers.google.com/android-publisher/getting_started">Google's getting-started guide</Anchor>.

## Step-by-Step Guide

### 1. Configure the connector in the Cleeng Dashboard

1. Log in to the Cleeng Dashboard.

2. Map your Google Play products to Cleeng offers. Each Google Play subscription has a `productId` and one or more base plans, each identified by a `basePlanId`. In Cleeng, every `productId` / `basePlanId` pair maps to a single Cleeng offer.

   For each base plan you want to sell:

   * Take the subscription's `productId` and the `basePlanId` of the base plan from Google Play Console.
   * Combine them in the form `{productId}/{basePlanId}`.
   * In the Cleeng Dashboard, open the corresponding Cleeng offer, add the resulting identifier under App store product IDs, and set the app store option to Android.

     **Example:** a subscription with `productId = "plan_premium"` and an annual base plan with `basePlanId = "annual"` should be linked to its Cleeng offer with the identifier `plan_premium/annual`.

   <Callout icon="📘" theme="info">
     ### **Backward compatibility**

     If you already use the legacy approach where the identifier under App store product IDs is the bare `productId` (no `basePlanId` suffix), it remains supported. Existing purchases continue to be reported correctly without any change on your side. You only need to switch to the `{productId}/{basePlanId}` form if you want different base plans of the same subscription to map to different Cleeng offers.
   </Callout>

   Upgrades and downgrades are configured separately - see <Anchor target="_blank" href="https://publisher.support.cleeng.com/hc/en-us/articles/360021700099-Subscription-upgrades-and-downgrades">Subscription upgrades and downgrades</Anchor>. All offer mappings must be in place before activating the integration - otherwise incoming purchases cannot be resolved to a Cleeng offer.

3. Go to **Admin & Tools > Integration Hub > Google Play Billing V2**.

4. Fill in the configuration form.

   <Image src="https://files.readme.io/a993533dd5f90dac63be8748ea6e2c6b1c05f131a07be37e984a3716632f0b85-cleeng_dashboard_integration_hub_google_play_billing_v2.png" align="center" caption="Cleeng Dashboard: Google Play Billing Configuration" border={true} />

   All three fields are required:

   * Do you need to migrate data? Pick the option that matches your situation:
     * *Migration is done / No migration needed* - default. Choose this if you are onboarding directly to the new connector with no legacy Android in-app data.

     * *Migrate data from the legacy connector* or *Migrate data to Cleeng* - choose one of these only when Cleeng is coordinating a data migration for your publisher account. While either migrating value is selected, purchase and notification events are buffered and replayed once the migration is marked done.

   * **Package name** - the Android application package name as registered in Google Play Console (for example, `com.example.app`). This value must match the `packageName` your app sends in each `POST /purchase`s and `POST /purchases/transfers` request, and the `packageName` published in every Real-Time Developer Notification.

   * **Service account JSON key** - paste the JSON key generated for your Google Cloud service account (the same key used to grant Cleeng access to the Google Play Android Developer API).

   <Callout icon="🚧" theme="warn">
     ### **Important - migrating from the legacy Google Play connector?**

     If you are currently using the legacy Google Play integration in Cleeng Core, **do not activate the configuration yet**.

     Save the form with “Do you need to migrate data?” set to _Migrate data from the legacy connector_ and leave the integration deactivated until the scheduled migration call with the Cleeng Support Team.

     Activating before migration starts will route live traffic to the new connector before any data has been migrated, leaving the new connector with no record of your existing subscriptions.     See the [Seamless Migration](https://developers.cleeng.com/docs/google-play-billing#seamless-migration) section below for the full step-by-step migration flow.
   </Callout>

5. Click **Connect** to save and activate the integration.

### 2. Set up Real-Time Developer Notifications

Real-Time Developer Notifications (RTDNs) are one-way push messages from Google Play to Cleeng. They keep the subscription state in Cleeng aligned with Google's authoritative state without any polling from your app - renewals, cancellations, grace period transitions, account holds, pauses, revocations, and refunds are all delivered as RTDN events.

The connector listens for RTDNs on the following endpoints. Replace {publisherId} with your Cleeng publisher ID:

| Environment | Notification URL                                                                            |
| :---------- | :------------------------------------------------------------------------------------------ |
| Production  | <https://inapp.api.prod.cleeng.com/google-play/notifications/broadcasters/{publisherId}>    |
| Sandbox     | <https://inapp.api.sandbox.cleeng.com/google-play/notifications/broadcasters/{publisherId}> |

<Callout icon="📘" theme="info">
  ### **Migrating from the legacy connector?**

  If you currently send RTDNs to the legacy v2.0 URL ([https://notification.cleeng.com/2.0/in_app/subscriptions/android/status_update_notification/heme="warn">
  ](https://notification.cleeng.com/2.0/in_app/subscriptions/android/status_update_notification/\{publisherId\})), switch to the **seamless** URL - see the Seamless Migration section - so the same endpoint keeps working before and after the cut-over. The deprecated v1.0 URL is not covered by seamless routing.
</Callout>

#### Supported notification types

The new connector processes the full subscription notification surface. The table below lists each `notificationType` value (per Google's <Anchor target="_blank" href="https://developer.android.com/google/play/billing/rtdn-reference">RTDN reference</Anchor>) and how Cleeng handles it:

|      Type     | Notification                              | Cleeng behavior                                                                                     |
| :-----------: | ----------------------------------------- | --------------------------------------------------------------------------------------------------- |
|       1       | SUBSCRIPTION\_RECOVERED                   | Subscription recovered from account hold - entitlement restored.                                    |
|       2       | SUBSCRIPTION\_RENEWED                     | Renewal recorded; next billing cycle and payment captured.                                          |
|       3       | SUBSCRIPTION\_CANCELED                    | Cancellation flagged; subscription remains active until `expiryTime`.                               |
|       4       | SUBSCRIPTION\_PURCHASED                   | Used for upgrades and downgrades. For initial purchase, your app must still call `POST /purchases`. |
|       5       | SUBSCRIPTION\_ON\_HOLD                    | Subscription moved to account hold - entitlement revoked until recovery.                            |
|       6       | SUBSCRIPTION\_IN\_GRACE\_PERIOD           | Grace period started - entitlement preserved while Google retries billing.                          |
|       7       | SUBSCRIPTION\_RESTARTED                   | Restart after user-initiated cancellation; subscription continues.                                  |
|       9       | SUBSCRIPTION\_DEFERRED                    | Deferred billing change applied - next billing date updated.                                        |
|       10      | SUBSCRIPTION\_PAUSED                      | Pause took effect - entitlement suspended.                                                          |
|       11      | SUBSCRIPTION\_PAUSE\_SCHEDULE\_CHANGED    | Scheduled pause start/end updated.                                                                  |
|       12      | SUBSCRIPTION\_REVOKED                     | Subscription revoked (refund or developer-initiated) - entitlement removed.                         |
|       13      | SUBSCRIPTION\_EXPIRED                     | Subscription expired - entitlement removed.                                                         |
|       19      | SUBSCRIPTION\_PRICE\_CHANGE\_UPDATED      | New price acknowledged at renewal.                                                                  |
|       20      | SUBSCRIPTION\_PENDING\_PURCHASE\_CANCELED | Pending purchase (deferred payment) was cancelled before approval.                                  |
|       —       | VOIDED\_PURCHASE                          | Refund/chargeback - entitlement updated to reflect the void.                                        |
| 8, 17, 18, 22 | (Deprecated / no-op types)                | Acknowledged to Google but require no state change in Cleeng.                                       |

One-time-product notifications are handled on the same endpoint:

| Type | Notification                        | Cleeng behavior                                                                      |
| ---- | ----------------------------------- | ------------------------------------------------------------------------------------ |
| 1    | ONE\_TIME\_PRODUCT\_PURCHASED       | Pass granted for the purchased product, with the expiry taken from the Cleeng offer. |
| 2    | ONE\_TIME\_PRODUCT\_CANCELED        | Pending purchase cancelled before payment completed - nothing is granted.            |
| -    | VOIDED\_PURCHASE (one-time product) | Refund or chargeback - the Cleeng payment is refunded and the pass terminated.       |

If Cleeng receives a one-time product notification before your app registers the purchase, the entitlement is held against an Unidentified User and reassigned to the real customer once your registration call arrives, finalizing it as `PURCHASE_RESTORED`. See [Handling "Unidentified Users"](https://developers.cleeng.com/docs/google-play-billing#handling-unidentified-users).

<Callout icon="📘" theme="info">
  ### Note

  Google does not send Real-Time Developer Notifications (RTDN) for "Refund only" events (where the customer is refunded but retains subscription access). Consequently, Cleeng system cannot detect or reflect these adjustments in real time  .

  You must refund and revoke access in order for Cleeng to detect this, as only refunding will not be detected. See <Anchor target="_blank" href="https://support.google.com/googleplay/android-developer/answer/2741495?hl=en#zippy=%2Crefund-subscriptions-including-refund-and-revoke">Google's documentation</Anchor>.
</Callout>

#### Set up Pub/Sub in Google Cloud and Google Play Console

Follow the steps below to configure a Cloud Pub/Sub topic and push subscription that delivers RTDNs to Cleeng.

1. Log in to your<Anchor target="_blank" href="https://console.cloud.google.com"> Google Cloud Console</Anchor>.

2. Open the <Anchor target="_blank" href="https://console.cloud.google.com/cloudpubsub/topic/list">Pub/Sub topic list</Anchor> and select the Google Cloud project linked to your Android app.

3. Create a topic. The topic ID is up to you (for example, realtime\_notification).

   <Image src="https://files.readme.io/51797da6144785babd888fc3b769ae767b5dc6acf2bda79d16dcb87d399b01fb-create_a_topic.png" align="center" caption="Create a topic" border={true} />

4. On the topic, create a subscription. The subscription ID is also free to choose.

   <Image src="https://files.readme.io/aab14429cf7db14894479830fce804eb5764e3ad855d7b1520858e6afbe8c7b1-create_a_subscription.png" align="center" caption="Create a subscription" border={true} />

   Configure the subscription with:

   * **Cloud Pub/Sub topic:** the topic you created in step 3.
   * **Delivery type:** switch from **Pull** to **Push** and enter the Cleeng notification URL for your environment:
     * Production: <https://inapp.api.prod.cleeng.com/google-play/notifications/broadcasters/{publisherId}>
     * Sandbox: <https://inapp.api.sandbox.cleeng.com/google-play/notifications/broadcasters/{publisherId}>

   <Image src="https://files.readme.io/90c6a6354dbf8f864954a82e1c6cc95b2cc975a8454833be5471bdf9f252010b-Delivery_type.png" align="center" caption="Delivery Type - Production Environment" border={true} />

   * **Enable authentication:** turn on **JWT** authentication. Choose your service account and set the **Audience** to the connector base URL:
     * Production: <https://notification.cleeng.com>

     * Sandbox: <https://notification.sandbox.cleeng.com> See Google's push authentication docs for details.

   * **Retry policy:** select **Retry after exponential backoff delay** with Google's recommended values.

     <Image src="https://files.readme.io/09d53b7f990ac2d1144ac05b8487b0a9cbe63bd72e1cf65db8f2bd628af797a2-Retry_policy.png" align="center" caption="Retry policy" border={true} />

5. Return to the **Topic list** and open the **View permissions** panel for your topic.

   <Image src="https://files.readme.io/a3ebcc9d37d571d4a5f562cd75937c8c8bdb917838639af854b6111354f13a02-view_permissions.png" align="center" caption="View permissions" border={true} />

6. Click **Add principal** and grant the **Pub/Sub Publisher** role to <google-play-developer-notifications@system.gserviceaccount.com>. This lets Google Play publish RTDNs to your topic.

   <Image src="https://files.readme.io/a5c10fa7862e81ed47bc15c20dfdc3e28373ea5c53a3f38af29a4c0f193545fc-add_member.png" align="center" caption="Add memeber" border={true} />

7. Open the <Anchor target="_blank" href="https://play.google.com/console/">Google Play Console</Anchor> and select your application.

8. Go to **Monetization setup** and paste the full topic name into the **Real-time developer notifications** field (you can copy it from the topic list in Google Cloud Console).

9. Click **Send test notification**. If Google reports success, save the settings - your RTDN pipeline is live.

### 3. Register purchases from your app

After a successful purchase in your app, call: [`POST /purchases`](https://developers.cleeng.com/reference/register-google-play-purchase) .

| Environment | Base URL                                           |
| ----------- | -------------------------------------------------- |
| Production  | `https://inapp.api.prod.cleeng.com/google-play`    |
| Sandbox     | `https://inapp.api.sandbox.cleeng.com/google-play` |

**Authentication:** send either `Authorization: Bearer {jwt}` (client integration) or `X-Publisher-Token` (server-to-server). Always include the `X-Publisher-Id` header.

**Request body:**

```json
{
  "cleengCustomerId": 123456789,
  "purchaseToken": "oepjlkkldmo...",
  "packageName": "com.example.app",
  "productType": "subscription"
}
```

`productType` must be `subscription` or `one_time_product` Any other value is rejected with HTTP 400.

**Response -&#x20;**`202 Accepted`**:**

```json
{
  "message": "Purchase accepted for processing",
  "synchronizationId": "e45211af-6360-4ff9-9a97-3f2392fe355e"
}
```

The endpoint is asynchronous. Use the returned `synchronizationId` to check status.

### 4. Receive the result

Once the purchase is registered, get the outcome in one of two ways (or both):

* **Polling** - [`GET /purchases/synchronizations/{synchronizationId}`](https://developers.cleeng.com/reference/check-google-play-purchase-synchronization-status) . The response contains `status` (`processing`, `retrying`, or `finalized`), and once finalized, an `accessGranted` flag, `offerId`, and a `result` code. Typical synchronization finalizes within 5–10 seconds. See more details on [polling statuses](https://developers.cleeng.com/docs/google-play-billing#polling-statuses) below.
* **Webhook** - subscribe to the <Anchor target="_blank" href="https://developers.cleeng.com/docs/webhooks-in-app-purchase-topics#inapppurchasesyncresult">`inappPurchaseSyncResult`</Anchor>  topic in your webhook configuration. The payload arrives once per synchronization, when the record is finalized, and includes the same fields as the polling response plus the original purchase context. In addition, the usual Cleeng subscription lifecycle topics are emitted for subscriptions.

The sequence diagram below shows both flows running in parallel after a single <Anchor target="_blank" href="https://developers.cleeng.com/reference/register-google-play-purchase">`POST /purchases`</Anchor>  call:

<Image src="https://files.readme.io/738742f859489f1efe0704c8a7b6b20bffa6ed87326658120a8fe5b75cbfb117-cleeng_google_play_subscriber_status_validation.png" align="center" />

Polling gives immediate UI feedback while the user waits; the webhook guarantees finalization even if the app is backgrounded or polling times out. Combine both for the most reliable client experience.

<Callout icon="👍" theme="okay">
  ### Tip: Checking entitlement directly

  You can also call the standard Cleeng <Anchor target="_blank" href="https://developers.cleeng.com/reference/get-entitlement">GET /entitlements</Anchor> endpoint. It returns the customer's entitlement state for an offer independently of the synchronization flow - useful as a fallback or as the source of truth for gating UI. Entitlements are updated only **after** the asynchronous synchronization process has completed.
</Callout>

While temporarily caching the entitlement is not mandatory, it is strongly recommended to enhance the user experience and ensure immediate access to content. Since purchase registration depends on an external API, there may be some delay before the process is completed and the access is granted permanently.

#### Polling statuses

Here are the possible scenarios and the corresponding response fields:

| status     | accessGranted | offerId | result                           | Description                                                                        |
| ---------- | ------------- | ------- | -------------------------------- | ---------------------------------------------------------------------------------- |
| processing |               | no      |                                  | The synchronization is still in progress.                                          |
| retrying   |               | no      |                                  | The synchronization encountered an error and is being retried.                     |
| finalized  | true          | yes     | PURCHASE\_SYNCHRONIZED           | Purchase was successfully synchronized, and access was granted.                    |
| finalized  | true          | yes     | PURCHASE\_OWNERSHIP\_TRANSFERRED | Purchase was successfully transferred to a new customer.                           |
| finalized  | true          | yes     | PURCHASE\_OWNERSHIP\_UNCHANGED   | Transfer targeted the customer who already owned the purchase - no change.         |
| finalized  | true          | yes     | PURCHASE\_RESTORED               | Purchase was reassigned from an unidentified customer to the requesting customer.  |
| finalized  | false         | no      | RECEIVED\_EXPIRED\_PURCHASE      | Google reported the purchase token as expired during synchronization.              |
| finalized  | false         | no      | PURCHASE\_TOKEN\_NOT\_FOUND      | The purchase token was not found in Google Play.                                   |
| finalized  | false         | yes     | ACCESS\_EXPIRED                  | The user's access was terminated as part of the synchronization.                   |
| finalized  | false         | no      | OWNED\_BY\_ANOTHER\_USER         | The purchase is already owned by another identified customer; transfer required.   |
| finalized  | false         | no      | SYNCHRONIZATION\_UNPROCESSABLE   | An unexpected condition prevented synchronization. Likely needs support.           |
| finalized  | false         | no      | PRODUCT\_TYPE\_NOT\_SUPPORTED    | The product type is not supported by the connector.                                |
| finalized  | false         | no      | MISSING\_OFFER\_MAPPING          | No Cleeng offer is configured for the purchased product, or it has no entitlement. |

### 5. Transfer a subscription between users (when needed)

If a registered purchase is already owned by a different Cleeng customer, the synchronization returns `result: OWNED_BY_ANOTHER_USER`. To re-assign ownership, call: [`POST /purchases/transfers`](https://developers.cleeng.com/reference/transfer-google-play-purchase)

```json
{
  "targetCustomerId": 999,
  "purchaseToken": "oepjlkkldmo...",
  "packageName": "com.example.app",
  "productType": "subscription"
}
```

The endpoint is asynchronous and returns a `synchronizationId` to poll. Possible results:

* `PURCHASE_OWNERSHIP_TRANSFERRED` - ownership moved to the target customer; the new owner is entitled.
* `PURCHASE_OWNERSHIP_UNCHANGED` - the target customer already owned the subscription; treat as success.

<Callout icon="📘" theme="info">
  ### **Note**

  Transfer is an ownership-only operation. It does **not** call Google Play and does **not** trigger a fresh synchronization - Google's view of the purchase is unchanged.
</Callout>

### 6. Keep subscribers synchronized (automatic)

Once a purchase is registered, Cleeng processes all subscription lifecycle events from Google's Real-Time Developer Notifications (RTDNs) automatically. Your app does not need to call any further endpoints to keep entitlements up to date.

The connector handles renewals, cancellations, grace periods, account holds, pause/resume, revocations, expirations, deferred billing, price-change notifications, and voided purchases (refunds). One-time product RTDNs are acknowledged to Google but otherwise ignored.

## Purchase Acknowledgement

When using the V2 Google Play connector, the Client application does not need to acknowledge the purchase manually. The connector acknowledges the initial purchase automatically.

Acknowledgement is required because Google Play refunds and revokes any purchase that is not acknowledged within three days (see <Anchor target="_blank" href="https://developer.android.com/google/play/billing/integrate#process">Google Documentation</Anchor>). The V2 connector handles this for you.

## Testing

Use the **sandbox environment** for end-to-end validation:

| Environment | Base URL                                           |
| ----------- | -------------------------------------------------- |
| Sandbox     | `https://inapp.api.sandbox.cleeng.com/google-play` |

**To test the integration:**

1. Configure a <Anchor target="_blank" href="https://developer.android.com/google/play/billing/test">Google Play test environment</Anchor>.
2. Create a <Anchor target="_blank" href="https://srm-sandbox.cleeng.com/register">Cleeng sandbox account</Anchor> (or log in if you have one) and create a matching test offer.
3. Make sure the Google product and Cleeng offer are mapped in the sandbox Dashboard.
4. Upload the sandbox service account JSON key in the Cleeng Dashboard.
5. Set up the Pub/Sub push subscription pointing to the sandbox notification URL.
6. Send a test notification from Play Console to verify connectivity.
7. Make a test purchase in your app and verify entitlement is granted.

**Scenarios to cover:**

* Initial subscription purchase.
* Recurring renewal.
* Failed payment → grace period → account hold → recovery.
* User-initiated cancellation and subsequent expiration.
* Pause and resume.
* Upgrade and downgrade between plans.
* Purchase restoration (reinstall or device switch).
* Subscription ownership transfer (including the `PURCHASE_OWNERSHIP_UNCHANGED` no-op case).

## Additional Features

* **Idempotent retries** - requests are deduplicated by `purchaseToken`. If a synchronization is already in progress for the same token, the API returns `409 Conflict` with the existing `synchronizationId` so your client can resume polling without creating a duplicate record. Safe to retry on network errors or app crashes.
* **Crash recovery** - on every app launch, call `BillingClient.queryPurchasesAsync()` and re-submit any unprocessed purchases to [`POST /purchases`](https://developers.cleeng.com/reference/register-google-play-purchase) . Idempotency ensures no double-processing.

## Common Errors & Troubleshooting

| Result / Error                                        | Cause                                                                                      | What to do                                                                                                                                                                                                                                                                         |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `PURCHASE_TOKEN_NOT_FOUND`                            | Token is not recognised by Google Play.                                                    | Verify the token comes from a valid `Purchase` object; refresh via `queryPurchasesAsync()`.                                                                                                                                                                                        |
| `RECEIVED_EXPIRED_PURCHASE`                           | Token belongs to an expired or refunded purchase.                                          | Do not retry. Prompt the user to make a new purchase.                                                                                                                                                                                                                              |
| `OWNED_BY_ANOTHER_USER`                               | The purchase is linked to a different Cleeng customer.                                     | Prompt the user to confirm transfer, then call [`POST /purchases/transfers`](https://developers.cleeng.com/reference/transfer-google-play-purchase) .                                                                                                                              |
| `PRODUCT_TYPE_NOT_SUPPORTED`                          | Provided product type in the request is not supported.                                     | Check offer mapping in the Cleeng Dashboard.                                                                                                                                                                                                                                       |
| `MISSING_OFFER_MAPPING`                               | No Cleeng offer mapped, or the mapped offer has no entitlement configured.                 | Make sure that all products from Google Play Console are mapped to appropriate Cleeng offers (see point 2 in the [Configure the connector in Cleeng Dashboard](https://developers.cleeng.com/docs/google-play-billing#1-configure-the-connector-in-the-cleeng-dashboard) section). |
| `PACKAGE_NAME_MISMATCH` (HTTP 422)                    | The `packageName` in the request is not configured for your publisher.                     | Verify the `packageName` matches a profile in the Cleeng Dashboard.                                                                                                                                                                                                                |
| `RESOURCE_TEMPORARY_LOCKED_FOR_PROCESSING` (HTTP 409) | A synchronization is already in progress for the same `purchaseToken`.                     | Not an error - extract `synchronizationId` from the response and resume polling.                                                                                                                                                                                                   |
| HTTP 400                                              | Request body is invalid or `productType` is neither `subscription` nor `one_time_product`. | Check required fields (`cleengCustomerId`, `purchaseToken`, `packageName`, `productType`).                                                                                                                                                                                         |

## Good to Know

### Handling "Unidentified Users"

If Cleeng receives a Real-Time Developer Notification (RTDN) for a successful transaction from Google Play, but your Android application fails to send the matching <Anchor target="_blank" href="https://developers.cleeng.com/reference/register-google-play-purchase">Purchase Registration</Anchor> API call, Cleeng creates a temporary placeholder account known as an Unidentified User.

While the payment is safely recorded in our system, content access is not granted to the user until this registration call is successfully received to sync the user's details. To ensure a seamless viewing experience on Android devices, it is critical that your application consistently triggers the <Anchor target="_blank" href="https://developers.cleeng.com/reference/register-google-play-purchase">Purchase Registration</Anchor> API to complete the purchase flow.

For more details on how these placeholder accounts work, how to identify them, and how to reconcile them, please read our comprehensive guide on <Anchor target="_blank" href="https://publisher.support.cleeng.com/hc/en-us/articles/27688710570652-Understanding-Unidentified-Users-in-In-App-Purchases">Understanding Unidentified Users in In-App Purchases</Anchor>.

## FAQs

**Q: Are one-time products supported?**<br />**A:** Yes. Send `productType=one_time_product` to `/purchases`. The entitlement is granted as a Cleeng pass. The pass expiry is taken from the Cleeng offer's entitlement configuration (a fixed date, or a duration counted from the purchase), never from Google. A product with no matching Cleeng offer, or a matched offer with no entitlement configured, finalizes as `MISSING_OFFER_MAPPING` and grants no access.

**Q: What happens when a one-time product is refunded or consumed?**
**A:** A refund or cancellation in Google terminates the pass and refunds the recorded Cleeng payment. A quantity-based partial refund keeps the pass active while refundable units remain. A product Google reports as consumed also terminates the pass. All three are detected from Google's own state, so no extra call from your app is needed.

**Q: Do I need to update my app immediately when my publisher account is migrated to the new connector?**<br />**A:** No. The legacy `POST /android/payment` endpoint and the legacy RTDN URL continue to work via a seamless routing layer. You can migrate to the new endpoints at your own pace.

**Q: Can I use polling and the webhook together?**<br />**A:** Yes - we recommend it. Polling gives immediate UI feedback while the user waits; the webhook guarantees finalization even if the app is backgrounded or polling times out.

**Q: What happens if my app crashes after Google confirms the purchase?**<br />**A:** Call `queryPurchasesAsync()` on every app launch. Re-submit any unprocessed purchases to `POST /purchases` - idempotency by `purchaseToken` ensures no double-processing.

**Q: Are voided purchases (refunds) reconciled automatically?**<br />**A:** Yes. Cleeng listens to Google's voided-purchase notifications and updates entitlement automatically.

**Q: What types of refunds can Cleeng detect?**<br />**A:**  Cleeng can only detect refunds with entitlements revocations. Refunds without entitlement revocation (where the customer gets their money back, but keeps subscription access) will not be detected. See <Anchor target="_blank" href="https://support.google.com/googleplay/android-developer/answer/2741495?hl=en#zippy=%2Crefund-subscriptions-including-refund-and-revoke">Google's documentation</Anchor> for more information.

## Seamless Migration

<Callout icon="🚧" theme="warn">
  ### **Note**

  This section applies only to publishers who are currently using the legacy Google Play integration in Cleeng Core (`POST /android/payment` and the v2.0 Pub/Sub notification URL).

  Publishers onboarding directly to the new connector should skip this section.
</Callout>

For publishers already on the legacy Google Play connector, Cleeng ensures a smooth transition to the new connector with **no Android app changes required**.

A gateway-level routing layer fronts the legacy `POST /android/payment` endpoint and the legacy v2.0 Pub/Sub notification URL, and forwards traffic to either the legacy connector or the new connector based on the per-publisher configuration in the Cleeng Dashboard.

During the migration window itself, incoming purchases, transfers, and Real-Time Developer Notifications are buffered in Cleeng and replayed once data migration finishes - no message loss.

### How It Works

* **Routing decision** - for each request, the seamless routers look up the **Google Play Billing V2** configuration for your publisher. If the configuration is **inactive** (or absent), traffic continues to be handled by the legacy connector. If it is **active**, traffic is routed to the new connector.
* **Deferral during migration** - when **Do you need to migrate data?** is set to either *Migrate data from the legacy connector* or *Migrate data to Cleeng*, Cleeng accepts each incoming event, and returns success to the caller but holds it rather than applying it. No subscription is created or modified yet.
* **Automatic resume** - when you switch **Do you need to migrate data?** to *Migration is done / No migration needed* and save, Cleeng automatically replays every held event. No manual replay required.

### Step-by-Step Guide

The migration requires coordinated actions from the publisher and Cleeng. The table below lists the order of steps and who owns each one.

<Table align={["left","left","left"]}>
  <thead>
    <tr>
      <th>
        #
      </th>

      <th>
        Action
      </th>

      <th>
        Owner
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        1
      </td>

      <td>
        **Initial setup**<br />Complete the [Prerequisites](#prerequisites)  and fill the **Google Play Billing V2** configuration profile in the Cleeng Dashboard (**Admin & Tools > Integration Hub > Google Play Billing V2**).<br />Fill in the **Service account JSON key** and **Package name** fields, and set **Do you need to migrate data?** to _Migrate data from the legacy connector_. **Save the configuration but do NOT activate it yet** - activation happens during the scheduled migration call.
      </td>

      <td>
        Publisher
      </td>
    </tr>

    <tr>
      <td>
        2
      </td>

      <td>
        **Pub/Sub endpoint update**<br />Update your Google Cloud Pub/Sub push subscription to the seamless RTDN URL:<br />• Production: `https://inapp.api.prod.cleeng.com/google-play/seamless/notifications/broadcasters/{publisherId}`<br />• Sandbox: `https://inapp.api.sandbox.cleeng.com/google-play/seamless/notifications/broadcasters/{publisherId}`

        The update is safe at any time and reversible - while your `google-play-billing-v2` configuration is still inactive, the seamless router forwards every push to the legacy Core RTDN handler, so behavior is unchanged. Once you activate the configuration in step 4, the same URL automatically starts routing to the new connector - no further URL change is ever required. The legacy v2.0 URL also continues to be accepted, but the seamless URL is the preferred publisher-facing label. **The deprecated v1.0 endpoint is not seamless-routed; publishers staying on v1.0 will not receive RTDN coverage in the new connector after migration.**
      </td>

      <td>
        Publisher
      </td>
    </tr>

    <tr>
      <td>
        3
      </td>

      <td>
        **Migration planning**<br />Contact the <Anchor target="_blank" href="https://publisher.support.cleeng.com/hc/en-us/requests/new">Cleeng Technical Support Team</Anchor> and agree on a migration date, choosing a time that minimises customer impact. Cleeng confirms and schedules the data migration accordingly.
      </td>

      <td>
        Both
      </td>
    </tr>

    <tr>
      <td>
        4
      </td>

      <td>
        **Activation & data migration**<br />On the agreed call, you activate the `google-play-billing-v2` configuration in the Cleeng Dashboard.

        From this moment, the seamless routers begin forwarding your traffic to the new connector, and every incoming purchase, transfer, and RTDN is buffered (no live processing yet). Cleeng runs the data migration job to import your existing subscription state from the legacy connector into the new connector.
      </td>

      <td>
        Both
      </td>
    </tr>

    <tr>
      <td>
        5
      </td>

      <td>
        **Resume processing**<br />Once Cleeng confirms the data migration is complete, switch **Do you need to migrate data?** from _Migrate data from the legacy connector_ to _Migration is done / No migration needed_ in the Cleeng Dashboard and save. Cleeng automatically replays every held event, oldest first.
      </td>

      <td>
        Publisher
      </td>
    </tr>

    <tr>
      <td>
        6
      </td>

      <td>
        **Sanity checks**<br />Both parties verify the migration: make a test purchase in the production app, confirm it appears in the Cleeng Dashboard for the correct customer, and verify the new Google Play Billing payment method is logged for the transaction. Confirm that webhook deliveries and RTDN-driven lifecycle updates continue as expected.
      </td>

      <td>
        Both
      </td>
    </tr>
  </tbody>
</Table>

:heavy\_check\_mark: **Migration complete.** Your seamless transition to the new Google Play Billing connector is now finished. The legacy `POST /android/payment` endpoint and the legacy v2.0 Pub/Sub notification URL continue to work via the seamless routing layer - you can migrate your app to the new endpoints at your own pace.

### Notes & Limitations

* The seamless purchase router supports re-routing of legacy `POST /android/payment` traffic only. It does not perform implicit cross-customer transfers - if a registered purchase needs to be re-assigned to a different Cleeng customer after migration, use the new <Anchor target="_blank" href="https://developers.cleeng.com/reference/transfer-google-play-purchase">`POST /purchases/transfers`</Anchor> endpoint directly.
* During the migration window (between activation in step 4 and *Migration is done* in step 5), entitlement changes derived from new Google notifications are not visible until step 6 completes and the held events are replayed. Plan the migration window accordingly.
* Held events are retained for 30 days. If a migration is left in the *Migrate data…* state for longer than 30 days, older events may pass that window and would not be replayed.

## Developer Checklist

* [ ] Google Play developer account configured; subscription and one-time products created.
* [ ] Google Cloud service account created with Android Developer API access.
* [ ] Service account JSON key uploaded in the Cleeng Dashboard.
* [ ] Google Play products mapped to Cleeng offers.
* [ ] Pub/Sub topic and push subscription configured with the Cleeng notification URL.
* [ ] Google Play Billing Library integrated in the Android app.
* [ ] App calls [`POST /purchases`](https://developers.cleeng.com/reference/register-google-play-purchase)  after a successful billing flow.
* [ ] Status check implemented via polling ([`GET /purchases/synchronizations/{id}`](https://developers.cleeng.com/reference/check-google-play-purchase-synchronization-status)) and/or [`inappPurchaseSyncResult`](https://developers.cleeng.com/docs/webhooks-in-app-purchase-topics#inapppurchasesyncresult) webhook.
* [ ] `OWNED_BY_ANOTHER_USER` handled with [`POST /purchases/transfers`](https://developers.cleeng.com/reference/transfer-google-play-purchase).
* [ ] Crash recovery implemented (`queryPurchasesAsync` on app launch).
* [ ] End-to-end tested in sandbox.
* [ ] Go live.

## Related Content

* <Anchor target="_blank" href="https://developers.cleeng.com/docs/webhooks-in-app-purchase-topics">Webhooks Guide</Anchor> - webhook topic catalogue and integration notes.
* <Anchor target="_blank" href="https://developer.android.com/google/play/billing">Google Play Billing Documentation</Anchor> - Google's official Billing Library docs.
* <Anchor target="_blank" href="https://developer.android.com/google/play/billing/rtdn-reference">Real-Time Developer Notifications Reference</Anchor> - Google's RTDN payload reference.