Fix für Short-Signups

This commit is contained in:
2026-09-10 22:27:57 +02:00
parent 4e981c140b
commit 328825293a
13 changed files with 242 additions and 57 deletions
@@ -2,35 +2,45 @@
namespace App\Domains\Event\Controllers;
use App\RelationModels\EventParticipationFee;
use App\Scopes\CommonController;
use App\ValueObjects\Amount;
use Illuminate\Http\JsonResponse;
/**
* Beitrag einer Kurzanmeldung. Teilnahmegruppe, Beitragsstufe und Zeitraum stehen fest, deshalb braucht der
* Endpunkt keine Eingaben -- und der Betrag lässt sich vom Client nicht beeinflussen.
* Beiträge einer Kurzanmeldung. Teilnahmegruppe und Zeitraum stehen fest; geliefert wird der Betrag je
* hinterlegter Beitragsstufe, damit der Client zwischen ihnen wählen kann, ohne erneut zu fragen. Der Endpunkt
* braucht keine Eingaben -- berechnet wird der gespeicherte Betrag bei der Anmeldung ohnehin neu.
*
* `amountValue` steuert im Frontend, ob der Schritt "Zahlungsart" gezeigt wird.
* `amountValue` der gewählten Stufe steuert im Frontend, ob der Schritt "Zahlungsart" gezeigt wird; mehr als
* eine Stufe blendet den Schritt "Beitrag" ein.
*/
class ShortCalculateAmountController extends CommonController {
public function __invoke(int $eventId) : JsonResponse {
$event = $this->events->getById($eventId, false);
$participationType = $event->firstParticipationTypeSlug();
$participationFee = $event->firstParticipationFee();
$eventResource = $event->toResource();
$amount = $participationType === null
? new Amount(0, 'Euro')
: $event->toResource()->calculateAmount(
$participationType,
'standard',
$event->start_date,
$event->end_date,
false
);
$feeTypes = array_map(function (string $feeType) use ($event, $eventResource, $participationFee) {
$amount = $participationFee === null
? new Amount(0, 'Euro')
: $eventResource->calculateAmount(
$participationFee->type,
$feeType,
$event->start_date,
$event->end_date,
false
);
return response()->json([
'amount' => $amount->toString(),
'amountValue' => $amount->getAmount(),
]);
return [
'value' => $feeType,
'label' => EventParticipationFee::FEE_TYPE_LABELS[$feeType],
'amount' => $amount->toString(),
'amountValue' => $amount->getAmount(),
];
}, $participationFee?->availableFeeTypes() ?? ['standard']);
return response()->json(['feeTypes' => $feeTypes]);
}
}