PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.0
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
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.0, at includes/Core/Integration/FluentCrm/FluentCrmHandler.php

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