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,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\ParticipantRefund\Actions\ResendRefundMail;
|
||||
|
||||
use App\Models\ParticipantRefund;
|
||||
|
||||
class ResendRefundMailRequest
|
||||
{
|
||||
public function __construct(
|
||||
public readonly ParticipantRefund $refund,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\ParticipantRefund\Actions\ResendRefundMail;
|
||||
|
||||
class ResendRefundMailResponse
|
||||
{
|
||||
public bool $success = false;
|
||||
|
||||
public ?string $message = null;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\ParticipantRefund\Controllers;
|
||||
|
||||
use App\Domains\ParticipantRefund\Actions\ResendRefundMail\ResendRefundMailCommand;
|
||||
use App\Domains\ParticipantRefund\Actions\ResendRefundMail\ResendRefundMailRequest;
|
||||
use App\Scopes\CommonController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ResendRefundMailController extends CommonController
|
||||
{
|
||||
public function __invoke(string $refundToken, Request $request): JsonResponse
|
||||
{
|
||||
$refund = $this->participantRefunds->getByToken($refundToken);
|
||||
|
||||
// Der Token ist hier keine Berechtigung: nachschicken darf nur, wer die Veranstaltung auch
|
||||
// verwalten kann. `getById()` prüft genau das.
|
||||
if ($refund === null || $this->events->getById($refund->event_id) === null) {
|
||||
abort(403, 'Zugriff verweigert.');
|
||||
}
|
||||
|
||||
$response = new ResendRefundMailCommand(new ResendRefundMailRequest($refund))->execute();
|
||||
|
||||
return response()->json([
|
||||
'status' => $response->success ? 'success' : 'error',
|
||||
'message' => $response->message,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ use App\Domains\ParticipantRefund\Controllers\AcceptRefundController;
|
||||
use App\Domains\ParticipantRefund\Controllers\CancelRefundController;
|
||||
use App\Domains\ParticipantRefund\Controllers\RefundDocumentController;
|
||||
use App\Domains\ParticipantRefund\Controllers\ReleaseRefundController;
|
||||
use App\Domains\ParticipantRefund\Controllers\ResendRefundMailController;
|
||||
use App\Middleware\IdentifyTenant;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
@@ -17,6 +18,7 @@ Route::prefix('api/v1')
|
||||
Route::middleware(['auth'])->group(function () {
|
||||
Route::post('{participantIdentifier}/release', ReleaseRefundController::class);
|
||||
Route::post('{refundToken}/cancel', CancelRefundController::class);
|
||||
Route::post('{refundToken}/resend-mail', ResendRefundMailController::class);
|
||||
Route::get('{refundToken}/document', RefundDocumentController::class);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user