# POST shop/checkout

> Validates the submitted data and starts the payment.

- Read more: <https://merx2.wagnerwagner.de/guide/getting-started/create-checkout.md>
- Source: `api/routes/checkout.php#L17` <https://github.com/wagnerwagner/merx/blob/2.0.0-alpha.11/api/routes/checkout.php#L17>

```js
fetch('/api/shop/checkout', {
	method: 'POST',
	headers: {
		'Accept': 'application/json',
		'Content-Type': 'application/json',
	},
	body: JSON.stringify({
		"paymentGateway": "invoice",
		"email": "jane@example.com",
		"company": "Example Inc.",
		"street": "Example Street 1",
		"postal_code": "12345",
		"city": "Example City",
		"country": "DE"
	}),
});
```

## Return type

`array`

Array with redirect url when json is the preferred mime type, otherwise redirects with code 303.

## Example response

`POST /api/shop/checkout`

```json
{
    "status": "error",
    "message": "An unexpected error occurred! Enable debug mode for more info: https://getkirby.com/docs/reference/system/options/debug",
    "code": 500,
    "key": null,
    "details": []
}
```

## Example errors

### Invalid or missing fields

```json title="Request body"
{
    "paymentGateway": "invoice",
    "email": "jane@example",
    "street": "Example Street 1",
    "city": "Example City",
    "country": "DE"
}
```

```json title="Response"
{
    "status": "error",
    "message": "An unexpected error occurred! Enable debug mode for more info: https://getkirby.com/docs/reference/system/options/debug",
    "code": 500,
    "key": null,
    "details": []
}
```

### No payment gateway

```json title="Request body"
{
    "email": "jane@example.com",
    "company": "Example Inc.",
    "street": "Example Street 1",
    "postal_code": "12345",
    "city": "Example City",
    "country": "DE"
}
```

```json title="Response"
{
    "status": "error",
    "message": "No payment gateway provided.",
    "code": 400,
    "key": "error.merx.noPaymentGateway",
    "details": []
}
```

### Empty cart

The example request, sent with an empty cart.

```json title="Response"
{
    "status": "error",
    "message": "Cart is empty.",
    "code": 500,
    "key": "error.merx.emptycart",
    "details": []
}
```
