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
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 2.10.2 All 137 releases
bit-form / includes / Core / Integration / Autonami / AutonamiHandler.php

AutonamiHandler.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.0, at includes/Core/Integration/Autonami/AutonamiHandler.php

154 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Autonami Integration
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\Autonami;
9
10 use BitCode\BitForm\Core\Integration\IntegrationHandler;
11 use BitCode\BitForm\Core\Util\ApiResponse as UtilApiResponse;
12 use BWFCRM_Fields;
13 use BWFCRM_Lists;
14 use BWFCRM_Tag;
15 use WP_Error;
16
17 class AutonamiHandler {
18 private $_formID;
19 private $_integrationID;
20
21 public function __construct($integrationID, $fromID) {
22 $this->_formID = $fromID;
23 $this->_integrationID = $integrationID;
24 }
25
26 /**
27 * Helps to register ajax function's with wp
28 *
29 * @return null
30 */
31 public static function registerAjax() {
32 add_action('wp_ajax_bitforms_autonami_authorize', [__CLASS__, 'autonamiAuthorize']);
33 add_action('wp_ajax_bitforms_autonami_lists_and_tags', [__CLASS__, 'autonamiListsAndTags']);
34 add_action('wp_ajax_bitforms_autonami_fields', [__CLASS__, 'autonamiFields']);
35 }
36
37 /**
38 * for chen autonami pro plugins are exists
39 */
40 public static function checkedExistsAutonami() {
41 if (!class_exists('BWFCRM_Contact')) {
42 wp_send_json_error(__('Autonami Pro Plugins not found', 'bit-form'), 400);
43 } else {
44 return true;
45 }
46 }
47
48 /**
49 * @return Autonami lists
50 */
51 public static function autonamiListsAndTags() {
52 if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
53 wp_send_json_error(__('Token expired', 'bit-form'), 401);
54 }
55
56 self::checkedExistsAutonami();
57
58 $lists = BWFCRM_Lists::get_lists();
59 $autonamiList = [];
60 foreach ($lists as $list) {
61 $autonamiList[$list['name']] = (object) [
62 'id' => $list['ID'],
63 'title' => $list['name']
64 ];
65 }
66
67 $tags = BWFCRM_Tag::get_tags();
68 $autonamiTags = [];
69 foreach ($tags as $tag) {
70 $autonamiTags[$tag['name']] = (object) [
71 'id' => $tag['ID'],
72 'title' => $tag['name']
73 ];
74 }
75
76 $response['autonamiList'] = $autonamiList;
77 $response['autonamiTags'] = $autonamiTags;
78 wp_send_json_success($response, 200);
79 }
80
81 public static function autonamiFields() {
82 if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
83 wp_send_json_error(__('Token expired', 'bit-form'), 401);
84 }
85
86 self::checkedExistsAutonami();
87
88 $fieldOptions = [];
89 $fieldOptions['Email'] = (object) [
90 'key' => 'email',
91 'label' => 'Email',
92 'type' => 'primary',
93 'required' => true
94 ];
95 foreach (BWFCRM_Fields::get_default_fields() as $key => $column) {
96 $fieldOptions[$column] = (object) [
97 'key' => $key,
98 'label' => $column,
99 'type' => 'primary'
100 ];
101 }
102 foreach (BWFCRM_Fields::get_custom_fields(1, 1) as $field) {
103 $fieldOptions[$field['slug']] = (object) [
104 'key' => $field['slug'],
105 'label' => $field['name'],
106 'type' => 'custom'
107 ];
108 }
109 $response['autonamiFields'] = $fieldOptions;
110 wp_send_json_success($response, 200);
111 }
112
113 /**
114 * @return True Autonami are exists
115 */
116 public static function autonamiAuthorize() {
117 if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
118 wp_send_json_error(__('Token expired', 'bit-form'), 401);
119 }
120
121 if (self::checkedExistsAutonami()) {
122 wp_send_json_success(true);
123 } else {
124 wp_send_json_error(__('Autonami Pro Plugins not found', 'bit-form'), 400);
125 }
126 }
127
128 public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) {
129 if (!class_exists('BWFCRM_Contact')) {
130 (new UtilApiResponse())->apiResponse($logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'insert'], 'error', 'Autonami Pro Plugins not found');
131 return;
132 }
133
134 $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details;
135
136 $fieldMap = $integrationDetails->field_map;
137 $lists = $integrationDetails->lists;
138 $tags = $integrationDetails->tags;
139 $actions = $integrationDetails->actions;
140
141 if (empty($fieldMap)) {
142 return new WP_Error('REQ_FIELD_EMPTY', __('module, fields are required for Autonami api', 'bit-form'));
143 }
144
145 $recordApiHelper = new RecordApiHelper($this->_integrationID, $logID, $entryID);
146 $autonamiApiResponse = $recordApiHelper->executeRecordApi($fieldValues, $fieldMap, $actions, $lists, $tags);
147
148 if (is_wp_error($autonamiApiResponse)) {
149 return $autonamiApiResponse;
150 }
151 return $autonamiApiResponse;
152 }
153 }
154