mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
45 lines
1.7 KiB
PHP
45 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\PerfexCRM\Services;
|
|
|
|
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CustomerContactObject;
|
|
use Illuminate\Support\Facades\Http;
|
|
use App\Classes\Exceptions\MalformedRequestException;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class CreatesPerfexCRMCustomerContact
|
|
{
|
|
/**
|
|
* @param CustomerContactObject $customerContactObject
|
|
* @return null|object
|
|
* @throws MalformedRequestException
|
|
*/
|
|
public function execute(CustomerContactObject $customerContactObject) {
|
|
try{
|
|
$data = [
|
|
'customer_id' => $customerContactObject->getCustomerId(),
|
|
'firstname' => $customerContactObject->getFirstName(),
|
|
'lastname' => $customerContactObject->getLastName(),
|
|
'email' => $customerContactObject->getEmail(), //$email
|
|
'password' => $customerContactObject->getPassword(),
|
|
'is_primary' => $customerContactObject->getIsPrimary(),
|
|
//'send_set_password_email' => $customerContactObject->getSendSetPasswordEmail(),
|
|
];
|
|
|
|
$response = Http::asForm()->withHeaders([
|
|
'authtoken' => config('perfexcrm.api_key')])
|
|
->post(config('perfexcrm.base_url').'/api/contacts',$data);
|
|
|
|
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());
|
|
}
|
|
}
|
|
}
|