# Shift End

## Overview

The Shift End workflow closes the driver's shift and unlinks the Taxi Meter and Payment Terminal. The Taxi Meter initiates the shift end by logging the driver out. CabFare Connect notifies the linked Payment Terminal to unlink and sends all required shift data to the Subsidy Provider. If the driver logs out of the Payment Terminal first, CabFare Connect notifies the Taxi Meter, which must then determine whether to also log the driver out or continue in unlinked mode.

## Sequence Diagram

```mermaid
sequenceDiagram
    actor Driver
    participant TM as Taxi Meter
    participant CC as CabFare Connect
    participant PT as Payment Terminal

    alt Driver logs out of Taxi Meter first
        Driver->>TM: Logs out of Taxi Meter

        alt Taxi Meter printer configured
            TM-->>Driver: Prints End of Shift report
        end

        TM->>CC: POST /meter/driver/logout (taxiMeterId, driverId, shiftData)
        CC-->>TM: 200 OK or 204 No Content
        CC->>PT: POST /driver/logout (driverId)
        PT-->>Driver: Unlinks from Taxi Meter, logs driver out if configured

        CC-->>CC: Sends shift data to Subsidy Provider

    else Driver logs out of Payment Terminal first
        Driver->>PT: Logs out of Payment Terminal
        PT->>CC: POST /terminal/driver/logout (terminalId, driverId)
        CC-->>PT: 200 OK or 204 No Content
        CC->>TM: POST /driver/logout (driverId)
        TM-->>Driver: Notified of Payment Terminal logout
        Note over TM: Taxi Meter determines whether to log out or continue in unlinked mode
    end
```

## Step-by-Step

### Step 1 — Driver logs out of Taxi Meter

This is the standard end of shift process. The driver logs out of the Taxi Meter. The specific action may vary by implementation — for example a dedicated End Shift button or a logout option in the menu.

If the system is configured with a Taxi Meter printer the Taxi Meter prints an End of Shift report before sending the logout notification to CabFare Connect.

**Taxi Meter calls:**
`POST /meter/driver/logout`

**Required fields:** `taxiMeterId`, `driverId`, shift end data

The shift end data must include all required information for Subsidy Provider reporting. If any Subsidy Scheme trips were processed during the shift this data must always be included regardless of when or how the shift ends.

***

### Step 2 — CabFare Connect processes shift end

CabFare Connect receives the logout notification and:

- Ends the shift session
- Sends a logout notification to the linked Payment Terminal
- Sends all required shift data to the Subsidy Provider

**CabFare Connect calls:**
`POST /driver/logout` on the Payment Terminal

The Payment Terminal receives the notification, unlinks from the Taxi Meter, and logs the driver out if configured to do so.

***

### Step 3 — Alternative: Driver logs out of Payment Terminal first

If the driver logs out of the Payment Terminal before the Taxi Meter the Payment Terminal notifies CabFare Connect.

**Payment Terminal calls:**
`POST /terminal/driver/logout`

**Required fields:** `terminalId`, `driverId`

CabFare Connect sends a logout notification to the linked Taxi Meter.

**CabFare Connect calls:**
`POST /driver/logout` on the Taxi Meter

It is then up to the Taxi Meter provider to determine whether this also logs the driver out of the Taxi Meter or whether the Taxi Meter continues operating in unlinked mode. Regardless of when the driver logs out of the Taxi Meter, the Taxi Meter must always send CabFare Connect the required shift end data if any Subsidy Scheme trips were processed during the shift.

***

### Step 4 — Shift data submitted to Subsidy Provider

CabFare Connect sends all required shift information to the Subsidy Provider once the Taxi Meter logout is complete. This includes all trip data, subsidy payments, and lifting fees processed during the shift.

***

## Key Points

- The Taxi Meter must always send shift end data to CabFare Connect if any Subsidy Scheme trips were processed during the shift — this is required regardless of the logout sequence
- A Taxi Meter logout automatically triggers a logout notification to the linked Payment Terminal via CabFare Connect
- If the driver logs out of the Payment Terminal first, the Taxi Meter determines whether to also log out or continue in unlinked mode
- All Subsidy Provider reporting is handled by CabFare Connect — integration partners do not submit data directly to the Subsidy Provider
- The shift is not considered closed until `POST /meter/driver/logout` has been successfully received by CabFare Connect

---
Source: https://docs.cabfare.com/api/shift-end
