Skip to content

D2D

This page specifies Door-to-Door (D2D) settings, eligibility, the Passenger D2D request workflow, detour limits, and the Driver route-plan contract. D2D extends the main route with Passenger-specific pickup/drop-off legs.

Slice 6 boundary: Slice 6 implements company D2D settings and the Passenger D2D request/Manager review workflow. The Directions-based detour estimation and the GET /driver/trips/{id}/route-plan endpoint remain future work; Slice 6 exposes only the approved D2D pickup/drop-off points to the assigned Driver. Slice 4 created route-stop Bookings only and did not accept D2D fields.

1. D2D rule

  • D2D means pickup/drop-off at the Passenger's chosen point.
  • Eligibility requires all of:
  • the Company's D2D settings record exists and enabled is true,
  • per_trip_enabled is true (per-trip availability),
  • the requesting Passenger holds an approved Booking on a scheduled, future Trip, and
  • the requested points satisfy the pickup/drop-off rules and the service zone/radius.
  • A D2D point whose detour exceeds max_detour_minutes is rejected when detour estimation is implemented (future work). Slice 6 stores the configured limit but does not compute detours.
  • Passengers pay nothing; D2D does not add a payment path.

2. D2DSettings (Slice 6)

One settings record per Company, stored in d2d_settings with a unique company_id. It is the single source of truth for D2D configuration and supersedes the earlier companies.d2d_enabled / companies.d2d_max_detour_minutes columns. company_id is derived from the authenticated Manager's membership and is never accepted from a client. The record uses CompanyScope.

Field Type Default Rule
id integer — Generated.
company_id integer — Unique FK to companies; never client-supplied.
enabled boolean false Company-wide D2D master switch.
zone_lat number|null null Service zone centre latitude, -90..90. Must be supplied with zone_lng and service_radius_meters.
zone_lng number|null null Service zone centre longitude, -180..180. Must be supplied with zone_lat and service_radius_meters.
service_radius_meters integer|null null 1..50000. When set with the zone centre, every D2D point must be within this great-circle distance of the centre.
pickup_enabled boolean true Allow D2D pickup points.
dropoff_enabled boolean true Allow D2D drop-off points.
per_trip_enabled boolean true Per-trip availability: when false, no D2D request is accepted for any Trip.
max_detour_minutes integer 15 1..1440. Reserved for the future detour estimator.
created_at, updated_at datetime — UTC.

GET /api/company/d2d/settings returns the stored record or, when none exists, an unsaved default record (enabled: false, zone/radius null, the three toggles true, max_detour_minutes: 15). PUT /api/company/d2d/settings upserts the record; enabled is required, all other fields are optional and omitted fields take the defaults above. Supplying only part of the zone triple (zone_lat, zone_lng, service_radius_meters) is a 422.

3. D2DRequest (Slice 6)

A D2D request is a company-scoped record linking an approved Booking to a Passenger-chosen pickup and drop-off point. It has its own lifecycle; it does not mutate the Booking's pickup_type or add D2D columns to bookings.

Field Type Rule
id integer Generated.
company_id integer FK to companies; never client-supplied; CompanyScope.
trip_id integer FK to trips; must equal the Booking's Trip.
booking_id integer FK to bookings; one active request per Booking.
passenger_id integer FK to users; derived from the authenticated Passenger.
status string pending\|approved\|rejected\|cancelled.
pickup_address string Required, max 255.
pickup_lat number Required, -90..90.
pickup_lng number Required, -180..180.
dropoff_address string Required, max 255.
dropoff_lat number Required, -90..90.
dropoff_lng number Required, -180..180.
rejection_reason string|null Optional on reject, max 1000.
requested_at datetime Set on creation.
decided_at datetime|null Set on approve/reject.
cancelled_at datetime|null Set on cancel.
created_at, updated_at datetime UTC.

Pickup/drop-off combination (open question resolved): both points are required. A request always carries a pickup and a drop-off address with coordinates; pickup-only or drop-off-only requests are not accepted in Slice 6.

