BillingClient.Builder

public final class BillingClient.Builder


Builder to configure and create a BillingClient instance.

All methods in the class can be called from any thread, and results will be posted to the same thread.

Summary

Public methods

BillingClient

Creates a Billing client instance.

BillingClient.Builder

Enables the ability to offer alternative billing without user choice to use Google Play billing.

BillingClient.Builder

Enables the ability to offer external offer.

BillingClient.Builder

This method is deprecated.

Use enablePendingPurchases instead.

BillingClient.Builder

Enables pending purchase support.

BillingClient.Builder
enableUserChoiceBilling(
    UserChoiceBillingListener userChoiceBillingListener
)

Enables the ability for users to select an alternative billing option during the purchase flow and registers a listener.

BillingClient.Builder

Specifies a valid listener for PurchasesUpdatedListener#onPurchasesUpdated events.

Public methods

build

public BillingClient build()

Creates a Billing client instance.

After creation, it will not yet be ready to use. You must initiate setup by calling startConnection and wait for setup to complete.

Returns
BillingClient

BillingClient instance

Throws
java.lang.IllegalArgumentException

if Context or PurchasesUpdatedListener were not set.

enableAlternativeBillingOnly

public BillingClient.Builder enableAlternativeBillingOnly()

Enables the ability to offer alternative billing without user choice to use Google Play billing.

enableExternalOffer

public BillingClient.Builder enableExternalOffer()

Enables the ability to offer external offer.

enablePendingPurchases

public BillingClient.Builder enablePendingPurchases()

Enables pending purchase support for one-time (in-app) items.

This method is required to be called to acknowledge your application has been updated to support purchases that are pending. Pending purchases are not automatically enabled since your application will require updates to ensure entitlement is not granted before payment has been secured. For more information on how to handle pending transactions see the Pending purchases section in the integration guide.

This method is equivalent to enablePendingPurchases(PendingPurchasesParams.newBuilder().enableOneTimeProducts().build()).

enablePendingPurchases

public BillingClient.Builder enablePendingPurchases(PendingPurchasesParams pendingPurchasesParams)

Enables pending purchase support.

Call this method to acknowledge your application has been updated to support purchases that are pending. Pending purchases are not automatically enabled since your application will require updates to ensure entitlement is not granted before payment has been secured. For more information on how to handle pending transactions see the Pending purchases section in the integration guide.

Prefer this method over enablePendingPurchases.

Parameters
PendingPurchasesParams pendingPurchasesParams

Params to specify the type of pending purchase.

enableUserChoiceBilling

public BillingClient.Builder enableUserChoiceBilling(
    UserChoiceBillingListener userChoiceBillingListener
)

Enables the ability for users to select an alternative billing option during the purchase flow and registers a listener.

Parameters
UserChoiceBillingListener userChoiceBillingListener

The listener for the result of the user choice billing operation returned asynchronously through the callback.

setListener

public BillingClient.Builder setListener(PurchasesUpdatedListener listener)

Specifies a valid listener for PurchasesUpdatedListener#onPurchasesUpdated events.

Parameters
PurchasesUpdatedListener listener

Your listener for app initiated and Play Store initiated purchases.