# Start a Square Terminal checkout

```http
POST https://secure.yoprint.com/v2/api/store/{team_slug}/v2/sales_order/{hash_id}/square_terminal/create
```

- Status: internal: built for YoPrint's own apps, don't build on it
- Moves money: see Side effects.
- API version: v2
- Operation ID: `v2_public_sales_order_payment_square_terminal_create`
- Section: Invoices and payments › [Payments](https://developer.yoprint.com/reference/payments.md)
- Web page: https://developer.yoprint.com/reference/payments/v2-sales-order-payment-square-terminal-create/
- Authentication: `Authorization: Bearer YOUR_API_KEY`

> **Internal.** Built for YoPrint's own apps, not for integrations. Don't build on it; use the other operations in this section.

Sends a payment request for this order to a Square Terminal device; the customer pays on the device. Needs the Square (v2) connection.

Send a whole number of thousandths: `12500` is 12.50. See [Money and quantities](/concepts/money-and-quantities/). The answer has the checkout from Square, with its id. `{hash_id}` is the order's `id` (for example `V4keXwwxMQyXw7`); the `ord_` unique key is not accepted here.

## Permission

Any member of the team.

## Business rules

- The amount is checked first: The amount to charge, less any `surcharge`, must be at least 1.00 in the order's currency: otherwise 422 `payment_below_minimum` ("Enter at least USD 1.00.", with the order's currency code), and `error.payment_amount_policy` gives `currency`, `minimum_payment` (a decimal pair, `{ "value": "1000", "dp": 3 }`) and `minimum_remaining_balance` (null). A negative `surcharge` is 422 `payment_surcharge_invalid` ("The payment surcharge cannot be negative."). The provider's own limits still apply.
- Then: only published orders (otherwise the error code "Action Not Allow", HTTP 500 today), and the team must have Square v2 connected (422 `{"message": "Square v2 Not Setup"}`).

## Side effects

- **Moves money.** Starts a checkout on the device through Square. Money moves when the customer pays.

## Path parameters

- `team_slug` (string, required): Your team slug, shown as Team ID next to your API key in Profile. Example `your-team`.
- `hash_id` (string, required): The sales order's or quote's `id` (a hash id). The `ord_` unique key and the order number do not work here. Example `V4keXwwxMQyXw7`.

## Request body

Content type `application/json`, required.

Fields:

- `amount` (integer, required): Send a whole number of thousandths: `12500` is 12.50. Must be at least 1.00 (`1000`) after any `surcharge`.
- `device_id` (string, required): The Square Terminal device id.
- `surcharge` (decimal pair, optional): Optional card surcharge included in `amount`, read only when the team charges one. It must not be negative; it is taken off `amount` for the minimum check. `{ "value": 1250, "dp": 2 }` is 12.50 (see https://developer.yoprint.com/concepts/money-and-quantities.md).

### Example request

```bash
curl -X POST 'https://secure.yoprint.com/v2/api/store/your-team/v2/sales_order/V4keXwwxMQyXw7/square_terminal/create' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Accept: application/json' \
  -H 'X-Yoprint-Decimal-Format: exact-v1' \
  -H 'Content-Type: application/json' \
  -d '{
    "amount": 85000,
    "device_id": "device-1001"
  }'
```

## Response

`200` Successful response.

Fields:

- `data` (object, required): Square's Terminal checkout, with empty fields left out (also `note`, `device_options`, `deadline_duration`, `created_at`, `updated_at`, `app_id`, `location_id`, `payment_type`).
  - `amount_money` (object, optional)
    - `amount` (integer, optional): In Square's smallest unit (cents for USD): 125000 thousandths is 12500.
    - `currency` (string, optional)
  - `id` (string, optional): Square's checkout id: use it to cancel.
  - `reference_id` (string, optional): The order number, for example SO1001.
  - `status` (string | null, optional): Square's checkout status, such as `PENDING`.
- `status` (integer, required)
- `success` (boolean, required)

Example response:

```json
{
  "data": {
    "amount_money": {
      "amount": 8500,
      "currency": "USD"
    },
    "id": "checkout-1001",
    "reference_id": "SO1001",
    "status": "PENDING"
  },
  "status": 200,
  "success": true
}
```

## Errors

- `401` The API key is missing or wrong (`unauthenticated`).
- `403` You are not allowed to do this. `api_access_not_in_plan`: your team's plan doesn't include API access (Pro and above, with an active subscription or trial), so every request answers this until the team upgrades. When your role lacks the permission the operation needs, the body is only `{"message": "Insufficient Permission"}`. Other refusals use the error envelope, with `unauthorized` or `user_is_not_authorized`.
- `404` Not found. `page_not_found`: the team slug is unknown, you are not a member of the team, or an id in the path is not one of this team's. `code: null`, with a message that starts "No query results for": there is no record with that id.
- `422` The request was refused and changed nothing. `validation_failed` lists what to fix in `error.fields`; other codes name a business rule, explained in `error.message`. A few checks answer with only `{"message": "..."}`. An operation that calls another service (a payment provider, a carrier, an accounting app) can answer `connect_timeout` ("Please retry again") when that service does not answer in time: the change may or may not have happened there, so read the record back before you retry.
  - When: Square v2 is not connected: `{"message": "Square v2 Not Setup"}`, with no envelope. Fix: Connect Square in Settings.
  - When: Square refused: `payment_capture_failed`, with Square's errors in `error.data`. Fix: Check the device id.
  - When: `amount` is missing or not a whole number (`validation_failed`), less than 1.00 after the surcharge (`payment_below_minimum`), or the surcharge is negative (`payment_surcharge_invalid`). Fix: Send at least 1.00 (`1000`) in thousandths.
- `500` A business rule refused the request (see the operation's errors), or something failed inside YoPrint. Refusals use the error envelope with a code such as `action_not_allowed`; an unexpected failure answers `{"message": "Server Error"}`. Repeating a refusal gets the same answer; after an unexpected failure, read the record back before you retry a change.
  - When: A draft order: `error.code` "Action Not Allow". Fix: Publish the order first.

## Related

- [Cancel a Square Terminal checkout](https://developer.yoprint.com/reference/payments/v2-sales-order-payment-square-terminal-cancel.md): `PATCH /v2/api/store/{team_slug}/v2/sales_order/{hash_id}/square_terminal/{checkout_id}/cancel`
