33 lines
1.2 KiB
PHP
33 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\ParticipantRefund\Controllers;
|
|
|
|
use App\Domains\ParticipantRefund\Actions\CreateRefundDocument\CreateRefundDocumentCommand;
|
|
use App\Domains\ParticipantRefund\Actions\CreateRefundDocument\CreateRefundDocumentRequest;
|
|
use App\Scopes\CommonController;
|
|
use Illuminate\Http\Response;
|
|
|
|
class RefundDocumentController extends CommonController
|
|
{
|
|
public function __invoke(string $refundToken): Response
|
|
{
|
|
$refund = $this->participantRefunds->getByToken($refundToken);
|
|
|
|
// Der Beleg enthält die Bankverbindung -- er gehört der Aktionsleitung, nicht dem Token.
|
|
if ($refund === null || $this->events->getById($refund->event_id) === null) {
|
|
abort(403, 'Zugriff verweigert.');
|
|
}
|
|
|
|
$documentResponse = new CreateRefundDocumentCommand(new CreateRefundDocumentRequest($refund))->execute();
|
|
|
|
if (!$documentResponse->success) {
|
|
abort(422, $documentResponse->message ?? 'Der Beleg konnte nicht erstellt werden.');
|
|
}
|
|
|
|
return response($documentResponse->pdfContent, 200, [
|
|
'Content-Type' => 'application/pdf',
|
|
'Content-Disposition' => 'attachment; filename="' . $documentResponse->filename . '"',
|
|
]);
|
|
}
|
|
}
|