, deposit_due_days: int, owner: array, bank: array} */ public static function capture(): array { return [ 'captured_at' => now()->toIso8601String(), 'texts' => collect(self::TEXT_KEYS)->mapWithKeys(fn (string $key): array => [$key => Content::get($key)])->all(), 'deposit_due_days' => (int) config('fewo.deposit_due_days'), 'owner' => (array) config('fewo.owner'), 'bank' => (array) config('fewo.bank'), ]; } public static function text(Booking $booking, string $key): ?string { $texts = $booking->offer_terms['texts'] ?? null; return is_array($texts) ? ($texts[$key] ?? null) : Content::get($key); } public static function html(Booking $booking, string $key): HtmlString { $value = self::text($booking, $key); return new HtmlString(filled($value) ? RichContentRenderer::make($value)->toHtml() : ''); } public static function depositDueDays(Booking $booking): int { return (int) ($booking->offer_terms['deposit_due_days'] ?? config('fewo.deposit_due_days')); } /** * @return array */ public static function owner(Booking $booking): array { return $booking->offer_terms['owner'] ?? (array) config('fewo.owner'); } /** * @return array */ public static function bank(Booking $booking): array { return $booking->offer_terms['bank'] ?? (array) config('fewo.bank'); } /** * Fingerprint of everything the guest agrees to in this offer version. The validity (hold_expires_at) is * not part of it – the landlord may extend it – but is checked separately. */ public static function hash(Booking $booking): string { return hash('sha256', json_encode(self::canonical([ 'version' => $booking->offer_version, 'arrival' => $booking->arrival->toDateString(), 'departure' => $booking->departure->toDateString(), 'guests' => $booking->guests, 'quote' => $booking->quote, 'total' => $booking->total, 'deposit' => $booking->deposit, 'balance_due_on' => $booking->balance_due_on->toDateString(), 'terms' => $booking->offer_terms, ]), JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE)); } private static function canonical(mixed $value): mixed { if (! is_array($value)) { return $value; } $value = array_map(self::canonical(...), $value); if (! array_is_list($value)) { ksort($value); } return $value; } }