MINI Sh3ll
<?php
namespace App\Solar\Repositories\Zendesk;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use App\Models\Company;
use App\Models\Plant;
use App\User;
use View;
use App\Models\Country;
use Huddle\Zendesk\Services\ZendeskService;
class ZendeskRepository implements ZendeskInterface {
private $zendesk;
public function __construct(ZendeskService $zendesk)
{
$this->zendesk = $zendesk;
$this->subdomain = config('zendesk-laravel.subdomain');
$this->userAuthorization = base64_encode(config('zendesk-laravel.username').':'.config('zendesk-laravel.password'));
}
//Get all Tickets
public function getAllTickets()
{
return $tickets = $this->zendesk->tickets()->findAll();
}
// Get All users
public function getAllUsers()
{
return $users = $this->zendesk->users()->findAll();
}
//get All user details
public function getUser($id)
{
return $users = $this->zendesk->users()->find($id);
}
// Create Ticket
public function createTicket($request) {
// $msg = (string)View::make('mail_templates.zendeskenquirymail',['msg' => $request['body']]);
$responce = $this->zendesk->tickets()->create([
"requester"=> ["name"=> $request['name'], "email"=> $request['email'] ],
'subject' => $request['subject'],
'comment' => [
'body' => 'Contact name : '.$request['name'].
'Mobile : '.$request['body']['mobile'].
'Company : '.$request['body']['company'].
'Plant : '.$request['body']['plant'].
'Product types : '.$request['body']['product_types'].
'Country : '.$request['body']['country'].
'Site locator : '.$request['body']['site_locator'].
'Date codes : '.$request['body']['date_codes'].
'Serial number : '.$request['body']['serial_number'].
'Issue type : '.$request['body']['issue_type'].
'Description : '.$request['body']['description']
],
'priority' => 'normal',
]);
return $responce;
}
// Get Ticket Comments
public function getTicketComments($id)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://".$this->subdomain.".zendesk.com/api/v2/tickets/".$id."/comments.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Basic ".$this->userAuthorization,
"cache-control: no-cache",
"postman-token: 3e15808b-867c-d631-6355-5dd669653898"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$results = json_decode($response,true);
return $results['comments'];
}
}
//Create Comment on ticket by requester 396101823133
public function createComment($id,$remark)
{
$curl = curl_init();
$ticket = $this->zendesk->tickets()->find($id);
//dd( $ticket);
$requester_id = $ticket->ticket->requester_id;
curl_setopt_array($curl, array(
CURLOPT_URL => "https://".$this->subdomain.".zendesk.com/api/v2/tickets/24.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"ticket\": {\"comment\": { \"body\": \"".$remark."\", \"author_id\":".$requester_id." }}}",
CURLOPT_HTTPHEADER => array(
"authorization: Basic ".$this->userAuthorization,
"cache-control: no-cache",
"content-type: application/json",
"postman-token: 73ed5636-010c-4f88-a566-9311796fe220"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
return $responce = json_decode($response);
//return redirect()->route('getTicketComments');
}
}
//Delete Ticket
public function deleteTicket($id)
{
$responce = $this->zendesk->tickets()->delete($id);
}
//Create Comment on ticket by assignee 396036653313
public function CreateReComment($id,$assignee_id,$remark)
{
$curl = curl_init();
if($assignee_id==0)
{
$ticket = $this->zendesk->tickets()->find($id);
$assignee_id = $ticket->ticket->assignee_id;
}
curl_setopt_array($curl, array(
CURLOPT_URL => "https://".$this->subdomain.".zendesk.com/api/v2/tickets/".$id.".json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"ticket\": {\"comment\": { \"body\": \"".$remark."\", \"author_id\":".$assignee_id." }}}",
CURLOPT_HTTPHEADER => array(
"authorization: Basic ".$this->userAuthorization,
"cache-control: no-cache",
"content-type: application/json",
"postman-token: 73ed5636-010c-4f88-a566-9311796fe220"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$response = json_decode($response);
return $response;
}
}
//Create User
public function createUser($name,$email)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://".$this->subdomain.".zendesk.com/api/v2/users/create_or_update.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"user\": {\"name\": \"".$name."\", \"email\": \"".$email."\"}}",
CURLOPT_HTTPHEADER => array(
"authorization: Basic ".$this->userAuthorization,
"cache-control: no-cache",
"content-type: application/json",
"postman-token: 545d3966-0080-1ad4-15e5-528602a76bd3"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
return json_decode($response);
}
}
public function updateUser($id,$name)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://".$this->subdomain.".zendesk.com/api/v2/users/".$id.".json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"user\": {\"name\": \"".$name."\"}}",
CURLOPT_HTTPHEADER => array(
"authorization: Basic ".$this->userAuthorization,
"cache-control: no-cache",
"content-type: application/json",
"postman-token: f1fa85b2-8311-bcfa-cda4-eebeb1acf15b"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
return $responce = json_decode($response);
}
}
//Change Ticket Status
public function changeTicketStatus($id,$status)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://".$this->subdomain.".zendesk.com/api/v2/tickets/".$id.".json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"ticket\": {\"status\": \"".$status."\"}}",
CURLOPT_HTTPHEADER => array(
"authorization: Basic ".$this->userAuthorization,
"cache-control: no-cache",
"content-type: application/json",
"postman-token: 471e47ef-6015-5972-2245-48a227ef26b4"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
return $responce = json_decode($response);
}
}
}
OHA YOOOO