PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.13
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.13
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 / SendFox / SendFoxHandler.php

SendFoxHandler.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.21.13, at includes/Core/Integration/SendFox/SendFoxHandler.php

153 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * SendFox Integration
5 */
6
7 namespace BitCode\BitForm\Core\Integration\SendFox;
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 class SendFoxHandler
19 {
20 private $integrationID;
21 public static $baseUrl = 'https://api.sendfox.com/';
22
23 private $formId;
24
25 public function __construct($integrationID, $fromID)
26 {
27 $this->integrationID = $integrationID;
28 $this->formId = $fromID;
29 }
30
31 public static function registerAjax()
32 {
33 add_action('wp_ajax_bitforms_sendFox_authorize', [__CLASS__, 'sendFoxAuthorize']);
34 add_action('wp_ajax_bitforms_sendfox_fetch_all_list', [__CLASS__, 'fetchContactLists']);
35 }
36
37 public static function sendFoxAuthorize($requestParams)
38 {
39 if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
40 wp_send_json_error(__('Token expired', 'bit-form'), 401);
41 }
42
43
44
45 GlobalHelper::requirePostMethod();
46
47 try {
48 $requestParams = GlobalHelper::formatRequestData();
49 } catch (\InvalidArgumentException $e) {
50 wp_send_json_error($e->getMessage(), 400);
51 }
52 if (empty($requestParams->access_token)) {
53 wp_send_json_error(
54 __(
55 'Requested parameter is empty',
56 'bit-form'
57 ),
58 400
59 );
60 }
61 $apiEndpoints = self::$baseUrl . 'me';
62 $header = [
63 'Authorization' => "Bearer {$requestParams->access_token}",
64 'Accept' => 'application/json',
65 ];
66
67 $response = HttpHelper::get($apiEndpoints, null, $header);
68 if ('Unauthenticated.' !== $response->message) {
69 wp_send_json_success($response, 200);
70 } else {
71 wp_send_json_error(
72 'The token is invalid',
73 400
74 );
75 }
76 }
77
78 public static function fetchContactLists($requestParams)
79 {
80 if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
81 wp_send_json_error(__('Token expired', 'bit-form'), 401);
82 }
83
84
85
86 GlobalHelper::requirePostMethod();
87
88 try {
89 $requestParams = GlobalHelper::formatRequestData();
90 } catch (\InvalidArgumentException $e) {
91 wp_send_json_error($e->getMessage(), 400);
92 }
93
94 if (empty($requestParams->access_token)) {
95 wp_send_json_error(
96 __(
97 'Requested parameter is empty',
98 'bit-form'
99 ),
100 400
101 );
102 }
103 $apiEndpoints = self::$baseUrl . 'lists';
104
105 $requestParams = [
106 'Authorization' => "Bearer {$requestParams->access_token}",
107 'Accept' => 'application/json',
108 ];
109
110 $response = HttpHelper::get($apiEndpoints, null, $requestParams);
111
112 if ('Unauthenticated.' !== $response->message) {
113 wp_send_json_success($response, 200);
114 } else {
115 wp_send_json_error(
116 'The token is invalid',
117 400
118 );
119 }
120 }
121
122 public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
123 {
124 $integrationDetails = json_decode($integrationData->integration_details);
125 $access_token = $integrationDetails->access_token;
126 $listId = $integrationDetails->listId;
127 $mainAction = $integrationDetails->mainAction;
128 $fieldMap = $integrationDetails->field_map;
129
130 if (
131 empty($mainAction)
132 || empty($access_token)
133 ) {
134 return new WP_Error('REQ_FIELD_EMPTY', __('module, fields are required for SendFox api', 'bit-form'));
135 }
136 $recordApiHelper = new RecordApiHelper($access_token, $this->integrationID, $logID, $entryID);
137 $sendFoxApiResponse = $recordApiHelper->execute(
138 $listId,
139 $mainAction,
140 $fieldValues,
141 $fieldMap,
142 $access_token,
143 $integrationDetails,
144 $this->formId
145 );
146
147 if (is_wp_error($sendFoxApiResponse)) {
148 return $sendFoxApiResponse;
149 }
150 return $sendFoxApiResponse;
151 }
152 }
153