PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
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 2.10.1 All 138 releases
← All changes | includes/Core/Integration/ZohoSign/ZohoSignHandler.php +58 -25 2.03.3.1 View file →
@@ -6,21 +6,28 @@
6 6 */
7 7
8 8 namespace BitCode\BitForm\Core\Integration\ZohoSign;
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\HttpHelper;
12 16 use BitCode\BitForm\Core\Util\IpTool;
17 +use BitCode\BitForm\GlobalHelper;
13 18 use WP_Error;
14 19
15 20 /**
16 21 * Provide functionality for ZohoCrm integration
17 22 */
18 -class ZohoSignHandler {
23 +class ZohoSignHandler
24 +{
19 25 private $_formID;
20 26 private $_integrationID;
21 27
22 - public function __construct($integrationID, $fromID) {
28 + public function __construct($integrationID, $fromID)
29 + {
23 30 $this->_formID = $fromID;
24 31 $this->_integrationID = $integrationID;
25 32 }
26 33
@@ -28,9 +35,10 @@
28 35 * Helps to register ajax function's with wp
29 36 *
30 37 * @return null
31 38 */
32 - public static function registerAjax() {
39 + public static function registerAjax()
40 + {
33 41 add_action('wp_ajax_bitforms_zsign_generate_token', [__CLASS__, 'generateTokens']);
34 42 add_action('wp_ajax_bitforms_zsign_refresh_templates', [__CLASS__, 'refreshTemplatesAjaxHelper']);
35 43 add_action('wp_ajax_bitforms_zsign_refresh_template_details', [__CLASS__, 'refreshTemplateDetailsAjaxHelper']);
36 44 }
@@ -39,12 +47,18 @@
39 47 * Process ajax request for generate_token
40 48 *
41 49 * @return JSON zoho crm api response and status
42 50 */
43 - public static function generateTokens() {
44 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
45 - $inputJSON = file_get_contents('php://input');
46 - $requestsParams = json_decode($inputJSON);
51 + public static function generateTokens()
52 + {
53 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
54 + GlobalHelper::requirePostMethod();
55 +
56 + try {
57 + $requestsParams = GlobalHelper::formatRequestData();
58 + } catch (\InvalidArgumentException $e) {
59 + wp_send_json_error($e->getMessage(), 400);
60 + }
47 61 if (
48 62 empty($requestsParams->{'accounts-server'})
49 63 || empty($requestsParams->dataCenter)
50 64 || empty($requestsParams->clientId)
@@ -92,12 +106,13 @@
92 106
93 107 /**
94 108 * Helps to refresh zoho crm access_token
95 109 *
96 - * @param Array $apiData Contains required data for refresh access token
97 - * @return JSON $tokenDetails API token details
110 + * @param object $apiData Contains required data for refresh access token
111 + * @return string|boolean $tokenDetails API token details
98 112 */
99 - protected static function _refreshAccessToken($apiData) {
113 + protected static function _refreshAccessToken($apiData)
114 + {
100 115 if (
101 116 empty($apiData->dataCenter)
102 117 || empty($apiData->clientId)
103 118 || empty($apiData->clientSecret)
@@ -127,15 +142,16 @@
127 142
128 143 /**
129 144 * Save updated access_token to avoid unnecessary token generation
130 145 *
131 - * @param Integer $fromID ID of Integration related form
132 - * @param Integer $integrationID ID of Zoho crm Integration
133 - * @param Obeject $tokenDetails refreshed token info
146 + * @param integer $fromID ID of Integration related form
147 + * @param integer $integrationID ID of Zoho crm Integration
148 + * @param object $tokenDetails refreshed token info
134 149 *
135 150 * @return null
136 151 */
137 - protected static function _saveRefreshedToken($formID, $integrationID, $tokenDetails, $others = null) {
152 + protected static function _saveRefreshedToken($formID, $integrationID, $tokenDetails, $others = null)
153 + {
138 154 if (empty($formID) || empty($integrationID)) {
139 155 return;
140 156 }
141 157
@@ -148,16 +164,24 @@
148 164 $newDetails = json_decode($zsignDetails[0]->integration_details);
149 165
150 166 $newDetails->tokenDetails = $tokenDetails;
151 167
152 - $integrationHandler->updateIntegration($integrationID, $zsignDetails[0]->integration_name, 'Zoho Sign', \json_encode($newDetails), 'form');
168 + $integrationHandler->updateIntegration($integrationID, $zsignDetails[0]->integration_name, 'Zoho Sign', wp_json_encode($newDetails), 'form');
153 169 }
154 170
155 - public function refreshTemplatesAjaxHelper() {
156 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
171 + public static function refreshTemplatesAjaxHelper()
172 + {
173 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
157 174 $authorizationHeader = null;
158 - $inputJSON = file_get_contents('php://input');
159 - $queryParams = json_decode($inputJSON);
175 +
176 + GlobalHelper::requirePostMethod();
177 +
178 + try {
179 + $queryParams = GlobalHelper::formatRequestData();
180 + } catch (\InvalidArgumentException $e) {
181 + wp_send_json_error($e->getMessage(), 400);
182 + }
183 +
160 184 if (
161 185 empty($queryParams->tokenDetails)
162 186 || empty($queryParams->dataCenter)
163 187 || empty($queryParams->clientId)
@@ -212,13 +236,21 @@
212 236 );
213 237 }
214 238 }
215 239
216 - public function refreshTemplateDetailsAjaxHelper() {
217 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
240 + public static function refreshTemplateDetailsAjaxHelper()
241 + {
242 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
218 243 $authorizationHeader = null;
219 - $inputJSON = file_get_contents('php://input');
220 - $queryParams = json_decode($inputJSON);
244 +
245 + GlobalHelper::requirePostMethod();
246 +
247 + try {
248 + $queryParams = GlobalHelper::formatRequestData();
249 + } catch (\InvalidArgumentException $e) {
250 + wp_send_json_error($e->getMessage(), 400);
251 + }
252 +
221 253 if (
222 254 empty($queryParams->tokenDetails)
223 255 || empty($queryParams->dataCenter)
224 256 || empty($queryParams->clientId)
@@ -273,9 +305,10 @@
273 305 );
274 306 }
275 307 }
276 308
277 - public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) {
309 + public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
310 + {
278 311 $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details;
279 312 $templateActions = $integrationDetails->templateActions;
280 313 $notes = $integrationDetails->notes;
281 314 $dataCenter = $integrationDetails->dataCenter;
@@ -298,9 +331,9 @@
298 331 }
299 332 }
300 333
301 334 // $actions = $integrationDetails->actions;
302 - $recordApiHelper = new RecordApiHelper($tokenDetails, $this->_integrationID, $logID);
335 + $recordApiHelper = new RecordApiHelper($tokenDetails, $this->_integrationID, $logID, $this->_formID, $entryID);
303 336
304 337 $zsignApiResponse = $recordApiHelper->executeRecordApi(
305 338 $dataCenter,
306 339 $template,