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 / ElasticEmail / ElasticEmailHandler.php

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

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