PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.13
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.13
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 / ElasticEmail / ElasticEmailHandler.php

ElasticEmailHandler.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.21.13, at includes/Core/Integration/ElasticEmail/ElasticEmailHandler.php

157 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Elastic Email Integration
5 */
6
7 namespace BitCode\BitForm\Core\Integration\ElasticEmail;
8
9 if (!defined('ABSPATH')) {
10 exit;
11 }
12
13 use BitCode\BitForm\Core\Integration\IntegrationHandler;
14 use BitCode\BitForm\Core\Util\HttpHelper;
15 use BitCode\BitForm\GlobalHelper;
16 use WP_Error;
17
18 /**
19 * Provide functionality for ZohoCrm integration
20 */
21 class ElasticEmailHandler
22 {
23 private $formID;
24
25 private $integrationID;
26
27 public function __construct($integrationID, $fromID)
28 {
29 $this->formID = $fromID;
30 $this->integrationID = $integrationID;
31 }
32
33 public static function registerAjax()
34 {
35 add_action('wp_ajax_bitforms_elasticemail_authorize', [__CLASS__, 'elasticEmailAuthorize']);
36 add_action('wp_ajax_bitforms_get_all_lists', [__CLASS__, 'getAllLists']);
37 }
38
39 public static function elasticEmailAuthorize()
40 {
41 if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
42
43
44 GlobalHelper::requirePostMethod();
45
46 try {
47 $requestsParams = GlobalHelper::formatRequestData();
48 } catch (\InvalidArgumentException $e) {
49 wp_send_json_error($e->getMessage(), 400);
50 }
51
52 if (empty($requestsParams->api_key)) {
53 wp_send_json_error(
54 __(
55 'Requested parameter is empty',
56 'bit-form'
57 ),
58 400
59 );
60 }
61
62 $apiEndpoint = 'https://api.elasticemail.com/v4/lists';
63 $apiKey = $requestsParams->api_key;
64 $header = [
65 'X-ElasticEmail-ApiKey' => $apiKey,
66 'Accept' => '*/*',
67 ];
68 $apiResponse = HttpHelper::get($apiEndpoint, null, $header);
69
70 if (is_wp_error($apiResponse) || isset($apiResponse->Error)) {
71 wp_send_json_error(
72 $apiResponse->Error,
73 400
74 );
75 }
76 wp_send_json_success(true);
77 }
78 }
79
80 public static function getAllLists()
81 {
82 if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
83 $response = null;
84
85
86 GlobalHelper::requirePostMethod();
87
88 try {
89 $requestsParams = GlobalHelper::formatRequestData();
90 } catch (\InvalidArgumentException $e) {
91 wp_send_json_error($e->getMessage(), 400);
92 }
93
94 if (empty($requestsParams->apiKey)) {
95 wp_send_json_error(
96 __(
97 'Requested parameter is empty',
98 'bit-form'
99 ),
100 400
101 );
102 }
103
104 $apiEndpoint = 'https://api.elasticemail.com/v4/lists';
105 $apiKey = $requestsParams->apiKey;
106 $header = [
107 'X-ElasticEmail-ApiKey' => $apiKey,
108 'Accept' => '*/*',
109 ];
110 $apiResponse = HttpHelper::get($apiEndpoint, null, $header);
111 $data = [];
112 foreach ($apiResponse as $list) {
113 $data[] = (object) [
114 'listId' => $list->PublicListID,
115 'listName' => $list->ListName
116 ];
117 }
118 $response['lists'] = $data;
119 wp_send_json_success($response, 200);
120 }
121
122 // wp_send_json_success(true);
123 }
124
125 public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
126 {
127 $integrationDetails = $integrationData->integration_details;
128 if (is_string($integrationDetails)) {
129 $integrationDetails = json_decode($integrationDetails);
130 }
131 $integId = $integrationData->id;
132
133 $api_key = $integrationDetails->api_key;
134 $fieldMap = $integrationDetails->field_map;
135 $actions = $integrationDetails->actions;
136 if (
137 empty($api_key)
138 || empty($fieldMap)
139 ) {
140 return new WP_Error('REQ_FIELD_EMPTY', __('module, fields are required for Elastic Email api', 'bit-form'));
141 }
142 $recordApiHelper = new RecordApiHelper($api_key, $integId, $logID, $integrationDetails, $entryID);
143 $elasticEmailApiResponse = $recordApiHelper->execute(
144 $integId,
145 $fieldValues,
146 $fieldMap,
147 $integrationDetails,
148 $this->formID,
149 );
150
151 if (is_wp_error($elasticEmailApiResponse)) {
152 return $elasticEmailApiResponse;
153 }
154 return $elasticEmailApiResponse;
155 }
156 }
157