# Quotes and booking

> The four endpoints you host: quote, book, cancel and get a trip.

## Quote

**Request**

```http
POST {your base URL}/quotes
```

**Body**

```json
{
  "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"
}
```

**Response 200**

```json
{ "quote_id": "q_8f21", "price": 650000, "eta_seconds": 300, "expires_at": "2026-12-03T10:05:00Z" }
```

**Response 200, no driver**

```json
{ "available": false }
```

- Answer within 2 seconds. No driver is not an error: answer `available: false`.
- `price` is what your own app charges for the same trip, in kobo. It is final in the pilot.
- Your commission is set in your contract, not per quote. `commission_rate_bps` is no longer sent; if you send it, it is ignored.
- Keep quotes valid for at least 2 minutes.
- Optional `stops`: see [Stops](https://docs.perfectride.io/docs/stops).

**cURL**

```bash
# Call your own sandbox the way PerfectRide does (signed with your secret).
# The signed path is the path after your base URL: /quotes.
TS=$(date +%s)
BODY='{"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"}'
SIG=$(printf '%s' "$TS.POST./quotes.$BODY" | openssl dgst -sha256 -hmac "$PR_SECRET" | sed 's/^.*= //')

curl "$YOUR_BASE_URL/quotes" \
  -H "Authorization: Bearer $KEY_YOU_GAVE_US" \
  -H "Content-Type: application/json" \
  -H "X-PR-Timestamp: $TS" \
  -H "X-PR-Signature: sha256=$SIG" \
  --data-raw "$BODY"
```

**Node**

```javascript
// Express. prVerify is in Keys and signing.
app.post("/quotes", express.raw({ type: "application/json" }), (req, res) => {
  const raw = req.body.toString("utf8");
  if (req.get("authorization") !== `Bearer ${process.env.OUR_KEY}` ||
      !prVerify(process.env.PR_SECRET, "POST", "/quotes", raw, req.headers)) {
    return res.status(401).json({ error: { code: "bad_signature", message: "Signature does not match" } });
  }
  const q = JSON.parse(raw);
  const offer = priceFor(q.pickup, q.dropoff, q.ride_class, q.stops || []); // your own pricing
  if (!offer) return res.json({ available: false }); // no driver: not an error
  res.json({
    quote_id: offer.id,
    price: offer.kobo, // what your own app charges, in kobo
    eta_seconds: offer.etaSeconds,
    expires_at: new Date(Date.now() + 2 * 60_000).toISOString(),
  });
});
```

**Python**

```python
# Flask. pr_verify is in Keys and signing.
from flask import Flask, request, jsonify
import datetime, json, os

app = Flask(__name__)

@app.post("/quotes")
def quotes():
    raw = request.get_data(as_text=True)
    if request.headers.get("Authorization") != f"Bearer {os.environ['OUR_KEY']}" or \
       not pr_verify(os.environ["PR_SECRET"], "POST", "/quotes", raw, request.headers):
        return jsonify(error={"code": "bad_signature", "message": "Signature does not match"}), 401
    q = json.loads(raw)
    offer = price_for(q["pickup"], q["dropoff"], q["ride_class"], q.get("stops", []))  # your own pricing
    if offer is None:
        return jsonify(available=False)  # no driver: not an error
    expires = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(minutes=2)
    return jsonify(quote_id=offer.id, price=offer.kobo, eta_seconds=offer.eta_seconds,
                   expires_at=expires.isoformat())
```

**PHP**

```php
<?php
// quotes.php. pr_verify is in Keys and signing.
$raw = file_get_contents('php://input');
header('Content-Type: application/json');
if (($_SERVER['HTTP_AUTHORIZATION'] ?? '') !== 'Bearer ' . getenv('OUR_KEY')
    || !pr_verify(getenv('PR_SECRET'), 'POST', '/quotes', $raw)) {
    http_response_code(401);
    echo json_encode(['error' => ['code' => 'bad_signature', 'message' => 'Signature does not match']]);
    exit;
}
$q = json_decode($raw, true);
$offer = price_for($q['pickup'], $q['dropoff'], $q['ride_class'], $q['stops'] ?? []); // your own pricing
if (!$offer) { echo json_encode(['available' => false]); exit; } // no driver: not an error
echo json_encode([
    'quote_id' => $offer['id'],
    'price' => $offer['kobo'],
    'eta_seconds' => $offer['eta_seconds'],
    'expires_at' => gmdate('Y-m-d\TH:i:s\Z', time() + 120),
]);
```

## Ride classes

| `ride_class` | Our name | The car |
|---|---|---|
| `standard` | Economy | Any car, with or without AC |
| `comfort` | Comfort | Working AC, and the car is clean |
| `premium` | Premium | Premium makes and models: Mercedes-Benz, Toyota Prado or Land Cruiser, Lexus, BMW, Range Rover and similar |

Quote only cars that meet the class. Riders report a car below its class like a wrong car.

## Book

**Request**

```http
POST {your base URL}/trips
Idempotency-Key: book:pr_55a9
```

**Body**

```json
{
  "quote_id": "q_8f21",
  "pr_trip_id": "pr_55a9",
  "rider": { "first_name": "Ada", "masked_phone": "+234803***4521" },
  "payment_method": "perfectride",
  "brand": "PerfectRide",
  "prepaid": true
}
```

**Response 201**

```json
{ "partner_trip_id": "t_9931", "status": "searching" }
```

- The same `Idempotency-Key` again returns the same trip. Never create a second one.
- `masked_phone` is for screens. The full number comes later in `trip.rider_contact`. `rider.phone` is no longer sent; ignore it if your code reads it.
- Show `brand` and `prepaid` to your driver: see [Driver app rules](https://docs.perfectride.io/docs/driver-app-rules).
- Cash bookings carry `payment_method: "cash"`, `prepaid: false` and `amount_to_collect`: see [Cash trips](https://docs.perfectride.io/docs/cash-trips).

**cURL**

```bash
TS=$(date +%s)
BODY='{"quote_id":"q_8f21","pr_trip_id":"pr_55a9","rider":{"first_name":"Ada","masked_phone":"+234803***4521"},"payment_method":"perfectride","brand":"PerfectRide","prepaid":true}'
SIG=$(printf '%s' "$TS.POST./trips.$BODY" | openssl dgst -sha256 -hmac "$PR_SECRET" | sed 's/^.*= //')

# Run it twice: the second answer must be the same trip.
curl "$YOUR_BASE_URL/trips" \
  -H "Authorization: Bearer $KEY_YOU_GAVE_US" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: book:pr_55a9" \
  -H "X-PR-Timestamp: $TS" \
  -H "X-PR-Signature: sha256=$SIG" \
  --data-raw "$BODY"
```

**Node**

```javascript
const trips = new Map(); // use your database

app.post("/trips", express.raw({ type: "application/json" }), (req, res) => {
  const raw = req.body.toString("utf8");
  if (!prVerify(process.env.PR_SECRET, "POST", "/trips", raw, req.headers)) {
    return res.status(401).json({ error: { code: "bad_signature", message: "Signature does not match" } });
  }
  const key = req.get("idempotency-key");
  if (trips.has(key)) return res.status(201).json(trips.get(key)); // same key, same trip
  const b = JSON.parse(raw);
  const trip = { partner_trip_id: createTrip(b), status: "searching" }; // your dispatch
  trips.set(key, trip);
  res.status(201).json(trip);
});
```

**Python**

```python
trips = {}  # use your database

@app.post("/trips")
def book():
    raw = request.get_data(as_text=True)
    if not pr_verify(os.environ["PR_SECRET"], "POST", "/trips", raw, request.headers):
        return jsonify(error={"code": "bad_signature", "message": "Signature does not match"}), 401
    key = request.headers["Idempotency-Key"]
    if key in trips:
        return jsonify(trips[key]), 201  # same key, same trip
    b = json.loads(raw)
    trips[key] = {"partner_trip_id": create_trip(b), "status": "searching"}  # your dispatch
    return jsonify(trips[key]), 201
```

**PHP**

```php
<?php
// trips.php. Store trips by Idempotency-Key in your database.
$raw = file_get_contents('php://input');
header('Content-Type: application/json');
if (!pr_verify(getenv('PR_SECRET'), 'POST', '/trips', $raw)) {
    http_response_code(401);
    echo json_encode(['error' => ['code' => 'bad_signature', 'message' => 'Signature does not match']]);
    exit;
}
$key = $_SERVER['HTTP_IDEMPOTENCY_KEY'] ?? '';
$trip = find_trip_by_key($key); // same key, same trip
if (!$trip) {
    $trip = ['partner_trip_id' => create_trip(json_decode($raw, true)), 'status' => 'searching'];
    save_trip_by_key($key, $trip);
}
http_response_code(201);
echo json_encode($trip);
```

## Cancel

**Request**

```http
POST {your base URL}/trips/{partner_trip_id}/cancel
Idempotency-Key: cancel:t_9931
```

**Body**

```json
{ "reason": "rider_cancelled" }
```

**Response 200**

```json
{ "status": "cancelled", "cancellation_fee": 0 }
```

- Reasons: `rider_cancelled`, `no_driver_in_time`, `driver_paused`.
- If a booking call times out or fails on our side, we send a best-effort cancel with our `pr_trip_id` in the path, reason `rider_cancelled` and `Idempotency-Key: cancel:<pr_trip_id>`. Accept either id.

## Get a trip

We call it if an event is missed.

**Request**

```http
GET {your base URL}/trips/{partner_trip_id}
```

**Response 200**

```json
{
  "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.8170, "lng": 7.0320 },
  "updated_at": "2026-12-03T10:01:40Z"
}
```

## How we call you

|   | Rule |
|---|---|
| Timeout | 2 seconds for quotes, 8 seconds for every other call |
| Redirects | Not followed. Answer at the URL you gave us |
| Hosts | Public HTTPS hosts only |
| User-Agent | `PerfectRide-PartnerAPI/1` |
| Signed path | The path after your base URL: base `https://api.you.example/pr` and call `/quotes` signs `/quotes` |

## Next

- [Trip events](https://docs.perfectride.io/docs/trip-events.md): Tell PerfectRide what happens on each trip, in order, and handle our answers.
- [Rider code (PIN)](https://docs.perfectride.io/docs/rider-code.md): A trip starts only when your driver enters the rider's 4-digit code.
- [Stops](https://docs.perfectride.io/docs/stops.md): Up to 3 stops between pickup and drop-off, priced in your quote. Off until you turn them on.

Source: https://docs.perfectride.io/docs/quotes-and-booking
