From a5b48c473069341d0460f2242c4998f45ea20819 Mon Sep 17 00:00:00 2001 From: IceToast Date: Thu, 2 Mar 2023 16:00:06 +0100 Subject: [PATCH 1/7] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Removed=20redundant?= =?UTF-8?q?=20closing=20div=20tags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/default/views/home.blade.php | 235 ++++++++++++++-------------- 1 file changed, 114 insertions(+), 121 deletions(-) diff --git a/themes/default/views/home.blade.php b/themes/default/views/home.blade.php index 69c14089..29d12926 100644 --- a/themes/default/views/home.blade.php +++ b/themes/default/views/home.blade.php @@ -168,139 +168,132 @@ @endif - - - -
-
-
-

- - {{ __('Activity Logs') }} -

-
- -
-
    - @foreach (Auth::user()->actions()->take(8)->orderBy('created_at', 'desc')->get() as $log) -
  • - - @if (str_starts_with($log->description, 'created')) - - @elseif(str_starts_with($log->description, 'redeemed')) - - @elseif(str_starts_with($log->description, 'deleted')) - - @elseif(str_starts_with($log->description, 'gained')) - - @elseif(str_starts_with($log->description, 'updated')) - - @endif - {{ explode('\\', $log->subject_type)[2] }} - {{ ucfirst($log->description) }} - - - {{ $log->created_at->diffForHumans() }} - -
  • - @endforeach -
-
- -
- - @if ($referral_settings->enabled) - +

- - {{ __('Partner program') }} + + {{ __('Activity Logs') }}

- @if ( - ($referral_settings->allowed == 'client' && Auth::user()->role != 'member') || - $referral_settings->allowed == 'everyone') -
-
- - - {{ __('Your referral URL') }}: - - {{ __('Click to copy') }} - +
    + @foreach (Auth::user()->actions()->take(8)->orderBy('created_at', 'desc')->get() as $log) +
  • + + @if (str_starts_with($log->description, 'created')) + + @elseif(str_starts_with($log->description, 'redeemed')) + + @elseif(str_starts_with($log->description, 'deleted')) + + @elseif(str_starts_with($log->description, 'gained')) + + @elseif(str_starts_with($log->description, 'updated')) + + @endif + {{ explode('\\', $log->subject_type)[2] }} + {{ ucfirst($log->description) }} -
-
- {{ __('Number of referred users:') }} - {{ $numberOfReferrals }} -
-
- @if ($partnerDiscount) -
- - - - - - - - - - - - - - - - - -
{{ __('Your discount') }}{{ __('Discount for your new users') }}{{ __('Reward per registered user') }}{{ __('New user payment commision') }}
{{ $partnerDiscount->partner_discount }}%{{ $partnerDiscount->registered_user_discount }}%{{ $referral_settings->reward }} - {{ $general_settings->credits_display_name }}{{ $partnerDiscount->referral_system_commission == -1 ? $referral_settings->percentage : $partnerDiscount->referral_system_commission }}% -
-
- @else -
- - - - - - - - - - - - - -
{{ __('Reward per registered user') }}{{ __('New user payment commision') }}
{{ $referral_settings->reward }} - {{ $general_settings->credits_display_name }}{{ $referral_settings->percentage }}%
-
- @endif - @else - - {{ __('Make a purchase to reveal your referral-URL') }} - @endif + + {{ $log->created_at->diffForHumans() }} + + + @endforeach +
- @endif - -
- - -
- + + @if ($referral_settings->enabled) + +
+
+

+ + {{ __('Partner program') }} +

