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

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

128 lines 3.5 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 use BitCode\BitForm\Core\Integration\IntegrationHandler;
10 use BitCode\BitForm\Core\Util\HttpHelper;
11 use WP_Error;
12
13 /**
14 * Provide functionality for ZohoCrm integration
15 */
16 class ElasticEmailHandler
17 {
18 public static function registerAjax()
19 {
20 add_action('wp_ajax_bitforms_elasticemail_authorize', [__CLASS__, 'elasticEmailAuthorize']);
21 add_action('wp_ajax_bitforms_get_all_lists', [__CLASS__, 'getAllLists']);
22 }
23
24 public static function elasticEmailAuthorize()
25 {
26 if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
27 $inputJSON = file_get_contents('php://input');
28 $requestsParams = json_decode($inputJSON);
29
30 if (empty($requestsParams->api_key)) {
31 wp_send_json_error(
32 __(
33 'Requested parameter is empty',
34 'bit-form'
35 ),
36 400
37 );
38 }
39
40 $apiEndpoint = 'https://api.elasticemail.com/v4/lists';
41 $apiKey = $requestsParams->api_key;
42 $header = [
43 'X-ElasticEmail-ApiKey' => $apiKey,
44 'Accept' => '*/*',
45 ];
46 $apiResponse = HttpHelper::get($apiEndpoint, null, $header);
47
48 if (is_wp_error($apiResponse) || isset($apiResponse->Error)) {
49 wp_send_json_error(
50 $apiResponse->Error,
51 400
52 );
53 }
54 wp_send_json_success(true);
55 }
56 }
57
58 public static function getAllLists()
59 {
60 if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
61 $response = null;
62 $inputJSON = file_get_contents('php://input');
63 $requestsParams = json_decode($inputJSON);
64
65 if (empty($requestsParams->apiKey)) {
66 wp_send_json_error(
67 __(
68 'Requested parameter is empty',
69 'bit-form'
70 ),
71 400
72 );
73 }
74
75 $apiEndpoint = 'https://api.elasticemail.com/v4/lists';
76 $apiKey = $requestsParams->apiKey;
77 $header = [
78 'X-ElasticEmail-ApiKey' => $apiKey,
79 'Accept' => '*/*',
80 ];
81 $apiResponse = HttpHelper::get($apiEndpoint, null, $header);
82 $data = [];
83 foreach ($apiResponse as $list) {
84 $data[] = (object) [
85 'listId' => $list->PublicListID,
86 'listName' => $list->ListName
87 ];
88 }
89 $response['lists'] = $data;
90 wp_send_json_success($response, 200);
91 }
92
93 // wp_send_json_success(true);
94 }
95
96 public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
97 {
98 $integrationDetails = $integrationData->integration_details;
99 if (is_string($integrationDetails)) {
100 $integrationDetails = json_decode($integrationDetails);
101 }
102 $integId = $integrationData->id;
103
104 $api_key = $integrationDetails->api_key;
105 $fieldMap = $integrationDetails->field_map;
106 $actions = $integrationDetails->actions;
107 if (
108 empty($api_key)
109 || empty($fieldMap)
110 ) {
111 return new WP_Error('REQ_FIELD_EMPTY', __('module, fields are required for Elastic Email api', 'bit-form'));
112 }
113 $recordApiHelper = new RecordApiHelper($api_key, $integId, $logID, $integrationDetails);
114 $elasticEmailApiResponse = $recordApiHelper->execute(
115 $integId,
116 $fieldValues,
117 $fieldMap,
118 $integrationDetails
119 // $actions
120 );
121
122 if (is_wp_error($elasticEmailApiResponse)) {
123 return $elasticEmailApiResponse;
124 }
125 return $elasticEmailApiResponse;
126 }
127 }
128