Creating Participation refunds
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Enumerations\ParticipationType;
|
||||
use App\Models\AvailablePaymentMethod;
|
||||
use App\Models\EventParticipant;
|
||||
use App\Models\PaymentMethod;
|
||||
use App\Repositories\ParticipantRefundRepository;
|
||||
use App\ValueObjects\Age;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
@@ -74,6 +75,10 @@ class EventParticipantResource extends JsonResource
|
||||
// Numerisch, damit das Frontend rechnen bzw. auf "kostenlos" prüfen kann -- `value` oben ist
|
||||
// ein Amount-Objekt und serialisiert nicht.
|
||||
'amountExpectedValue' => $this->resource->amount?->getAmount() ?? 0.0,
|
||||
'amountPaidValue' => $this->resource->amount_paid?->getAmount() ?? 0.0,
|
||||
// Der laufende bzw. bestätigte Erstattungsvorgang -- null, wenn keiner existiert oder
|
||||
// der letzte abgebrochen wurde.
|
||||
'refund' => $this->refund($request),
|
||||
'alcoholicsAllowed' => new Age($this->resource->birthday)->getAge() >= $event->alcoholics_age,
|
||||
'localGroupPostcode' => $this->resource->localGroup()->first()?->postcode ?? '00000',
|
||||
'localGroupCity' => $this->resource->localGroup()->first()?->city ?? '00000',
|
||||
@@ -106,4 +111,17 @@ class EventParticipantResource extends JsonResource
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Der für die Anzeige maßgebliche Erstattungsvorgang.
|
||||
*
|
||||
* Abgebrochene Vorgänge bleiben außen vor: für die Aktionsleitung soll die Anmeldung danach
|
||||
* aussehen wie vor der Freigabe.
|
||||
*/
|
||||
private function refund($request): ?array
|
||||
{
|
||||
$refund = new ParticipantRefundRepository()->currentFor($this->resource);
|
||||
|
||||
return $refund?->toResource()->toArray($request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Resources;
|
||||
|
||||
use App\Models\ParticipantRefund;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* Der Erstattungsvorgang für das Frontend.
|
||||
*
|
||||
* Bewusst NICHT `$this->resource->toArray()` als Basis wie in {@see EventParticipantResource}: die
|
||||
* Bankverbindung darf nur dorthin, wo sie hingehört (Beleg und Auszahlung), nicht in jede
|
||||
* Teilnehmerliste. Deshalb werden die Felder hier einzeln aufgeführt.
|
||||
*/
|
||||
class ParticipantRefundResource extends JsonResource
|
||||
{
|
||||
public function __construct(ParticipantRefund $refund)
|
||||
{
|
||||
parent::__construct($refund);
|
||||
}
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'token' => $this->resource->token,
|
||||
'status' => $this->resource->status,
|
||||
'amount' => $this->resource->amount?->toString() ?? '0,00 Euro',
|
||||
'amountValue' => $this->resource->amount?->getAmount() ?? 0.0,
|
||||
'reason' => $this->resource->reason,
|
||||
'reasonLabel' => $this->resource->reasonLabel(),
|
||||
'reasonNote' => $this->resource->reason_note,
|
||||
'releasedAt' => $this->resource->released_at?->format('d.m.Y'),
|
||||
'acceptedAt' => $this->resource->accepted_at?->format('d.m.Y'),
|
||||
'cancelledAt' => $this->resource->cancelled_at?->format('d.m.Y'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user