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 / MailPoet / MailPoetHandler.php

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

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