CRM integration MVP Phase 1

This commit is contained in:
Dillon
2023-02-17 09:06:18 +08:00
parent 515c71daa7
commit 1b84ccf60e
36 changed files with 2102 additions and 8 deletions
@@ -0,0 +1,35 @@
<?php
namespace App\Classes\Modules\PerfexCRM\Services;
use Illuminate\Support\Facades\Http;
use App\Classes\Exceptions\MalformedRequestException;
use Illuminate\Support\Facades\Log;
class FetchesPerfexCRMTask
{
/**
* @param string $taskName
* @param string $milestoneId
* @return null|object
* @throws MalformedRequestException
*/
public function execute(string $taskName, string $milestoneId) {
try{
$response = Http::withHeaders([
'authtoken' => config('perfexcrm.api_key'),])
->get(config('perfexcrm.base_url').'/api/tasks/bynameandmilestoneid/'.rawurlencode($taskName).'/'.$milestoneId);
if($response->successful()){
$data = $response->json();
return (object) $data;
}else{
Log::error($response);
return null;
}
}catch(\Exception $exception){
throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage());
}
}
}