3.1 Status lifecycle

Current Action Actor Result
— Request Active Passenger with an approved Booking pending
pending Approve Manager of the Company approved, decided_at set
pending Reject (optional reason) Manager of the Company rejected, rejection_reason + decided_at set
pending\|approved Cancel System, when the Booking or Trip is cancelled cancelled, cancelled_at set
approved\|rejected\|cancelled Approve/Reject Manager 422 errors.status

cancelled is part of the status vocabulary and the domain transition set. Slice 6 does not expose a Passenger cancel endpoint; cancellation is reserved for system wiring when a Booking/Trip is cancelled.

3.2 One-request rule

At most one active (pending or approved) D2D request may exist per Booking. A duplicate active request returns 422 errors.booking_id. After rejection or cancellation the Passenger may request again. Request creation serializes on the Trip row, mirroring Booking creation.

4. Validation rules (Passenger request)

  1. D2D settings exist and enabled is true → otherwise 422 errors.d2d ("D2D is not enabled for this company.").
  2. per_trip_enabled is true → otherwise 422 errors.d2d.
  3. pickup_enabled is true → otherwise 422 errors.pickup; dropoff_enabled is true → otherwise 422 errors.dropoff.
  4. Trip exists in the Passenger's Company and is scheduled with a future departure_at → missing/cross-company 404, wrong status/timing 422 errors.trip.
  5. Booking exists in the Company, belongs to that Trip and to the authenticated Passenger, and is approved → missing/cross-company/other Passenger 404, wrong status 422 errors.booking.
  6. Coordinates are valid and paired → 422 field errors (pickup_lat, pickup_lng, dropoff_lat, dropoff_lng).
  7. When the service zone centre and radius are configured, each point must be within service_radius_meters of the centre (great-circle/haversine, mean Earth radius 6,371,000 m) → 422 errors.pickup / errors.dropoff.
  8. No other active request exists for the Booking → 422 errors.booking_id.

Tier and Trip seat limits are unaffected: a D2D request neither creates a subscription Seat nor occupies a Trip seat. The approved Booking already occupies its seat.

5. API contract (Slice 6)

All routes require auth:sanctum and the company middleware. company_id is never accepted from a client. Cross-tenant resources return 404; a suspended Company returns 403 {"message":"Company is suspended."}.

Method Path Auth / role Use case
GET /api/company/d2d/settings Manager GetSettings
PUT /api/company/d2d/settings Manager UpdateSettings
GET /api/company/d2d/requests Manager ListRequests
POST /api/company/d2d/requests/{id}/approve Manager ApproveRequest
POST /api/company/d2d/requests/{id}/reject Manager RejectRequest
POST /api/passenger/d2d/requests Active Passenger RequestD2D
GET /api/driver/trips/{id}/d2d-requests Active assigned Driver Driver D2D view

ListRequests filters: status=pending\|approved\|rejected\|cancelled\|all, trip_id, page, per_page (default 15, max 100). Collections use data, meta (current_page, last_page, per_page, total), and links.

POST /api/passenger/d2d/requests body:

{
  "trip_id": 12,
  "booking_id": 401,
  "pickup_address": "12 Sana'a Street",
  "pickup_lat": 15.3694,
  "pickup_lng": 44.1910,
  "dropoff_address": "Airport Terminal 1",
  "dropoff_lat": 15.4000,
  "dropoff_lng": 44.2200
}

POST /api/company/d2d/requests/{id}/reject body: optional { "reason": "Outside service zone" } (max 1000).

5.1 Resources

D2DSettingsResource: {id, company_id, enabled, zone_lat, zone_lng, service_radius_meters, pickup_enabled, dropoff_enabled, per_trip_enabled, max_detour_minutes, created_at, updated_at}. id is null for the unsaved default record.

D2DRequestResource (Manager/Passenger): {id, company_id, trip_id, booking_id, passenger:{id,name}, status, pickup_address, pickup_lat, pickup_lng, dropoff_address, dropoff_lat, dropoff_lng, rejection_reason, requested_at, decided_at, cancelled_at, created_at, updated_at}.

