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
bit-form / includes / Core / Integration / ZohoCampaigns / RecordApiHelper.php

RecordApiHelper.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 3.3.1, at includes/Core/Integration/ZohoCampaigns/RecordApiHelper.php

86 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * ZohoRecruit Record Api
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\ZohoCampaigns;
9
10 use BitCode\BitForm\Core\Util\ApiResponse as UtilApiResponse;
11 use BitCode\BitForm\Core\Util\HttpHelper;
12 use WP_Error;
13
14 /**
15 * Provide functionality for Record insert,upsert
16 */
17 class RecordApiHelper
18 {
19 private $_defaultHeader;
20 private $_apiDomain;
21 private $_tokenDetails;
22
23 private $_integrationID;
24
25 private $_logID;
26
27 private $_logResponse;
28
29 private $_formId;
30
31 private $_entryId;
32
33 public function __construct($tokenDetails, $integId, $logID, $formId, $entryId)
34 {
35 $this->_defaultHeader['Authorization'] = "Zoho-oauthtoken {$tokenDetails->access_token}";
36 $this->_apiDomain = \urldecode($tokenDetails->api_domain);
37 $this->_tokenDetails = $tokenDetails;
38 $this->_integrationID = $integId;
39 $this->_logID = $logID;
40 $this->_logResponse = new UtilApiResponse();
41
42 $this->_formId = $formId;
43 $this->_entryId = $entryId;
44 }
45
46 public function insertRecord($list, $dataCenter, $data)
47 {
48 $insertRecordEndpoint = "https://campaigns.zoho.{$dataCenter}/api/v1.1/json/listsubscribe?resfmt=JSON&listkey={$list}&contactinfo=" . urlencode($data);
49
50 return HttpHelper::post($insertRecordEndpoint, null, $this->_defaultHeader);
51 }
52
53 public function executeRecordApi($list, $dataCenter, $fieldValues, $fieldMap, $required)
54 {
55 $fieldData = [];
56 $entryDetails = [
57 'formId' => $this->_formId,
58 'entryId' => $this->_entryId,
59 'fieldValues' => $fieldValues
60 ];
61 foreach ($fieldMap as $fieldPair) {
62 if (!empty($fieldPair->zohoFormField) && !empty($fieldPair->formField)) {
63 if ('custom' === $fieldPair->formField && isset($fieldPair->customValue)) {
64 $fieldData[$fieldPair->zohoFormField] = $fieldPair->customValue;
65 } else {
66 $fieldData[$fieldPair->zohoFormField] = $fieldValues[$fieldPair->formField];
67 }
68 }
69 if (empty($fieldData[$fieldPair->zohoFormField]) && \in_array($fieldPair->zohoFormField, $required)) {
70 /* translators: %s is the zoho campaigns field name which is required but not found in the form submission data. */
71 $error = new WP_Error('REQ_FIELD_EMPTY', wp_sprintf(__('%s is required for zoho campaigns', 'bit-form'), $fieldPair->zohoFormField));
72 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'field'], 'validation', $error, $entryDetails);
73 return $error;
74 }
75 }
76
77 $recordApiResponse = $this->insertRecord($list, $dataCenter, wp_json_encode($fieldData));
78 if (isset($recordApiResponse->status) && 'error' === $recordApiResponse->status) {
79 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'list'], 'error', $recordApiResponse, $entryDetails);
80 } else {
81 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'list'], 'success', $recordApiResponse, $entryDetails);
82 }
83 return $recordApiResponse;
84 }
85 }
86