adrema/app/Payment/Actions/PaymentStoreAction.php

59 lines
1.5 KiB
PHP
Raw Normal View History

2023-10-16 16:21:23 +02:00
<?php
namespace App\Payment\Actions;
2023-10-16 16:32:06 +02:00
use App\Lib\JobMiddleware\JobChannels;
use App\Lib\JobMiddleware\WithJobState;
use App\Lib\Queue\TracksJob;
use App\Member\Member;
2023-10-16 16:21:23 +02:00
use Illuminate\Http\JsonResponse;
2023-10-16 16:32:06 +02:00
use Lorisleiva\Actions\ActionRequest;
2023-10-16 16:21:23 +02:00
use Lorisleiva\Actions\Concerns\AsAction;
class PaymentStoreAction
{
use AsAction;
2023-10-16 16:32:06 +02:00
use TracksJob;
2023-10-16 16:21:23 +02:00
2023-10-18 18:14:07 +02:00
/**
* @param array<string, string> $attributes
*/
2023-10-16 16:32:06 +02:00
public function handle(Member $member, array $attributes): void
2023-10-16 16:21:23 +02:00
{
2023-10-16 16:32:06 +02:00
$member->createPayment($attributes);
2023-10-16 16:21:23 +02:00
}
/**
2023-10-18 18:14:07 +02:00
* @return array<string, string>
2023-10-16 16:21:23 +02:00
*/
public function rules(): array
{
2023-10-16 16:32:06 +02:00
return [
'nr' => 'required',
'subscription_id' => 'required|exists:subscriptions,id',
'status_id' => 'required|exists:statuses,id',
];
2023-10-16 16:21:23 +02:00
}
2023-10-16 16:32:06 +02:00
public function asController(Member $member, ActionRequest $request): JsonResponse
2023-10-16 16:21:23 +02:00
{
2023-10-16 16:32:06 +02:00
$this->startJob($member, $request->validated());
return response()->json([]);
2023-10-16 16:21:23 +02:00
}
2023-10-16 16:32:06 +02:00
/**
* @param mixed $parameters
*/
public function jobState(WithJobState $jobState, ...$parameters): WithJobState
2023-10-16 16:21:23 +02:00
{
2023-10-16 16:32:06 +02:00
$member = $parameters[0];
return $jobState
->before('Zahlung für ' . $member->fullname . ' wird gespeichert')
->after('Zahlung für ' . $member->fullname . ' gespeichert')
->failed('Fehler beim Erstellen der Zahlung für ' . $member->fullname)
->shouldReload(JobChannels::make()->add('member')->add('payment'));
2023-10-16 16:21:23 +02:00
}
}