# AMSPaymentElement.Builder

> AMSPaymentElement.Builder is a constructor class used to progressively configure and ultimately create AMSPaymentElement instances.

`AMSPaymentElement.Builder` is a constructor class used to progressively configure and ultimately create [`AMSPaymentElement`](https://docs.antom.com/ac/sdks/android_AMSPaymentElement.md) instances. After passing the necessary parameters through its constructor, the `build()` method must be called on the main thread to complete the instance construction.

## Constructor

#### Tab: Java

```java
new AMSPaymentElement.Builder(Activity activity, AMSBaseConfiguration configuration)
```

#### Tab: Kotlin

```kotlin
AMSPaymentElement.Builder(activity: Activity, configuration: AMSBaseConfiguration)
```

### Parameters

When creating an `AMSPaymentElement.Builder` instance, you need to pass in the following parameters:

| **Parameter** | **Data type** | **Required** | **Description** |
| --- | --- | --- | --- |
| _activity_ | Activity | Yes | The current Activity context. |
| _configuration_ | AMSBaseConfiguration | Yes | An instance of the [`AMSBaseConfiguration`](https://docs.antom.com/ac/sdks/android_AMSBaseConfiguration.md) class, used to provide the configuration required for SDK initialization. |

### Return value

Returns an `AMSPaymentElement.Builder` instance, which is used to continue configuring and constructing the [`AMSPaymentElement`](https://docs.antom.com/ac/sdks/android_AMSPaymentElement.md) object.

## build()

After completing the `Builder` initialization, call the `build()` method to construct the [`AMSPaymentElement`](https://docs.antom.com/ac/sdks/android_AMSPaymentElement.md) instance.

### Method signature

#### Tab: Java

```java
public AMSPaymentElement build()
```

#### Tab: Kotlin

```kotlin
fun build(): AMSPaymentElement?
```

### Parameters

This method takes no parameters.

### Return value

Returns the constructed [`AMSPaymentElement`](https://docs.antom.com/ac/sdks/android_AMSPaymentElement.md) instance. This instance contains the following methods:

> **Note**: If configuration is `null`, then `null` is returned. If not called on the main thread, _RuntimeException_ will be thrown.

| **Method name** | **Description** |
|------------------|-----------------|
| [`preload()`](https://docs.antom.com/ac/sdks/android_preload.md) | Used to preload WebApp page and KYC page resources. |
| [`createComponent()`](https://docs.antom.com/ac/sdks/android_createComponent.md) | Used to create and display the payment component UI. This method is mutually exclusive with the [`confirmPayment()`](https://docs.antom.com/ac/sdks/android_confirmPayment.md) method. |
| [`confirmPayment()`](https://docs.antom.com/ac/sdks/android_confirmPayment.md) | Used to submit and confirm saved card payment for the current component instance. This method is mutually exclusive with the [`createComponent()`](https://docs.antom.com/ac/sdks/android_createComponent.md) method. |
| [`reset()`](https://docs.antom.com/ac/sdks/android_reset.md) | Used to reset the payment process and clear the current state. |
| [`onDestroy()`](https://docs.antom.com/ac/sdks/android_onDestroy.md) | Used to destroy the instance and release all associated resources. |

## Sample

```java
AMSBaseConfiguration configuration = new AMSBaseConfiguration();
configuration.setLocale(new Locale("en", "US"));
configuration.setOption("sandbox", true);

AMSPaymentElement paymentElement = new AMSPaymentElement.Builder(activity, configuration).build();
```