PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.10.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.10.0
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 / FluentCrm / FluentCrmHandler.php

FluentCrmHandler.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.10.0, at includes/Core/Integration/FluentCrm/FluentCrmHandler.php

219 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Fluent CRM Integration
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\FluentCrm;
9
10 use BitCode\BitForm\Core\Integration\IntegrationHandler;
11 use FluentCrm\App\Models\CustomContactField;
12 use FluentCrm\App\Models\Lists;
13 use FluentCrm\App\Models\Subscriber;
14 use FluentCrm\App\Models\Tag;
15 use WP_Error;
16
17 /**
18 * Provide functionality for ZohoCrm integration
19 */
20 class FluentCrmHandler
21 {
22 private $_formID;
23 private $_integrationID;
24
25 public function __construct($integrationID, $fromID)
26 {
27 $this->_formID = $fromID;
28 $this->_integrationID = $integrationID;
29 }
30
31 /**
32 * Helps to register ajax function's with wp
33 *
34 * @return null
35 */
36 public static function registerAjax()
37 {
38 add_action('wp_ajax_bitforms_fluent_crm_authorize', [__CLASS__, 'fluentCrmAuthorize']);
39 add_action('wp_ajax_bitforms_refresh_fluent_crm_lists', [__CLASS__, 'fluentCrmLists']);
40 add_action('wp_ajax_bitforms_fluent_crm_headers', [__CLASS__, 'fluentCrmFields']);
41 }
42
43 /**
44 * for chen fluent crm plugins are exists
45 */
46 public static function checkedExistsFluentCRM()
47 {
48 return is_plugin_active('fluent-crm/fluent-crm.php') ? true : false;
49 }
50
51 /**
52 * @return Fluent CRM lists
53 */
54 public static function fluentCrmLists()
55 {
56 if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
57 $response = null;
58 if (self::checkedExistsFluentCRM()) {
59 $lists = Lists::get();
60 $fluentCrmList = [];
61 foreach ($lists as $list) {
62 $fluentCrmList[$list->title] = (object) [
63 'id' => $list->id,
64 'title' => $list->title
65 ];
66 }
67 $tags = Tag::get();
68 $fluentCrmTags = [];
69 foreach ($tags as $tag) {
70 $fluentCrmTags[$tag->title] = (object) [
71 'id' => $tag->id,
72 'title' => $tag->title
73 ];
74 }
75 $response['fluentCrmList'] = $fluentCrmList;
76 $response['fluentCrmTags'] = $fluentCrmTags;
77 } else {
78 wp_send_json_error(
79 __(
80 'Fluent CRM Plugins not found',
81 'bit-form'
82 ),
83 400
84 );
85 }
86 wp_send_json_success($response, 200);
87 } else {
88 wp_send_json_error(
89 __(
90 'Token expired',
91 'bit-form'
92 ),
93 401
94 );
95 }
96 }
97
98 public static function fluentCrmFields()
99 {
100 if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
101 $response = null;
102 if (self::checkedExistsFluentCRM()) {
103 $fieldOptions = [];
104 $primaryField = ['first_name', 'last_name', 'full_name', 'email'];
105
106 foreach (Subscriber::mappables() as $key => $column) {
107 if (in_array($key, $primaryField)) {
108 if ('email' === $key) {
109 $fieldOptions[$column] = (object) [
110 'key' => $key,
111 'label' => $column,
112 'type' => 'primary',
113 'required' => true
114 ];
115 } else {
116 $fieldOptions[$column] = (object) [
117 'key' => $key,
118 'label' => $column,
119 'type' => 'primary'
120 ];
121 }
122 } else {
123 $fieldOptions[$column] = (object) [
124 'key' => $key,
125 'label' => $column,
126 'type' => 'custom'
127 ];
128 }
129 }
130 foreach ((new CustomContactField())->getGlobalFields()['fields'] as $field) {
131 $fieldOptions[$field['label']] = (object) [
132 'key' => $field['slug'],
133 'label' => $field['label'],
134 'type' => 'custom'
135 ];
136 }
137 $response['fluentCrmFlelds'] = $fieldOptions;
138 } else {
139 wp_send_json_error(
140 __(
141 'Fluent CRM Plugins not found',
142 'bit-form'
143 ),
144 400
145 );
146 }
147 wp_send_json_success($response, 200);
148 } else {
149 wp_send_json_error(
150 __(
151 'Token expired',
152 'bit-form'
153 ),
154 401
155 );
156 }
157 }
158
159 /**
160 * @return True Fluent crm are exists
161 */
162 public static function fluentCrmAuthorize()
163 {
164 if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
165 if (self::checkedExistsFluentCRM()) {
166 wp_send_json_success(true);
167 } else {
168 wp_send_json_error(
169 __(
170 'Please! Insatall Fluent CRM',
171 'bit-form'
172 ),
173 400
174 );
175 }
176 } else {
177 wp_send_json_error(
178 __(
179 'Token expired',
180 'bit-form'
181 ),
182 401
183 );
184 }
185 }
186
187 public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
188 {
189 $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details;
190
191 // wp_send_json_success($integrationDetails);
192
193 $fieldMap = $integrationDetails->field_map;
194 $defaultDataConf = $integrationDetails->default;
195 $list_id = $integrationDetails->list_id;
196 $tags = $integrationDetails->tags;
197 $actions = $integrationDetails->actions;
198 // wp_send_json_success($fieldMap);
199 if (empty($fieldMap)) {
200 return new WP_Error('REQ_FIELD_EMPTY', __('module, fields are required for Fluent CRM api', 'bit-form'));
201 }
202
203 $recordApiHelper = new RecordApiHelper($this->_integrationID, $logID, $entryID);
204
205 $fluentCrmApiResponse = $recordApiHelper->executeRecordApi(
206 $fieldValues,
207 $fieldMap,
208 $actions,
209 $list_id,
210 $tags
211 );
212
213 if (is_wp_error($fluentCrmApiResponse)) {
214 return $fluentCrmApiResponse;
215 }
216 return $fluentCrmApiResponse;
217 }
218 }
219