DriverD2DRequestResource: {id, trip_id, booking_id, status, pickup_address, pickup_lat, pickup_lng, dropoff_address, dropoff_lat, dropoff_lng}. It deliberately omits passenger, company_id, and all timestamps. The Driver view returns only approved requests for the assigned Trip. No phone, email, licence, document, or other-Passenger data is exposed on any D2D resource.

5.2 Errors

Case Status Envelope
Field validation / invalid coordinates / partial zone triple 422 message + field-level errors
D2D disabled or per-trip availability off 422 errors.d2d
Pickup/drop-off rule disabled 422 errors.pickup / errors.dropoff
Point outside service radius 422 errors.pickup / errors.dropoff
Trip not scheduled/future 422 errors.trip
Booking not approved 422 errors.booking
Duplicate active request 422 errors.booking_id
Invalid approve/reject transition 422 errors.status
Wrong role / inactive Passenger or Driver Membership 403 message only
Suspended Company 403 message only
Missing/cross-tenant Trip, Booking, Request, or unassigned Driver Trip 404 message only

6. Booking flow (with Slice 6 request)

sequenceDiagram
    autonumber
    participant P as Passenger App
    participant API as API
    participant M as Manager (Fleet Dashboard)
    participant D as Driver App

    P->>API: POST /passenger/trips/{id}/bookings (route-stop)
    API-->>P: 201 pending Booking
    M->>API: Approve Booking
    API-->>P: Booking approved
    P->>API: POST /passenger/d2d/requests {booking_id, points}
    API->>API: Check settings, Booking, Trip, zone, duplicate
    API-->>P: 201 pending D2D request
    M->>API: POST /company/d2d/requests/{id}/approve
    API-->>P: D2D request approved
    D->>API: GET /driver/trips/{id}/d2d-requests
    API-->>D: Approved pickup/drop-off points

7. Route plan (future work)

The main route is the default base. For each approved D2D point, compute where to leave the main route, how to reach the door, and where to rejoin. Use the Directions API with waypoints first; write a custom snap-and-rejoin planner only if Directions proves insufficient. Display the main route in one colour and each D2D leg as a secondary route with a Passenger label and detour minutes. The Driver decides when to take it. The same plan appears in the Fleet Dashboard Live tab and the Passenger live view. GET /driver/trips/{id}/route-plan is not implemented in Slice 6.

8. Data fields (physical)

Location Field Purpose
d2d_settings company_id, enabled, zone_lat, zone_lng, service_radius_meters, pickup_enabled, dropoff_enabled, per_trip_enabled, max_detour_minutes Company D2D configuration (Slice 6).
d2d_requests company_id, trip_id, booking_id, passenger_id, status, pickup_address, pickup_lat, pickup_lng, dropoff_address, dropoff_lat, dropoff_lng, rejection_reason, requested_at, decided_at, cancelled_at Passenger D2D request lifecycle (Slice 6).
trip_analytics d2d_detour_minutes Reported separately so detours are not blamed on Driver (future work).

9. Open questions (remaining)

  • Detour calculation basis: scheduled route duration, estimated no-D2D route, or live traffic baseline?
  • Recompute triggers: when a D2D request is approved/cancelled after a route plan is generated, when is the plan recomputed and how are Drivers/Passengers notified?
  • Point geometry constraints: maximum distance from the route corridor (beyond the company service radius), coordinate precision, and label requirements.
  • Eligibility changes: if company/member D2D is disabled after a request is approved, how existing approved requests are handled.
  • Directions fallback: the custom snap-and-rejoin planner trigger/behavior is intentionally deferred until Directions is insufficient.
  • Per-member eligibility: the earlier company_members.d2d_enabled toggle is not implemented in Slice 6; company-level settings plus an approved Booking gate D2D. Per-member bulk selection by gender remains a Fleet/Dashboard concern.