# google::play::billing::BillingClient


`#include <billing/client.h>`

Entrypoint for the Google Play Billing API.

## Summary

| ### Constructors and Destructors ||
|---|---|
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1ab37ad67715270323b393019d8c60573a(const https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/billing-client-params#structgoogle_1_1play_1_1billing_1_1_billing_client_params & params)` ||
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1aeed6f4c0dd187d65c6f4d7a1cad66db4()` ||

| ### Public functions ||
|---|---|
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1ae2885b0119c6c9bf7e4eb51147ba6e74(const https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/acknowledge-purchase-params#structgoogle_1_1play_1_1billing_1_1_acknowledge_purchase_params & params, AcknowledgePurchaseContinuation continuation)` | `void` Acknowledges a purchase with Play Billing. |
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a952bb4e38e8000318b54fb02beb971b6(const https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/consume-purchase-params#structgoogle_1_1play_1_1billing_1_1_consume_purchase_params & params, ConsumePurchaseContinuation continuation)` | `void` Consumes a purchase with Play Billing. |
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1af5555444d755749896037e087fc44735(const https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/create-billing-program-reporting-details-params#structgoogle_1_1play_1_1billing_1_1_create_billing_program_reporting_details_params & params, CreateBillingProgramReportingDetailsContinuation continuation)` | `void` Creates billing program reporting details. |
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a03b80f9d6f347d687920742ebb0938fb(const https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/is-billing-program-available-params#structgoogle_1_1play_1_1billing_1_1_is_billing_program_available_params & params, IsBillingProgramAvailableContinuation continuation)` | `void` Checks if a billing program is available. |
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a5b7a22b5fe4fbfe92079c8fb2b4dc782(const https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/launch-purchase-flow-params#structgoogle_1_1play_1_1billing_1_1_launch_purchase_flow_params & params, LaunchPurchaseFlowContinuation continuation)` | `void` Launches the purchase flow for the requested product offers. |
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a658cc254f3b4e45eab7a9d92ad5de1c0(const https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/query-product-details-params#structgoogle_1_1play_1_1billing_1_1_query_product_details_params & params, QueryProductDetailsContinuation continuation)` | `void` Queries for products available to the user so they may be purchased. |
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a820169ec4ead7c85a24e449a78ab1cd2(QueryPurchasesContinuation continuation)` | `void` Returns purchases associated with the current user. |

## Public functions

### AcknowledgePurchase

```
void AcknowledgePurchase(
  const AcknowledgePurchaseParams & params,
  AcknowledgePurchaseContinuation continuation
)
```
Acknowledges a purchase with Play Billing.

Acknowledges that an entitlement of the purchase has been granted to the user. This updates the Play Billing system's record of the purchase. Future calls to [QueryPurchases](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a820169ec4ead7c85a24e449a78ab1cd2) wll now reflect that purchase as acknowledged.

If your application has a secure backend, we recommend that you use the server-side API to acknowledge the purchase instead of this API inside of SDK.

If your application is client-only, use this API to acknowledge the purchase. Note that usage of this client-side API requires your application to be allow-listed.

Acknowledgement is intended to be used for one-time purchases such as a cosmetic item in a game. If it should be possible for the user to purchase that product again see [ConsumePurchase](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a952bb4e38e8000318b54fb02beb971b6).

<br />

Details Parameters `params` Parameters containing the purchase token of product to be acknowledged. `continuation` The async callback to return the data to.

### BillingClient

```
 BillingClient(
  const BillingClientParams & params
)
```

### ConsumePurchase

```
void ConsumePurchase(
  const ConsumePurchaseParams & params,
  ConsumePurchaseContinuation continuation
)
```
Consumes a purchase with Play Billing.

Consuming a purchased product removes the purchase from future purchase queries (see [QueryPurchases](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a820169ec4ead7c85a24e449a78ab1cd2)) and allows a user to purchase the same product again.

If your application is client-only, use this API to consume the purchase. Note that usage of this client-side API requires your application to be allow-listed.

Consuming is intended to be used for products that can be purchased multiple times by the user such as a virtual currency. For purchase that should only be purchased once, see [AcknowledgePurchase](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1ae2885b0119c6c9bf7e4eb51147ba6e74).

<br />

Details Parameters `request` Parameters containing the purchase token of the product to be consumed. `continuation` The async callback to return the data to.

### CreateBillingProgramReportingDetails

```
void CreateBillingProgramReportingDetails(
  const CreateBillingProgramReportingDetailsParams & params,
  CreateBillingProgramReportingDetailsContinuation continuation
)
```
Creates billing program reporting details.

Returns an external transaction token that may be used to report transactions happening outside Google Play's billing system in supported countries, such as alternative billing transactions.

The external transaction token is a required parameter when reporting an external transaction using the server-side `Externaltransactions` Play Billing API.

Before requesting billing program reporting details, ensure that the current user is eligible using [IsBillingProgramAvailable](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a03b80f9d6f347d687920742ebb0938fb).

<br />

Details Parameters `params` Parameters containing the billing program. `continuation` The async callback to return the data to.

### IsBillingProgramAvailable

```
void IsBillingProgramAvailable(
  const IsBillingProgramAvailableParams & params,
  IsBillingProgramAvailableContinuation continuation
)
```
Checks if a billing program is available.

Determines if the current user is eligible for the specified billing program. Before offering programs outside of Google Play Billing, your game must complete the required enrollment steps.

If a billing program is available for the current user, and your application performs an external transaction, you must report this transaction using [CreateBillingProgramReportingDetails](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1af5555444d755749896037e087fc44735).

<br />

Details Parameters `params` Parameters containing the billing program. `continuation` The async callback to return the data to.

### LaunchPurchaseFlow

```
void LaunchPurchaseFlow(
  const LaunchPurchaseFlowParams & params,
  LaunchPurchaseFlowContinuation continuation
)
```
Launches the purchase flow for the requested product offers.

Start a purchase flow for the given product offers previously queried using the [QueryProductDetails](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a658cc254f3b4e45eab7a9d92ad5de1c0) API.

On a successful purchase, the continuation will be called with a [LaunchPurchaseFlowResultValue](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/launch-purchase-flow-result-value#structgoogle_1_1play_1_1billing_1_1_launch_purchase_flow_result_value) containing a ProductPurchaseDetail with a purchase token. This purchase token should then be acknowledged once the purchase has been granted to the user in your application (see [AcknowledgePurchase](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1ae2885b0119c6c9bf7e4eb51147ba6e74)) or consumed if it should be possible for the user to purchase the product again (see [ConsumePurchase](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a952bb4e38e8000318b54fb02beb971b6)). Failure to do so will cause the purchase to automatically refunded.

Purchases can optionally be associated with the details of your application's user profile or account (see [LaunchPurchaseFlowParams::obfuscated_account_id](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/launch-purchase-flow-params#structgoogle_1_1play_1_1billing_1_1_launch_purchase_flow_params_1a5fad067af07ff63cd4b03b8ccc18065d) and [LaunchPurchaseFlowParams::obfuscated_profile_id](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/launch-purchase-flow-params#structgoogle_1_1play_1_1billing_1_1_launch_purchase_flow_params_1aaee08fdfa1051380d9eea657adef05a7)). These values help Google Play detect irregular activity, such as many devices making purchases on the same account in a short period of time and prevent fraud.

If the user does not complete the purchase within a set timeout period, the continuation will be called with a LaunchPurchaseFlowResult containing the error BillingError::kUserCanceled.

<br />

Details Parameters `params` Parameters specifying the product offer to be purchased. `continuation` The async callback to return the data to.

### QueryProductDetails

```
void QueryProductDetails(
  const QueryProductDetailsParams & params,
  QueryProductDetailsContinuation continuation
)
```
Queries for products available to the user so they may be purchased.

Querying for product details is an important step before displaying your products to your users, as it returns localized product information.

When querying for product details, pass a list of product identifiers associated with products registered for your application in the Google Play Console.

The response contains a list of [ProductDetails](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/product-details#structgoogle_1_1play_1_1billing_1_1_product_details) for each product identifier passed in the request that was available to the user. Each contains a list of offers (see [ProductOffer](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/product-offer#structgoogle_1_1play_1_1billing_1_1_product_offer)) with pricing details as well as an offer token. To purchase a product, pass the offer token associated with the offer into the [LaunchPurchaseFlow](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a5b7a22b5fe4fbfe92079c8fb2b4dc782) API.

<br />

Details Parameters `params` Parameters containing the collection of product identifiers to be queried. `continuation` The async callback to return the data to.

### QueryPurchases

```
void QueryPurchases(
  QueryPurchasesContinuation continuation
)
```
Returns purchases associated with the current user.

Queries for purchases made by the current user. This includes both completed as well as pending purchases. Pending purchases should be processed by your application to ensure that the user is granted entitlement for the purchased product. Note that once a purchase is consumed (see [ConsumePurchase](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a952bb4e38e8000318b54fb02beb971b6)) it will no longer be returned by this API.

It is recommended to query for purchases when your application start as well as when it is foregrounded to check for purchases that may have been while your application was not running or on a different device.

The response contains a list of ProductPurchaseDetail for each purchase made by the user.

Check for purchases that are ready to be processed. These are purchases that have not yet been acknowledged or consumed and have a purchase state of PurchaseState::kPurchaseStatePurchased. To process these purchases use the associated purchase token to either acknowledge the purchase (see [AcknowledgePurchase](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1ae2885b0119c6c9bf7e4eb51147ba6e74)) or consume the purchase (see [ConsumePurchase](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/billing/billing-client#classgoogle_1_1play_1_1billing_1_1_billing_client_1a952bb4e38e8000318b54fb02beb971b6)).

If your application is client-only, you may check for one-time purchases the user has a recorded entitlement for using [ProductPurchaseDetails::is_acknowledged](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/billing/product-purchase-details#structgoogle_1_1play_1_1billing_1_1_product_purchase_details_1a826b8baf4eeaac8d6b7238a83e8c2ca9). For example, in a single player game without a backend game server, the game could use this to check if the user has purchased a cosmetic item or access to paid game content.

<br />

Details Parameters `continuation` The async callback to return the data to.

### \~BillingClient

```
 ~BillingClient()
```