# Checkout

You can perform Store Transfer operations by submitting a list of SKU with corresponding amounts. Alternatively, you can also provide a list of raw items for retailers like AmazonFresh and Instacart.

## Checkout Flow

Retailers provide different ways to the authenticated user and match products in-store. Currently we support 3 different flows.

It can affect your user experience. Please check details for each flow in [retailers sections](https://docs.whisk.com/master/api/retailers/retailers-checkout-flow)

## Affiliates

Whisk supports several affiliate networks. You can pass your affiliate codes through checkout API.

Supported affiliate services at the moment: `Awin`, `VigLink`, `CJ Affiliate`.

Stores which support affiliates:

* Instacart
* AmazonFresh
* BritishCornerShop
* Billa
* Tesco
* Ocado
* Waitrose
* Walmart
* Woolworths

Use field extra to pass your affiliate codes.

## Checkout

<mark style="color:green;">`POST`</mark> `https://graph.whisk.com/v1/carts/checkout`

#### Request Body

| Name        | Type   | Description                                                                          |
| ----------- | ------ | ------------------------------------------------------------------------------------ |
| retailerId  | string | Retailer Id to perform Checkout for. (short names can be used)                       |
| credentials | object | Authentication credentials in store. Might be Basic or OAuth                         |
| items       | array  | An array of CheckoutItem objects holding items to checkout                           |
| extra       | object | A CheckoutExtra object holding extra properties that may be specific to the retailer |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

### CheckoutItem

| ATTRIBUTE | TYPE                   | DESCRIPTION |
| --------- | ---------------------- | ----------- |
| storeItem | StoreItemCheckoutValue |             |
| raw       | RawItemCheckoutValue   |             |

### CheckoutExtra

| ATTRIBUTE | TYPE          | DESCRIPTION           |
| --------- | ------------- | --------------------- |
| affiliate | AffiliateInfo | Affiliate information |

### AffiliateInfo

| ATTRIBUTE | TYPE   | DESCRIPTION       |
| --------- | ------ | ----------------- |
| awin      | string | Awin code         |
| cj        | string | CJ Affiliate code |
| vigLink   | string | VigLink code      |

### StoreItemCheckoutValue

| ATTRIBUTE | TYPE    | DESCRIPTION                                  |
| --------- | ------- | -------------------------------------------- |
| sku\*     | string  | item identifier in Retailer                  |
| quantity  | integer | Number of items to checkout Default value: 1 |

### RawItemCheckoutValue

| ATTRIBUTE | TYPE   | DESCRIPTION                          |
| --------- | ------ | ------------------------------------ |
| name\*    | string | Raw item text. Example: 1 tbsp sugar |

### Credentials

| ATTRIBUTE | TYPE             | DESCRIPTION                            |
| --------- | ---------------- | -------------------------------------- |
| basic     | BasicCredentials | Basic credentials, login, and password |
| oauth     | OAuthCredentials | Basic credentials, login, and password |

### BasicCredentials

| ATTRIBUTE  | TYPE   | DESCRIPTION |
| ---------- | ------ | ----------- |
| username\* | string |             |
| password\* | string |             |

### OAuthCredentials

| ATTRIBUTE | TYPE   | DESCRIPTION |
| --------- | ------ | ----------- |
| token\*   | string | OAuth token |

## CheckoutResponse

| ATTRIBUTE           | TYPE                    | DESCRIPTION                                                                                                                                                          |
| ------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| status\*            | enum                    | status indicates the state of checkout and provides info on the following action users need to take. Possible values: CompleteCheckoutUrlProvided, ItemsTransferred. |
| items               | array \[CheckedOutItem] | list of items added to basket (if applicable)                                                                                                                        |
| completeCheckoutUrl | string                  | URL to complete checkout (if applicable)                                                                                                                             |

### CheckedOutItem

| ATTRIBUTE | TYPE          | DESCRIPTION                                                                                                                                        |
| --------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| sku\*     | string        | item identifier in a store                                                                                                                         |
| status\*  | enum          | status indicates whether an item was added to retailers cart or not Possible values: CheckedOut, Failed, OutOfStock, ReachedMaxItems, Unavailable. |
| item      | InventoryItem | item details                                                                                                                                       |

### InventoryItem

| ATTRIBUTE  | TYPE                     | DESCRIPTION              |
| ---------- | ------------------------ | ------------------------ |
| sku\*      | string                   | item identifier in store |
| name\*     | string                   | item name                |
| quantity\* | object                   | count of items           |
| url\*      | string                   | direct item URL          |
| price\*    | Price                    | item price               |
| images\*   | array \[ResponsiveImage] | responsive images        |

### Price

| ATTRIBUTE | TYPE   | DESCRIPTION |
| --------- | ------ | ----------- |
| list      | number | Total price |

### Sample Request

```bash
curl -X POST "https://graph.whisk.com/v1/carts/checkout" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Token <Access-Token>" \
  -d '{
    "items": [
      {
        "storeItem": {
          "sku": "278272994",
          "quantity": 1
        }
      },
      {
        "storeItem": {
          "sku": "258270595"
        }
      }
    ],
    "retailerId": "tesco",
    "credentials": {
      "basic": {
        "username": "email@example.com",
        "password": "s3cret"
      }
    }
  }'
```

### Example with AmazonFresh

```bash
curl -X POST "https://graph.whisk.com/v1/carts/checkout" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Token <Access-Token>" \
  -d '{
    "items": [
      {
        "raw": {
          "name": "4 large eggs"
        }
      },
      {
        "raw": {
          "name": "handful basil leaves"
        }
      }
    ],
    "retailerId": "amazonfresh-us"
  }'
```
