# Checkout

## The `onCheckout` callback

When the Assistant detects that the user is trying to checkout, it invokes the callback associated with the checkout user journey. The callback looks like this:

{% tabs %}
{% tab title="Android Native" %}

```
public CheckoutAppState onCheckOut(CheckoutInfo checkoutInfo, CheckoutUserJourney checkoutUserJourney) {
```

{% endtab %}

{% tab title="React Native" %}

```
TBD
```

{% endtab %}

{% tab title="Web" %}

```
TBD
```

{% endtab %}
{% endtabs %}

1. Start the process by navigating to the first page of the checkout journey
2. Now the journey provides ways to collect some relevant inputs from the user if required. The app should return the appropriate app state and condition to indicate which details need to be collected
3. If no data needs to be collected, it can just return SUCCESS condition for the CheckoutComplete AppState&#x20;

For  example, if the app needs to collect the name and then phone number of the user, it can do that as shown below &#x20;

{% tabs %}
{% tab title="Android Native" %}

```
public CheckoutAppState onCheckOut(CheckoutInfo checkoutInfo, CheckoutUserJourney checkoutUserJourney) {

   if (checkoutInfo.getCheckoutName() == null) {
     return new CheckoutCompleteAppState(
       CheckoutCompleteAppState.NAME_NOT_SPECIFIED
     );
   } else if (checkoutInfo.getCheckoutPhoneNumber() == null) {
     return new CheckoutCompleteAppState(
       CheckoutCompleteAppState.PHONE_NUMBER_NOT_SPECIFIED
     );
   } else return new CheckoutCompleteAppState(
       CheckoutCompleteAppState.SUCCESS
     );
 }
```

{% endtab %}

{% tab title="React Native" %}

```
TBD
```

{% endtab %}

{% tab title="Web" %}

```javascript
TBD
```

{% endtab %}
{% endtabs %}

## Sample Utterances that could trigger Checkout&#x20;

The following are some examples of commands that could trigger this user journey

* *"checkout"*
* *"i am done*

## `CheckoutInfo` Parameter

The parameter`CheckoutInfo` contains the breakdown of the original order request. It has the following structure:

{% tabs %}
{% tab title="Android Native" %}

```
Class CheckoutInfo {
	String getCheckoutPhoneNumber(); 
	String getCheckoutName(); 
	Date getCheckoutDate();
}
```

{% endtab %}

{% tab title="React Native" %}

```
TBD
```

{% endtab %}

{% tab title="Web" %}

```
TBD
```

{% endtab %}
{% endtabs %}

## Supported `AppState`s

The following `AppState`s are supported:

* **CHECKOUT\_COMPLETE (`CheckoutCompleteAppState`):**  To be returned when the app handles the checkout process
* **UNSUPPORTED (`UnsupportedAppState`):** To be returned when the app is not ready to handle checkout via voice yet. The Assistant will speak out an appropriate prompt to the user.&#x20;

{% hint style="info" %}
The Slang Retail Assistant provides a special `AppState` call **`WAITING (WaitingAppState)`** that is common across all `UserJourney` types for completing asynchronous operations within the callback. Refer to the [Asynchronous Action Handling](https://docs.conva.ai/slang/getting-started/integrating-slang-retail-assistant/code-integration-basic-steps/code-integration-basic-steps-1/supported-user-journeys/broken-reference) section for details of how to deal with asynchronous operations.
{% endhint %}

### Supported `Condition`s

The following `Conditions` are supported for each of the `AppState`s supported by the Assistant

| **App State**                                       | **Condition**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **CHECKOUT\_COMPLETE (`CheckoutCompleteAppState`)** | <ul><li><strong>SUCCESS</strong> - The order could be shown successfully</li><li><strong>NAME\_NOT\_SPECIFIED</strong> - The app wants to collect the user's name associated with the order</li><li><strong>PHONE\_NUMBER\_NOT\_SPECIFIED</strong> - The app wants to collect the phone number to be used for the order</li><li><strong>DATE\_NOT\_SPECIFIED</strong> - The app wants to collect the delivery date for the order</li><li><strong>FAILURE</strong> - There was a failure during the checkout process</li></ul> |

## Assistant Prompts

Based on the App State and the Condition that was set, the Assistant will speak out an appropriate message to the user. You can examine the default set of prompts configured for the Assistant through the Console and also customize it to your needs. Refer to the [Customizing the Assistant](https://docs.conva.ai/slang/getting-started/integrating-slang-retail-assistant/code-integration-basic-steps/code-integration-basic-steps-1/supported-user-journeys/broken-reference) section for details.
