PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.2.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.2.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 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 3.2.2, at includes/Core/Integration/ElasticEmail/ElasticEmailHandler.php

154 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 GlobalHelper::requirePostMethod();
43
44 try {
45 $requestsParams = GlobalHelper::formatRequestData();
46 } catch (\InvalidArgumentException $e) {
47 wp_send_json_error($e->getMessage(), 400);
48 }
49
50 if (empty($requestsParams->api_key)) {
51 wp_send_json_error(
52 __(
53 'Requested parameter is empty',
54 'bit-form'
55 ),
56 400
57 );
58 }
59
60 $apiEndpoint = 'https://api.elasticemail.com/v4/lists';
61 $apiKey = $requestsParams->api_key;
62 $header = [
63 'X-ElasticEmail-ApiKey' => $apiKey,
64 'Accept' => '*/*',
65 ];
66 $apiResponse = HttpHelper::get($apiEndpoint, null, $header);
67
68 if (is_wp_error($apiResponse) || isset($apiResponse->Error)) {
69 wp_send_json_error(
70 $apiResponse->Error,
71 400
72 );
73 }
74 wp_send_json_success(true);
75 }
76 }
77
78 public static function getAllLists()
79 {
80 if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
81 $response = null;
82
83 GlobalHelper::requirePostMethod();
84
85 try {
86 $requestsParams = GlobalHelper::formatRequestData();
87 } catch (\InvalidArgumentException $e) {
88 wp_send_json_error($e->getMessage(), 400);
89 }
90
91 if (empty($requestsParams->apiKey)) {
92 wp_send_json_error(
93 __(
94 'Requested parameter is empty',
95 'bit-form'
96 ),
97 400
98 );
99 }
100
101 $apiEndpoint = 'https://api.elasticemail.com/v4/lists';
102 $apiKey = $requestsParams->apiKey;
103 $header = [
104 'X-ElasticEmail-ApiKey' => $apiKey,
105 'Accept' => '*/*',
106 ];
107 $apiResponse = HttpHelper::get($apiEndpoint, null, $header);
108 $data = [];
109 foreach ($apiResponse as $list) {
110 $data[] = (object) [
111 'listId' => $list->PublicListID,
112 'listName' => $list->ListName
113 ];
114 }
115 $response['lists'] = $data;
116 wp_send_json_success($response, 200);
117 }
118
119 // wp_send_json_success(true);
120 }
121
122 public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
123 {
124 $integrationDetails = $integrationData->integration_details;
125 if (is_string($integrationDetails)) {
126 $integrationDetails = json_decode($integrationDetails);
127 }
128 $integId = $integrationData->id;
129
130 $api_key = $integrationDetails->api_key;
131 $fieldMap = $integrationDetails->field_map;
132 $actions = $integrationDetails->actions;
133 if (
134 empty($api_key)
135 || empty($fieldMap)
136 ) {
137 return new WP_Error('REQ_FIELD_EMPTY', __('module, fields are required for Elastic Email api', 'bit-form'));
138 }
139 $recordApiHelper = new RecordApiHelper($api_key, $integId, $logID, $integrationDetails, $entryID);
140 $elasticEmailApiResponse = $recordApiHelper->execute(
141 $integId,
142 $fieldValues,
143 $fieldMap,
144 $integrationDetails,
145 $this->formID,
146 );
147
148 if (is_wp_error($elasticEmailApiResponse)) {
149 return $elasticEmailApiResponse;
150 }
151 return $elasticEmailApiResponse;
152 }
153 }
154