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 = '';
|
||||
}
|
||||
Reference in New Issue
Block a user