diff --git a/app/Extensions/PaymentGateways/PayPal/PayPalSettings.php b/app/Extensions/PaymentGateways/PayPal/PayPalSettings.php new file mode 100644 index 00000000..1688c011 --- /dev/null +++ b/app/Extensions/PaymentGateways/PayPal/PayPalSettings.php @@ -0,0 +1,67 @@ +>> + */ + public static function getOptionInputData() + { + return [ + 'category_icon' => 'fas fa-dollar-sign', + 'client_id' => [ + 'type' => 'string', + 'label' => 'Client ID', + 'description' => 'The Client ID of your PayPal App', + ], + 'client_secret' => [ + '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/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/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..5792abec --- /dev/null +++ b/app/Extensions/PaymentGateways/PayPal/migrations/2023_03_04_135248_create_pay_pal_settings.php @@ -0,0 +1,100 @@ +exists(); + + + $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/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/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/app/Helpers/ExtensionHelper.php b/app/Helpers/ExtensionHelper.php index 7e1bbda3..772b117c 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,75 @@ 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; + } + + /** + * Summary of getAllExtensionSettings + * @return array of all setting classes look like: App\Extensions\PaymentGateways\PayPal\PayPalSettings + */ + public static function getAllExtensionSettingsClasses() + { + $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; + } + } + + 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 d98ca015..3a38b5a4 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,13 +26,26 @@ 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); + $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::getAllExtensionSettingsClasses()); + + + foreach ($settings_files as $file) { + + $className = $file; + // instantiate the class and call toArray method to get all options $options = (new $className())->toArray(); + // call getOptionInputData method to get all options if (method_exists($className, 'getOptionInputData')) { $optionInputData = $className::getOptionInputData(); } else { @@ -54,8 +68,9 @@ class SettingsController extends Controller if (isset($optionInputData['category_icon'])) { $optionsData['category_icon'] = $optionInputData['category_icon']; } + $optionsData['settings_class'] = $className; - $settings[str_replace('Settings.php', '', $file)] = $optionsData; + $settings[str_replace('Settings', '', class_basename($className))] = $optionsData; } $settings->sort(); @@ -77,10 +92,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 = []; } @@ -91,7 +106,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/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/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); - // } } } 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/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, ], 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(); + }); + } +}; 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/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
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 + + 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)