PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / V3.0.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder vV3.0.2
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 / MailPoet / MailPoetHandler.php

MailPoetHandler.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder V3.0.2, at includes/Core/Integration/MailPoet/MailPoetHandler.php

183 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * ZohoSheet Integration
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\MailPoet;
9
10 if (!defined('ABSPATH')) {
11 exit;
12 }
13
14 use BitCode\BitForm\Core\Integration\IntegrationHandler;
15 use WP_Error;
16
17 /**
18 * Provide functionality for ZohoCrm integration
19 */
20 class MailPoetHandler
21 {
22 private $_integrationID;
23
24 private $formId;
25
26 public function __construct($integrationID, $fromID)
27 {
28 $this->_integrationID = $integrationID;
29
30 $this->formId = $fromID;
31 }
32
33 /**
34 * Helps to register ajax function's with wp
35 *
36 * @return null
37 */
38 public static function registerAjax()
39 {
40 add_action('wp_ajax_bitforms_mail_poet_authorize', [__CLASS__, 'mailPoetAuthorize']);
41 add_action('wp_ajax_bitforms_refresh_news_letter', [__CLASS__, 'refreshNeswLetter']);
42 add_action('wp_ajax_bitforms_mail_poet_list_headers', [__CLASS__, 'mailPoetListHeaders']);
43 }
44
45 /**
46 * Process ajax request for generate_token
47 *
48 * @return string zoho crm api response and status
49 */
50 public static function mailPoetAuthorize()
51 {
52 if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
53 if (class_exists(\MailPoet\API\API::class)) {
54 wp_send_json_success(true);
55 } else {
56 wp_send_json_error(
57 __(
58 'Please! Insatall MailPoet',
59 'bit-form'
60 ),
61 400
62 );
63 }
64 } else {
65 wp_send_json_error(
66 __(
67 'Token expired',
68 'bit-form'
69 ),
70 401
71 );
72 }
73 }
74
75 /**
76 * Process ajax request for refresh crm modules
77 *
78 * @return string JSON crm module data
79 */
80 public static function refreshNeswLetter()
81 {
82 $response = null;
83 if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
84 if (class_exists(\MailPoet\API\API::class)) {
85 $mailpoet_api = \MailPoet\API\API::MP('v1');
86 $newsletterList = $mailpoet_api->getLists();
87
88 $allList = [];
89
90 foreach ($newsletterList as $newsletter) {
91 $allList[$newsletter['name']] = (object) [
92 'newsletterId' => $newsletter['id'],
93 'newsletterName' => $newsletter['name']
94 ];
95 }
96 $response['newsletterList'] = $allList;
97 wp_send_json_success($response, 200);
98 } else {
99 wp_send_json_error(
100 __(
101 'Please! Install MailPoet',
102 'bit-form'
103 ),
104 400
105 );
106 }
107 } else {
108 wp_send_json_error(
109 __(
110 'Token expired',
111 'bit-form'
112 ),
113 401
114 );
115 }
116 }
117
118 public static function mailPoetListHeaders()
119 {
120 $response = null;
121 if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
122 if (class_exists(\MailPoet\API\API::class)) {
123 $mailpoet_api = \MailPoet\API\API::MP('v1');
124 $subscriber_form_fields = $mailpoet_api->getSubscriberFields();
125
126 $allList = [];
127
128 foreach ($subscriber_form_fields as $fields) {
129 $allList[$fields['name']] = (object) [
130 'id' => $fields['id'],
131 'name' => $fields['name'],
132 'required' => $fields['params']['required']
133 ];
134 }
135 $response['mailPoetFields'] = $allList;
136 wp_send_json_success($response, 200);
137 } else {
138 wp_send_json_error(
139 __(
140 'Please! Insatall MailPoet',
141 'bit-form'
142 ),
143 400
144 );
145 }
146 } else {
147 wp_send_json_error(
148 __(
149 'Token expired',
150 'bit-form'
151 ),
152 401
153 );
154 }
155 }
156
157 public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
158 {
159 $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details;
160
161 $fieldMap = $integrationDetails->field_map;
162 $defaultDataConf = $integrationDetails->default;
163 $lists = $integrationDetails->lists;
164 if (empty($fieldMap)) {
165 return new WP_Error('REQ_FIELD_EMPTY', __('module, fields are required for Mail Poet api', 'bit-form'));
166 }
167
168 $recordApiHelper = new RecordApiHelper($this->_integrationID, $logID, $entryID);
169
170 $maiPoetApiResponse = $recordApiHelper->executeRecordApi(
171 $fieldValues,
172 $fieldMap,
173 $lists,
174 $this->formId,
175 );
176
177 if (is_wp_error($maiPoetApiResponse)) {
178 return $maiPoetApiResponse;
179 }
180 return $maiPoetApiResponse;
181 }
182 }
183