HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/api.aianced.com/app/Services/MakeWebhookService.php
<?php

namespace App\Services;

use App\Models\Lead;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class MakeWebhookService
{
    /**
     * Fire the Make.com webhook for a new lead.
     * Silently logs on failure — never throws.
     */
    public function sendLead(Lead $lead): void
    {
        $url = config('aianced.make_webhook_url');

        if (!$url) {
            return; // Webhook not configured — skip silently
        }

        $summary = $lead->summary ?? [];

        $payload = [
            'name'         => $lead->name,
            'email'        => $lead->email,
            'phone'        => $lead->phone ?? '',
            'idea'         => $lead->idea_text,
            'product_type' => $summary['productType'] ?? '',
            'features'     => $summary['features'] ?? [],
        ];

        $http = Http::timeout(10);

        $apiKey = config('aianced.make_api_key');
        if ($apiKey) {
            $http = $http->withHeaders(['x-make-apikey' => $apiKey]);
        }

        try {
            $response = $http->post($url, $payload);

            if (!$response->successful()) {
                Log::warning('Make.com webhook returned non-2xx', [
                    'status'  => $response->status(),
                    'body'    => $response->body(),
                    'lead_id' => $lead->id,
                ]);
            }
        } catch (\Throwable $e) {
            Log::error('Make.com webhook failed', [
                'error'   => $e->getMessage(),
                'lead_id' => $lead->id,
            ]);
        }
    }
}