adrema/app/Payment/Actions/PaymentDestroyAction.php

43 lines
1.1 KiB
PHP
Raw Normal View History

2023-10-16 16:21:23 +02:00
<?php
namespace App\Payment\Actions;
2023-10-16 16:39:06 +02:00
use App\Lib\JobMiddleware\JobChannels;
use App\Lib\JobMiddleware\WithJobState;
use App\Lib\Queue\TracksJob;
use App\Payment\Payment;
2023-10-16 16:21:23 +02:00
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\Concerns\AsAction;
class PaymentDestroyAction
{
use AsAction;
2023-10-16 16:39:06 +02:00
use TracksJob;
2023-10-16 16:21:23 +02:00
2023-10-18 13:45:41 +02:00
public function handle(int $paymentId): void
2023-10-16 16:21:23 +02:00
{
2023-10-18 13:45:41 +02:00
Payment::find($paymentId)->delete();
2023-10-16 16:21:23 +02:00
}
2023-10-16 16:39:06 +02:00
public function asController(Payment $payment): JsonResponse
2023-10-16 16:21:23 +02:00
{
2023-10-18 13:45:41 +02:00
$this->startJob($payment->id, $payment->member->fullname);
2023-10-16 16:39:06 +02:00
return response()->json([]);
2023-10-16 16:21:23 +02:00
}
/**
2023-10-16 16:39:06 +02:00
* @param mixed $parameters
2023-10-16 16:21:23 +02:00
*/
2023-10-16 16:39:06 +02:00
public function jobState(WithJobState $jobState, ...$parameters): WithJobState
2023-10-16 16:21:23 +02:00
{
2023-10-18 13:45:41 +02:00
$memberName = $parameters[1];
2023-10-16 16:21:23 +02:00
2023-10-16 16:39:06 +02:00
return $jobState
2023-10-18 13:45:41 +02:00
->before('Zahlung für ' . $memberName . ' wird gelöscht')
->after('Zahlung für ' . $memberName . ' gelöscht')
->failed('Fehler beim Löschen der Zahlung für ' . $memberName)
2023-10-16 16:39:06 +02:00
->shouldReload(JobChannels::make()->add('member')->add('payment'));
2023-10-16 16:21:23 +02:00
}
}