diff --git a/.env b/.env index 0938e5a..2805a26 100644 --- a/.env +++ b/.env @@ -84,7 +84,7 @@ APP_TRAVEL_SNAPSHOT_RETENTION_BUFFER_DAYS=14 # Emails APP_DEFAULT_EMAIL_FROM=info@ep-reisen.de APP_DEFAULT_EMAIL_TO=info@ep-reisen.de -ACCOMMODATION_INQUIRY_EMAIL=info@ep-reisen.de +ACCOMMODATION_INQUIRY_EMAIL=gruppen@ep-reisen.de # Global common defaults APP_SEASON_WINTER_FROM=2026-10-01 diff --git a/config/services.yaml b/config/services.yaml index ebd8ae9..2c78cb1 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -265,7 +265,7 @@ services: App\Service\AccommodationBookingService: arguments: - $officeEmail: '%accommodation_inquiry_email%' + $accommodationEmail: '%accommodation_inquiry_email%' App\Service\GroupsPriceCalculator: arguments: diff --git a/src/Service/AccommodationBookingService.php b/src/Service/AccommodationBookingService.php index cda3557..5c3dc4c 100644 --- a/src/Service/AccommodationBookingService.php +++ b/src/Service/AccommodationBookingService.php @@ -37,7 +37,7 @@ class AccommodationBookingService private readonly CmsDataProvider $cmsDataProvider, private readonly AccommodationBookingLinkSigner $linkSigner, private readonly AccommodationBookingBreakdownCalculator $breakdownCalculator, - private readonly string $officeEmail, + private readonly string $accommodationEmail, ) { } @@ -369,6 +369,30 @@ class AccommodationBookingService public function sendNotificationEmail(AccommodationBooking $booking): void { + $this->sendBookingEmail( + $booking, + $this->accommodationEmail, + sprintf( + 'Neue Unterkunfts%s: %s', + $booking->isInquiry() ? 'anfrage' : 'buchung', + $booking->getAccommodation()?->getName(), + ), + 'email/accommodation_booking.html.twig', + 'Failed to send accommodation booking notification email', + ); + } + + /** + * All accommodation mail is sent from the group desk address so customer replies + * land there rather than in the general inbox. + */ + private function sendBookingEmail( + AccommodationBooking $booking, + string $to, + string $subject, + string $template, + string $errorMessage, + ): void { try { $this->mailer->createAndSendEmail( [ @@ -376,18 +400,15 @@ class AccommodationBookingService 'accessLink' => $this->accessLinkOrNull($booking), ], [ - 'to' => $this->officeEmail, - 'subject' => sprintf( - 'Neue Unterkunfts%s: %s', - $booking->isInquiry() ? 'anfrage' : 'buchung', - $booking->getAccommodation()?->getName(), - ), - 'template' => 'email/accommodation_booking.html.twig', + 'from' => $this->accommodationEmail, + 'to' => $to, + 'subject' => $subject, + 'template' => $template, 'attachments' => [], ], ); } catch (\Throwable $e) { - $this->logger->error('Failed to send accommodation booking notification email', [ + $this->logger->error($errorMessage, [ 'booking_id' => $booking->getId(), 'error' => $e->getMessage(), ]); @@ -415,27 +436,15 @@ class AccommodationBookingService */ public function sendCustomerConfirmationEmail(AccommodationBooking $booking): void { - try { - $this->mailer->createAndSendEmail( - [ - 'booking' => $booking, - 'accessLink' => $this->accessLinkOrNull($booking), - ], - [ - 'to' => $booking->getEmail(), - 'subject' => $booking->isInquiry() - ? 'Deine Anfrage ist bei uns eingegangen' - : 'Deine Buchung ist bestätigt', - 'template' => 'email/accommodation_booking_customer.html.twig', - 'attachments' => [], - ], - ); - } catch (\Throwable $e) { - $this->logger->error('Failed to send accommodation booking customer confirmation email', [ - 'booking_id' => $booking->getId(), - 'error' => $e->getMessage(), - ]); - } + $this->sendBookingEmail( + $booking, + $booking->getEmail(), + $booking->isInquiry() + ? 'Deine Anfrage ist bei uns eingegangen' + : 'Deine Buchung ist bestätigt', + 'email/accommodation_booking_customer.html.twig', + 'Failed to send accommodation booking customer confirmation email', + ); } /** @@ -469,48 +478,24 @@ class AccommodationBookingService public function sendOfferAcceptedNotificationEmail(AccommodationBooking $booking): void { - try { - $this->mailer->createAndSendEmail( - [ - 'booking' => $booking, - 'accessLink' => $this->accessLinkOrNull($booking), - ], - [ - 'to' => $this->officeEmail, - 'subject' => sprintf('Angebot angenommen: %s', $booking->getAccommodation()?->getName()), - 'template' => 'email/offer_accepted.html.twig', - 'attachments' => [], - ], - ); - } catch (\Throwable $e) { - $this->logger->error('Failed to send offer accepted notification email', [ - 'booking_id' => $booking->getId(), - 'error' => $e->getMessage(), - ]); - } + $this->sendBookingEmail( + $booking, + $this->accommodationEmail, + sprintf('Angebot angenommen: %s', $booking->getAccommodation()?->getName()), + 'email/offer_accepted.html.twig', + 'Failed to send offer accepted notification email', + ); } public function sendOfferAcceptedCustomerEmail(AccommodationBooking $booking): void { - try { - $this->mailer->createAndSendEmail( - [ - 'booking' => $booking, - 'accessLink' => $this->accessLinkOrNull($booking), - ], - [ - 'to' => $booking->getEmail(), - 'subject' => 'Deine Buchung ist bestätigt', - 'template' => 'email/offer_accepted_customer.html.twig', - 'attachments' => [], - ], - ); - } catch (\Throwable $e) { - $this->logger->error('Failed to send offer accepted customer email', [ - 'booking_id' => $booking->getId(), - 'error' => $e->getMessage(), - ]); - } + $this->sendBookingEmail( + $booking, + $booking->getEmail(), + 'Deine Buchung ist bestätigt', + 'email/offer_accepted_customer.html.twig', + 'Failed to send offer accepted customer email', + ); } private function accessLinkOrNull(AccommodationBooking $booking): ?string diff --git a/tests/Service/AccommodationBookingServiceTest.php b/tests/Service/AccommodationBookingServiceTest.php index d44a79f..019cf81 100644 --- a/tests/Service/AccommodationBookingServiceTest.php +++ b/tests/Service/AccommodationBookingServiceTest.php @@ -124,6 +124,7 @@ class AccommodationBookingServiceTest extends TestCase ->with( self::callback(static fn (array $context) => 'https://example.com/offer/signed-link' === $context['accessLink']), self::callback(static fn (array $options) => 'customer@example.com' === $options['to'] + && 'office@example.com' === $options['from'] && 'email/accommodation_booking_customer.html.twig' === $options['template']), ); @@ -219,6 +220,7 @@ class AccommodationBookingServiceTest extends TestCase ->with( self::anything(), self::callback(static fn (array $options) => in_array($options['to'], ['office@example.com', 'customer@example.com'], true) + && 'office@example.com' === $options['from'] && in_array($options['template'], ['email/offer_accepted.html.twig', 'email/offer_accepted_customer.html.twig'], true)), );