mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
e7c0e17ee4
# Conflicts: # app/Classes/Modules/Segments/ControllersLogic/UpdateConstantPostcodeLogic.php # app/Classes/ValueObjects/Constants/TransactionType.php # routes/api.php # routes/web.php
50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\PerfexCRM\Services;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
use App\Classes\Exceptions\MalformedRequestException;
|
|
use Illuminate\Support\Facades\Log;
|
|
use App\Classes\General\Helper;
|
|
|
|
class FetchesPerfexCRMTask
|
|
{
|
|
/**
|
|
* @param string $taskName
|
|
* @param string $milestoneId
|
|
* @param string $relType
|
|
* @param string $relId
|
|
* @return null|object
|
|
* @throws MalformedRequestException
|
|
*/
|
|
public function execute(string $taskName, string $milestoneId, string $relType, string $relId) {
|
|
try{
|
|
$data = [
|
|
'name' => $taskName,
|
|
'rel_type' => $relType,
|
|
'rel_id' => $relId,
|
|
];
|
|
|
|
if($milestoneId != '') {
|
|
$newItem = ['milestone' => $milestoneId ];
|
|
$data = array_merge($data, $newItem);
|
|
}
|
|
|
|
$response = Http::asForm()->withHeaders([
|
|
'authtoken' => config('perfexcrm.api_key')])
|
|
->post(config('perfexcrm.base_url').'/api/tasks/customsearch', $data);
|
|
|
|
if($response->successful()){
|
|
$data = $response->json();
|
|
|
|
return (object) $data;
|
|
}else{
|
|
Helper::debugLoggerForPerfexCRM($response);
|
|
return null;
|
|
}
|
|
}catch(\Exception $exception){
|
|
throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage());
|
|
}
|
|
}
|
|
}
|