Fix für Short-Signups
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Enumerations\FirstAidPermission;
|
||||
use App\Enumerations\SwimmingPermission;
|
||||
use App\Mail\ParticipantParticipationMails\EventSignUpSuccessfullMail;
|
||||
use App\Providers\DoubleCheckEventRegistrationProvider;
|
||||
use App\RelationModels\EventParticipationFee;
|
||||
use App\Scopes\CommonController;
|
||||
use DateTime;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -53,6 +54,8 @@ class ShortSignupController extends CommonController {
|
||||
'participationOptions' => 'array',
|
||||
'paymentMethod' => 'nullable|string',
|
||||
'paymentOptions' => 'array',
|
||||
// Ob die Stufe für die Teilnahmegruppe hinterlegt ist, prüft der Command.
|
||||
'feeType' => 'nullable|string|in:' . implode(',', array_keys(EventParticipationFee::FEE_TYPE_LABELS)),
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
@@ -99,6 +102,7 @@ class ShortSignupController extends CommonController {
|
||||
paymentMethod: $request->input('paymentMethod') ?: null,
|
||||
paymentOptions: (array)$request->input('paymentOptions', []),
|
||||
participationOptions: (array)$request->input('participationOptions', []),
|
||||
feeType: $request->input('feeType') ?: 'standard',
|
||||
);
|
||||
|
||||
$shortSignUpResponse = new ShortSignUpCommand($shortSignUpRequest)->execute();
|
||||
|
||||
Reference in New Issue
Block a user