Download the PHP package bestys-mobile/google-play-billing without Composer
On this page you can find all versions of the php package bestys-mobile/google-play-billing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package google-play-billing
PHP 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 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
Install the package via composer:
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
- In the Cloud Console, go to the Create service account key page.
- From the Service account list, select New service account.
- In the Service account name field, enter a name.
- From the Role list, select Project > Owner.
- Click Create. A JSON file that contains your key downloads to your computer.
- You can set the environment variable by:
Sell products
With any type of your products, you can use the REST api to:
- acknowledge: Acknowledges a purchase of an inapp item.
- get: Checks the purchase and consumption status of an inapp item.
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.
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.
The get() method returns a Bestys\GooglePlay\Products\ProductPurchase
object, which contains the following methods:
Method | Description |
---|---|
getKind | ... |
getPurchaseTime | ... |
getPurchaseState | ... |
getConsumptionState | ... |
getDeveloperPayload | ... |
getOrderId | ... |
getAcknowledgementState | ... |
getPurchaseToken | ... |
getProductId | ... |
getQuantity | ... |
getObfuscatedExternalAccountId | ... |
getObfuscatedExternalProfileId | ... |
getRegionCode | ... |
Sell subscriptions
This section describes how to handle subscription lifecycle events, such as renewals and expiration.
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
A subscription can go through various state changes throughout its lifecycle 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.
State | Is returned | expiryTimeMillis | paymentState | autoRenewing |
---|---|---|---|---|
Active | Yes | Future | 1 (Payment Received) | True |
Cancelled | Yes | Future | 1 (Payment Received) | False |
In grace period | Yes | Future | 0 (Payment Pending) | True |
On hold | Yes | Past | 0 (Payment Pending) | True |
Paused | Yes | Past | 1 (Payment Received) | True |
Expired | Yes | Past | 1 (Payment Received) | False |
The following methods are available to be used on a subscription:
- acknowledge: Acknowledges a subscription purchase.
- get: Checks whether a user's subscription purchase is valid and returns its expiry time.
cancel: Cancels a user's subscription purchase.defer: Defers a user's subscription purchase until a specified future expiration time.refund: Refunds a user's subscription purchase, but the subscription remains valid until its expiration time and it will continue to recur.revoke: Refunds and immediately revokes a user's subscription purchase.
N.B. The stroked method are not implemented yet. help us with your contributions 😅.
The Following methods are available in Bestys\GooglePlay\Subscriptions\SubscriptionPurchase
Object
Method | Description |
---|---|
getKind | ... |
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 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:
State | Notification | Value |
---|---|---|
New subscriptions | SUBSCRIPTION_PURCHASED | 4 |
Renewals | SUBSCRIPTION_RENEWED | 2 |
Expiration | SUBSCRIPTION_EXPIRED | 13 |
Cancellations | SUBSCRIPTION_CANCELLED | |
Revocations | SUBSCRIPTION_REVOKED | 3 |
Account hold | SUBSCRIPTION_ON_HOLD | 5 |
Grace period | SUBSCRIPTION_IN_GRACE_PERIOD | 6 |
Paused subscriptions | SUBSCRIPTION_PAUSED | 10 |
Restorations | ... | ... |
Upgrades, downgrades, and re-sign-ups | ... | ... |
After receiving a real-time developer notification, you can parse its contents as follows:
The Following methods are available in
Bestys\GooglePlay\DeveloperNotifications\DeveloperNotification
Method | Description |
---|---|
parse | ... |
getType | ... |
getVersion | ... |
getPackageName | ... |
getEventTime | ... |
getSubscriptionNotification | ... |
getOneTimeProductNotification | ... |
getTestNotification | ... |
The Following methods are available in
Bestys\GooglePlay\DeveloperNotifications\SubscriptionNotification
Method | Description |
---|---|
getVersion | ... |
getNotificationType | ... |
getPurchaseToken | ... |
getSubscriptionId | ... |
All versions of google-play-billing with dependencies
google/auth Version ^1.14
ext-json Version *
nesbot/carbon Version ^2.41
guzzlehttp/guzzle Version ^6.0|^7.0