+
+ +
+ @if ( + ($referral_settings->allowed == 'client' && Auth::user()->role != 'member') || + $referral_settings->allowed == 'everyone') +
+
+ + + {{ __('Your referral URL') }}: + + {{ __('Click to copy') }} + + +
+
+ {{ __('Number of referred users:') }} + {{ $numberOfReferrals }} +
+
+ @if ($partnerDiscount) +
+ + + + + + + + + + + + + + + + + +
{{ __('Your discount') }}{{ __('Discount for your new users') }}{{ __('Reward per registered user') }}{{ __('New user payment commision') }}
{{ $partnerDiscount->partner_discount }}%{{ $partnerDiscount->registered_user_discount }}%{{ $referral_settings->reward }} + {{ $general_settings->credits_display_name }}{{ $partnerDiscount->referral_system_commission == -1 ? $referral_settings->percentage : $partnerDiscount->referral_system_commission }}% +
+
+ @else +
+ + + + + + + + + + + + + +
{{ __('Reward per registered user') }}{{ __('New user payment commision') }}
{{ $referral_settings->reward }} + {{ $general_settings->credits_display_name }}{{ $referral_settings->percentage }}%
+
+ @endif + @else + + {{ __('Make a purchase to reveal your referral-URL') }} + @endif +
+ +
+ @endif + + From 322bfed97257cf02f2ee0cb306e3b83e1b67c6be Mon Sep 17 00:00:00 2001 From: IceToast Date: Sat, 4 Mar 2023 15:13:14 +0100 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=E2=9C=A8=20Added=20PayPal=20Settin?= =?UTF-8?q?gs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PaymentGateways/PayPal/PayPalSettings.php | 48 ++++++++++ ...3_03_04_135248_create_pay_pal_settings.php | 19 ++++ app/Providers/AppServiceProvider.php | 89 +------------------ 3 files changed, 69 insertions(+), 87 deletions(-) create mode 100644 app/Extensions/PaymentGateways/PayPal/PayPalSettings.php create mode 100644 app/Extensions/PaymentGateways/PayPal/migrations/2023_03_04_135248_create_pay_pal_settings.php diff --git a/app/Extensions/PaymentGateways/PayPal/PayPalSettings.php b/app/Extensions/PaymentGateways/PayPal/PayPalSettings.php new file mode 100644 index 00000000..3413a451 --- /dev/null +++ b/app/Extensions/PaymentGateways/PayPal/PayPalSettings.php @@ -0,0 +1,48 @@ +>> + */ + public static function getOptionInputData() + { + return [ + 'category_icon' => 'fas fa-dollar-sign', + 'client_id' => [ + 'type' => 'text', + 'label' => 'Client ID', + 'description' => 'The Client ID of your PayPal App', + ], + 'client_secret' => [ + 'type' => 'text', + 'label' => 'Client Secret', + 'description' => 'The Client Secret of your PayPal App', + ] + ]; + } +} diff --git a/app/Extensions/PaymentGateways/PayPal/migrations/2023_03_04_135248_create_pay_pal_settings.php b/app/Extensions/PaymentGateways/PayPal/migrations/2023_03_04_135248_create_pay_pal_settings.php new file mode 100644 index 00000000..67d85524 --- /dev/null +++ b/app/Extensions/PaymentGateways/PayPal/migrations/2023_03_04_135248_create_pay_pal_settings.php @@ -0,0 +1,19 @@ +migrator->addEncrypted('paypal.client_id', "1234"); + $this->migrator->addEncrypted('paypal.client_secret', "123456"); + } + + public function down(): void + { + $this->migrator->delete('paypal.client_id'); + $this->migrator->delete('paypal.client_secret'); + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index c6018744..97a269c0 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,6 +2,7 @@ namespace App\Providers; +use App\Extensions\PaymentGateways\PayPal\PayPalSettings; use App\Models\UsefulLink; use App\Settings\MailSettings; use Exception; @@ -10,7 +11,7 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Validator; use Illuminate\Support\ServiceProvider; -use Qirolab\Theme\Theme; + class AppServiceProvider extends ServiceProvider { @@ -64,91 +65,5 @@ class AppServiceProvider extends ServiceProvider $settings = $this->app->make(MailSettings::class); $settings->setConfig(); - - //only run if the installer has been executed - // try { - // $settings = Settings::all(); - // // Set all configs from database - // foreach ($settings as $setting) { - // config([$setting->key => $setting->value]); - // } - - // if(!file_exists(base_path('themes') . "/" . config("SETTINGS::SYSTEM:THEME"))){ - // config(['SETTINGS::SYSTEM:THEME' => "default"]); - // } - - // if(config('SETTINGS::SYSTEM:THEME') !== config('theme.active')){ - // Theme::set(config("SETTINGS::SYSTEM:THEME"), "default"); - // } - - // // Set Mail Config - // //only update config if mail settings have changed in DB - // if ( - // config('mail.default') != config('SETTINGS:MAIL:MAILER') || - // config('mail.mailers.smtp.host') != config('SETTINGS:MAIL:HOST') || - // config('mail.mailers.smtp.port') != config('SETTINGS:MAIL:PORT') || - // config('mail.mailers.smtp.username') != config('SETTINGS:MAIL:USERNAME') || - // config('mail.mailers.smtp.password') != config('SETTINGS:MAIL:PASSWORD') || - // config('mail.mailers.smtp.encryption') != config('SETTINGS:MAIL:ENCRYPTION') || - // config('mail.from.address') != config('SETTINGS:MAIL:FROM_ADDRESS') || - // config('mail.from.name') != config('SETTINGS:MAIL:FROM_NAME') - // ) { - // config(['mail.default' => config('SETTINGS::MAIL:MAILER')]); - // config(['mail.mailers.smtp' => [ - // 'transport' => 'smtp', - // 'host' => config('SETTINGS::MAIL:HOST'), - // 'port' => config('SETTINGS::MAIL:PORT'), - // 'encryption' => config('SETTINGS::MAIL:ENCRYPTION'), - // 'username' => config('SETTINGS::MAIL:USERNAME'), - // 'password' => config('SETTINGS::MAIL:PASSWORD'), - // 'timeout' => null, - // 'auth_mode' => null, - // ]]); - // config(['mail.from' => ['address' => config('SETTINGS::MAIL:FROM_ADDRESS'), 'name' => config('SETTINGS::MAIL:FROM_NAME')]]); - - // Artisan::call('queue:restart'); - // } - - // // Set Recaptcha API Config - // // Load recaptcha package if recaptcha is enabled - // if (config('SETTINGS::RECAPTCHA:ENABLED') == 'true') { - // $this->app->register(\Biscolab\ReCaptcha\ReCaptchaServiceProvider::class); - // } - - // //only update config if recaptcha settings have changed in DB - // if ( - // config('recaptcha.api_site_key') != config('SETTINGS::RECAPTCHA:SITE_KEY') || - // config('recaptcha.api_secret_key') != config('SETTINGS::RECAPTCHA:SECRET_KEY') - // ) { - // config(['recaptcha.api_site_key' => config('SETTINGS::RECAPTCHA:SITE_KEY')]); - // config(['recaptcha.api_secret_key' => config('SETTINGS::RECAPTCHA:SECRET_KEY')]); - - // Artisan::call('config:clear'); - // Artisan::call('cache:clear'); - // } - - // try { - // $stringfromfile = file(base_path().'/.git/HEAD'); - - // $firstLine = $stringfromfile[0]; //get the string from the array - - // $explodedstring = explode('/', $firstLine, 3); //seperate out by the "/" in the string - - // $branchname = $explodedstring[2]; //get the one that is always the branch name - // } catch (Exception $e) { - // $branchname = 'unknown'; - // Log::notice($e); - // } - // config(['BRANCHNAME' => $branchname]); - - // // Set Discord-API Config - // config(['services.discord.client_id' => config('SETTINGS::DISCORD:CLIENT_ID')]); - // config(['services.discord.client_secret' => config('SETTINGS::DISCORD:CLIENT_SECRET')]); - // } catch (Exception $e) { - // error_log('Settings Error: Could not load settings from database. The Installation probably is not done yet.'); - // error_log($e); - // Log::error('Settings Error: Could not load settings from database. The Installation probably is not done yet.'); - // Log::error($e); - // } } } From 3ea5b4e01028aa6c07da1650fe7a63a9b1f90957 Mon Sep 17 00:00:00 2001 From: IceToast Date: Sat, 4 Mar 2023 15:20:49 +0100 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20=E2=9C=A8=20Added=20Extensionmigrat?= =?UTF-8?q?ions=20to=20laravel-settings=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Helpers/ExtensionHelper.php | 25 ++++++++++++++++++++++++- config/settings.php | 7 +++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/Helpers/ExtensionHelper.php b/app/Helpers/ExtensionHelper.php index 7e1bbda3..1f37cd4a 100644 --- a/app/Helpers/ExtensionHelper.php +++ b/app/Helpers/ExtensionHelper.php @@ -2,6 +2,9 @@ namespace App\Helpers; +/** + * Summary of ExtensionHelper + */ class ExtensionHelper { /** @@ -60,7 +63,7 @@ class ExtensionHelper /** * Get all extensions - * @return array + * @return array of all extension paths look like: app/Extensions/ExtensionNamespace/ExtensionName */ public static function getAllExtensions() { @@ -79,4 +82,24 @@ class ExtensionHelper return $extensions; } + + /** + * Summary of getAllExtensionMigrations + * @return array of all migration paths look like: app/Extensions/ExtensionNamespace/ExtensionName/migrations/ + */ + public static function getAllExtensionMigrations() + { + $extensions = ExtensionHelper::getAllExtensions(); + + // get all migration directories of the extensions and return them as array + $migrations = []; + foreach ($extensions as $extension) { + $migrationDir = $extension . '/migrations'; + if (file_exists($migrationDir)) { + $migrations[] = $migrationDir; + } + } + + return $migrations; + } } diff --git a/config/settings.php b/config/settings.php index f3a6393b..67838a5c 100644 --- a/config/settings.php +++ b/config/settings.php @@ -1,5 +1,6 @@ [ database_path('settings'), + ...ExtensionHelper::getAllExtensionMigrations() + ], /* @@ -88,7 +91,7 @@ return [ 'global_casts' => [ DateTimeInterface::class => Spatie\LaravelSettings\SettingsCasts\DateTimeInterfaceCast::class, DateTimeZone::class => Spatie\LaravelSettings\SettingsCasts\DateTimeZoneCast::class, -// Spatie\DataTransferObject\DataTransferObject::class => Spatie\LaravelSettings\SettingsCasts\DtoCast::class, + // Spatie\DataTransferObject\DataTransferObject::class => Spatie\LaravelSettings\SettingsCasts\DtoCast::class, Spatie\LaravelData\Data::class => Spatie\LaravelSettings\SettingsCasts\DataCast::class, ], From 1a8f883b63845f60885710339759d20090b2f1b5 Mon Sep 17 00:00:00 2001 From: IceToast Date: Sat, 4 Mar 2023 19:59:59 +0100 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20=E2=9C=A8=20Add=20Extension=20Setti?= =?UTF-8?q?ngs=20to=20Settingspage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Helpers/ExtensionHelper.php | 30 +++++++++++++++++++ .../Controllers/Admin/SettingsController.php | 30 ++++++++++++++----- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/app/Helpers/ExtensionHelper.php b/app/Helpers/ExtensionHelper.php index 1f37cd4a..bce70f99 100644 --- a/app/Helpers/ExtensionHelper.php +++ b/app/Helpers/ExtensionHelper.php @@ -102,4 +102,34 @@ class ExtensionHelper return $migrations; } + + /** + * Summary of getAllExtensionSettings + * @return array of all setting classes look like: App\Extensions\PaymentGateways\PayPal\PayPalSettings + */ + public static function getAllExtensionSettings() + { + $extensions = ExtensionHelper::getAllExtensions(); + + $settings = []; + foreach ($extensions as $extension) { + + $extensionName = basename($extension); + $settingFile = $extension . '/' . $extensionName . 'Settings.php'; + if (file_exists($settingFile)) { + // remove the base path from the setting file path to get the namespace + + $settingFile = str_replace(app_path() . '/', '', $settingFile); + $settingFile = str_replace('.php', '', $settingFile); + $settingFile = str_replace('/', '\\', $settingFile); + $settingFile = 'App\\' . $settingFile; + $settings[] = $settingFile; + } + } + + error_log(print_r($settings, true)); + + + return $settings; + } } diff --git a/app/Http/Controllers/Admin/SettingsController.php b/app/Http/Controllers/Admin/SettingsController.php index d98ca015..d746d9de 100644 --- a/app/Http/Controllers/Admin/SettingsController.php +++ b/app/Http/Controllers/Admin/SettingsController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Admin; +use App\Helpers\ExtensionHelper; use App\Http\Controllers\Controller; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; @@ -25,18 +26,33 @@ class SettingsController extends Controller // get all other settings in app/Settings directory // group items by file name like $categories $settings = collect(); - foreach (scandir(app_path('Settings')) as $file) { - if (in_array($file, ['.', '..'])) { - continue; - } - $className = 'App\\Settings\\' . str_replace('.php', '', $file); - $options = (new $className())->toArray(); + $settings_classes = []; + // get all app settings + $app_settings = scandir(app_path('Settings')); + $app_settings = array_diff($app_settings, ['.', '..']); + // append App\Settings to class name + foreach ($app_settings as $app_setting) { + $settings_classes[] = 'App\\Settings\\' . str_replace('.php', '', $app_setting); + } + // get all extension settings + $settings_files = array_merge($settings_classes, ExtensionHelper::getAllExtensionSettings()); + + + foreach ($settings_files as $file) { + + $className = $file; + // instantiate the class and call toArray method to get all options + $options = (new $className())->toArray(); + error_log(print_r($className, true)); + + // call getOptionInputData method to get all options if (method_exists($className, 'getOptionInputData')) { $optionInputData = $className::getOptionInputData(); } else { $optionInputData = []; } + error_log(print_r($optionInputData, true)); // collect all option input data $optionsData = []; @@ -55,7 +71,7 @@ class SettingsController extends Controller $optionsData['category_icon'] = $optionInputData['category_icon']; } - $settings[str_replace('Settings.php', '', $file)] = $optionsData; + $settings[str_replace('Settings', '', class_basename($className))] = $optionsData; } $settings->sort(); From 3cba1c60f826f1291f0723dbb6b7964c0ab389a6 Mon Sep 17 00:00:00 2001 From: IceToast Date: Sat, 4 Mar 2023 20:00:22 +0100 Subject: [PATCH 5/7] =?UTF-8?q?feat:=20=E2=9C=A8=20Add=20Extension=20Setti?= =?UTF-8?q?ngs=20and=20migrations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PaymentGateways/PayPal/PayPalSettings.php | 29 +++++- .../PaymentGateways/PayPal/config.php | 2 - ...3_03_04_135248_create_pay_pal_settings.php | 85 +++++++++++++++- .../PaymentGateways/Stripe/StripeSettings.php | 63 ++++++++++++ ...23_03_04_181917_create_stripe_settings.php | 98 +++++++++++++++++++ ...3_15_150022_delete_old_settings_table.php} | 68 ++++++------- 6 files changed, 302 insertions(+), 43 deletions(-) create mode 100644 app/Extensions/PaymentGateways/Stripe/StripeSettings.php create mode 100644 app/Extensions/PaymentGateways/Stripe/migrations/2023_03_04_181917_create_stripe_settings.php rename database/migrations/{2023_02_13_150022_delete_old_settings_table.php => 2023_03_15_150022_delete_old_settings_table.php} (95%) diff --git a/app/Extensions/PaymentGateways/PayPal/PayPalSettings.php b/app/Extensions/PaymentGateways/PayPal/PayPalSettings.php index 3413a451..1688c011 100644 --- a/app/Extensions/PaymentGateways/PayPal/PayPalSettings.php +++ b/app/Extensions/PaymentGateways/PayPal/PayPalSettings.php @@ -6,9 +6,11 @@ use Spatie\LaravelSettings\Settings; class PayPalSettings extends Settings { + public bool $enabled = false; public ?string $client_id; public ?string $client_secret; - + public ?string $sandbox_client_id; + public ?string $sandbox_client_secret; public static function group(): string { @@ -20,7 +22,9 @@ class PayPalSettings extends Settings { return [ 'client_id', - 'client_secret' + 'client_secret', + 'sandbox_client_id', + 'sandbox_client_secret' ]; } @@ -34,15 +38,30 @@ class PayPalSettings extends Settings return [ 'category_icon' => 'fas fa-dollar-sign', 'client_id' => [ - 'type' => 'text', + 'type' => 'string', 'label' => 'Client ID', 'description' => 'The Client ID of your PayPal App', ], 'client_secret' => [ - 'type' => 'text', + 'type' => 'string', 'label' => 'Client Secret', 'description' => 'The Client Secret of your PayPal App', - ] + ], + 'enabled' => [ + 'type' => 'boolean', + 'label' => 'Enabled', + 'description' => 'Enable this payment gateway', + ], + 'sandbox_client_id' => [ + 'type' => 'string', + 'label' => 'Sandbox Client ID', + 'description' => 'The Sandbox Client ID used when app_env = local', + ], + 'sandbox_client_secret' => [ + 'type' => 'string', + 'label' => 'Sandbox Client Secret', + 'description' => 'The Sandbox Client Secret used when app_env = local', + ], ]; } } diff --git a/app/Extensions/PaymentGateways/PayPal/config.php b/app/Extensions/PaymentGateways/PayPal/config.php index 6fa98a13..f47cccfa 100644 --- a/app/Extensions/PaymentGateways/PayPal/config.php +++ b/app/Extensions/PaymentGateways/PayPal/config.php @@ -6,8 +6,6 @@ function getConfig() { return [ "name" => "PayPal", - "description" => "PayPal payment gateway", "RoutesIgnoreCsrf" => [], - "enabled" => (config('SETTINGS::PAYMENTS:PAYPAL:SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID')) || (config('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID') && env("APP_ENV") === "local"), ]; } diff --git a/app/Extensions/PaymentGateways/PayPal/migrations/2023_03_04_135248_create_pay_pal_settings.php b/app/Extensions/PaymentGateways/PayPal/migrations/2023_03_04_135248_create_pay_pal_settings.php index 67d85524..5792abec 100644 --- a/app/Extensions/PaymentGateways/PayPal/migrations/2023_03_04_135248_create_pay_pal_settings.php +++ b/app/Extensions/PaymentGateways/PayPal/migrations/2023_03_04_135248_create_pay_pal_settings.php @@ -1,19 +1,100 @@ exists(); - $this->migrator->addEncrypted('paypal.client_id', "1234"); - $this->migrator->addEncrypted('paypal.client_secret', "123456"); + + $this->migrator->addEncrypted('paypal.client_id', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID') : null); + $this->migrator->addEncrypted('paypal.client_secret', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:PAYPAL:SECRET') : null); + $this->migrator->addEncrypted('paypal.sandbox_client_id', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID') : null); + $this->migrator->addEncrypted('paypal.sandbox_client_secret', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET') : null); + $this->migrator->add('paypal.enabled', false); } public function down(): void { + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID', + 'value' => $this->getNewValue('client_id'), + 'type' => 'string', + 'description' => 'The Client ID of your PayPal App' + ], + [ + 'key' => 'SETTINGS::PAYMENTS:PAYPAL:SECRET', + 'value' => $this->getNewValue('client_secret'), + 'type' => 'string', + 'description' => 'The Client Secret of your PayPal App' + ], + [ + 'key' => 'SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID', + 'value' => $this->getNewValue('sandbox_client_id'), + 'type' => 'string', + 'description' => 'The Sandbox Client ID of your PayPal App' + ], + [ + 'key' => 'SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET', + 'value' => $this->getNewValue('sandbox_client_secret'), + 'type' => 'string', + 'description' => 'The Sandbox Client Secret of your PayPal App' + ] + ]); + + $this->migrator->delete('paypal.client_id'); $this->migrator->delete('paypal.client_secret'); + $this->migrator->delete('paypal.enabled'); + $this->migrator->delete('paypal.sandbox_client_id'); + $this->migrator->delete('paypal.sandbox_client_secret'); + } + + public function getNewValue(string $name) + { + $new_value = DB::table('settings')->where([['group', '=', 'paypal'], ['name', '=', $name]])->get(['payload'])->first(); + + // Some keys returns '""' as a value. + if ($new_value->payload === '""') { + return null; + } + + // remove the quotes from the string + if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') { + return substr($new_value->payload, 1, -1); + } + + return $new_value->payload; + } + + public function getOldValue(string $key) + { + // Always get the first value of the key. + $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first(); + + // Handle the old values to return without it being a string in all cases. + if ($old_value->type === "string" || $old_value->type === "text") { + if (is_null($old_value->value)) { + return ''; + } + + // Some values have the type string, but their values are boolean. + if ($old_value->value === "false" || $old_value->value === "true") { + return filter_var($old_value->value, FILTER_VALIDATE_BOOL); + } + + return $old_value->value; + } + + if ($old_value->type === "boolean") { + return filter_var($old_value->value, FILTER_VALIDATE_BOOL); + } + + return filter_var($old_value->value, FILTER_VALIDATE_INT); } } diff --git a/app/Extensions/PaymentGateways/Stripe/StripeSettings.php b/app/Extensions/PaymentGateways/Stripe/StripeSettings.php new file mode 100644 index 00000000..c7a2d7bd --- /dev/null +++ b/app/Extensions/PaymentGateways/Stripe/StripeSettings.php @@ -0,0 +1,63 @@ + 'fas fa-dollar-sign', + 'secret_key' => [ + 'type' => 'string', + 'label' => 'Secret Key', + 'description' => 'The Secret Key of your Stripe App', + ], + 'endpoint_secret' => [ + 'type' => 'string', + 'label' => 'Endpoint Secret', + 'description' => 'The Endpoint Secret of your Stripe App', + ], + 'test_secret_key' => [ + 'type' => 'string', + 'label' => 'Test Secret Key', + 'description' => 'The Test Secret Key used when app_env = local', + ], + 'test_endpoint_secret' => [ + 'type' => 'string', + 'label' => 'Test Endpoint Secret', + 'description' => 'The Test Endpoint Secret used when app_env = local', + ], + 'enabled' => [ + 'type' => 'boolean', + 'label' => 'Enabled', + 'description' => 'Enable this payment gateway', + ] + ]; + } +} diff --git a/app/Extensions/PaymentGateways/Stripe/migrations/2023_03_04_181917_create_stripe_settings.php b/app/Extensions/PaymentGateways/Stripe/migrations/2023_03_04_181917_create_stripe_settings.php new file mode 100644 index 00000000..a8145a7c --- /dev/null +++ b/app/Extensions/PaymentGateways/Stripe/migrations/2023_03_04_181917_create_stripe_settings.php @@ -0,0 +1,98 @@ +exists(); + + $this->migrator->addEncrypted('stripe.secret_key', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:STRIPE:SECRET') : null); + $this->migrator->addEncrypted('stripe.endpoint_secret', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') : null); + $this->migrator->addEncrypted('stripe.test_secret_key', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:STRIPE:TEST_SECRET') : null); + $this->migrator->addEncrypted('stripe.test_endpoint_secret', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET') : null); + $this->migrator->add('stripe.enabled', false); + } + + public function down(): void + { + DB::table('settings_old')->insert([ + [ + 'key' => 'SETTINGS::PAYMENTS:STRIPE:SECRET', + 'value' => $this->getNewValue('secret_key'), + 'type' => 'string', + 'description' => 'The Secret Key of your Stripe App' + ], + [ + 'key' => 'SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET', + 'value' => $this->getNewValue('endpoint_secret'), + 'type' => 'string', + 'description' => 'The Endpoint Secret of your Stripe App' + + ], + [ + 'key' => 'SETTINGS::PAYMENTS:STRIPE:TEST_SECRET', + 'value' => $this->getNewValue('test_secret_key'), + 'type' => 'string', + 'description' => 'The Test Secret Key of your Stripe App' + ], + [ + 'key' => 'SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET', + 'value' => $this->getNewValue('test_endpoint_secret'), + 'type' => 'string', + 'description' => 'The Test Endpoint Secret of your Stripe App' + ] + ]); + + $this->migrator->delete('stripe.secret_key'); + $this->migrator->delete('stripe.endpoint_secret'); + $this->migrator->delete('stripe.enabled'); + $this->migrator->delete('stripe.test_secret_key'); + $this->migrator->delete('stripe.test_endpoint_secret'); + } + + public function getNewValue(string $name) + { + $new_value = DB::table('settings')->where([['group', '=', 'stripe'], ['name', '=', $name]])->get(['payload'])->first(); + + // Some keys returns '""' as a value. + if ($new_value->payload === '""') { + return null; + } + + // remove the quotes from the string + if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') { + return substr($new_value->payload, 1, -1); + } + + return $new_value->payload; + } + + public function getOldValue(string $key) + { + // Always get the first value of the key. + $old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first(); + + // Handle the old values to return without it being a string in all cases. + if ($old_value->type === "string" || $old_value->type === "text") { + if (is_null($old_value->value)) { + return ''; + } + + // Some values have the type string, but their values are boolean. + if ($old_value->value === "false" || $old_value->value === "true") { + return filter_var($old_value->value, FILTER_VALIDATE_BOOL); + } + + return $old_value->value; + } + + if ($old_value->type === "boolean") { + return filter_var($old_value->value, FILTER_VALIDATE_BOOL); + } + + return filter_var($old_value->value, FILTER_VALIDATE_INT); + } +} diff --git a/database/migrations/2023_02_13_150022_delete_old_settings_table.php b/database/migrations/2023_03_15_150022_delete_old_settings_table.php similarity index 95% rename from database/migrations/2023_02_13_150022_delete_old_settings_table.php rename to database/migrations/2023_03_15_150022_delete_old_settings_table.php index 81c069c3..11f107cc 100644 --- a/database/migrations/2023_02_13_150022_delete_old_settings_table.php +++ b/database/migrations/2023_03_15_150022_delete_old_settings_table.php @@ -1,34 +1,34 @@ -string('key', 191)->primary(); - $table->text('value')->nullable(); - $table->string('type'); - $table->longText('description')->nullable(); - $table->timestamps(); - }); - } -}; +string('key', 191)->primary(); + $table->text('value')->nullable(); + $table->string('type'); + $table->longText('description')->nullable(); + $table->timestamps(); + }); + } +}; From d7a36c61b2ba64804c9667745813011fca0d4739 Mon Sep 17 00:00:00 2001 From: IceToast Date: Sat, 4 Mar 2023 20:28:27 +0100 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=E2=9C=A8=20Migrate=20Extensions=20?= =?UTF-8?q?from=20old=20to=20new=20settings=20system?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PaymentGateways/PayPal/index.php | 13 ++++++++-- .../PaymentGateways/Stripe/config.php | 2 -- .../PaymentGateways/Stripe/index.php | 13 ++++++---- app/Helpers/ExtensionHelper.php | 26 ++++++++++++++++++- .../Controllers/Admin/PaymentController.php | 5 +++- .../Controllers/Admin/SettingsController.php | 11 ++++---- .../views/admin/settings/index.blade.php | 4 ++- 7 files changed, 57 insertions(+), 17 deletions(-) diff --git a/app/Extensions/PaymentGateways/PayPal/index.php b/app/Extensions/PaymentGateways/PayPal/index.php index 648913ae..181ad252 100644 --- a/app/Extensions/PaymentGateways/PayPal/index.php +++ b/app/Extensions/PaymentGateways/PayPal/index.php @@ -2,6 +2,7 @@ use App\Events\PaymentEvent; use App\Events\UserUpdateCreditsEvent; +use App\Extensions\PaymentGateways\PayPal\PayPalSettings; use App\Models\PartnerDiscount; use App\Models\Payment; use App\Models\ShopProduct; @@ -25,6 +26,8 @@ use PayPalHttp\HttpException; */ function PaypalPay(Request $request) { + $settings = new PayPalSettings(); + /** @var User $user */ $user = Auth::user(); $shopProduct = ShopProduct::findOrFail($request->shopProduct); @@ -111,6 +114,8 @@ function PaypalPay(Request $request) */ function PaypalSuccess(Request $laravelRequest) { + $settings = new PayPalSettings(); + $user = Auth::user(); $user = User::findOrFail($user->id); @@ -165,6 +170,8 @@ function PaypalSuccess(Request $laravelRequest) */ function getPayPalClient() { + $settings = new PayPalSettings(); + $environment = env('APP_ENV') == 'local' ? new SandboxEnvironment(getPaypalClientId(), getPaypalClientSecret()) : new ProductionEnvironment(getPaypalClientId(), getPaypalClientSecret()); @@ -175,12 +182,14 @@ function getPayPalClient() */ function getPaypalClientId() { - return env('APP_ENV') == 'local' ? config("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID") : config("SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID"); + $settings = new PayPalSettings(); + return env('APP_ENV') == 'local' ? $settings->sandbox_client_id : $settings->client_id; } /** * @return string */ function getPaypalClientSecret() { - return env('APP_ENV') == 'local' ? config("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET") : config("SETTINGS::PAYMENTS:PAYPAL:SECRET"); + $settings = new PayPalSettings(); + return env('APP_ENV') == 'local' ? $settings->sandbox_client_secret : $settings->client_secret; } diff --git a/app/Extensions/PaymentGateways/Stripe/config.php b/app/Extensions/PaymentGateways/Stripe/config.php index cac2547a..92a43b8e 100644 --- a/app/Extensions/PaymentGateways/Stripe/config.php +++ b/app/Extensions/PaymentGateways/Stripe/config.php @@ -6,10 +6,8 @@ function getConfig() { return [ "name" => "Stripe", - "description" => "Stripe payment gateway", "RoutesIgnoreCsrf" => [ "payment/StripeWebhooks", ], - "enabled" => config('SETTINGS::PAYMENTS:STRIPE:SECRET') && config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') || config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET') && config('SETTINGS::PAYMENTS:STRIPE:TEST_SECRET') && env("APP_ENV") === "local", ]; } diff --git a/app/Extensions/PaymentGateways/Stripe/index.php b/app/Extensions/PaymentGateways/Stripe/index.php index 56e898c2..aaf67f3a 100644 --- a/app/Extensions/PaymentGateways/Stripe/index.php +++ b/app/Extensions/PaymentGateways/Stripe/index.php @@ -2,6 +2,7 @@ use App\Events\PaymentEvent; use App\Events\UserUpdateCreditsEvent; +use App\Extensions\PaymentGateways\Stripe\StripeSettings; use App\Models\PartnerDiscount; use App\Models\Payment; use App\Models\ShopProduct; @@ -79,7 +80,6 @@ function StripePay(Request $request) ], 'mode' => 'payment', - 'payment_method_types' => str_getcsv(config('SETTINGS::PAYMENTS:STRIPE:METHODS')), 'success_url' => route('payment.StripeSuccess', ['payment' => $payment->id]) . '&session_id={CHECKOUT_SESSION_ID}', 'cancel_url' => route('payment.Cancel'), 'payment_intent_data' => [ @@ -244,9 +244,11 @@ function getStripeClient() */ function getStripeSecret() { + $settings = new StripeSettings(); + return env('APP_ENV') == 'local' - ? config('SETTINGS::PAYMENTS:STRIPE:TEST_SECRET') - : config('SETTINGS::PAYMENTS:STRIPE:SECRET'); + ? $settings->test_secret_key + : $settings->secret_key; } /** @@ -254,9 +256,10 @@ function getStripeSecret() */ function getStripeEndpointSecret() { + $settings = new StripeSettings(); return env('APP_ENV') == 'local' - ? config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET') - : config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET'); + ? $settings->test_endpoint_secret + : $settings->endpoint_secret; } /** * @param $amount diff --git a/app/Helpers/ExtensionHelper.php b/app/Helpers/ExtensionHelper.php index bce70f99..6844268b 100644 --- a/app/Helpers/ExtensionHelper.php +++ b/app/Helpers/ExtensionHelper.php @@ -107,7 +107,7 @@ class ExtensionHelper * Summary of getAllExtensionSettings * @return array of all setting classes look like: App\Extensions\PaymentGateways\PayPal\PayPalSettings */ - public static function getAllExtensionSettings() + public static function getAllExtensionSettingsClasses() { $extensions = ExtensionHelper::getAllExtensions(); @@ -132,4 +132,28 @@ class ExtensionHelper return $settings; } + + public static function getExtensionSettings(string $extensionName) + { + $extensions = ExtensionHelper::getAllExtensions(); + + // find the setting file of the extension and return an instance of it + foreach ($extensions as $extension) { + if (!(basename($extension) == $extensionName)) { + continue; + } + + $extensionName = basename($extension); + $settingFile = $extension . '/' . $extensionName . 'Settings.php'; + if (file_exists($settingFile)) { + // remove the base path from the setting file path to get the namespace + + $settingFile = str_replace(app_path() . '/', '', $settingFile); + $settingFile = str_replace('.php', '', $settingFile); + $settingFile = str_replace('/', '\\', $settingFile); + $settingFile = 'App\\' . $settingFile; + return new $settingFile(); + } + } + } } diff --git a/app/Http/Controllers/Admin/PaymentController.php b/app/Http/Controllers/Admin/PaymentController.php index 65b534f8..25d2c9ce 100644 --- a/app/Http/Controllers/Admin/PaymentController.php +++ b/app/Http/Controllers/Admin/PaymentController.php @@ -51,7 +51,10 @@ class PaymentController extends Controller // build a paymentgateways array that contains the routes for the payment gateways and the image path for the payment gateway which lays in public/images/Extensions/PaymentGateways with the extensionname in lowercase foreach ($extensions as $extension) { $extensionName = basename($extension); - if (!ExtensionHelper::getExtensionConfig($extensionName, 'enabled')) continue; // skip if not enabled + + $extensionSettings = ExtensionHelper::getExtensionSettings($extensionName); + if ($extensionSettings->enabled == false) continue; + $payment = new \stdClass(); $payment->name = ExtensionHelper::getExtensionConfig($extensionName, 'name'); diff --git a/app/Http/Controllers/Admin/SettingsController.php b/app/Http/Controllers/Admin/SettingsController.php index d746d9de..456166bd 100644 --- a/app/Http/Controllers/Admin/SettingsController.php +++ b/app/Http/Controllers/Admin/SettingsController.php @@ -36,7 +36,7 @@ class SettingsController extends Controller $settings_classes[] = 'App\\Settings\\' . str_replace('.php', '', $app_setting); } // get all extension settings - $settings_files = array_merge($settings_classes, ExtensionHelper::getAllExtensionSettings()); + $settings_files = array_merge($settings_classes, ExtensionHelper::getAllExtensionSettingsClasses()); foreach ($settings_files as $file) { @@ -70,6 +70,7 @@ class SettingsController extends Controller if (isset($optionInputData['category_icon'])) { $optionsData['category_icon'] = $optionInputData['category_icon']; } + $optionsData['settings_class'] = $className; $settings[str_replace('Settings', '', class_basename($className))] = $optionsData; } @@ -93,10 +94,10 @@ class SettingsController extends Controller public function update(Request $request) { $category = request()->get('category'); + $settings_class = request()->get('settings_class'); - $className = 'App\\Settings\\' . $category . 'Settings'; - if (method_exists($className, 'getValidations')) { - $validations = $className::getValidations(); + if (method_exists($settings_class, 'getValidations')) { + $validations = $settings_class::getValidations(); } else { $validations = []; } @@ -107,7 +108,7 @@ class SettingsController extends Controller return Redirect::to('admin/settings' . '#' . $category)->withErrors($validator)->withInput(); } - $settingsClass = new $className(); + $settingsClass = new $settings_class(); foreach ($settingsClass->toArray() as $key => $value) { switch (gettype($value)) { diff --git a/themes/default/views/admin/settings/index.blade.php b/themes/default/views/admin/settings/index.blade.php index 12af0aab..8b0c3612 100644 --- a/themes/default/views/admin/settings/index.blade.php +++ b/themes/default/views/admin/settings/index.blade.php @@ -71,10 +71,12 @@
@csrf @method('POST') + @foreach ($options as $key => $value) - @if ($key == 'category_icon') + @if ($key == 'category_icon' || $key == 'settings_class') @continue @endif
From d7ed67a842e31b52a6c6455761b57c8d932d2320 Mon Sep 17 00:00:00 2001 From: IceToast Date: Sat, 4 Mar 2023 20:41:02 +0100 Subject: [PATCH 7/7] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Added=20store=5Fenabl?= =?UTF-8?q?ed=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Helpers/ExtensionHelper.php | 3 - .../Controllers/Admin/SettingsController.php | 2 - .../Admin/ShopProductController.php | 13 +--- app/Http/Controllers/StoreController.php | 16 ++--- app/Settings/GeneralSettings.php | 27 ++------ ...3_02_01_164731_create_general_settings.php | 2 + themes/default/views/layouts/main.blade.php | 26 ++++---- themes/default/views/store/index.blade.php | 63 ++++++++++--------- 8 files changed, 61 insertions(+), 91 deletions(-) diff --git a/app/Helpers/ExtensionHelper.php b/app/Helpers/ExtensionHelper.php index 6844268b..772b117c 100644 --- a/app/Helpers/ExtensionHelper.php +++ b/app/Helpers/ExtensionHelper.php @@ -127,9 +127,6 @@ class ExtensionHelper } } - error_log(print_r($settings, true)); - - return $settings; } diff --git a/app/Http/Controllers/Admin/SettingsController.php b/app/Http/Controllers/Admin/SettingsController.php index 456166bd..3a38b5a4 100644 --- a/app/Http/Controllers/Admin/SettingsController.php +++ b/app/Http/Controllers/Admin/SettingsController.php @@ -44,7 +44,6 @@ class SettingsController extends Controller $className = $file; // instantiate the class and call toArray method to get all options $options = (new $className())->toArray(); - error_log(print_r($className, true)); // call getOptionInputData method to get all options if (method_exists($className, 'getOptionInputData')) { @@ -52,7 +51,6 @@ class SettingsController extends Controller } else { $optionInputData = []; } - error_log(print_r($optionInputData, true)); // collect all option input data $optionsData = []; diff --git a/app/Http/Controllers/Admin/ShopProductController.php b/app/Http/Controllers/Admin/ShopProductController.php index 87e04290..690493f8 100644 --- a/app/Http/Controllers/Admin/ShopProductController.php +++ b/app/Http/Controllers/Admin/ShopProductController.php @@ -22,20 +22,13 @@ class ShopProductController extends Controller * * @return Application|Factory|View|Response */ - public function index(LocaleSettings $locale_settings) + public function index(LocaleSettings $locale_settings, GeneralSettings $general_settings) { - $isPaymentSetup = false; + $isStoreEnabled = $general_settings->store_enabled; - if ( - env('APP_ENV') == 'local' || - config('SETTINGS::PAYMENTS:PAYPAL:SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID') || - config('SETTINGS::PAYMENTS:STRIPE:SECRET') && config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') && config('SETTINGS::PAYMENTS:STRIPE:METHODS') - ) { - $isPaymentSetup = true; - } return view('admin.store.index', [ - 'isPaymentSetup' => $isPaymentSetup, + 'isStoreEnabled' => $isStoreEnabled, 'locale_datatables' => $locale_settings->datatables ]); } diff --git a/app/Http/Controllers/StoreController.php b/app/Http/Controllers/StoreController.php index 6ae24117..42b7a6dc 100644 --- a/app/Http/Controllers/StoreController.php +++ b/app/Http/Controllers/StoreController.php @@ -12,29 +12,21 @@ class StoreController extends Controller /** Display a listing of the resource. */ public function index(UserSettings $user_settings, GeneralSettings $general_settings) { - $isPaymentSetup = false; - - if ( - env('APP_ENV') == 'local' || - config('SETTINGS::PAYMENTS:PAYPAL:SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID') || - config('SETTINGS::PAYMENTS:STRIPE:SECRET') && config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') && config('SETTINGS::PAYMENTS:STRIPE:METHODS') - ) { - $isPaymentSetup = true; - } + $isStoreEnabled = $general_settings->store_enabled; //Required Verification for creating an server - if ($user_settings->force_email_verification && ! Auth::user()->hasVerifiedEmail()) { + if ($user_settings->force_email_verification && !Auth::user()->hasVerifiedEmail()) { return redirect()->route('profile.index')->with('error', __('You are required to verify your email address before you can purchase credits.')); } //Required Verification for creating an server - if ($user_settings->force_discord_verification && ! Auth::user()->discordUser) { + if ($user_settings->force_discord_verification && !Auth::user()->discordUser) { return redirect()->route('profile.index')->with('error', __('You are required to link your discord account before you can purchase Credits')); } return view('store.index')->with([ 'products' => ShopProduct::where('disabled', '=', false)->orderBy('type', 'asc')->orderBy('price', 'asc')->get(), - 'isPaymentSetup' => true, + 'isStoreEnabled' => $isStoreEnabled, 'credits_display_name' => $general_settings->credits_display_name ]); } diff --git a/app/Settings/GeneralSettings.php b/app/Settings/GeneralSettings.php index 0b479cd0..906e4696 100644 --- a/app/Settings/GeneralSettings.php +++ b/app/Settings/GeneralSettings.php @@ -6,6 +6,7 @@ use Spatie\LaravelSettings\Settings; class GeneralSettings extends Settings { + public bool $store_enabled = true; public string $credits_display_name; public bool $recaptcha_enabled; public string $recaptcha_site_key; @@ -31,27 +32,6 @@ class GeneralSettings extends Settings ]; } - /** - * Summary of validations array - * @return array - */ - public static function getValidations() - { - return [ - 'credits_display_name' => 'required|string', - 'initial_user_credits' => 'required|numeric', - 'initial_server_limit' => 'required|numeric', - 'recaptcha_enabled' => 'nullable|string', - 'recaptcha_site_key' => 'nullable|string', - 'recaptcha_secret_key' => 'nullable|string', - 'phpmyadmin_url' => 'nullable|string', - 'alert_enabled' => 'nullable|string', - 'alert_type' => 'nullable|string', - 'alert_message' => 'nullable|string', - 'theme' => 'required|string' - ]; - } - /** * Summary of optionTypes * Only used for the settings page @@ -61,6 +41,11 @@ class GeneralSettings extends Settings { return [ 'category_icon' => "fas fa-cog", + 'store_enabled' => [ + 'type' => 'boolean', + 'label' => 'Enable Store', + 'description' => 'Enable the store for users to purchase credits.' + ], 'credits_display_name' => [ 'type' => 'string', 'label' => 'Credits Display Name', diff --git a/database/settings/2023_02_01_164731_create_general_settings.php b/database/settings/2023_02_01_164731_create_general_settings.php index 3c84dac9..d93efe52 100644 --- a/database/settings/2023_02_01_164731_create_general_settings.php +++ b/database/settings/2023_02_01_164731_create_general_settings.php @@ -10,6 +10,7 @@ class CreateGeneralSettings extends SettingsMigration $table_exists = DB::table('settings_old')->exists(); // Get the user-set configuration values from the old table. + $this->migrator->add('general.store_enabled', true); $this->migrator->add('general.credits_display_name', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME') : 'Credits'); $this->migrator->addEncrypted('general.recaptcha_site_key', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:SITE_KEY") : env('RECAPTCHA_SITE_KEY', '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI')); $this->migrator->addEncrypted('general.recaptcha_secret_key', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:SECRET_KEY") : env('RECAPTCHA_SECRET_KEY', '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe')); @@ -88,6 +89,7 @@ class CreateGeneralSettings extends SettingsMigration ], ]); + $this->migrator->delete('general.store_enabled'); $this->migrator->delete('general.credits_display_name'); $this->migrator->delete('general.recaptcha_site_key'); $this->migrator->delete('general.recaptcha_secret_key'); diff --git a/themes/default/views/layouts/main.blade.php b/themes/default/views/layouts/main.blade.php index 01a9d619..16ddcb3a 100644 --- a/themes/default/views/layouts/main.blade.php +++ b/themes/default/views/layouts/main.blade.php @@ -3,13 +3,16 @@ @php($website_settings = app(App\Settings\WebsiteSettings::class)) + @php($general_settings = app(App\Settings\GeneralSettings::class)) - exists('logo.png') ? asset('storage/logo.png') : asset('images/controlpanel_logo.png') }}' property="og:image"> + exists('logo.png') ? asset('storage/logo.png') : asset('images/controlpanel_logo.png') }}' + property="og:image"> {{ config('app.name', 'Laravel') }} @endif - @foreach($useful_links as $link) - + @foreach ($useful_links as $link) + @endforeach @@ -232,11 +235,7 @@ - @if (env('APP_ENV') == 'local' || - (config('SETTINGS::PAYMENTS:PAYPAL:SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID')) || - (config('SETTINGS::PAYMENTS:STRIPE:SECRET') && - config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') && - config('SETTINGS::PAYMENTS:STRIPE:METHODS'))) + @if (env('APP_ENV') == 'local' || $general_settings->store_enabled)
diff --git a/themes/default/views/store/index.blade.php b/themes/default/views/store/index.blade.php index 28aa47eb..31393c19 100644 --- a/themes/default/views/store/index.blade.php +++ b/themes/default/views/store/index.blade.php @@ -10,10 +10,9 @@
@@ -31,8 +30,7 @@ - @if ($isPaymentSetup && $products->count() > 0) - + @if ($isStoreEnabled && $products->count() > 0)
{{ $credits_display_name }}
@@ -40,43 +38,48 @@
- - - - - - + + + + + + - @foreach ($products as $product) - - - - + + + - - - @endforeach + {{ $product->display }} + + + + @endforeach
{{ __('Price') }}{{ __('Type') }}{{ __('Description') }}
{{ __('Price') }}{{ __('Type') }}{{ __('Description') }}
{{ $product->formatToCurrency($product->price) }}{{ strtolower($product->type) == 'credits' ? $credits_display_name : $product->type }} - @if(strtolower($product->type) == 'credits') - - @elseif (strtolower($product->type) == 'server slots') - - @endif + @foreach ($products as $product) +
{{ $product->formatToCurrency($product->price) }}{{ strtolower($product->type) == 'credits' ? $credits_display_name : $product->type }} + + @if (strtolower($product->type) == 'credits') + + @elseif (strtolower($product->type) == 'server slots') + + @endif - {{ $product->display }}{{ __('Purchase') }} -
{{ __('Purchase') }} +
- @else
-

@if ($products->count() == 0) {{ __('There are no store products!') }} @else {{ __('The store is not correctly configured!') }} @endif +

+ @if ($products->count() == 0) + {{ __('There are no store products!') }} + @else + {{ __('The store is not correctly configured!') }} + @endif

- @endif