openapi: 3.1.0
info:
  title: PerfectRide Partner API
  version: 1.0.0-preview
  summary: Fulfil PerfectRide trips with your own drivers.
  description: |
    Source: https://developers.perfectride.io/docs

    Two halves:
    - Endpoints you implement (server `{partnerBaseUrl}`): PerfectRide calls them.
    - `POST /events` on PerfectRide: where you send trip events.
    - `POST /supply` on PerfectRide: driver counts, required every 1 to 5 minutes while drivers are online (at least every 15 minutes otherwise).
    - `webhooks.perfectrideEvent`: events PerfectRide sends to your webhook URL.

    Stops (additive, 2026-12-05): quotes and bookings may carry an optional `stops` array (up to 3), and you may send `trip.arrived_at_stop` and `trip.departed_stop`. We only send stops to partners whose Max stops (0 to 3, default 0, set in the partner portal) allows them.

    Money is in kobo (integers), NGN only. Times are ISO 8601 UTC.
    Payment is card or wallet in PerfectRide; the driver never collects money.

    Signing, both directions. Every request carries
    `Authorization: Bearer <key>`, `X-PR-Timestamp: <unix seconds>` and
    `X-PR-Signature: sha256=<hex>`, where
    `hex = HMAC-SHA256(shared_secret, "<timestamp>.<METHOD>.<path>.<body>")`.
    `path` is the path after the base URL with the query string
    (`/quotes`, `/trips/t_9931/cancel`, `/settlements?date=2026-12-03`); `/events`
    for events you send us; `/supply` for supply reports; `/` for events we send you. `body` is the raw body,
    empty for GET. Reject a wrong signature, or a timestamp more than 300 seconds
    from now, with 401.
  contact:
    name: PerfectRide
    email: hello@perfectride.io
    url: https://developers.perfectride.io/docs
servers:
  - url: "{partnerBaseUrl}"
    description: Your API. PerfectRide calls these endpoints.
    variables:
      partnerBaseUrl:
        default: https://partner.example/pr
        description: The base URL you give PerfectRide at onboarding.
security:
  - bearer: []
    prTimestamp: []
    prSignature: []
tags:
  - name: Required
    description: Endpoints you must implement.
  - name: Optional
    description: We use them when they exist. A 404 is fine.
  - name: PerfectRide
    description: Hosted by PerfectRide.
