77 lines
3.5 KiB
PHP
77 lines
3.5 KiB
PHP
<?php
|
||
|
||
namespace App\Process\Tester\Scenarios;
|
||
|
||
use App\Actions\ProcessPortalMail;
|
||
use App\Actions\TakeOverExternalBooking;
|
||
use App\Channels\Mail\PortalMail;
|
||
use App\Enums\IntakeKind;
|
||
use App\Process\Tester\SandboxContext;
|
||
use Carbon\CarbonImmutable;
|
||
|
||
/**
|
||
* V2.1: a booking binding at the portal is known without the portal's confirmation mail, e.g. from a calendar or a manual entry; the
|
||
* mail comes at once, late or never. Shows what waits (documents, booking information), that the occupation does not,
|
||
* and the escalation when the mail stays away.
|
||
*/
|
||
final class PortalConfirmationWait extends Scenario
|
||
{
|
||
public static function key(): string
|
||
{
|
||
return 'portal_confirmation_wait';
|
||
}
|
||
|
||
public static function label(): string
|
||
{
|
||
return 'Bestätigungsmail des Portals: sofort, verspätet oder ausbleibend';
|
||
}
|
||
|
||
public static function description(): string
|
||
{
|
||
return 'Die Buchung ist bekannt, die Bestätigungsmail des Portals kommt sofort, nach einigen Stunden oder gar nicht. Zeigt, was wartet, was nicht, und wann Sie eine Aufgabe erhalten.';
|
||
}
|
||
|
||
public static function intakes(): array
|
||
{
|
||
return [IntakeKind::Booking];
|
||
}
|
||
|
||
public static function inputs(): array
|
||
{
|
||
return [
|
||
...parent::inputs(),
|
||
'confirmation' => ['label' => 'Bestätigungsmail', 'default' => 'late', 'type' => 'select', 'options' => ['immediate' => 'sofort', 'late' => 'nach 5 Stunden', 'missing' => 'bleibt aus']],
|
||
];
|
||
}
|
||
|
||
public function events(array $inputs): array
|
||
{
|
||
$known = new ScenarioEvent('Buchung ist bekannt (ohne Bestätigungsmail des Portals)', function (SandboxContext $context): void {
|
||
$context->booking = app(TakeOverExternalBooking::class)->handle($context->property, $context->channel, $context->arrival(), $context->departure(), [
|
||
'portal_reference' => $this->reference($context), 'portal_total' => 98000, 'guests' => $context->guests(),
|
||
'guest' => ['first_name' => 'Testgast', 'last_name' => 'Portal', 'email' => 'portalgast@tester.invalid', 'street' => 'Teststraße 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'],
|
||
]);
|
||
});
|
||
|
||
return [$known, ...match ((string) ($inputs['confirmation'] ?? 'late')) {
|
||
'immediate' => [$this->mailEvent()],
|
||
'missing' => [new ScenarioEvent('60 Stunden vergehen – die Mail bleibt aus', fn (SandboxContext $context) => $context->travel(60 * 60))],
|
||
default => [new ScenarioEvent('5 Stunden vergehen', fn (SandboxContext $context) => $context->travel(5 * 60)), $this->mailEvent()],
|
||
}];
|
||
}
|
||
|
||
private function mailEvent(): ScenarioEvent
|
||
{
|
||
return new ScenarioEvent('Bestätigungsmail des Portals kommt an', function (SandboxContext $context): void {
|
||
$senders = array_values(array_filter(array_map('trim', explode(',', (string) ($context->channel->setting('email_senders') ?? '')))));
|
||
$text = "Gast: Testgast Portal\nAnreise: ".$context->arrival()->format('d.m.Y')."\nAbreise: ".$context->departure()->format('d.m.Y')."\nBuchungsnummer: ".$this->reference($context);
|
||
app(ProcessPortalMail::class)->handle(new PortalMail('<'.md5($text).'@tester.invalid>', 'buchung@'.($senders[0] ?? 'portal.invalid'), 'Neue Buchung', $text, CarbonImmutable::now()));
|
||
});
|
||
}
|
||
|
||
private function reference(SandboxContext $context): string
|
||
{
|
||
return 'TEST-'.$context->arrival()->format('md');
|
||
}
|
||
}
|