fix: give chatbot pickups per-leg surcharges including the return leg
This commit is contained in:
1 parent
ac5ca7b18b
commit
3cb1548f2f
8 files changed
+58
-7
No files matched your search
@@ -585,6 +585,11 @@ class TripCatalog
|
||||
}
|
||||
|
||||
/**
|
||||
* BusPro prices a boarding point per leg, so a customer travelling both ways pays the
|
||||
* surcharge twice. Both legs and their sum are spelled out, because a single figure
|
||||
* reads as the whole price. A leg listed without a price is billed nothing, so it is 0;
|
||||
* the return is absent only where the point is not served on the way back.
|
||||
*
|
||||
* @param array<string, mixed> $row
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
@@ -598,12 +603,17 @@ class TripCatalog
|
||||
continue;
|
||||
}
|
||||
|
||||
$outbound = (float) ($pickup['price'] ?? 0);
|
||||
$return = ($pickup['returnLeg'] ?? false) ? (float) ($pickup['returnPrice'] ?? 0) : null;
|
||||
|
||||
$pickups[] = array_filter([
|
||||
'city' => $pickup['city'],
|
||||
'place' => $pickup['street'] ?? null,
|
||||
// A clock reading without an offset, as BusPro states it.
|
||||
'departure' => is_string($pickup['datetime'] ?? null) ? str_replace('T', ' ', substr($pickup['datetime'], 0, 16)) : null,
|
||||
'surcharge' => $pickup['price'] ?? null,
|
||||
'surchargeOutbound' => $outbound,
|
||||
'surchargeReturn' => $return,
|
||||
'surchargeRoundTrip' => null !== $return ? round($outbound + $return, 2) : null,
|
||||
], static fn (mixed $value): bool => null !== $value);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user