paths:
  /quotes:
    post:
      tags: [Required]
      operationId: createQuote
      summary: Get a quote
      description: 'Answer within 2 seconds. With no driver, answer 200 `{ "available": false }`. With `stops`, the price covers the whole route: pickup, each stop in order, then drop-off. No fee per stop.'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/QuoteRequest" }
            example:
              pickup: { lat: 4.8156, lng: 7.0345, address: "Hotel Presidential, Aba Road, Port Harcourt" }
              dropoff: { lat: 4.8242, lng: 6.9969, address: "Genesis Centre, GRA Phase 2, Port Harcourt" }
              ride_class: standard
              passengers: 1
              payment_method: perfectride
      responses:
        "200":
          description: A quote, or no supply.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: "#/components/schemas/Quote"
                  - $ref: "#/components/schemas/Unavailable"
              examples:
                quote:
                  value: { quote_id: q_8f21, price: 650000, eta_seconds: 300, expires_at: "2026-12-03T10:05:00Z" }
                unavailable:
                  value: { available: false }
        "401": { $ref: "#/components/responses/Unauthorized" }
  /trips:
    post:
      tags: [Required]
      operationId: bookTrip
      summary: Book a trip
      description: Idempotent. The same `Idempotency-Key` returns the same trip.
      parameters:
        - name: Idempotency-Key
          in: header
          required: true
          schema: { type: string, pattern: "^book:.+$" }
          example: "book:pr_55a9"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/BookRequest" }
            example:
              quote_id: q_8f21
              pr_trip_id: pr_55a9
              rider: { first_name: Ada, masked_phone: "+234803***4521" }
              payment_method: perfectride
      responses:
        "201":
          description: Booked (or the same trip again for a repeated key).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/BookResponse" }
              example: { partner_trip_id: t_9931, status: searching }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
  /trips/{partner_trip_id}/cancel:
    post:
      tags: [Required]
      operationId: cancelTrip
      summary: Cancel a trip
      description: |
        Idempotent by `Idempotency-Key`. If a booking call (`POST /trips`) times out or fails on our side,
        we send a best-effort cancel with OUR trip id (`pr_trip_id`) in the path, reason `rider_cancelled`
        and `Idempotency-Key: cancel:<pr_trip_id>`. Accept either id in the path.
      parameters:
        - $ref: "#/components/parameters/PartnerTripId"
        - name: Idempotency-Key
          in: header
          required: true
          schema: { type: string, pattern: "^cancel:.+$" }
          example: "cancel:t_9931"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/CancelRequest" }
            example: { reason: rider_cancelled }
      responses:
        "200":
          description: Cancelled.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/CancelResponse" }
              example: { status: cancelled, cancellation_fee: 0 }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
  /trips/{partner_trip_id}:
    get:
      tags: [Required]
      operationId: getTrip
      summary: Get a trip
      description: Used if an event is missed. Signed with an empty body.
      parameters:
        - $ref: "#/components/parameters/PartnerTripId"
      responses:
        "200":
          description: The trip.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Trip" }
              example:
                partner_trip_id: t_9931
                pr_trip_id: pr_55a9
                status: driver_assigned
                driver: { id: d_771, name: "Musa A." }
                vehicle: { make: Toyota, model: Corolla, plate: PHC-123-AB }
                location: { lat: 4.817, lng: 7.032 }
                updated_at: "2026-12-03T10:01:40Z"
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
  /trips/{partner_trip_id}/rating:
    post:
      tags: [Optional]
      operationId: rateTrip
      summary: Receive the rider's rating and tip
      description: Tips are 100% the driver's. We pay them to you with your payout.
      parameters:
        - $ref: "#/components/parameters/PartnerTripId"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/RatingRequest" }
            example: { stars: 4, tags: [on_time, clean_car], comment: "Great driver", tip: 50000 }
      responses:
        "200": { description: Received. }
        "404": { description: Not implemented, or unknown trip. Fine. }
  /settlements:
    get:
      tags: [Optional]
      operationId: getSettlementReport
      summary: Your report for a day
      description: A Nigerian calendar day (WAT), to compare with our statement. PerfectRide issues the statement.
      parameters:
        - name: date
          in: query
          required: true
          schema: { type: string, format: date }
          example: "2026-12-03"
      responses:
        "200":
          description: One row per trip.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SettlementReport" }
              example:
                date: "2026-12-03"
                trips:
                  - { pr_trip_id: pr_55a9, partner_trip_id: t_9931, status: completed, final_price: 650000, tip: 50000 }
        "404": { description: Not implemented. Fine. }
  /events:
    post:
      tags: [PerfectRide]
      operationId: sendEvent
      summary: Send a trip event to PerfectRide
      description: |
        Signed with path `/events`. Limits: 64 KB per event, 1,200 events a minute.
        Retry 409, 429, 5xx and timeouts with backoff: 1 s, doubling, up to 1 hour between tries, for 24 hours.
        Keep the same `event_id` on every try. Do not retry 400, 401 or 404 unchanged.
      servers:
        - url: https://www.perfectride.io/api/partner/v1
          description: Sandbox and live, told apart by key.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/PartnerEvent" }
            examples:
              driver_assigned:
                value:
                  event: trip.driver_assigned
                  event_id: ev_0001
                  partner_trip_id: t_9931
                  pr_trip_id: pr_55a9
                  occurred_at: "2026-12-03T10:01:12Z"
                  driver: { id: d_771, name: "Musa A.", phone: "+2348090001122", partner_driver_ref: drv_771, photo_url: "https://cdn.partner.example/d_771.jpg", rating: 4.9, trips: 2140 }
                  vehicle: { make: Toyota, model: Corolla, color: Black, plate: PHC-123-AB }
                  location: { lat: 4.817, lng: 7.032 }
                  eta_seconds: 240
              started:
                value: { event: trip.started, event_id: ev_0007, partner_trip_id: t_9931, pr_trip_id: pr_55a9, occurred_at: "2026-12-03T10:06:02Z", pin: "4821" }
              arrived_at_stop:
                value: { event: trip.arrived_at_stop, event_id: ev_0020, partner_trip_id: t_9931, pr_trip_id: pr_55a9, occurred_at: "2026-12-03T10:12:30Z", stop_order: 1 }
              departed_stop:
                value: { event: trip.departed_stop, event_id: ev_0021, partner_trip_id: t_9931, pr_trip_id: pr_55a9, occurred_at: "2026-12-03T10:15:10Z", stop_order: 1 }
              completed:
                value: { event: trip.completed, event_id: ev_0042, partner_trip_id: t_9931, pr_trip_id: pr_55a9, occurred_at: "2026-12-03T10:24:40Z", final_price: 650000 }
      responses:
        "200":
          description: Done. A duplicate event_id is done too. Stop.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/EventAccepted" }
              example: { ok: true, result: applied }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: |
            retry_later: it arrived before an earlier event, or the trip was busy. Retry with backoff.
            complete_required: a cash trip that has started can't be cancelled. Send trip.completed when it ends.
            cancel_not_allowed: after the driver arrived, a cash trip can only be cancelled as a rider no-show (reason rider_no_show). Card and wallet trips are unchanged.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
              example: { error: { code: retry_later, message: "Retry this event" } }
        "411":
          description: length_required. Send a Content-Length header (chunked bodies are refused).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "413":
          description: too_large. Over 64 KB.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "422":
          description: wrong_pin (ask the driver again, send a new event), pin_locked (5 wrong codes; the trip cannot start) or fee_not_supported (cash trips take no cancellation fee in the pilot; send cancellation_fee 0).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
              example: { error: { code: wrong_pin, message: "Wrong rider code" } }
        "429":
          description: rate_limited. Retry after Retry-After.
          headers:
            Retry-After:
              schema: { type: integer }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
  /supply:
    post:
      tags: [PerfectRide]
      operationId: sendSupply
      summary: Report your drivers (required)
      description: |
        Required for every partner: every 1 to 5 minutes while you have drivers online, at least every 15 minutes otherwise.
        Aggregate counts only, no driver identities or exact locations. Signed with path `/supply`.
        Per state + city + tier: total, online and on-trip drivers; your fleet total; online drivers per ~5 km cell (geohash precision 5).
        We keep the latest report; it is stale after 10 minutes. A certification run needs one valid report.
        Limits: 64 KB, 60 reports a minute.
      servers:
        - url: https://www.perfectride.io/api/partner/v1
          description: Sandbox and live, told apart by key.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/SupplyReport" }
            example:
              reported_at: "2026-12-05T09:30:00Z"
              fleet_total_drivers: 420
              areas:
                - { state: Rivers, city: Port Harcourt, tier: Economy, total_drivers: 180, online_drivers: 42, on_trip_drivers: 17 }
                - { state: FCT, tier: Comfort, total_drivers: 60, online_drivers: 11, on_trip_drivers: 4 }
              cells:
                - { geohash5: s0v52, tier: Economy, online_drivers: 9 }
                - { geohash5: s1t7d, tier: Comfort, online_drivers: 3 }
      responses:
        "200":
          description: Stored. `ignored` counts rows older than a report we already hold.
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok: { type: boolean }
                  stored: { type: integer }
                  ignored: { type: integer }
                  cells: { type: integer }
                  stale_after_seconds: { type: integer }
              example: { ok: true, stored: 3, ignored: 0, cells: 2, stale_after_seconds: 600 }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "411":
          description: length_required. Send a Content-Length header (chunked bodies are refused).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "413":
          description: too_large. Over 64 KB.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "422":
          description: inconsistent_counts. online_drivers over total_drivers, or on_trip_drivers over online_drivers.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
              example: { error: { code: inconsistent_counts, message: "areas[0]: online_drivers (50) is more than total_drivers (40)" } }
        "429":
          description: rate_limited. Retry after Retry-After.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
