clock->now(); $booking = $this->bookings->find_by_id( $booking_id ); if ( null === $booking ) { throw new DomainException( 'booking.not_found', 'Booking not found.' ); } if ( ! $force ) { $policy = $this->policy->assert_cancellable( $booking, $now ); if ( $policy->is_err() ) { throw new DomainException( esc_html( $policy->error_code() ), esc_html( $policy->error_message() ) ); } } $cancelled = $this->tx->run( function () use ( $booking, $by, $reason, $now ): Booking { $booking->cancel( $by, $reason, $now ); $this->bookings->save( $booking, false ); return $booking; } ); $this->reminders->cancel_for_booking( (int) $cancelled->id() ); $this->bus->dispatch( new BookingCancelled( (int) $cancelled->id(), $cancelled->uuid(), $by, $reason, $now, $notify_customer ) ); return $cancelled; } }