2020-07-23 10:29:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2024-04-09 15:20:28 +02:00
|
|
|
use App\Enums\Settings\SettingsType;
|
2026-06-23 17:53:34 +02:00
|
|
|
use App\Lib\Axepta\AxeptaApiGateway;
|
|
|
|
|
use App\Lib\Axepta\AxeptaConfig;
|
|
|
|
|
use App\Lib\Axepta\AxeptaPaymentService;
|
|
|
|
|
use App\Lib\Axepta\AxeptaSignatureVerifier;
|
2026-09-25 16:25:31 +02:00
|
|
|
use App\Lib\Axepta\AxeptaTokenManager;
|
2024-04-09 15:20:28 +02:00
|
|
|
use App\Models\GeneralSetting;
|
2024-04-18 12:05:10 +02:00
|
|
|
use App\Models\MenuNodeData;
|
2024-10-24 09:03:17 +00:00
|
|
|
use App\Providers\TelescopeServiceProvider as CustomTelescopeServiceProvider;
|
2026-09-25 16:25:31 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2024-01-10 14:49:46 +01:00
|
|
|
use Illuminate\Support\Carbon;
|
2021-09-15 14:25:12 +02:00
|
|
|
use Illuminate\Support\Facades\App;
|
2024-10-08 17:23:51 +02:00
|
|
|
use Illuminate\Support\Facades\Blade;
|
2026-06-23 14:45:00 +02:00
|
|
|
use Illuminate\Support\Facades\Config;
|
2026-09-25 16:25:31 +02:00
|
|
|
use Illuminate\Support\Facades\URL;
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
2024-10-24 09:03:17 +00:00
|
|
|
use Laravel\Telescope\TelescopeServiceProvider;
|
2024-06-28 10:06:04 +02:00
|
|
|
use Money\Currencies\ISOCurrencies;
|
|
|
|
|
use Money\Currency;
|
|
|
|
|
use Money\Formatter\IntlMoneyFormatter;
|
2026-06-23 14:45:00 +02:00
|
|
|
use Psr\Log\LoggerInterface;
|
2024-07-12 16:33:26 +02:00
|
|
|
use Snipe\BanBuilder\CensorWords;
|
2020-07-23 10:29:36 +02:00
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap any application services.
|
|
|
|
|
*/
|
2024-09-30 15:04:24 +02:00
|
|
|
public function boot(): void
|
2020-07-23 10:29:36 +02:00
|
|
|
{
|
2026-09-25 16:25:31 +02:00
|
|
|
Model::shouldBeStrict(! $this->app->environment('production'));
|
2024-01-10 14:49:46 +01:00
|
|
|
|
|
|
|
|
// * HTTPS FIX
|
2023-01-10 09:21:53 +01:00
|
|
|
URL::forceScheme('https');
|
|
|
|
|
|
2024-01-10 14:49:46 +01:00
|
|
|
// * HA PROXY FIX
|
2021-09-15 14:25:12 +02:00
|
|
|
App::singleton('clientIp', function () {
|
2024-09-30 15:04:24 +02:00
|
|
|
return (config('app.env') === 'local')
|
|
|
|
|
? request()->getClientIp()
|
|
|
|
|
: request()->server('HTTP_X_FORWARDED_FOR') ?? request()->getClientIp();
|
2021-09-15 14:25:12 +02:00
|
|
|
});
|
2024-01-10 14:49:46 +01:00
|
|
|
|
2022-04-01 11:40:12 +02:00
|
|
|
// * LOCAL FORCE eg: for Carbon
|
2024-01-10 14:49:46 +01:00
|
|
|
setlocale(LC_ALL, \sprintf(
|
|
|
|
|
'%s_%s.UTF-8',
|
|
|
|
|
config('app.locale'),
|
|
|
|
|
\strtoupper(config('app.locale'))
|
|
|
|
|
));
|
2021-09-15 14:25:12 +02:00
|
|
|
Carbon::setLocale(config('app.locale'));
|
2024-04-09 15:20:28 +02:00
|
|
|
|
|
|
|
|
// * SETTINGS
|
2026-09-25 16:25:31 +02:00
|
|
|
App::singleton('settings', fn () => GeneralSetting::getCached());
|
2024-04-09 15:20:28 +02:00
|
|
|
// * Menu
|
2026-09-25 16:25:31 +02:00
|
|
|
App::singleton('menuNodeList', fn () => App::get('settings')
|
2024-04-18 12:05:10 +02:00
|
|
|
->where('type', SettingsType::mainMenu)->firstOrFail());
|
2026-09-25 16:25:31 +02:00
|
|
|
App::singleton('menuNodeDataList', fn () => MenuNodeData::getCached());
|
2024-06-28 10:06:04 +02:00
|
|
|
|
2024-07-12 16:33:26 +02:00
|
|
|
// * Censor
|
2026-09-25 16:25:31 +02:00
|
|
|
App::singleton('censor', fn () => new CensorWords());
|
2024-07-12 16:33:26 +02:00
|
|
|
|
2026-06-23 14:45:00 +02:00
|
|
|
// * Axepta
|
2026-06-23 17:53:34 +02:00
|
|
|
$this->app->singleton(AxeptaPaymentService::class, function () {
|
2026-06-23 14:45:00 +02:00
|
|
|
$logger = resolve(LoggerInterface::class);
|
2026-06-23 17:53:34 +02:00
|
|
|
$config = new AxeptaConfig(
|
|
|
|
|
endpoint: Config::string('axepta.endpoint'),
|
|
|
|
|
merchantId: Config::string('axepta.merchantId'),
|
|
|
|
|
apiKey: Config::string('axepta.apiKey'),
|
|
|
|
|
hmac: Config::string('axepta.hmac')
|
|
|
|
|
);
|
|
|
|
|
|
2026-09-25 16:25:31 +02:00
|
|
|
$gateway = new AxeptaApiGateway($config);
|
|
|
|
|
$tokenManager = new AxeptaTokenManager($gateway, $config);
|
2026-06-23 17:53:34 +02:00
|
|
|
$signatureVerifier = new AxeptaSignatureVerifier($config, $logger);
|
|
|
|
|
|
|
|
|
|
return new AxeptaPaymentService(
|
2026-06-23 14:45:00 +02:00
|
|
|
$logger,
|
2026-06-23 17:53:34 +02:00
|
|
|
$config,
|
|
|
|
|
$gateway,
|
|
|
|
|
$tokenManager,
|
|
|
|
|
$signatureVerifier
|
2026-06-23 14:45:00 +02:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-28 10:06:04 +02:00
|
|
|
$this->setPaymentCurrency();
|
2024-10-08 17:23:51 +02:00
|
|
|
|
|
|
|
|
// * BLADE DIRECTIVES
|
|
|
|
|
Blade::if('isExport', function () {
|
|
|
|
|
return request()->routeIs('fo.*.export');
|
|
|
|
|
});
|
2024-06-28 10:06:04 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-23 18:13:56 +02:00
|
|
|
/**
|
|
|
|
|
* Register any application services.
|
|
|
|
|
*/
|
|
|
|
|
public function register(): void
|
|
|
|
|
{
|
|
|
|
|
if ($this->app->environment('local')) {
|
|
|
|
|
$this->app->register(TelescopeServiceProvider::class);
|
2024-10-24 09:03:17 +00:00
|
|
|
$this->app->register(CustomTelescopeServiceProvider::class);
|
2024-10-23 18:13:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-28 10:06:04 +02:00
|
|
|
/**
|
2024-09-30 15:04:24 +02:00
|
|
|
* Set formatters and payment currency.
|
2024-06-28 10:06:04 +02:00
|
|
|
*/
|
|
|
|
|
private function setPaymentCurrency(): void
|
|
|
|
|
{
|
|
|
|
|
// * Php Money currency (This is used everywhere), default is Euro
|
|
|
|
|
App::singleton('phpMoneyCurrency', function () {
|
|
|
|
|
return new Currency(config('money.currency'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// * Php Money formater (using app locale)
|
|
|
|
|
App::singleton('phpMoneyFormatter', function () {
|
|
|
|
|
// * Number format using app locale.
|
|
|
|
|
$currencies = new ISOCurrencies();
|
|
|
|
|
$numberFormatter = new \NumberFormatter(\sprintf(
|
|
|
|
|
'%s_%s',
|
|
|
|
|
config('app.locale'),
|
|
|
|
|
\strtoupper(config('app.locale'))
|
|
|
|
|
), \NumberFormatter::CURRENCY);
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2024-06-28 10:06:04 +02:00
|
|
|
return new IntlMoneyFormatter($numberFormatter, $currencies);
|
|
|
|
|
});
|
2020-07-23 10:29:36 +02:00
|
|
|
}
|
|
|
|
|
}
|