64 lines
2.2 KiB
PHP
64 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\ParticipantRefund\Controllers;
|
|
|
|
use App\Domains\ParticipantRefund\Actions\AcceptRefund\AcceptRefundCommand;
|
|
use App\Models\ParticipantRefund;
|
|
use App\Providers\InertiaProvider;
|
|
use App\Scopes\CommonController;
|
|
use Inertia\Response;
|
|
|
|
/**
|
|
* Die öffentliche Seite, auf der der Teili seine Bankverbindung hinterlegt.
|
|
*
|
|
* Liefert ausschließlich Anzeigedaten -- niemals die bereits erfasste Bankverbindung: der Token wandert
|
|
* durch ein Postfach, und was einmal eingetragen ist, muss von dort nicht wieder herauslesbar sein.
|
|
*/
|
|
class RefundPageController extends CommonController
|
|
{
|
|
public function __invoke(string $refundToken): Response
|
|
{
|
|
$refund = $this->participantRefunds->getByToken($refundToken);
|
|
|
|
return new InertiaProvider('ParticipantRefund/RefundPage', $this->props($refund))->render();
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function props(?ParticipantRefund $refund): array
|
|
{
|
|
// Unbekannt und abgebrochen sind für den Teili derselbe Zustand: es gibt nichts zu tun.
|
|
if ($refund === null || $refund->status === ParticipantRefund::STATUS_CANCELLED) {
|
|
return [
|
|
'state' => 'unavailable',
|
|
'message' => AcceptRefundCommand::NO_OPEN_REFUND,
|
|
];
|
|
}
|
|
|
|
$participant = $refund->participant;
|
|
$event = $refund->event;
|
|
|
|
$common = [
|
|
'token' => $refund->token,
|
|
'name' => $participant->getNicename(),
|
|
'eventTitle' => $event->name,
|
|
'eventEmail' => $event->email,
|
|
'amount' => $refund->amount?->toString() ?? '0,00 Euro',
|
|
'reason' => $refund->reasonLabel(),
|
|
'reasonNote' => $refund->reason_note,
|
|
];
|
|
|
|
if ($refund->isAccepted()) {
|
|
return array_merge($common, [
|
|
'state' => 'accepted',
|
|
'acceptedAt' => $refund->accepted_at?->format('d.m.Y'),
|
|
// Wurde gespendet, darf der Abschlusstext keine Überweisung ankündigen, die nicht kommt.
|
|
'donation' => $refund->isDonation(),
|
|
]);
|
|
}
|
|
|
|
return array_merge($common, ['state' => 'open']);
|
|
}
|
|
}
|