Overview for refunds
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\ParticipantRefund\Actions\ResendRefundMail;
|
||||
|
||||
use App\Mail\ParticipantRefundMails\RefundReleasedMail;
|
||||
use App\Models\EventParticipant;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
/**
|
||||
* Schickt die Mail zu einer freigegebenen Erstattung noch einmal.
|
||||
*
|
||||
* Der häufige Fall, wenn ein Vorgang hängt: die erste Mail ist untergegangen. Am Vorgang ändert sich
|
||||
* dabei nichts -- `released_at` bleibt der Zeitpunkt der Vormerkung, der Token bleibt derselbe, der alte
|
||||
* Link funktioniert also weiter.
|
||||
*
|
||||
* Nur solange die Bankverbindung fehlt: nach der Bestätigung wäre der Link wertlos, nach dem Abbruch
|
||||
* liefe er ins Leere.
|
||||
*/
|
||||
class ResendRefundMailCommand
|
||||
{
|
||||
public function __construct(private readonly ResendRefundMailRequest $request)
|
||||
{
|
||||
}
|
||||
|
||||
public function execute(): ResendRefundMailResponse
|
||||
{
|
||||
$response = new ResendRefundMailResponse();
|
||||
$refund = $this->request->refund;
|
||||
|
||||
if (!$refund->isPending()) {
|
||||
$response->message = $refund->isAccepted()
|
||||
? 'Diese Erstattung wurde bereits bestätigt -- es gibt nichts mehr nachzureichen.'
|
||||
: 'Diese Erstattung wurde abgebrochen.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->notify();
|
||||
|
||||
$response->success = true;
|
||||
$response->message = 'Die Rückerstattungsmail wurde erneut versendet.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Teili und Kontaktperson bekommen je eine eigene Mail -- dasselbe Muster wie bei der Freigabe
|
||||
* (siehe ReleaseRefundCommand).
|
||||
*/
|
||||
private function notify(): void
|
||||
{
|
||||
/** @var EventParticipant $participant */
|
||||
$participant = $this->request->refund->participant()->first();
|
||||
|
||||
$recipients = [$participant->email_1];
|
||||
|
||||
// `filled()` und nicht `!== null`: Der Anmeldewizard überspringt den Schritt "Kontaktperson" bei
|
||||
// Volljährigen und legt das Feld als Leerstring an -- `Mail::to('')` liefe ins Leere.
|
||||
if (filled($participant->email_2)) {
|
||||
$recipients[] = $participant->email_2;
|
||||
}
|
||||
|
||||
foreach ($recipients as $recipient) {
|
||||
Mail::to($recipient)->send(new RefundReleasedMail(
|
||||
participant: $participant,
|
||||
refund: $this->request->refund,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user