webhooks:
  perfectrideEvent:
    post:
      summary: Events PerfectRide sends you
      description: |
        POSTed to your webhook URL, signed the same way with path `/`.
        Retried with backoff for 24 hours until you answer 2xx. Use `event_id` to ignore repeats.

        `trip.rider_contact` is sent on live trips when a driver is assigned, and again when you reassign the trip
        to the new driver. The number is for the driver to call the rider about the pickup only.
        Rider data belongs to PerfectRide. You may show it to the assigned driver (the driver app may keep showing it to that driver for that trip) and use it only to run that trip and handle its support, safety and legal issues. You must not add our riders to your own user or customer database, create accounts for them, market to them (calls, SMS, WhatsApp, email, push), sell or share the data, or use it to build profiles. Delete rider personal data from your systems within 30 days of the trip, except where the law requires you to keep it. PerfectRide may audit this and suspend you for a breach.
        Driver data: for every trip you share the assigned driver's name, phone, photo, car and plate with PerfectRide. PerfectRide may contact the driver directly about safety, lost items, complaints and legal matters. On request you give PerfectRide the driver's full legal name, ID and licence details and the trip records: within 24 hours, or right away in a safety emergency. You keep a 24/7 safety contact (name and phone) in your portal settings; it is required before the pilot. PerfectRide does not recruit or market to your drivers using this data.
        For something left in the car after the trip, the driver contacts PerfectRide through you; the rider uses Report a problem,
        "Left something in the car", in our app.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/PerfectRideEvent" }
            examples:
              statement_ready:
                value: { event: statement.ready, event_id: pev_7f3a, occurred_at: "2026-12-04T06:00:00Z", date: "2026-12-03", trips: 38, amount: 21450000 }
              driver_paused:
                value: { event: driver.paused, event_id: pev_11c2, occurred_at: "2026-12-03T12:00:00Z", driver_id: d_771, reason: rider_complaints, until: "2026-12-10T00:00:00Z" }
              rider_contact:
                value: { event: trip.rider_contact, event_id: pev_21d4, occurred_at: "2026-12-03T10:01:13Z", pr_trip_id: pr_55a9, partner_trip_id: t_9931, rider: { first_name: Ada, phone: "+2348031234521" } }
      responses:
        "200": { description: Received. }
        "401": { description: Wrong key, signature or timestamp. }
