google::play::billing::BillingClient

#include <billing/client.h>

Entrypoint for the Google Play Billing API.

Summary

Constructors and Destructors

BillingClient()
~BillingClient()

Public functions

AcknowledgePurchase(const AcknowledgePurchaseParams & params, AcknowledgePurchaseContinuation continuation)
void
Acknowledges a purchase with Play Billing.
ConsumePurchase(const ConsumePurchaseParams & params, ConsumePurchaseContinuation continuation)
void
Consumes a purchase with Play Billing.
CreateBillingProgramReportingDetails(const CreateBillingProgramReportingDetailsParams & params, CreateBillingProgramReportingDetailsContinuation continuation)
void
Creates billing program reporting details.
IsBillingProgramAvailable(const IsBillingProgramAvailableParams & params, IsBillingProgramAvailableContinuation continuation)
void
Checks if a billing program is available.
LaunchPurchaseFlow(const LaunchPurchaseFlowParams & params, LaunchPurchaseFlowContinuation continuation)
void
Launches the purchase flow for the requested product offers.
QueryProductDetails(const QueryProductDetailsParams & params, QueryProductDetailsContinuation continuation)
void
Queries for products available to the user so they may be purchased.
QueryPurchases(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 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.

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

BillingClient

 BillingClient()

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) and allows a user to purchase the same product again.

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.

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.

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.

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 API.

On a successful purchase, the continuation will be called with a LaunchPurchaseFlowResultValue 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) or consumed if it should be possible for the user to purchase the product again (see ConsumePurchase). 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 and LaunchPurchaseFlowParams::obfuscated_profile_id). 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.

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 for each product identifier passed in the request that was available to the user. Each contains a list of offers (see ProductOffer) with pricing details as well as an offer token. To purchase a product, pass the offer token associated with the offer into the LaunchPurchaseFlow API.

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) 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) or consume the purchase (see ConsumePurchase).

If your application is client-only, you may check for one-time purchases the user has a recorded entitlement for using ProductPurchaseDetails::is_acknowledged. 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.

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

~BillingClient

 ~BillingClient()