feat(weeztix): auto company from OAuth, remove company UI
Store company_guid after OAuth via profile API; drop company select and companies endpoint. Coupons AJAX uses stored company only. Form request no longer accepts company fields from the browser. Made-with: Cursor
This commit is contained in:
@@ -13,38 +13,10 @@ use RuntimeException;
|
||||
|
||||
class WeeztixApiController extends Controller
|
||||
{
|
||||
public function companies(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'page_id' => ['required', 'integer', 'exists:preregistration_pages,id'],
|
||||
]);
|
||||
|
||||
$page = PreregistrationPage::query()->findOrFail($request->integer('page_id'));
|
||||
$this->authorize('update', $page);
|
||||
|
||||
$config = $page->weeztixConfig;
|
||||
if ($config === null || ! $config->is_connected) {
|
||||
return response()->json([
|
||||
'message' => __('Niet verbonden met Weeztix.'),
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$companies = (new WeeztixService($config))->getCompanies();
|
||||
|
||||
return response()->json(['companies' => $companies]);
|
||||
} catch (RuntimeException) {
|
||||
return response()->json([
|
||||
'message' => __('Kon bedrijven niet laden. Vernieuw de verbinding indien nodig.'),
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
||||
public function coupons(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'page_id' => ['required', 'integer', 'exists:preregistration_pages,id'],
|
||||
'company_guid' => ['required', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$page = PreregistrationPage::query()->findOrFail($request->integer('page_id'));
|
||||
@@ -57,9 +29,12 @@ class WeeztixApiController extends Controller
|
||||
], 422);
|
||||
}
|
||||
|
||||
$companyGuid = $request->string('company_guid')->toString();
|
||||
$previousGuid = $config->company_guid;
|
||||
$config->setAttribute('company_guid', $companyGuid);
|
||||
$companyGuid = $config->company_guid;
|
||||
if (! is_string($companyGuid) || $companyGuid === '') {
|
||||
return response()->json([
|
||||
'message' => __('Geen Weeztix-bedrijf gekoppeld. Verbind opnieuw met Weeztix.'),
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$raw = (new WeeztixService($config))->getCoupons();
|
||||
@@ -70,8 +45,6 @@ class WeeztixApiController extends Controller
|
||||
return response()->json([
|
||||
'message' => __('Kon kortingsbonnen niet laden.'),
|
||||
], 422);
|
||||
} finally {
|
||||
$config->setAttribute('company_guid', $previousGuid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,10 @@ class WeeztixOAuthController extends Controller
|
||||
try {
|
||||
$service = new WeeztixService($config);
|
||||
$service->exchangeAuthorizationCode($request->string('code')->toString());
|
||||
$config = $config->fresh();
|
||||
if ($config !== null) {
|
||||
(new WeeztixService($config))->ensureCompanyStoredFromWeeztix();
|
||||
}
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error('Weeztix OAuth callback failed', [
|
||||
'page_id' => $page->id,
|
||||
|
||||
Reference in New Issue
Block a user