Files
HickLab3D_Dashboard/app/Http/Controllers/IntegrationSettingsController.php
T
Hickmeister 61dd05384f
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 1m1s
Use Parcel2Go public API scope by default
2026-10-11 16:50:13 +01:00

43 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\IntegrationSetting;
use App\Services\IntegrationSettings;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
class IntegrationSettingsController extends Controller
{
public function update(Request $request, string $provider, IntegrationSettings $settings): RedirectResponse
{
abort_unless($request->user()->role === 'admin', 403);
abort_unless(in_array($provider, ['parcel2go', 'bambuddy', 'dryer'], true), 404);
$rules = match ($provider) {
'parcel2go' => [
'client_id' => ['nullable', 'string', 'max:255'],
'client_secret' => ['nullable', 'string', 'max:255'],
'auth_url' => ['nullable', 'url:https', 'max:2048'],
'base_url' => ['nullable', 'url:https', 'max:2048'],
'scope' => ['nullable', 'string', 'in:public-api,public-api my-profile,public-api payment,public-api payment my-profile'],
],
default => [
'url' => ['nullable', 'url:https', 'max:2048'],
'api_key' => ['nullable', 'string', 'max:512'],
],
};
$submitted = array_filter($request->validate($rules), fn (?string $value): bool => filled($value));
$effective = $settings->for($provider);
if ($submitted === [] && ! collect($effective)->contains(fn ($value): bool => filled($value))) {
return redirect()->route('settings.index')->with('status', 'No integration settings changed.');
}
$record = IntegrationSetting::find($provider) ?? new IntegrationSetting(['provider' => $provider]);
$record->settings = array_replace($effective, $submitted);
$record->save();
return redirect()->route('settings.index')->with('status', ucfirst($provider).' settings saved.');
}
}