| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Modules\PaymentMethods\Core; |
| 4 |
|
| 5 |
use FluentCart\App\App; |
| 6 |
use FluentCart\App\Models\Meta; |
| 7 |
use FluentCart\Framework\Support\Arr; |
| 8 |
|
| 9 |
abstract class BaseGatewaySettings |
| 10 |
{ |
| 11 |
public static array $allSettings = []; |
| 12 |
private static bool $settingsLoaded = false; |
| 13 |
|
| 14 |
public $settings; |
| 15 |
public $methodHandler; |
| 16 |
|
| 17 |
public function __construct() |
| 18 |
{ |
| 19 |
if (!self::$settingsLoaded) { |
| 20 |
self::$allSettings = Meta::query() |
| 21 |
->whereLike('meta_key', 'fluent_cart_payment_settings\\_%',) |
| 22 |
->get() |
| 23 |
->pluck('meta_value', 'meta_key') |
| 24 |
//->keyBy('meta_key') |
| 25 |
->toArray(); |
| 26 |
|
| 27 |
self::$settingsLoaded = true; |
| 28 |
} |
| 29 |
|
| 30 |
try { |
| 31 |
$settings = Arr::get(self::$allSettings, $this->methodHandler, []); |
| 32 |
} catch (\Exception $e) { |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
if (!is_array($settings)) { |
| 37 |
$settings = []; |
| 38 |
} |
| 39 |
|
| 40 |
$this->settings = wp_parse_args($settings, static::getDefaults()); |
| 41 |
} |
| 42 |
|
| 43 |
abstract public function get($key = ''); |
| 44 |
abstract public function getMode(); |
| 45 |
abstract public function isActive(); |
| 46 |
|
| 47 |
public function getCachedSettings() |
| 48 |
{ |
| 49 |
return Arr::get(self::$allSettings, $this->methodHandler); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
|