subscription config

This commit is contained in:
Čarodej
2022-06-06 18:31:03 +02:00
parent 59e3f55ac3
commit 8a943747eb
3 changed files with 145 additions and 96 deletions

View File

@@ -1,6 +1,7 @@
<?php
namespace App\Providers;
use Domain\Settings\Models\Setting;
use Schema;
use Illuminate\Support\ServiceProvider;
@@ -24,6 +25,49 @@ class AppServiceProvider extends ServiceProvider
{
Schema::defaultStringLength(191);
// Set subscription config
$this->setSubscriptionConfig();
// Set app locale
$this->setLocale();
// Get all migrations with all directories
$this->setMigrations();
dd(
config('subscription.metered_billing')
);
}
private function setMigrations(): void
{
$mainPath = database_path('migrations');
$directories = glob($mainPath . '/*', GLOB_ONLYDIR);
$this->loadMigrationsFrom(
array_merge([$mainPath], $directories)
);
}
private function setSubscriptionConfig(): void
{
$settings = getAllSettings();
config([
'subscription.metered_billing.fraud_prevention_mechanism' => [
'usage_bigger_than_balance' => [
'active' => isset($settings->usage_bigger_than_balance) ? intval($settings->usage_bigger_than_balance) : true,
],
'limit_usage_in_new_accounts' => [
'active' => isset($settings->limit_usage_in_new_accounts) ? intval($settings->limit_usage_in_new_accounts) : true,
'amount' => isset($settings->limit_usage_in_new_accounts_amount) ? intval($settings->limit_usage_in_new_accounts_amount) : 20,
],
]
]);
}
private function setLocale(): void
{
try {
$app_locale = get_settings('language') ?? 'en';
} catch (\PDOException $e) {
@@ -35,21 +79,5 @@ class AppServiceProvider extends ServiceProvider
// Set locale for carbon dates
setlocale(LC_TIME, $app_locale . '_' . mb_strtoupper($app_locale));
// Get all migrations with all directories
$this->loadMigrationsFrom(
$this->get_migration_paths()
);
}
/**
* @return array
*/
private function get_migration_paths(): array
{
$mainPath = database_path('migrations');
$directories = glob($mainPath . '/*', GLOB_ONLYDIR);
return array_merge([$mainPath], $directories);
}
}