From 747c8297a0db12ba6f873fb9bf1c078832320528 Mon Sep 17 00:00:00 2001 From: TheLeo Date: Thu, 29 Aug 2024 15:16:52 +0000 Subject: [PATCH] Update src/Controller/FDShim_Controller.php --- .../Controller/FDShim_Controller.php | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) rename FDShim_Controller.php => src/Controller/FDShim_Controller.php (97%) diff --git a/FDShim_Controller.php b/src/Controller/FDShim_Controller.php similarity index 97% rename from FDShim_Controller.php rename to src/Controller/FDShim_Controller.php index c5835b0..722c708 100644 --- a/FDShim_Controller.php +++ b/src/Controller/FDShim_Controller.php @@ -1,51 +1,51 @@ -isMethod('POST')) { - $postData = $request->request->all(); - - // Initial variables - $apiUrl = 'https://jvmanufacturing-help.freshdesk.com/api/v2/tickets'; - $apiKey = 'OTBuVjM4cVA0dDdHaXVJeUhoWDpY'; - $fd = curl_init($apiUrl); - $headers = [ - 'Content-Type: multipart/form-data', - 'Authorization: ' . $apiKey - ]; - - // 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_HTTPHEADER, $headers); - - $response = curl_exec($fd); - - // HTTP Response Codes: - // 200 - Request OK - // 405 - Method Not Allowed - // 500 - Internal Error - - if (curl_errno($fd)) { - // cURL error handling - $error = curl_error($fd); - curl_close($fd); - return new JsonResponse(['error' => $error], 500); - } else { - // return cURL response if successful - curl_close($fd); - return new JsonResponse(json_decode($response, true), 200); - } - } else { - // reject all methods that aren't POST requests - return new JsonResponse(['error'=> 'Method Not Allowed'], 405); - } - } +isMethod('POST')) { + $postData = $request->request->all(); + + // Initial variables + $apiUrl = 'https://jvmanufacturing-help.freshdesk.com/api/v2/tickets'; + $apiKey = 'OTBuVjM4cVA0dDdHaXVJeUhoWDpY'; + $fd = curl_init($apiUrl); + $headers = [ + 'Content-Type: multipart/form-data', + 'Authorization: ' . $apiKey + ]; + + // 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_HTTPHEADER, $headers); + + $response = curl_exec($fd); + + // HTTP Response Codes: + // 200 - Request OK + // 405 - Method Not Allowed + // 500 - Internal Error + + if (curl_errno($fd)) { + // cURL error handling + $error = curl_error($fd); + curl_close($fd); + return new JsonResponse(['error' => $error], 500); + } else { + // return cURL response if successful + curl_close($fd); + return new JsonResponse(json_decode($response, true), 200); + } + } else { + // reject all methods that aren't POST requests + return new JsonResponse(['error'=> 'Method Not Allowed'], 405); + } + } } \ No newline at end of file