['label' => 'Gesamtpreis laut Portal (€)', 'default' => 980, 'type' => 'int'], 'cancellation' => ['label' => 'Portal meldet eine Stornierung', 'default' => false, 'type' => 'bool'], ]; } public function events(array $inputs): array { $total = max(1, (int) ($inputs['portal_total'] ?? 980)) * 100; $events = [ new ScenarioEvent('Buchungsmail des Portals kommt an', fn (SandboxContext $context) => $this->sendPortalMail($context, 'Neue Buchung: '.$context->property->name, $this->text($context))), new ScenarioEvent('Dieselbe Buchungsmail kommt noch einmal', fn (SandboxContext $context) => $this->sendPortalMail($context, 'Neue Buchung: '.$context->property->name, $this->text($context))), new ScenarioEvent('Gastdaten laut Portal', fn (SandboxContext $context) => app(ContributeCaseFacts::class)->handle($context->booking->fresh(), ['guest.first_name' => 'Testgast', 'guest.last_name' => 'Portal', 'guest.email' => 'portalgast@tester.invalid', 'booking.guests' => (string) $context->guests()], FactSource::PortalMail)), new ScenarioEvent('Portal meldet Preis, Gastzahlung und angekündigte Auszahlung', fn (SandboxContext $context) => app(RecordPortalAmounts::class)->handle($context->booking->fresh(), $total, [['kind' => 'payout_announced', 'amount' => (int) round($total * 0.9)]], [['amount' => (int) round($total * 0.4), 'paid_on' => now()->toDateString()]], $context->channel->name)), ]; if ((bool) ($inputs['cancellation'] ?? false)) { $events[] = new ScenarioEvent('Portal meldet eine Stornierung', fn (SandboxContext $context) => $this->sendPortalMail($context, 'Buchung storniert: '.$this->reference($context), 'Die Buchung vom '.$context->arrival()->format('d.m.Y').' bis '.$context->departure()->format('d.m.Y').' wurde storniert. Buchungsnummer: '.$this->reference($context))); } $events[] = new ScenarioEvent('Drei Tage nach der Abreise', fn (SandboxContext $context) => $context->travelTo($context->departure()->addDays(3)->setTime(9, 0))); return $events; } private function reference(SandboxContext $context): string { return 'TEST-'.$context->arrival()->format('md'); } private function text(SandboxContext $context): string { return "Gast: Testgast Portal\nAnreise: ".$context->arrival()->format('d.m.Y')."\nAbreise: ".$context->departure()->format('d.m.Y')."\nBuchungsnummer: ".$this->reference($context); } private function sendPortalMail(SandboxContext $context, string $subject, string $text): void { $senders = array_values(array_filter(array_map('trim', explode(',', (string) ($context->channel->setting('email_senders') ?? ''))))); $sender = 'buchung@'.($senders[0] ?? 'portal.invalid'); app(ProcessPortalMail::class)->handle(new PortalMail('<'.md5($subject).'@tester.invalid>', $sender, $subject, $text, CarbonImmutable::now())); $context->booking = Booking::query()->latest('id')->first() ?? $context->booking; } }