- Summary view when Weeztix is configured; edits only via 3-step wizard - Step 1: reuse or replace OAuth client ID/secret; callback URL shown - Step 2: OAuth connect (resume wizard after callback when started from wizard) - Step 3: coupon, prefix, usage; finishing exits wizard - PreregistrationPage: mailwizz/weeztix integration status helpers - Pages index: Integrations column with MW/WZ badges; edit page: status cards Made-with: Cursor
94 lines
3.1 KiB
PHP
94 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\UpdateWeeztixConfigRequest;
|
|
use App\Models\PreregistrationPage;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\View\View;
|
|
|
|
class WeeztixController extends Controller
|
|
{
|
|
public function edit(Request $request, PreregistrationPage $page): View
|
|
{
|
|
$this->authorize('update', $page);
|
|
|
|
$page->load('weeztixConfig');
|
|
|
|
$showWizard = $page->weeztixConfig === null || $request->boolean('wizard');
|
|
$wizardStep = $showWizard ? min(3, max(1, (int) $request->query('step', 1))) : 1;
|
|
if ($showWizard && $page->weeztixConfig === null && $wizardStep !== 1) {
|
|
return redirect()
|
|
->route('admin.pages.weeztix.edit', ['page' => $page, 'wizard' => 1, 'step' => 1]);
|
|
}
|
|
$hasStoredCredentials = $page->weeztixConfig !== null
|
|
&& is_string($page->weeztixConfig->client_id)
|
|
&& $page->weeztixConfig->client_id !== '';
|
|
|
|
return view('admin.weeztix.edit', compact(
|
|
'page',
|
|
'showWizard',
|
|
'wizardStep',
|
|
'hasStoredCredentials'
|
|
));
|
|
}
|
|
|
|
public function update(UpdateWeeztixConfigRequest $request, PreregistrationPage $page): RedirectResponse
|
|
{
|
|
$validated = $request->validated();
|
|
|
|
foreach (['client_id', 'client_secret'] as $key) {
|
|
if (array_key_exists($key, $validated) && $validated[$key] === '' && $page->weeztixConfig !== null) {
|
|
unset($validated[$key]);
|
|
}
|
|
}
|
|
|
|
$validated['redirect_uri'] = route('admin.weeztix.callback', absolute: true);
|
|
|
|
DB::transaction(function () use ($page, $validated): void {
|
|
$page->weeztixConfig()->updateOrCreate(
|
|
['preregistration_page_id' => $page->id],
|
|
array_merge($validated, ['preregistration_page_id' => $page->id])
|
|
);
|
|
});
|
|
|
|
$page->load('weeztixConfig');
|
|
|
|
if ($request->boolean('wizard')) {
|
|
if ($request->boolean('wizard_coupon_save')) {
|
|
return redirect()
|
|
->route('admin.pages.weeztix.edit', ['page' => $page])
|
|
->with('status', __('Weeztix-configuratie opgeslagen.'));
|
|
}
|
|
|
|
return redirect()
|
|
->route('admin.pages.weeztix.edit', [
|
|
'page' => $page,
|
|
'wizard' => 1,
|
|
'step' => 2,
|
|
])
|
|
->with('status', __('Weeztix-configuratie opgeslagen.'));
|
|
}
|
|
|
|
return redirect()
|
|
->route('admin.pages.weeztix.edit', ['page' => $page])
|
|
->with('status', __('Weeztix-configuratie opgeslagen.'));
|
|
}
|
|
|
|
public function destroy(PreregistrationPage $page): RedirectResponse
|
|
{
|
|
$this->authorize('update', $page);
|
|
|
|
$page->weeztixConfig()?->delete();
|
|
|
|
return redirect()
|
|
->route('admin.pages.weeztix.edit', $page)
|
|
->with('status', __('Weeztix-integratie verwijderd.'));
|
|
}
|
|
}
|