BillingClient.Builder

public static final class BillingClient.Builder
extends Object

java.lang.Object
   ↳ com.android.billingclient.api.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 build()

Creates a Billing client instance.

BillingClient.Builder enableAlternativeBilling(AlternativeBillingListener alternativeBillingListener)

This method is deprecated. Use enableUserChoiceBilling(UserChoiceBillingListener) instead. Included in documentation by the annotations: @Annotations.AlternativeBilling

BillingClient.Builder enableAlternativeBillingOnly()

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

BillingClient.Builder enablePendingPurchases()

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

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 setListener(PurchasesUpdatedListener listener)

Specifies a valid listener for PurchasesUpdatedListener.onPurchasesUpdated(BillingResult, List) events.

Inherited methods

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 BillingClient.startConnection(BillingClientStateListener) and wait for setup to complete.

Returns
BillingClient BillingClient instance

Throws
IllegalArgumentException if Context or PurchasesUpdatedListener were not set.

enableAlternativeBilling

public BillingClient.Builder enableAlternativeBilling (AlternativeBillingListener alternativeBillingListener)
Included in documentation by the annotations: @Annotations.AlternativeBilling

This method is deprecated.
Use enableUserChoiceBilling(UserChoiceBillingListener) instead.

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

Parameters
alternativeBillingListener AlternativeBillingListener: The listener for the result of the alternative billing operation returned asynchronously through the callback.

Returns
BillingClient.Builder

enableAlternativeBillingOnly

public BillingClient.Builder enableAlternativeBillingOnly ()

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

Returns
BillingClient.Builder

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 https://developer.android.com/google/play/billing/billing_library_overview.

If this method is not called, BillingClient instance creation fails.

Returns
BillingClient.Builder

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.

Returns
BillingClient.Builder

setListener

public BillingClient.Builder setListener (PurchasesUpdatedListener listener)

Specifies a valid listener for PurchasesUpdatedListener.onPurchasesUpdated(BillingResult, List) events.

Parameters
listener PurchasesUpdatedListener: Your listener for app initiated and Play Store initiated purchases.

Returns
BillingClient.Builder