components:
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: The receiver's key for the sender. Sandbox `prk_test_`, live `prk_live_`.
    prTimestamp:
      type: apiKey
      in: header
      name: X-PR-Timestamp
      description: Unix seconds. Rejected when more than 300 seconds from now.
    prSignature:
      type: apiKey
      in: header
      name: X-PR-Signature
      description: '`sha256=` + lowercase hex HMAC-SHA256(shared_secret, "<timestamp>.<METHOD>.<path>.<body>").'
  parameters:
    PartnerTripId:
      name: partner_trip_id
      in: path
      required: true
      schema: { type: string }
      example: t_9931
  responses:
    BadRequest:
      description: Fix the request. Do not retry unchanged.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Unauthorized:
      description: unauthorized, bad_signature or stale_timestamp.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example: { error: { code: bad_signature, message: "X-PR-Signature does not match" } }
    NotFound:
      description: unknown_trip.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
  schemas:
    SupplyReport:
      type: object
      required: [reported_at, fleet_total_drivers, areas, cells]
      properties:
        reported_at: { type: string, format: date-time, description: When you counted. At most 5 minutes ahead of our clock, at most 24 hours old. }
        fleet_total_drivers: { type: integer, minimum: 0, description: "All your active drivers, every area (for example, drove in the last 30 days)." }
        areas:
          type: array
          minItems: 1
          maxItems: 50
          items:
            type: object
            required: [state, tier, total_drivers, online_drivers]
            properties:
              state: { type: string, description: 'A Nigerian state, e.g. Rivers, FCT, Lagos ("Abuja", "Port Harcourt" understood).' }
              city: { type: string, maxLength: 80, description: Leave out for the whole state. }
              tier: { type: string, enum: [Economy, Comfort, Premium] }
              total_drivers: { type: integer, minimum: 0, description: Active drivers on your platform in this area and tier. }
              online_drivers: { type: integer, minimum: 0, description: "Online now, free or on a trip. At most total_drivers." }
              on_trip_drivers: { type: integer, minimum: 0, description: "On a trip now. At most online_drivers. Recommended." }
        cells:
          type: array
          maxItems: 500
          description: Online drivers per ~5 km cell. Empty when nobody is online; leave out cells with 0.
          items:
            type: object
            required: [geohash5, tier, online_drivers]
            properties:
              geohash5: { type: string, pattern: "^[0-9b-hjkmnp-z]{5}$", description: Geohash, precision 5. }
              tier: { type: string, enum: [Economy, Comfort, Premium] }
              online_drivers: { type: integer, minimum: 0 }
    Kobo:
      type: integer
      minimum: 0
      description: Money in kobo. 650000 = NGN 6,500.
    LatLng:
      type: object
      required: [lat, lng]
      properties:
        lat: { type: number }
        lng: { type: number }
    Place:
      allOf:
        - $ref: "#/components/schemas/LatLng"
        - type: object
          required: [address]
          properties:
            address: { type: string }
    Driver:
      type: object
      required: [id, name, phone]
      properties:
        id: { type: string }
        name: { type: string }
        phone: { type: string, description: "Required. International (+234XXXXXXXXXX) or local Nigerian (0XXXXXXXXXX). Missing or invalid gets 400 invalid_event. Riders see a Call driver button (pickup calls only)." }
        licence_number: { type: string, maxLength: 40, description: Optional. }
        partner_driver_ref: { type: string, maxLength: 128, description: "Optional. Your own reference for the driver." }
        photo_url: { type: string, format: uri }
        rating: { type: number }
        trips: { type: integer }
    Vehicle:
      type: object
      required: [make, model, plate]
      properties:
        make: { type: string }
        model: { type: string }
        color: { type: string }
        plate: { type: string }
    RideClass:
      type: string
      enum: [standard, comfort, premium]
      description: |
        standard (Economy): any car, with or without AC.
        comfort: working AC and a clean car.
        premium: premium makes and models such as Mercedes-Benz, Toyota Prado or Land Cruiser, Lexus, BMW, Range Rover.
        Quote only cars that meet the class.
    TripStatus:
      type: string
      enum: [searching, driver_assigned, driver_arrived, started, completed, cancelled, no_driver]
    QuoteRequest:
      type: object
      required: [pickup, dropoff, ride_class, passengers, payment_method]
      properties:
        pickup: { $ref: "#/components/schemas/Place" }
        dropoff: { $ref: "#/components/schemas/Place" }
        ride_class: { $ref: "#/components/schemas/RideClass" }
        passengers: { type: integer, minimum: 1 }
        payment_method: { type: string, const: perfectride }
        stops: { $ref: "#/components/schemas/Stops" }
    Stops:
      type: array
      maxItems: 3
      description: Optional, additive (2026-12-05). Up to 3 stops between pickup and drop-off, in driving order. Absent or empty means no stops. Only sent when your Max stops (partner portal, Settings) is at least the number of stops. The price covers pickup, each stop in order, then drop-off; no fee per stop. Waiting at stops is handled by PerfectRide with the rider, not added to the price.
      items: { $ref: "#/components/schemas/Stop" }
    Stop:
      allOf:
        - $ref: "#/components/schemas/Place"
        - type: object
          required: [order]
          properties:
            order: { type: integer, minimum: 1, maximum: 3, description: "Position in driving order, 1 to N." }
    Quote:
      type: object
      required: [quote_id, price, eta_seconds, expires_at]
      description: The price is final in the pilot. Your commission is in your contract; a `commission_rate_bps` field is ignored.
      properties:
        quote_id: { type: string }
        price: { $ref: "#/components/schemas/Kobo" }
        eta_seconds: { type: integer }
        expires_at: { type: string, format: date-time }
    Unavailable:
      type: object
      required: [available]
      properties:
        available: { type: boolean, const: false }
    BookRequest:
      type: object
      required: [quote_id, pr_trip_id, rider, payment_method]
      properties:
        quote_id: { type: string }
        pr_trip_id: { type: string }
        rider:
          type: object
          required: [first_name, masked_phone]
          properties:
            first_name: { type: string }
            phone: { type: string, deprecated: true, description: "Deprecated. No longer sent; ignore it if your code reads it. The full number arrives in trip.rider_contact." }
            masked_phone: { type: string, description: The rider's number with the middle hidden. }
        stops: { $ref: "#/components/schemas/Stops" }
        payment_method: { type: string, enum: [perfectride, cash], description: "cash only for partners PerfectRide switched cash on for." }
        amount_to_collect: { type: integer, description: "Cash trips: kobo the driver collects, exactly (the whole price the rider saw)." }
        brand: { type: string, const: PerfectRide, description: "Show the trip in your driver app as a PerfectRide trip; the trip-complete screen shows Powered by PerfectRide." }
        prepaid: { type: boolean, description: "true: label the trip PAID ₦X · held, released when the trip ends (the driver takes no money). false: label it CASH ₦X with amount_to_collect, and the driver takes exactly that." }
    BookResponse:
      type: object
      required: [partner_trip_id, status]
      properties:
        partner_trip_id: { type: string }
        status: { type: string, const: searching }
    CancelRequest:
      type: object
      required: [reason]
      properties:
        reason: { type: string, enum: [rider_cancelled, no_driver_in_time, driver_paused] }
    CancelResponse:
      type: object
      required: [status, cancellation_fee]
      properties:
        status: { type: string, const: cancelled }
        cancellation_fee: { type: integer, const: 0 }
    Trip:
      type: object
      required: [partner_trip_id, pr_trip_id, status, updated_at]
      properties:
        partner_trip_id: { type: string }
        pr_trip_id: { type: string }
        status: { $ref: "#/components/schemas/TripStatus" }
        driver: { $ref: "#/components/schemas/Driver" }
        vehicle: { $ref: "#/components/schemas/Vehicle" }
        location: { $ref: "#/components/schemas/LatLng" }
        updated_at: { type: string, format: date-time }
    RatingTag:
      type: string
      enum: [on_time, clean_car, safe_driving, polite, good_route, late, unsafe_driving, wrong_route, overcharged, asked_for_cash, rude]
    RatingRequest:
      type: object
      required: [stars, tags, tip]
      properties:
        stars: { type: integer, minimum: 1, maximum: 5 }
        tags: { type: array, items: { $ref: "#/components/schemas/RatingTag" } }
        comment: { type: string }
        tip: { $ref: "#/components/schemas/Kobo" }
    SettlementReport:
      type: object
      required: [date, trips]
      properties:
        date: { type: string, format: date }
        trips:
          type: array
          items:
            type: object
            required: [pr_trip_id, partner_trip_id, status, final_price]
            properties:
              pr_trip_id: { type: string }
              partner_trip_id: { type: string }
              status: { $ref: "#/components/schemas/TripStatus" }
              final_price: { $ref: "#/components/schemas/Kobo" }
              tip: { $ref: "#/components/schemas/Kobo" }
    ErrorCode:
      type: string
      enum: [unauthorized, bad_signature, stale_timestamp, invalid_json, invalid_event, invalid_supply, inconsistent_counts, unknown_trip, trip_mismatch, wrong_pin, pin_locked, retry_later, complete_required, cancel_not_allowed, fee_not_supported, length_required, too_large, rate_limited]
    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message]
          properties:
            code:
              description: One of ErrorCode for our answers. Your own codes are fine on your endpoints.
              anyOf:
                - $ref: "#/components/schemas/ErrorCode"
                - type: string
            message: { type: string }
    EventAccepted:
      type: object
      required: [ok, result]
      properties:
        ok: { type: boolean, const: true }
        result: { type: string, enum: [applied, duplicate] }
    TripEventBase:
      type: object
      required: [event, event_id, partner_trip_id, pr_trip_id, occurred_at]
      properties:
        event: { type: string }
        event_id: { type: string, description: Unique per event. Keep it the same on retries. }
        partner_trip_id: { type: string }
        pr_trip_id: { type: string }
        occurred_at: { type: string, format: date-time }
    DriverAssignedEvent:
      description: A driver accepts. Send again with the new driver if you reassign before pickup.
      allOf:
        - $ref: "#/components/schemas/TripEventBase"
        - type: object
          required: [event, driver, vehicle, eta_seconds]
          properties:
            event: { const: trip.driver_assigned }
            driver: { $ref: "#/components/schemas/Driver" }
            vehicle: { $ref: "#/components/schemas/Vehicle" }
            eta_seconds: { type: integer }
            location: { $ref: "#/components/schemas/LatLng" }
    DriverLocationEvent:
      description: Every 10 s before pickup, every 30 s on the trip.
      allOf:
        - $ref: "#/components/schemas/TripEventBase"
        - type: object
          required: [event, location]
          properties:
            event: { const: trip.driver_location }
            location: { $ref: "#/components/schemas/LatLng" }
    DriverArrivedEvent:
      description: At pickup.
      allOf:
        - $ref: "#/components/schemas/TripEventBase"
        - type: object
          properties:
            event: { const: trip.driver_arrived }
    StartedEvent:
      description: The driver entered the rider's 4-digit code. 422 wrong_pin if it is wrong; pin_locked after 5 wrong codes.
      allOf:
        - $ref: "#/components/schemas/TripEventBase"
        - type: object
          required: [event, pin]
          properties:
            event: { const: trip.started }
            pin: { type: string, pattern: "^[0-9]{4}$" }
    ArrivedAtStopEvent:
      description: Optional. The driver reached a stop. Send only between trip.started and trip.completed. Before trip.started we answer 409 retry_later; a stop_order the trip does not have is 400 invalid_event; a repeat is a duplicate (200). Does not change the trip status.
      allOf:
        - $ref: "#/components/schemas/TripEventBase"
        - type: object
          required: [event, stop_order]
          properties:
            event: { const: trip.arrived_at_stop }
            stop_order: { type: integer, minimum: 1, maximum: 3 }
    DepartedStopEvent:
      description: Optional. The driver left a stop. Same rules as trip.arrived_at_stop.
      allOf:
        - $ref: "#/components/schemas/TripEventBase"
        - type: object
          required: [event, stop_order]
          properties:
            event: { const: trip.departed_stop }
            stop_order: { type: integer, minimum: 1, maximum: 3 }
    CompletedEvent:
      description: Drop-off. final_price must equal the quoted price; a different number is flagged for review, never paid.
      allOf:
        - $ref: "#/components/schemas/TripEventBase"
        - type: object
          required: [event, final_price]
          properties:
            event: { const: trip.completed }
            final_price: { $ref: "#/components/schemas/Kobo" }
    CancelledEvent:
      description: Your side cancels.
      allOf:
        - $ref: "#/components/schemas/TripEventBase"
        - type: object
          required: [event, cancelled_by, reason]
          properties:
            event: { const: trip.cancelled }
            cancelled_by: { type: string, enum: [driver, partner] }
            reason: { type: string }
    NoDriverEvent:
      description: Nobody could take it, within 3 minutes of booking.
      allOf:
        - $ref: "#/components/schemas/TripEventBase"
        - type: object
          properties:
            event: { const: trip.no_driver }
    RiderRatedEvent:
      description: Optional. The driver rated the rider.
      allOf:
        - $ref: "#/components/schemas/TripEventBase"
        - type: object
          required: [event, stars, tags]
          properties:
            event: { const: trip.rider_rated }
            stars: { type: integer, minimum: 1, maximum: 5 }
            tags: { type: array, items: { type: string } }
    PartnerEvent:
      oneOf:
        - $ref: "#/components/schemas/DriverAssignedEvent"
        - $ref: "#/components/schemas/DriverLocationEvent"
        - $ref: "#/components/schemas/DriverArrivedEvent"
        - $ref: "#/components/schemas/StartedEvent"
        - $ref: "#/components/schemas/ArrivedAtStopEvent"
        - $ref: "#/components/schemas/DepartedStopEvent"
        - $ref: "#/components/schemas/CompletedEvent"
        - $ref: "#/components/schemas/CancelledEvent"
        - $ref: "#/components/schemas/NoDriverEvent"
        - $ref: "#/components/schemas/RiderRatedEvent"
      discriminator:
        propertyName: event
        mapping:
          trip.driver_assigned: "#/components/schemas/DriverAssignedEvent"
          trip.driver_location: "#/components/schemas/DriverLocationEvent"
          trip.driver_arrived: "#/components/schemas/DriverArrivedEvent"
          trip.started: "#/components/schemas/StartedEvent"
          trip.arrived_at_stop: "#/components/schemas/ArrivedAtStopEvent"
          trip.departed_stop: "#/components/schemas/DepartedStopEvent"
          trip.completed: "#/components/schemas/CompletedEvent"
          trip.cancelled: "#/components/schemas/CancelledEvent"
          trip.no_driver: "#/components/schemas/NoDriverEvent"
          trip.rider_rated: "#/components/schemas/RiderRatedEvent"
    PerfectRideEventBase:
      type: object
      required: [event, event_id, occurred_at]
      properties:
        event: { type: string }
        event_id: { type: string }
        occurred_at: { type: string, format: date-time }
    DriverPausedEvent:
      allOf:
        - $ref: "#/components/schemas/PerfectRideEventBase"
        - type: object
          required: [event, driver_id, reason, until]
          properties:
            event: { const: driver.paused }
            driver_id: { type: string }
            reason: { type: string, enum: [rider_complaints, low_ratings, safety_review, documents, other] }
            until: { type: [string, "null"], format: date-time }
    DriverReinstatedEvent:
      allOf:
        - $ref: "#/components/schemas/PerfectRideEventBase"
        - type: object
          required: [event, driver_id]
          properties:
            event: { const: driver.reinstated }
            driver_id: { type: string }
    BalanceDueEvent:
      allOf:
        - $ref: "#/components/schemas/PerfectRideEventBase"
        - type: object
          required: [event, amount_due, currency, period_start, period_end]
          properties:
            event: { const: partner.balance_due }
            amount_due: { $ref: "#/components/schemas/Kobo" }
            currency: { type: string, const: NGN }
            period_start: { type: string, format: date }
            period_end: { type: string, format: date }
    AccountStatusChangedEvent:
      allOf:
        - $ref: "#/components/schemas/PerfectRideEventBase"
        - type: object
          required: [event, from, to]
          properties:
            event: { const: account.status_changed }
            from: { $ref: "#/components/schemas/AccountStatus" }
            to: { $ref: "#/components/schemas/AccountStatus" }
            reason: { type: string }
    StatementReadyEvent:
      description: What we owe you for that day.
      allOf:
        - $ref: "#/components/schemas/PerfectRideEventBase"
        - type: object
          required: [event, date, trips, amount]
          properties:
            event: { const: statement.ready }
            date: { type: string, format: date }
            trips: { type: integer }
            amount: { $ref: "#/components/schemas/Kobo" }
    RiderContactEvent:
      description: A driver was assigned (or the trip was reassigned). The number is for pickup calls only.
      allOf:
        - $ref: "#/components/schemas/PerfectRideEventBase"
        - type: object
          required: [event, pr_trip_id, partner_trip_id, rider]
          properties:
            event: { const: trip.rider_contact }
            pr_trip_id: { type: string }
            partner_trip_id: { type: string }
            rider:
              type: object
              required: [first_name, phone]
              properties:
                first_name: { type: string }
                phone: { type: string }
    AccountStatus:
      type: string
      enum: [sandbox, in_review, pilot, live, paused]
    PerfectRideEvent:
      oneOf:
        - $ref: "#/components/schemas/DriverPausedEvent"
        - $ref: "#/components/schemas/DriverReinstatedEvent"
        - $ref: "#/components/schemas/BalanceDueEvent"
        - $ref: "#/components/schemas/AccountStatusChangedEvent"
        - $ref: "#/components/schemas/StatementReadyEvent"
        - $ref: "#/components/schemas/RiderContactEvent"
      discriminator:
        propertyName: event
        mapping:
          driver.paused: "#/components/schemas/DriverPausedEvent"
          driver.reinstated: "#/components/schemas/DriverReinstatedEvent"
          partner.balance_due: "#/components/schemas/BalanceDueEvent"
          account.status_changed: "#/components/schemas/AccountStatusChangedEvent"
          statement.ready: "#/components/schemas/StatementReadyEvent"
          trip.rider_contact: "#/components/schemas/RiderContactEvent"
