Files
mareike/app/Domains/ParticipantInvoice/Controllers/CreateParticipantInvoiceController.php
T

34 lines
1.2 KiB
PHP

<?php
namespace App\Domains\ParticipantInvoice\Controllers;
use App\Domains\ParticipantInvoice\Actions\CreateParticipantInvoice\CreateParticipantInvoiceCommand;
use App\Domains\ParticipantInvoice\Actions\CreateParticipantInvoice\CreateParticipantInvoiceRequest;
use App\Scopes\CommonController;
use Illuminate\Http\Response;
class CreateParticipantInvoiceController extends CommonController
{
public function __invoke(string $participantIdentifier): Response
{
$participant = $this->eventParticipants->getByIdentifier($participantIdentifier, $this->events);
if ($participant === null) {
abort(403, 'Zugriff verweigert.');
}
$invoiceRequest = new CreateParticipantInvoiceRequest($participant);
$invoiceCommand = new CreateParticipantInvoiceCommand($invoiceRequest);
$invoiceResponse = $invoiceCommand->execute();
if (!$invoiceResponse->success) {
abort(422, $invoiceResponse->message ?? 'Die Rechnung konnte nicht erstellt werden.');
}
return response($invoiceResponse->pdfContent, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="' . $invoiceResponse->filename . '"',
]);
}
}