35 lines
1.3 KiB
PHP
35 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Resources;
|
|
|
|
use App\Models\AvailablePaymentMethod;
|
|
use App\Models\PaymentMethod;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class AvailablePaymentMethodResource extends JsonResource {
|
|
private AvailablePaymentMethod $availablePaymentMethod;
|
|
|
|
public function __construct(AvailablePaymentMethod $availablePaymentMethod) {
|
|
$this->availablePaymentMethod = $availablePaymentMethod;
|
|
}
|
|
|
|
public function toArray($request) : array {
|
|
// Wird die Instanz über Event::paymentMethods() geladen, liegt die pro-Event-Konfiguration
|
|
// im Pivot; ansonsten (Tenant-Kontext) gilt die Konfiguration der Instanz selbst.
|
|
$pivot = $this->availablePaymentMethod->pivot ?? null;
|
|
$configuration = $pivot !== null
|
|
? ($pivot->configuration ?? [])
|
|
: ($this->availablePaymentMethod->configuration ?? []);
|
|
|
|
return [
|
|
'id' => $this->availablePaymentMethod->id,
|
|
'slug' => $this->availablePaymentMethod->slug,
|
|
'name' => $this->availablePaymentMethod->name,
|
|
'description' => $this->availablePaymentMethod->description,
|
|
'active' => $this->availablePaymentMethod->active,
|
|
'configuration' => (object) $configuration,
|
|
'optionsSchema' => PaymentMethod::optionsFor($this->availablePaymentMethod->slug),
|
|
];
|
|
}
|
|
}
|