# 5. Set for payment

Committing is where **editing stops and paying starts**:

- Every calculation in the payroll, and the payroll itself, moves to `paymentStarted`.
- Salaxy **generates the invoices** — you never create them. The worker's `net` invoice is released to the payment channel as `unread`; the periodic `tax` and `union` invoices are prepared as `preview`.
- From here the payment moves on in the payment channel, and you follow it through statuses — [step 6](https://code.salaxy.com/get-started/rest/track-status.md).

Examples use the **test** environment (`test-secure.salaxy.com`); see [Environments](https://code.salaxy.com/get-started/environments.md) for demo and production.

## The endpoints

| Method | Endpoint | Does |
|---|---|---|
| `POST` | `/v03/api/payroll/validate` | Pre-check: returns per-calculation validation errors |
| `POST` | `/v03/api/invoices/create-for-payroll/{channel}/{payrollId}` | **Commits the whole payroll.** Returns the generated invoices |
| `POST` | `/v03/api/invoices/create-by-id/{channel}` | Commits only some calculations — body: an array of calculation ids, e.g. to re-submit one after a cancellation |

- `channel` — the payment channel code: `palkkausManual` in this guide; a real integration uses the channel provisioned for it.
- Prefer `create-for-payroll` for the normal case: `create-by-id` does not validate or stamp dates on the payroll as a whole.

The commit returns the generated invoices, trimmed here — the worker's `net` invoice released to the channel, and a periodic `tax` invoice in preview:

```json
[
  {
    "id": "<invoice id>",
    "header": { "type": "net", "status": "unread", "payrollId": "<payroll id>" }
  },
  {
    "id": "<invoice id>",
    "header": { "type": "tax", "status": "preview", "payrollId": "<payroll id>" }
  }
]
```

**Save for the next step:**
- The **calculation ids** from step 4 — the calculation is what you follow in [step 6](https://code.salaxy.com/get-started/rest/track-status.md), not the invoice.
- If you run the payment channel yourself, the invoices are what it pays: see [Payroll lifecycle and statuses](https://code.salaxy.com/integration/payroll-lifecycle.md).

## What can be committed

- **The payroll must validate.** Every calculation must be ready for payment — `info.isReadyForPayment` is `true` on the saved payroll. If it is not, the commit returns **400** with `error` and `messageHtml` (localised texts). **Validate first**: `payroll/validate` gives the per-calculation errors that the 400 body does not.
- **Calculations commit from their editable statuses:** `draft`, `payrollDraft`, `proDraft`, `waitingApproval`, `sharedApproved`. A `paymentStarted` calculation cannot be committed again, and a `paymentSucceeded` one is never paid twice — corrections to paid salaries go through Salaxy support.

For the whole flow after this point — invoices, timings, cancelling — see [Payroll lifecycle and statuses](https://code.salaxy.com/integration/payroll-lifecycle.md).

## Check

- You validated the payroll before committing.
- After the commit, the payroll and its calculations are `paymentStarted`, and the response lists the generated invoices.
- Your code never commits the same payroll twice without checking its status first.

**Runnable sample:**
The interactive version of this step — sign in and run it against your test account — is on the current developer site: [set for payment](https://code.salaxy.com/docs/set-for-payment). The runnable samples stay there; the steps and endpoints are here.

← [4. Create a payroll](https://code.salaxy.com/get-started/rest/create-payroll.md) · [6. Track the payment status](https://code.salaxy.com/get-started/rest/track-status.md) →
