Deploy Ladill Frontdesk / deploy (push) Successful in 44s
Host alerts use email/phone on the host record without requiring a Ladill account link; SMS and over-quota emails debit the org wallet at platform rates. Co-authored-by: Cursor <cursoragent@cursor.com>
98 lines
3.5 KiB
PHP
98 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Frontdesk;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
|
|
use App\Models\WebhookEndpoint;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class IntegrationController extends Controller
|
|
{
|
|
use ScopesToAccount;
|
|
|
|
public function edit(Request $request): View
|
|
{
|
|
$this->authorizeAbility($request, 'settings.view');
|
|
$organization = $this->organization($request);
|
|
$plans = app(\App\Services\Frontdesk\PlanService::class);
|
|
|
|
if (! $plans->hasFeature($organization, 'integrations')) {
|
|
return view('frontdesk.integrations.upgrade', [
|
|
'organization' => $organization,
|
|
'proPriceMinor' => $plans->proPriceMinor(),
|
|
]);
|
|
}
|
|
|
|
$canManage = app(\App\Services\Frontdesk\FrontdeskPermissions::class)
|
|
->isAdmin($this->member($request));
|
|
|
|
$webhook = WebhookEndpoint::owned($this->ownerRef($request))
|
|
->where('organization_id', $organization->id)
|
|
->first();
|
|
|
|
return view('frontdesk.integrations.edit', [
|
|
'organization' => $organization,
|
|
'canManage' => $canManage,
|
|
'webhook' => $webhook,
|
|
'webhookEvents' => config('frontdesk.webhook_events', []),
|
|
'integrations' => config('frontdesk.integrations', []),
|
|
'icalUrl' => $this->signedIcalUrl($organization->id, $this->ownerRef($request)),
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request): RedirectResponse
|
|
{
|
|
$this->authorizeAbility($request, 'settings.manage');
|
|
$organization = $this->organization($request);
|
|
|
|
if (! app(\App\Services\Frontdesk\PlanService::class)->hasFeature($organization, 'integrations')) {
|
|
return back()->with('error', 'Webhooks and calendar feeds require Frontdesk Pro.');
|
|
}
|
|
|
|
$validated = $request->validate([
|
|
'webhook_url' => ['nullable', 'url', 'max:500'],
|
|
'webhook_secret' => ['nullable', 'string', 'max:128'],
|
|
'webhook_events' => ['nullable', 'array'],
|
|
'webhook_events.*' => ['string'],
|
|
'webhook_active' => ['boolean'],
|
|
]);
|
|
|
|
if (empty($validated['webhook_url'])) {
|
|
WebhookEndpoint::owned($this->ownerRef($request))
|
|
->where('organization_id', $organization->id)
|
|
->delete();
|
|
|
|
return back()->with('success', 'Integration settings saved.');
|
|
}
|
|
|
|
WebhookEndpoint::updateOrCreate(
|
|
[
|
|
'owner_ref' => $this->ownerRef($request),
|
|
'organization_id' => $organization->id,
|
|
],
|
|
[
|
|
'url' => $validated['webhook_url'],
|
|
'secret' => $validated['webhook_secret'] ?? null,
|
|
'events' => array_values($validated['webhook_events'] ?? config('frontdesk.webhook_events')),
|
|
'is_active' => $request->boolean('webhook_active', true),
|
|
],
|
|
);
|
|
|
|
return back()->with('success', 'Integration settings saved.');
|
|
}
|
|
|
|
protected function signedIcalUrl(int $organizationId, string $ownerRef): string
|
|
{
|
|
$token = hash_hmac('sha256', "{$organizationId}:{$ownerRef}", (string) config('app.key'));
|
|
|
|
return route('frontdesk.integrations.ical', [
|
|
'organization' => $organizationId,
|
|
'owner' => $ownerRef,
|
|
'token' => $token,
|
|
]);
|
|
}
|
|
}
|