mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-21 13:33:57 +00:00
54 lines
1.8 KiB
PHP
54 lines
1.8 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 App\Classes\General\LogHelper;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class CreatesPerfexCRMSupportTicket
|
|
{
|
|
/**
|
|
* @param string $subject
|
|
* @param string $department
|
|
* @param int $contactid
|
|
* @param int $userid
|
|
* @return null|object
|
|
* @throws MalformedRequestException
|
|
*/
|
|
public function execute(string $subject, string $department, int $contactid, int $userid) {
|
|
try{
|
|
$data = [
|
|
'subject' => $subject,
|
|
'department' => $department,
|
|
'contactid' => $contactid,
|
|
'userid' => $userid,
|
|
];
|
|
|
|
$response = Http::asForm()->withHeaders([
|
|
'authtoken' => config('perfexcrm.api_key')])
|
|
->post(config('perfexcrm.base_url').'/api/tickets',$data);
|
|
|
|
if($response->successful()){
|
|
$data = $response->json();
|
|
return (object) $data;
|
|
}else{
|
|
LogHelper::channel('perfex_crm')->info($response);
|
|
return null;
|
|
}
|
|
}
|
|
catch(\Illuminate\Http\Client\ConnectionException $exception){
|
|
$error = 'Failed to connect to CRM';
|
|
throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString());
|
|
}
|
|
catch(\Exception $exception){
|
|
$error = 'Support Ticket creation failed';
|
|
Log::error($error. ": ". $exception->getMessage());
|
|
Log::error('Payload: '.json_encode($data));
|
|
throw new MalformedRequestException($error);
|
|
}
|
|
}
|
|
}
|