# Adding custom fields

If you’d like to collect additional customer information during a [low-code checkout](https://docs.digitalriver.com/digital-river-api/integration-options/low-code-checkouts), you can add custom fields to the experience.

Digital River adds what these fields contain to the [checkout-session](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/drop-in-checkout-sessions#drop-in-checkout-sessions) so that you can use it in downstream processes.

## Setup custom fields

On [Digital River Dashboard’s Prebuilt Checkout page](https://docs.digitalriver.com/digital-river-api/administration/dashboard/settings/prebuilt-checkout), you can configure a maximum of two custom fields, each of which can accept a number, text (i.e., string), or a set of pre-defined drop-down options.

<figure><img src="https://334437993-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LqH4RJfLVLuHPXuJyTZ%2Fuploads%2Fweo2YDTftG6M5OusKXe2%2Fimage.png?alt=media&#x26;token=dd4230af-8105-4933-9063-09284f83ca0b" alt=""><figcaption></figcaption></figure>

For each field, you need to:

* Indicate whether it’s required or optional.

{% hint style="warning" %}
If you mark it as required, then express checkout is disabled in [Prebuilt Checkout](https://docs.digitalriver.com/digital-river-api/integration-options/low-code-checkouts/drop-in-checkout).
{% endhint %}

* Define a unique key and make sure it contains no whitespaces.
* Define a label that will be displayed to customers in the experience.

If you’re using the drop-down field, you must enumerate acceptable values and provide a display label for each.

## The checkout experience

Depending on whether you add [physical or digital-only products](https://docs.digitalriver.com/digital-river-api/product-management/skus#how-products-are-classified-as-physical-or-digital) to the [checkout-session’s](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/drop-in-checkout-sessions/checkout-sessions-basics) [`items[]`](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/drop-in-checkout-sessions/checkout-sessions-basics#product-data)Digital River renders your custom fields in the shipping or billing information forms.

{% tabs %}
{% tab title="Prebuilt Checkout" %}
**Physical products in `items[]`**

<div align="left"><figure><img src="https://334437993-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LqH4RJfLVLuHPXuJyTZ%2Fuploads%2F4Wbcirc5BHdEu52APebV%2Fimage.png?alt=media&#x26;token=635bc1ac-8ed9-4bf7-bb91-f9844054d634" alt=""><figcaption></figcaption></figure></div>

**Digital only products in `items[]`**

<div align="left"><figure><img src="https://334437993-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LqH4RJfLVLuHPXuJyTZ%2Fuploads%2FMkhHIIXNufkwssnsWE77%2Fimage.png?alt=media&#x26;token=0c0cc1f8-cdc3-4cf3-938c-bd2a5f148013" alt=""><figcaption></figcaption></figure></div>
{% endtab %}

{% tab title="Address Component" %}
**Physical products in `items[]`**

<div align="left"><figure><img src="https://334437993-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LqH4RJfLVLuHPXuJyTZ%2Fuploads%2FSGZvO4keOnO4LAjqBur8%2Fimage.png?alt=media&#x26;token=f8e25363-bbf8-4e37-98a7-cfc3ebe7b820" alt=""><figcaption></figcaption></figure></div>

**Digital only products in `items[]`**

<div align="left"><figure><img src="https://334437993-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LqH4RJfLVLuHPXuJyTZ%2Fuploads%2Fm1fTfp3xFvtYKerlezdg%2Fimage.png?alt=media&#x26;token=825c6ed5-898e-4331-8dad-44d2e0b89f75" alt=""><figcaption></figcaption></figure></div>
{% endtab %}
{% endtabs %}

If you mark a field as required and customers don't provide a value, they are prompted for input.

{% tabs %}
{% tab title="Prebuilt Checkout" %}

<div align="left"><figure><img src="https://334437993-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LqH4RJfLVLuHPXuJyTZ%2Fuploads%2F4qLGQSOeFCIhG40Awczm%2Fimage.png?alt=media&#x26;token=d93c2d4f-f437-4622-b3b0-c3656ce6bd57" alt=""><figcaption></figcaption></figure></div>
{% endtab %}

{% tab title="Address Component" %}

<div align="left"><figure><img src="https://334437993-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LqH4RJfLVLuHPXuJyTZ%2Fuploads%2FsiFM86F271kLIXEIGLxD%2Fimage.png?alt=media&#x26;token=a3068dc3-48ec-4515-b6f1-51902dbe15a6" alt=""><figcaption></figcaption></figure></div>
{% endtab %}
{% endtabs %}

Number-only fields provide help text if customers enter a non-digit character.

{% tabs %}
{% tab title="Prebuilt Checkout" %}

<div align="left"><figure><img src="https://334437993-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LqH4RJfLVLuHPXuJyTZ%2Fuploads%2FOtvfPmXq8ae2t99pfqNU%2Fimage.png?alt=media&#x26;token=78821394-8e9e-49d0-989c-2e4a3a576667" alt=""><figcaption></figcaption></figure></div>
{% endtab %}

{% tab title="Address Component" %}

<div align="left"><figure><img src="https://334437993-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LqH4RJfLVLuHPXuJyTZ%2Fuploads%2FLHQjf11ZBPPccecviu1T%2Fimage.png?alt=media&#x26;token=c5ac717b-ec87-451a-9b0d-2ac4195404a8" alt=""><figcaption></figcaption></figure></div>
{% endtab %}
{% endtabs %}

Number and text fields accept values with a maximum length of 500 characters.

Labels aren't translated into the [`language` ](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/drop-in-checkout-sessions/checkout-sessions-basics#language)of the [checkout-session](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/drop-in-checkout-sessions), but instead default to English.

## Implement custom fields in Components

The [`done()`](https://docs.digitalriver.com/digital-river-api/integration-options/implementing-a-components-checkout#submitting-components) function, which submits the data collected by the [address component](https://docs.digitalriver.com/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/components/address-component) in an update [checkout-session](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/drop-in-checkout-sessions) request, returns `false` if the user (1) fails to enter a value in a custom field that you marked as required or (2) enters a value that exceeds 500 characters in a custom number or text field.

If your application is set up correctly, this should block customers from proceeding to the checkout's next stage.

For details, refer to [Controlling the checkout flow](https://docs.digitalriver.com/digital-river-api/integration-options/implementing-a-components-checkout#controlling-the-checkout-flow).

You might want to disable the [wallet component](https://docs.digitalriver.com/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/components/wallet-component), if you [mark a custom field as required in the Digital River Dashboard](#setup-custom-fields),  When users click a button in this component, they are redirected to a payment provider. However, the form in the provider's interface lacks a field to collect your custom data, so it won't get added to the [checkout-session](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/drop-in-checkout-sessions/checkout-sessions-basics).

## Retrieve the collected data

After customers successfully submit the form, Digital River adds the key and value of each field they completed to the [checkout-session’s](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/drop-in-checkout-sessions#drop-in-checkout-sessions) `metadata`.

You can access this data by:

* [Configuring a webhook](https://docs.digitalriver.com/digital-river-api/order-management/events-and-webhooks-1/webhooks/creating-a-webhook) to listen for certain [types](https://docs.digitalriver.com/digital-river-api/order-management/events-and-webhooks-1/events-1#event-types) of [events](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/events), such as [`checkout_session.order.created`](https://docs.digitalriver.com/digital-river-api/order-management/events-and-webhooks-1/events-1/event-types#checkout_session.order.created), [`order.accepted`](https://docs.digitalriver.com/digital-river-api/order-management/events-and-webhooks-1/events-1/event-types#order.accepted), [`fulfillment.created`](https://docs.digitalriver.com/digital-river-api/order-management/events-and-webhooks-1/events-1/event-types#fulfillment.created), `order.fulfilled`, and [`order.refunded`](https://docs.digitalriver.com/digital-river-api/order-management/events-and-webhooks-1/events-1/event-types#order.refunded).

{% tabs %}
{% tab title="order.accepted" %}

```json
{
    "id": "66524f24-74d5-4356-b30f-ff1da95db3eb",
    "type": "order.accepted",
    "data": {
        "object": {
            "id": "295121620336",
           ...
            "metadata": {
                "freeSample": "chewToy",
                "giftCardMessage": "A special treat for Zoey's birthday"
            },
            ...
        }
    },
    ...
}
```

{% endtab %}

{% tab title="fulfillment.created" %}
{% code title="Event" %}

```json
{
    "id": "9baea62d-cec5-49e1-b8ac-8546b2007e8d",
    "type": "fulfillment.created",
    "data": {
        "object": {
            "id": "ful_854dee4b-cf4b-43b9-aecb-89d46a9f96cf",
            ...
            "orderDetails": {
                "id": "295121620336",
                ...
                "metadata": {
                    "freeSample": "chewToy",
                    "giftCardMessage": "A special treat for Zoey's birthday"
                },
                ...
            }
        }
    },
   ...
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

* Assigning a callback to [`onCheckoutComplete`](https://docs.digitalriver.com/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/configuring-prebuilt-checkout#oncheckoutcomplete) in [Prebuilt Checkout's configuration object](https://docs.digitalriver.com/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/configuring-prebuilt-checkout) and then implementing a handler.
* Assigning a callback to [`onSuccess`](https://docs.digitalriver.com/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/components/configuring-components#success-event) in the [Component's configuration object](https://docs.digitalriver.com/digital-river-api/developer-resources/digitalrivercheckout.js-reference/digitalrivercheckout-object/components/configuring-components) and then implementing a handler.
* Making a call to [retrieve the order](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/orders#orders).

Once you have this `metadata`, you can use it to populate email notifications, fulfill an order’s goods, or perform other operations of your choice.
