# BillingClient.Builder


```
public final class BillingClient.Builder
```

<br />

*** ** * ** ***

Builder to configure and create a `https://developer.android.com/reference/com/android/billingclient/api/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 |
|---|---|
| `https://developer.android.com/reference/com/android/billingclient/api/BillingClient` | `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#build()()` Creates a Billing client instance. |
| `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder` | `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#enableAlternativeBillingOnly()()` Enables the ability to offer alternative billing without user choice to use Google Play billing. |
| `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder` | `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#enableAutoServiceReconnection()()` Enables automatic reconnection to the billing service in case of a disconnection. |
| `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder` | `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#enableBillingProgram(com.android.billingclient.api.EnableBillingProgramParams)(https://developer.android.com/reference/com/android/billingclient/api/EnableBillingProgramParams params)` Enables the ability to offer a given billing program. |
| `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder` | `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#enableBillingProgram(int)(int program)` Enables the ability to offer a given billing program. |
| `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder` | `[enableExternalOffer](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#enableExternalOffer())()` **This method is deprecated.** Use `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#enableBillingProgram(int)` with `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.BillingProgram#EXTERNAL_OFFER()` instead. <br /> |
| `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder` | `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#enablePendingPurchases(com.android.billingclient.api.PendingPurchasesParams)(https://developer.android.com/reference/com/android/billingclient/api/PendingPurchasesParams pendingPurchasesParams)` Enables pending purchase support. |
| `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder` | `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#enableUserChoiceBilling(com.android.billingclient.api.UserChoiceBillingListener)( https://developer.android.com/reference/com/android/billingclient/api/UserChoiceBillingListener userChoiceBillingListener )` Enables the ability for users to select an alternative billing option during the purchase flow and registers a listener. |
| `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder` | `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#setListener(com.android.billingclient.api.PurchasesUpdatedListener)(https://developer.android.com/reference/com/android/billingclient/api/PurchasesUpdatedListener listener)` Specifies a valid listener for `https://developer.android.com/reference/com/android/billingclient/api/PurchasesUpdatedListener#onPurchasesUpdated(com.android.billingclient.api.BillingResult,java.util.List<com.android.billingclient.api.Purchase>)` 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 `https://developer.android.com/reference/com/android/billingclient/api/BillingClient#startConnection(com.android.billingclient.api.BillingClientStateListener)` and wait for setup to complete.

| Returns |
|---|---|
| `https://developer.android.com/reference/com/android/billingclient/api/BillingClient` | BillingClient instance |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | 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.

### enableAutoServiceReconnection

```
public BillingClient.Builder enableAutoServiceReconnection()
```

Enables automatic reconnection to the billing service in case of a disconnection.

### enableBillingProgram

```
public BillingClient.Builder enableBillingProgram(EnableBillingProgramParams params)
```

Enables the ability to offer a given billing program.

Calling this method multiple times with different billing programs will enable all of them.

### enableBillingProgram

```
public BillingClient.Builder enableBillingProgram(int program)
```

Enables the ability to offer a given billing program.

Calling this method multiple times with different billing programs will enable all of them.

### enableExternalOffer

```
public BillingClient.Builder [enableExternalOffer](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#enableExternalOffer())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#enableBillingProgram(int)` with `https://developer.android.com/reference/com/android/billingclient/api/BillingClient.BillingProgram#EXTERNAL_OFFER()` instead.

Enables provision of an external offer.

### enablePendingPurchases

```
public BillingClient.Builder enablePendingPurchases(PendingPurchasesParams pendingPurchasesParams)
```

Enables pending purchase support.

Call this method to enable pending purchases in your application. Pending purchases aren't automatically enabled to ensure that entitlements aren't granted until the payment is secured. For more information on how to handle pending transactions see the [Pending purchases](https://developer.android.com/google/play/billing/integrate#pending) section in the integration guide.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/android/billingclient/api/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 |
|---|---|
| `https://developer.android.com/reference/com/android/billingclient/api/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 `https://developer.android.com/reference/com/android/billingclient/api/PurchasesUpdatedListener#onPurchasesUpdated(com.android.billingclient.api.BillingResult,java.util.List<com.android.billingclient.api.Purchase>)` events.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/android/billingclient/api/PurchasesUpdatedListener listener` | Your listener for app initiated and Play Store initiated purchases. |