Basic implementation of payment methods
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Domains\Admin\Actions\CreateTenant;
|
||||
|
||||
use App\Models\AvailablePaymentMethod;
|
||||
use App\Models\PaymentMethod;
|
||||
use App\Models\Tenant;
|
||||
|
||||
class CreateTenantAction
|
||||
@@ -29,6 +31,18 @@ class CreateTenantAction
|
||||
'has_active_instance' => true,
|
||||
]);
|
||||
|
||||
foreach (PaymentMethod::all() as $paymentMethod) {
|
||||
$defaults = PaymentMethod::DEFAULTS[$paymentMethod->slug] ?? ['name' => $paymentMethod->slug, 'description' => null];
|
||||
|
||||
AvailablePaymentMethod::create([
|
||||
'tenant' => $tenant->slug,
|
||||
'slug' => $paymentMethod->slug,
|
||||
'name' => $defaults['name'],
|
||||
'description' => $defaults['description'],
|
||||
'active' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
$response->success = true;
|
||||
$response->message = 'Stamm wurde angelegt.';
|
||||
$response->slug = $tenant->slug;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\RemovePaymentMethodUsage;
|
||||
|
||||
use App\Mail\EventReportMails\PaymentMethodsExhaustedMail;
|
||||
use App\Models\AvailablePaymentMethod;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class RemovePaymentMethodUsageAction
|
||||
{
|
||||
public function execute(AvailablePaymentMethod $availablePaymentMethod): void
|
||||
{
|
||||
foreach ($availablePaymentMethod->events()->get() as $event) {
|
||||
$event->paymentMethods()->detach($availablePaymentMethod->id);
|
||||
|
||||
$remainingActive = $event->paymentMethods()->where('active', true)->count();
|
||||
if ($remainingActive === 0 && $event->registration_allowed) {
|
||||
$event->registration_allowed = false;
|
||||
$event->save();
|
||||
|
||||
$recipients = $event->eventManagers;
|
||||
if ($event->costUnit !== null) {
|
||||
$recipients = $recipients->merge($event->costUnit->treasurers);
|
||||
}
|
||||
|
||||
foreach ($recipients->unique('id') as $recipient) {
|
||||
Mail::to($recipient->email)->send(new PaymentMethodsExhaustedMail($event));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\UpdateAvailablePaymentMethod;
|
||||
|
||||
use App\Domains\Admin\Actions\RemovePaymentMethodUsage\RemovePaymentMethodUsageAction;
|
||||
|
||||
class UpdateAvailablePaymentMethodAction
|
||||
{
|
||||
public function __construct(private UpdateAvailablePaymentMethodRequest $request)
|
||||
{
|
||||
}
|
||||
|
||||
public function execute(): UpdateAvailablePaymentMethodResponse
|
||||
{
|
||||
$response = new UpdateAvailablePaymentMethodResponse();
|
||||
$wasActive = $this->request->availablePaymentMethod->active;
|
||||
|
||||
$this->request->availablePaymentMethod->update([
|
||||
'name' => $this->request->name,
|
||||
'description' => $this->request->description,
|
||||
'active' => $this->request->active,
|
||||
]);
|
||||
|
||||
if ($wasActive && !$this->request->active) {
|
||||
(new RemovePaymentMethodUsageAction())->execute($this->request->availablePaymentMethod);
|
||||
}
|
||||
|
||||
$response->success = true;
|
||||
$response->message = 'Zahlungsmethode wurde gespeichert.';
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\UpdateAvailablePaymentMethod;
|
||||
|
||||
use App\Models\AvailablePaymentMethod;
|
||||
|
||||
class UpdateAvailablePaymentMethodRequest
|
||||
{
|
||||
public function __construct(
|
||||
public AvailablePaymentMethod $availablePaymentMethod,
|
||||
public string $name,
|
||||
public ?string $description,
|
||||
public bool $active,
|
||||
) {
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Actions\UpdateAvailablePaymentMethod;
|
||||
|
||||
class UpdateAvailablePaymentMethodResponse
|
||||
{
|
||||
public bool $success = false;
|
||||
public string $message = '';
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Controllers;
|
||||
|
||||
use App\Models\AvailablePaymentMethod;
|
||||
use App\Scopes\CommonController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TenantPaymentMethodsGetController extends CommonController
|
||||
{
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'paymentMethods' => AvailablePaymentMethod::all(),
|
||||
'saveEndpoint' => '/api/v1/admin/tenant/payment-methods',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Admin\Controllers;
|
||||
|
||||
use App\Domains\Admin\Actions\UpdateAvailablePaymentMethod\UpdateAvailablePaymentMethodAction;
|
||||
use App\Domains\Admin\Actions\UpdateAvailablePaymentMethod\UpdateAvailablePaymentMethodRequest;
|
||||
use App\Models\AvailablePaymentMethod;
|
||||
use App\Scopes\CommonController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TenantPaymentMethodsUpdateController extends CommonController
|
||||
{
|
||||
public function __invoke(int $id, Request $request): JsonResponse
|
||||
{
|
||||
$availablePaymentMethod = AvailablePaymentMethod::findOrFail($id);
|
||||
|
||||
$action = new UpdateAvailablePaymentMethodAction(new UpdateAvailablePaymentMethodRequest(
|
||||
availablePaymentMethod: $availablePaymentMethod,
|
||||
name: $request->input('name'),
|
||||
description: $request->input('description'),
|
||||
active: (bool) $request->input('active'),
|
||||
));
|
||||
|
||||
$response = $action->execute();
|
||||
|
||||
return response()->json([
|
||||
'status' => $response->success ? 'success' : 'error',
|
||||
'message' => $response->message,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,8 @@ use App\Domains\Admin\Controllers\TenantImpressUpdateController;
|
||||
use App\Domains\Admin\Controllers\TenantListApiController;
|
||||
use App\Domains\Admin\Controllers\TenantPaymentGetController;
|
||||
use App\Domains\Admin\Controllers\TenantPaymentUpdateController;
|
||||
use App\Domains\Admin\Controllers\TenantPaymentMethodsGetController;
|
||||
use App\Domains\Admin\Controllers\TenantPaymentMethodsUpdateController;
|
||||
use App\Middleware\AdminRoleMiddleware;
|
||||
use App\Middleware\IdentifyTenant;
|
||||
use App\Middleware\LvOnlyMiddleware;
|
||||
@@ -36,6 +38,8 @@ Route::middleware([IdentifyTenant::class, 'auth', AdminRoleMiddleware::class])->
|
||||
Route::post('/contact', TenantContactUpdateController::class);
|
||||
Route::get('/payment', TenantPaymentGetController::class);
|
||||
Route::post('/payment', TenantPaymentUpdateController::class);
|
||||
Route::get('/payment-methods', TenantPaymentMethodsGetController::class);
|
||||
Route::post('/payment-methods/{id}', TenantPaymentMethodsUpdateController::class);
|
||||
Route::get('/impress', TenantImpressGetController::class);
|
||||
Route::post('/impress', TenantImpressUpdateController::class);
|
||||
Route::get('/gdpr', TenantGdprGetController::class);
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import FullScreenModal from "../../../../Views/Components/FullScreenModal.vue";
|
||||
import { useAjax } from "../../../../../resources/js/components/ajaxHandler.js";
|
||||
import { toast } from "vue3-toastify";
|
||||
|
||||
const props = defineProps({
|
||||
data: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
})
|
||||
|
||||
const { request } = useAjax()
|
||||
|
||||
const paymentMethods = ref(props.data.paymentMethods ?? [])
|
||||
const editing = ref(null)
|
||||
const form = ref({ name: '', description: '', active: true })
|
||||
|
||||
function edit(paymentMethod) {
|
||||
editing.value = paymentMethod
|
||||
form.value = {
|
||||
name: paymentMethod.name,
|
||||
description: paymentMethod.description ?? '',
|
||||
active: paymentMethod.active,
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
editing.value = null
|
||||
}
|
||||
|
||||
async function save() {
|
||||
const response = await request('/api/v1/admin/tenant/payment-methods/' + editing.value.id, {
|
||||
method: 'POST',
|
||||
body: form.value,
|
||||
})
|
||||
|
||||
if (response && response.status === 'success') {
|
||||
toast.success(response.message)
|
||||
Object.assign(editing.value, form.value)
|
||||
close()
|
||||
} else {
|
||||
toast.error(response?.message ?? 'Fehler beim Speichern')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<table class="payment-method-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Slug</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="paymentMethod in paymentMethods" :key="paymentMethod.id">
|
||||
<td>{{ paymentMethod.name }}</td>
|
||||
<td>{{ paymentMethod.slug }}</td>
|
||||
<td>
|
||||
<span :class="paymentMethod.active ? 'badge-active' : 'badge-inactive'">
|
||||
{{ paymentMethod.active ? 'Aktiv' : 'Inaktiv' }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-edit" @click="edit(paymentMethod)">Bearbeiten</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<FullScreenModal :show="editing !== null" @close="close">
|
||||
<template v-if="editing">
|
||||
<h2>Zahlungsweg bearbeiten</h2>
|
||||
<table class="data-table">
|
||||
<tr><th>Name:</th><td><input type="text" v-model="form.name" class="form-input" /></td></tr>
|
||||
<tr><th>Slug:</th><td>{{ editing.slug }}</td></tr>
|
||||
<tr><th>Beschreibung:</th><td><textarea v-model="form.description" class="form-input"></textarea></td></tr>
|
||||
<tr><th>Aktiv:</th><td><input type="checkbox" v-model="form.active" /></td></tr>
|
||||
</table>
|
||||
<div class="btn-group">
|
||||
<button class="btn-save" @click="save">Speichern</button>
|
||||
<button class="btn-cancel" @click="close">Abbrechen</button>
|
||||
</div>
|
||||
</template>
|
||||
</FullScreenModal>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.payment-method-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.payment-method-table thead th {
|
||||
text-align: left;
|
||||
padding: 10px 16px;
|
||||
background-color: #f9fafb;
|
||||
color: #374151;
|
||||
font-weight: bold;
|
||||
border-bottom: 2px solid #d1d5db;
|
||||
}
|
||||
|
||||
.payment-method-table tbody td {
|
||||
padding: 10px 16px;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.badge-active {
|
||||
display: inline-block;
|
||||
padding: 3px 12px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.85rem;
|
||||
font-weight: bold;
|
||||
color: #166534;
|
||||
background-color: #dcfce7;
|
||||
border: 1px solid #22c55e;
|
||||
}
|
||||
|
||||
.badge-inactive {
|
||||
display: inline-block;
|
||||
padding: 3px 12px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.85rem;
|
||||
font-weight: bold;
|
||||
color: #991b1b;
|
||||
background-color: #fee2e2;
|
||||
border: 1px solid #ef4444;
|
||||
}
|
||||
|
||||
.btn-edit {
|
||||
padding: 6px 16px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
font-size: 0.9rem;
|
||||
background-color: #1d4899;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.btn-edit:hover {
|
||||
background-color: #163a7a;
|
||||
}
|
||||
|
||||
.data-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.data-table th {
|
||||
text-align: left;
|
||||
padding: 8px 12px;
|
||||
width: 200px;
|
||||
color: #374151;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.data-table td {
|
||||
padding: 8px 12px;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.form-input {
|
||||
width: 100%;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 6px;
|
||||
font-size: 0.95rem;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.btn-save, .btn-cancel {
|
||||
padding: 8px 20px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.btn-save {
|
||||
background-color: #16a34a;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.btn-save:hover {
|
||||
background-color: #15803d;
|
||||
}
|
||||
|
||||
.btn-cancel {
|
||||
background-color: #e5e7eb;
|
||||
color: #374151;
|
||||
}
|
||||
|
||||
.btn-cancel:hover {
|
||||
background-color: #d1d5db;
|
||||
}
|
||||
</style>
|
||||
@@ -6,6 +6,7 @@ import TenantContact from "./Partials/TenantContact.vue";
|
||||
import TenantPayment from "./Partials/TenantPayment.vue";
|
||||
import TenantImpress from "./Partials/TenantImpress.vue";
|
||||
import TenantGdpr from "./Partials/TenantGdpr.vue";
|
||||
import TenantPaymentMethods from "./Partials/TenantPaymentMethods.vue";
|
||||
|
||||
const props = defineProps({
|
||||
tenant: Object,
|
||||
@@ -22,6 +23,11 @@ const tabs = [
|
||||
component: TenantPayment,
|
||||
endpoint: '/api/v1/admin/tenant/payment',
|
||||
},
|
||||
{
|
||||
title: 'Zahlungswege',
|
||||
component: TenantPaymentMethods,
|
||||
endpoint: '/api/v1/admin/tenant/payment-methods',
|
||||
},
|
||||
{
|
||||
title: 'Impressum',
|
||||
component: TenantImpress,
|
||||
|
||||
Reference in New Issue
Block a user