Add Payment store
This commit is contained in:
parent
c764f3d3b7
commit
1e74a6055e
|
@ -2,16 +2,23 @@
|
||||||
|
|
||||||
namespace App\Payment\Actions;
|
namespace App\Payment\Actions;
|
||||||
|
|
||||||
|
use App\Lib\JobMiddleware\JobChannels;
|
||||||
|
use App\Lib\JobMiddleware\WithJobState;
|
||||||
|
use App\Lib\Queue\TracksJob;
|
||||||
|
use App\Member\Member;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Validation\Rules\In;
|
use Illuminate\Validation\Rules\In;
|
||||||
|
use Lorisleiva\Actions\ActionRequest;
|
||||||
use Lorisleiva\Actions\Concerns\AsAction;
|
use Lorisleiva\Actions\Concerns\AsAction;
|
||||||
|
|
||||||
class PaymentStoreAction
|
class PaymentStoreAction
|
||||||
{
|
{
|
||||||
use AsAction;
|
use AsAction;
|
||||||
|
use TracksJob;
|
||||||
|
|
||||||
public function handle(): void
|
public function handle(Member $member, array $attributes): void
|
||||||
{
|
{
|
||||||
|
$member->createPayment($attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,19 +26,31 @@ class PaymentStoreAction
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [];
|
return [
|
||||||
|
'nr' => 'required',
|
||||||
|
'subscription_id' => 'required|exists:subscriptions,id',
|
||||||
|
'status_id' => 'required|exists:statuses,id',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function asController(Member $member, ActionRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$this->startJob($member, $request->validated());
|
||||||
|
|
||||||
|
return response()->json([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<string, string>
|
* @param mixed $parameters
|
||||||
*/
|
*/
|
||||||
public function getValidationAttributes(): array
|
public function jobState(WithJobState $jobState, ...$parameters): WithJobState
|
||||||
{
|
{
|
||||||
return [];
|
$member = $parameters[0];
|
||||||
}
|
|
||||||
|
|
||||||
public function asController(): JsonResponse
|
return $jobState
|
||||||
{
|
->before('Zahlung für ' . $member->fullname . ' wird gespeichert')
|
||||||
return response()->json([]);
|
->after('Zahlung für ' . $member->fullname . ' gespeichert')
|
||||||
|
->failed('Fehler beim Erstellen der Zahlung für ' . $member->fullname)
|
||||||
|
->shouldReload(JobChannels::make()->add('member')->add('payment'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,19 +11,6 @@ use Illuminate\Http\Response;
|
||||||
|
|
||||||
class PaymentController extends Controller
|
class PaymentController extends Controller
|
||||||
{
|
{
|
||||||
public function store(Request $request, Member $member): Response
|
|
||||||
{
|
|
||||||
$member->createPayment($request->validate([
|
|
||||||
'nr' => 'required',
|
|
||||||
'subscription_id' => 'required|exists:subscriptions,id',
|
|
||||||
'status_id' => 'required|exists:statuses,id',
|
|
||||||
]));
|
|
||||||
|
|
||||||
ClientMessage::make('Zahlung erstellt.')->shouldReload()->dispatch();
|
|
||||||
|
|
||||||
return response('');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(Request $request, Member $member, Payment $payment): Response
|
public function update(Request $request, Member $member, Payment $payment): Response
|
||||||
{
|
{
|
||||||
$payment->update($request->validate([
|
$payment->update($request->validate([
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Payment;
|
||||||
|
|
||||||
|
use App\Lib\Events\JobFinished;
|
||||||
|
use App\Lib\Events\JobStarted;
|
||||||
|
use App\Lib\Events\ReloadTriggered;
|
||||||
|
use App\Member\Member;
|
||||||
|
use App\Payment\Status;
|
||||||
|
use App\Payment\Subscription;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class StoreTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function testItStoresAPayment(): void
|
||||||
|
{
|
||||||
|
Event::fake([JobStarted::class, JobFinished::class, ReloadTriggered::class]);
|
||||||
|
$this->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
$subscription = Subscription::factory()->create();
|
||||||
|
$member = Member::factory()->defaults()->create();
|
||||||
|
$status = Status::factory()->create();
|
||||||
|
|
||||||
|
$this->post("/member/{$member->id}/payment", [
|
||||||
|
'status_id' => $status->id,
|
||||||
|
'subscription_id' => $subscription->id,
|
||||||
|
'nr' => '2019',
|
||||||
|
])->assertOk();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('payments', [
|
||||||
|
'member_id' => $member->id,
|
||||||
|
'status_id' => $status->id,
|
||||||
|
'subscription_id' => $subscription->id,
|
||||||
|
'nr' => '2019',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Event::assertDispatched(JobStarted::class, fn ($event) => $event->broadcastOn()[0]->name === 'jobs' && $event->message !== null);
|
||||||
|
Event::assertDispatched(JobFinished::class, fn ($event) => $event->broadcastOn()[0]->name === 'jobs' && $event->message !== null);
|
||||||
|
Event::assertDispatched(ReloadTriggered::class, fn ($event) => ['member', 'payment'] === $event->channels->toArray());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue