PHPackages                             bestys-mobile/google-play-billing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. bestys-mobile/google-play-billing

ActiveLibrary[Payment Processing](/categories/payments)

bestys-mobile/google-play-billing
=================================

Google Play Billing

v0.1.0(5y ago)02621PHPPHP &gt;=7.1

Since Jan 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/bestys-mobile/google-play-billing)[ Packagist](https://packagist.org/packages/bestys-mobile/google-play-billing)[ RSS](/packages/bestys-mobile-google-play-billing/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (8)Versions (2)Used By (1)

PHP Google Play Billing
=======================

[](#php-google-play-billing)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8869d410701aa22da38e6561456645c9efe1984e1eb40c21c8ac1258cb9529e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d6468656d792f676f6f676c652d706c61792d62696c6c696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/imdhemy/google-play-billing)[![Total Downloads](https://camo.githubusercontent.com/bb81f3dec2c8992af29419d19db9b98565e978c3f1bca0cfbda0028d297abe17/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696d6468656d792f676f6f676c652d706c61792d62696c6c696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/imdhemy/google-play-billing)

**PHP Google Play Billing** provides the required implementation to add Google Play's billing system to your php project.

Google Play's billing system overview
-------------------------------------

[](#google-plays-billing-system-overview)

Google Play's billing system is a service that enables you to sell digital products and content in your Android app.

You can use Google Play's billing system to sell the following types of digital content:

- **One-time products**: A one-time product is content that users can purchase with a single, non-recurring charge to the user's form of payment. One-time products can be either consumable or non-consumable:

    - *A consumable product* is one that a user consumes to receive in-app content, such as in-game currency. When a user consumes the product, your app dispenses the associated content, and the user can then purchase the item again.
    - *A non-consumable product* is a product that is purchased only once to provide a permanent benefit. Examples include premium upgrades and level packs.
- **Subscriptions**: A subscription is a product that provides access to content on a recurring basis . Subscriptions renew automatically until they're canceled. Examples of subscriptions include access to online magazines and music streaming services.

Installation
------------

[](#installation)

Install the package via composer:

```
composer require imdhemy/google-play-billing

```

Configuration
-------------

[](#configuration)

Requests to the Google Play Developer API, requires authentication and scopes. To authenticate your machine create a service account, then set the environment variable `GOOGLE_APPLICATION_CREDENTIALS`

1. In the Cloud Console, go to the [Create service account](https://console.cloud.google.com/apis/credentials/serviceaccountkey?_ga=2.92610013.131807880.1603050486-1132570079.1602633482) key page.
2. From the **Service account** list, select **New service account**.
3. In the **Service account name** field, enter a name.
4. From the **Role** list, select **Project** &gt; **Owner**.
5. Click **Create**. A JSON file that contains your key downloads to your computer.
6. You can set the environment variable by:

```
$path = 'path/to/google-app-credentials.json';
putenv(sprintf("GOOGLE_APPLICATION_CREDENTIALS=%s", $path));
```

Sell products
-------------

[](#sell-products)

With any type of your products, you can use the REST api to:

1. **acknowledge**: Acknowledges a purchase of an inapp item.
2. **get**: Checks the purchase and consumption status of an inapp item.

### Acknowledge a product

[](#acknowledge-a-product)

To acknowledge a product, you need a Client, which can be created by `ClientFactory` using the android publisher scope , then create an instance of the `Bestys\Products\Product` class, finally trigger the `acknowledge()` method.

```
use Bestys\GooglePlay\ClientFactory;
use Bestys\GooglePlay\Products\Product;

$client = ClientFactory::create([ClientFactory::SCOPE_ANDROID_PUBLISHER]);
$product = new Product($client, 'com.example.package.name', 'productId', 'Purchase_Token');
$product->acknowledge();
```

### Get the consumption state of a product

[](#get-the-consumption-state-of-a-product)

To check the purchase and consumption status of an inapp item, use the same steps used to acknowledge a product , but trigger the `get()` method not the acknowledge one.

```
use Bestys\GooglePlay\ClientFactory;
use Bestys\GooglePlay\Products\Product;

$client = ClientFactory::create([ClientFactory::SCOPE_ANDROID_PUBLISHER]);
$product = new Product($client, 'com.example.package.name', 'productId', 'Purchase_Token');
$resource = $product->get();
```

The get() method returns a `Bestys\GooglePlay\Products\ProductPurchase` object, which contains the following methods:

MethodDescriptiongetKind...getPurchaseTime...getPurchaseState...getConsumptionState...getDeveloperPayload...getOrderId...getAcknowledgementState...getPurchaseToken...getProductId...getQuantity...getObfuscatedExternalAccountId...getObfuscatedExternalProfileId...getRegionCode...Sell subscriptions
------------------

[](#sell-subscriptions)

This section describes how to handle subscription lifecycle events, such as renewals and expiration.

### Life of a purchase

[](#life-of-a-purchase)

Here's a typical purchase flow for a one-time purchase or a subscription.

- Show the user what they can buy.
- Launch the purchase flow for the user to accept the purchase.
- Verify the purchase on your server.
- Give content to the user, and acknowledge delivery of the content. Optionally, mark the item as consumed so that the user can buy the item again.

Subscriptions automatically renew until they are canceled. A subscription can go through the following states:

- **Active**: User is in good standing and has access to the subscription.
- **Cancelled**: User has cancelled but still has access until expiration.
- **In grace period**: User experienced a payment issue, but still has access while Google is retrying the payment method.
- **On hold**: User experienced a payment issue, and no longer has access while Google is retrying the payment method.
- **Paused**: User paused their access, and does not have access until they resume.
- **Expired**: User has cancelled and lost access to the subscription. The user is considered churned at expiration.

### Handling the subscription lifecycle

[](#handling-the-subscription-lifecycle)

A subscription can go through various state changes throughout its [lifecycle](#life-of-a-purchase) and your app needs to respond to each change . To check the subscriber's state, your app can query using the Purchases.subscriptions:get (provided by this package) in the Google Play Developer API.

StateIs returnedexpiryTimeMillispaymentStateautoRenewingActiveYesFuture1 (Payment Received)TrueCancelledYesFuture1 (Payment Received)FalseIn grace periodYesFuture0 (Payment Pending)TrueOn holdYesPast0 (Payment Pending)TruePausedYesPast1 (Payment Received)TrueExpiredYesPast1 (Payment Received)FalseThe following methods are available to be used on a subscription:

1. acknowledge: Acknowledges a subscription purchase.
2. get: Checks whether a user's subscription purchase is valid and returns its expiry time.
3. cancel: Cancels a user's subscription purchase.
4. defer: Defers a user's subscription purchase until a specified future expiration time.
5. refund: Refunds a user's subscription purchase, but the subscription remains valid until its expiration time and it will continue to recur.
6. revoke: Refunds and immediately revokes a user's subscription purchase.

**N.B.** The stroked method are not implemented yet. help us with your contributions 😅.

```
use Bestys\GooglePlay\ClientFactory;
use Bestys\GooglePlay\Subscriptions\Subscription;

$client = ClientFactory::create([ClientFactory::SCOPE_ANDROID_PUBLISHER]);
$subscription = new Subscription($client, 'com.example.package.name', 'subscriptionId', 'Purchase_Token');
$subscription->acknowledge();
$resource = $subscription->get(); // Bestys\GooglePlay\Subscriptions\SubscriptionPurchase
```

The Following methods are available in `Bestys\GooglePlay\Subscriptions\SubscriptionPurchase` Object

MethodDescriptiongetKind...isAutoRenewing...getPriceCurrencyCode...getPriceAmountMicros...getCountryCode...getDeveloperPayload...getOrderId...getLinkedPurchaseToken...getEmailAddress...getGivenName...getProfileId...getExternalAccountId...getObfuscatedExternalAccountId...getObfuscatedExternalProfileId...getStartTime...getExpiryTime...getAutoResumeTime...getIntroductoryPriceInfo...getPriceChange...getCancellation...getPromotionType...getAcknowledgementState...Your app should listen for state changes using [Real-time developer notifications](https://developer.android.com/google/play/billing/getting-ready#configure-rtdn) to ensure state is kept in-sync. A SubscriptionNotification is sent for events affecting subscription state such as renewals and cancellations. You need to call the developer API after receiving a Real-time developer notifications to get the complete status and update your own backend state. These notifications tell you only that the subscription state changed. They do not give you complete information about overall subscription status.

> Note: Due to quota restrictions, it is not recommended to check state by polling the Google Play Developer API at regular intervals instead of leveraging Real-time developer notifications.

Your app needs to handle the state changes that are described in the following table:

StateNotificationValueNew subscriptionsSUBSCRIPTION\_PURCHASED4RenewalsSUBSCRIPTION\_RENEWED2ExpirationSUBSCRIPTION\_EXPIRED13CancellationsSUBSCRIPTION\_CANCELLEDRevocationsSUBSCRIPTION\_REVOKED3Account holdSUBSCRIPTION\_ON\_HOLD5Grace periodSUBSCRIPTION\_IN\_GRACE\_PERIOD6Paused subscriptionsSUBSCRIPTION\_PAUSED10Restorations......Upgrades, downgrades, and re-sign-ups......After receiving a real-time developer notification, you can parse its contents as follows:

```
use Bestys\GooglePlay\DeveloperNotifications\DeveloperNotification;
$data = 'the_received_base_64_encoded_string';
$developerNotification = DeveloperNotification::parse($data); // Bestys\GooglePlay\DeveloperNotifications\DeveloperNotification
$subscriptionNotification = $developerNotification->getSubscriptionNotification(); // Bestys\GooglePlay\DeveloperNotifications\SubscriptionNotification
```

The Following methods are available in `Bestys\GooglePlay\DeveloperNotifications\DeveloperNotification`

MethodDescriptionparse...getType...getVersion...getPackageName...getEventTime...getSubscriptionNotification...getOneTimeProductNotification...getTestNotification...The Following methods are available in `Bestys\GooglePlay\DeveloperNotifications\SubscriptionNotification`

MethodDescriptiongetVersion...getNotificationType...getPurchaseToken...getSubscriptionId...

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1952d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/77055705?v=4)[bestys-mobile](/maintainers/bestys-mobile)[@bestys-mobile](https://github.com/bestys-mobile)

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bestys-mobile-google-play-billing/health.svg)

```
[![Health](https://phpackages.com/badges/bestys-mobile-google-play-billing/health.svg)](https://phpackages.com/packages/bestys-mobile-google-play-billing)
```

###  Alternatives

[imdhemy/google-play-billing

Google Play Billing

491.3M5](/packages/imdhemy-google-play-billing)[lemonsqueezy/laravel

A package to easily integrate your Laravel application with Lemon Squeezy.

58596.1k](/packages/lemonsqueezy-laravel)[shetabit/multipay

PHP Payment Gateway Integration Package

291348.2k3](/packages/shetabit-multipay)[buckaroo/sdk

Buckaroo payment SDK

12189.1k9](/packages/buckaroo-sdk)[contica/facturador-electronico-cr

Un facturador de código libre para integrar facturación electrónica en Costa Rica a un proyecto PHP

2128.8k](/packages/contica-facturador-electronico-cr)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
