Implement Weeztix integration per documentation: database config and subscriber coupon_code, OAuth redirect/callback, admin setup UI with company/coupon selection via AJAX, synchronous coupon creation on public subscribe with duplicate and rate-limit handling, Mailwizz field mapping for coupon codes, subscriber table and CSV export, and connection hint on the pages list. Made-with: Cursor
60 lines
1.8 KiB
PHP
60 lines
1.8 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\Support\Facades\DB;
|
|
use Illuminate\View\View;
|
|
|
|
class WeeztixController extends Controller
|
|
{
|
|
public function edit(PreregistrationPage $page): View
|
|
{
|
|
$this->authorize('update', $page);
|
|
|
|
$page->load('weeztixConfig');
|
|
|
|
return view('admin.weeztix.edit', compact('page'));
|
|
}
|
|
|
|
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])
|
|
);
|
|
});
|
|
|
|
return redirect()
|
|
->route('admin.pages.weeztix.edit', $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.'));
|
|
}
|
|
}
|