From 9fd33f7f18e9d9145bf48e218f4729909206eb1c Mon Sep 17 00:00:00 2001 From: TheLeo Date: Thu, 29 Aug 2024 21:58:31 +0000 Subject: [PATCH] Update FreshdeskShim/src/Controller/FDShim_Controller.php added Data Validation, and moved the Freshdesk payload creation into the Shim. --- .../src/Controller/FDShim_Controller.php | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/FreshdeskShim/src/Controller/FDShim_Controller.php b/FreshdeskShim/src/Controller/FDShim_Controller.php index 722c708..570c921 100644 --- a/FreshdeskShim/src/Controller/FDShim_Controller.php +++ b/FreshdeskShim/src/Controller/FDShim_Controller.php @@ -9,7 +9,12 @@ use Symfony\Component\HttpFoundation\Request; class FDShim_Controller extends ControllerBase { public function fd_route(Request $request) { if ($request->isMethod('POST')) { - $postData = $request->request->all(); + //$postData = $request->request->all(); + + // Data Validation + if (!isset($request['name']) || !isset($request['phone']) || !isset($request['email'])) { + return new JsonResponse(['error' => 'Bad Request'], 400); + } // Initial variables $apiUrl = 'https://jvmanufacturing-help.freshdesk.com/api/v2/tickets'; @@ -19,11 +24,34 @@ class FDShim_Controller extends ControllerBase { 'Content-Type: multipart/form-data', 'Authorization: ' . $apiKey ]; + $descriptionString = + '
Name: ' . $request['name'] . '
' . + '
Date: ' . $request['date'] . '
' . + '
Phone: ' . $request['phone_num'] . '
' . + '
Hinge Type: ' . $request['hinge_type'] . '
' . + '
Ceiling Greater than 14ft: ' . $request['ceiling_height'] . '
' . + '
Loading Dock: ' . $request['loading_dock'] . '
' . + '
Basement Under Baler: ' . $request['baler_over_basement'] . '
' . + '
Voltage: ' . $request['voltage'] . '
'; + + // Converting the POST request data into the correct format for Fresdesk ticket creation + $postData = [ + 'name' => $request['name'], + 'email' => $request['email'], + 'phone' => $request['phone'], + 'subject' => '[Webform Submission] ' . $request['name'] . ' Baler Request', + 'description' => $descriptionString, + 'attachments[]' => $request['attachments[]'], + 'status' => '2', + 'priority' => '1', + 'group' => '154000339633' + ]; + // cURL Options curl_setopt($fd, CURLOPT_RETURNTRANSFER, true); curl_setopt($fd, CURLOPT_POST, true); - curl_setopt($fd, CURLOPT_POSTFIELDS, http_build_query($postData)); + curl_setopt($fd, CURLOPT_POSTFIELDS, $postData); curl_setopt($fd, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($fd);