PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / V3.3.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder vV3.3.2
V3.3.2 3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 All 139 releases
← All changes | includes/Core/Integration/ZohoCampaigns/ZohoCampaignsHandler.php +69 -29 2.0 → V3.3.2 View file →
@@ -6,23 +6,31 @@
6 6 */
7 7
8 8 namespace BitCode\BitForm\Core\Integration\ZohoCampaigns;
9 9
10 +if (!defined('ABSPATH')) {
11 + exit;
12 +}
13 +
10 14 use BitCode\BitForm\Core\Integration\IntegrationHandler;
11 15 use BitCode\BitForm\Core\Util\ApiResponse as UtilApiResponse;
12 16 use BitCode\BitForm\Core\Util\HttpHelper;
13 17 use BitCode\BitForm\Core\Util\IpTool;
18 +use BitCode\BitForm\GlobalHelper;
19 +use WP_Error;
14 20
15 21 /**
16 22 * Provide functionality for ZohoCrm integration
17 23 */
18 -class ZohoCampaignsHandler {
24 +class ZohoCampaignsHandler
25 +{
19 26 private $_formID;
20 27 private $_integrationID;
21 28
22 29 private $_logResponse;
23 30
24 - public function __construct($integrationID, $fromID) {
31 + public function __construct($integrationID, $fromID)
32 + {
25 33 $this->_formID = $fromID;
26 34 $this->_integrationID = $integrationID;
27 35 $this->_logResponse = new UtilApiResponse();
28 36 }
@@ -31,9 +39,10 @@
31 39 * Helps to register ajax function's with wp
32 40 *
33 41 * @return null
34 42 */
35 - public static function registerAjax() {
43 + public static function registerAjax()
44 + {
36 45 add_action('wp_ajax_bitforms_zcampaigns_generate_token', [__CLASS__, 'generateTokens']);
37 46 add_action('wp_ajax_bitforms_zcampaigns_refresh_lists', [__CLASS__, 'refreshListsAjaxHelper']);
38 47 add_action('wp_ajax_bitforms_zcampaigns_refresh_contact_fields', [__CLASS__, 'refreshContactFieldsAjaxHelper']);
39 48 }
@@ -40,14 +49,20 @@
40 49
41 50 /**
42 51 * Process ajax request for generate_token
43 52 *
44 - * @return JSON zoho crm api response and status
53 + * @return string zoho crm api response and status
45 54 */
46 - public static function generateTokens() {
47 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
48 - $inputJSON = file_get_contents('php://input');
49 - $requestsParams = json_decode($inputJSON);
55 + public static function generateTokens()
56 + {
57 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
58 + GlobalHelper::requirePostMethod();
59 +
60 + try {
61 + $requestsParams = GlobalHelper::formatRequestData();
62 + } catch (\InvalidArgumentException $e) {
63 + wp_send_json_error($e->getMessage(), 400);
64 + }
50 65 if (
51 66 empty($requestsParams->{'accounts-server'})
52 67 || empty($requestsParams->dataCenter)
53 68 || empty($requestsParams->clientId)
@@ -95,15 +110,23 @@
95 110
96 111 /**
97 112 * Process ajax request for refresh crm modules
98 113 *
99 - * @return JSON crm module data
114 + * @return string crm module data
100 115 */
101 - public static function refreshListsAjaxHelper() {
102 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
116 + public static function refreshListsAjaxHelper()
117 + {
118 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
103 119 $authorizationHeader = null;
104 - $inputJSON = file_get_contents('php://input');
105 - $queryParams = json_decode($inputJSON);
120 +
121 + GlobalHelper::requirePostMethod();
122 +
123 + try {
124 + $queryParams = GlobalHelper::formatRequestData();
125 + } catch (\InvalidArgumentException $e) {
126 + wp_send_json_error($e->getMessage(), 400);
127 + }
128 +
106 129 if (
107 130 empty($queryParams->tokenDetails)
108 131 || empty($queryParams->dataCenter)
109 132 || empty($queryParams->clientId)
@@ -164,15 +187,23 @@
164 187
165 188 /**
166 189 * Process ajax request for refesh crm layouts
167 190 *
168 - * @return JSON crm layout data
191 + * @return string crm layout data
169 192 */
170 - public static function refreshContactFieldsAjaxHelper() {
171 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
193 + public static function refreshContactFieldsAjaxHelper()
194 + {
195 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
172 196 $authorizationHeader = null;
173 - $inputJSON = file_get_contents('php://input');
174 - $queryParams = json_decode($inputJSON);
197 +
198 + GlobalHelper::requirePostMethod();
199 +
200 + try {
201 + $queryParams = GlobalHelper::formatRequestData();
202 + } catch (\InvalidArgumentException $e) {
203 + wp_send_json_error($e->getMessage(), 400);
204 + }
205 +
175 206 if (
176 207 empty($queryParams->list)
177 208 || empty($queryParams->tokenDetails)
178 209 || empty($queryParams->dataCenter)
@@ -235,12 +266,13 @@
235 266
236 267 /**
237 268 * Helps to refresh zoho crm access_token
238 269 *
239 - * @param Array $apiData Contains required data for refresh access token
240 - * @return JSON $tokenDetails API token details
270 + * @param object $apiData Contains required data for refresh access token
271 + * @return string | boolean $tokenDetails API token details
241 272 */
242 - protected static function _refreshAccessToken($apiData) {
273 + protected static function _refreshAccessToken($apiData)
274 + {
243 275 if (
244 276 empty($apiData->dataCenter)
245 277 || empty($apiData->clientId)
246 278 || empty($apiData->clientSecret)
@@ -270,15 +302,16 @@
270 302
271 303 /**
272 304 * Save updated access_token to avoid unnecessary token generation
273 305 *
274 - * @param Integer $fromID ID of Integration related form
275 - * @param Integer $integrationID ID of Zoho crm Integration
276 - * @param Obeject $tokenDetails refreshed token info
306 + * @param integer $fromID ID of Integration related form
307 + * @param integer $integrationID ID of Zoho crm Integration
308 + * @param object $tokenDetails refreshed token info
277 309 *
278 310 * @return null
279 311 */
280 - protected static function _saveRefreshedToken($formID, $integrationID, $tokenDetails, $others = null) {
312 + protected static function _saveRefreshedToken($formID, $integrationID, $tokenDetails, $others = null)
313 + {
281 314 if (empty($formID) || empty($integrationID)) {
282 315 return;
283 316 }
284 317
@@ -300,12 +333,13 @@
300 333 if (!empty($others['required'])) {
301 334 $newDetails->default->required = $others['required'];
302 335 }
303 336
304 - $integrationHandler->updateIntegration($integrationID, $zcampaignsDetails[0]->integration_name, 'Zoho Campaigns', \json_encode($newDetails), 'form');
337 + $integrationHandler->updateIntegration($integrationID, $zcampaignsDetails[0]->integration_name, 'Zoho Campaigns', wp_json_encode($newDetails), 'form');
305 338 }
306 339
307 - public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) {
340 + public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
341 + {
308 342 $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details;
309 343
310 344 $tokenDetails = $integrationDetails->tokenDetails;
311 345 $list = $integrationDetails->list;
@@ -311,8 +345,14 @@
311 345 $list = $integrationDetails->list;
312 346 $dataCenter = $integrationDetails->dataCenter;
313 347 $fieldMap = $integrationDetails->field_map;
314 348 $required = $integrationDetails->default->fields->{$list}->required;
349 +
350 + $entryDetails = [
351 + 'formId' => $this->_formID,
352 + 'entryId' => $entryID,
353 + 'fieldValues' => $fieldValues
354 + ];
315 355 if (
316 356 empty($tokenDetails)
317 357 || empty($list)
318 358 || empty($fieldMap)
@@ -317,9 +357,9 @@
317 357 || empty($list)
318 358 || empty($fieldMap)
319 359 ) {
320 360 $error = new WP_Error('REQ_FIELD_EMPTY', __('list are required for zoho campaigns api', 'bit-form'));
321 - $this->_logResponse->apiResponse($logID, $this->_integrationID, 'record', 'validation', $error);
361 + $this->_logResponse->apiResponse($logID, $this->_integrationID, 'record', 'validation', $error, $entryDetails);
322 362 return $error;
323 363 }
324 364
325 365 $requiredParams = null;
@@ -335,9 +375,9 @@
335 375 }
336 376 }
337 377
338 378 // $actions = $integrationDetails->actions;
339 - $recordApiHelper = new RecordApiHelper($tokenDetails, $this->_integrationID, $logID);
379 + $recordApiHelper = new RecordApiHelper($tokenDetails, $this->_integrationID, $logID, $this->_formID, $entryID);
340 380
341 381 $zcampaignsApiResponse = $recordApiHelper->executeRecordApi(
342 382 $list,
343 383 $dataCenter,