mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\PerfexCRM\Services;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
use App\Classes\Exceptions\MalformedRequestException;
|
|
use App\Classes\Exceptions\ConnectionErrorException;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class FetchesPerfexCRMLead
|
|
{
|
|
/**
|
|
* @param string $email
|
|
* @return null|object
|
|
* @throws MalformedRequestException
|
|
*/
|
|
public function execute(string $email) {
|
|
try{
|
|
$response = Http::withHeaders([
|
|
'authtoken' => config('perfexcrm.api_key'),])
|
|
->get(config('perfexcrm.base_url').'/api/leads/byemail/'.$email);
|
|
|
|
if($response->successful()){
|
|
$data = $response->json();
|
|
|
|
return (object) $data;
|
|
}else{
|
|
Log::channel('perfex_crm')->info('FetchesPerfexCRMLead: '.$response);
|
|
return null;
|
|
}
|
|
}
|
|
catch(\Illuminate\Http\Client\ConnectionException $exception){
|
|
$error = 'Failed to connect to CRM';
|
|
throw new ConnectionErrorException($error, $exception->getMessage(), $email, $exception->getTraceAsString());
|
|
}
|
|
catch(\Exception $exception){
|
|
throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage());
|
|
}
|
|
}
|
|
}
|