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
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.0, at includes/Core/Integration/SendFox/SendFoxHandler.php

124 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 * SendFox Integration
5 */
6
7 namespace BitCode\BitForm\Core\Integration\SendFox;
8
9 use BitCode\BitForm\Core\Integration\IntegrationHandler;
10 use BitCode\BitForm\Core\Util\HttpHelper;
11 use WP_Error;
12
13 class SendFoxHandler {
14 private $integrationID;
15 public static $baseUrl = 'https://api.sendfox.com/';
16
17 public function __construct($integrationID, $fromID) {
18 $this->integrationID = $integrationID;
19 }
20
21 public static function registerAjax() {
22 add_action('wp_ajax_bitforms_sendFox_authorize', [__CLASS__, 'sendFoxAuthorize']);
23 add_action('wp_ajax_bitforms_sendfox_fetch_all_list', [__CLASS__, 'fetchContactLists']);
24 }
25
26 public static function sendFoxAuthorize($requestParams) {
27 if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
28 wp_send_json_error(__('Token expired', 'bit-form'), 401);
29 }
30
31 $inputJSON = file_get_contents('php://input');
32 $requestParams = json_decode($inputJSON);
33 if (empty($requestParams->access_token)) {
34 wp_send_json_error(
35 __(
36 'Requested parameter is empty',
37 'bit-form'
38 ),
39 400
40 );
41 }
42 $apiEndpoints = self::$baseUrl . 'me';
43 $header = [
44 'Authorization' => "Bearer {$requestParams->access_token}",
45 'Accept' => 'application/json',
46 ];
47
48 $response = HttpHelper::get($apiEndpoints, null, $header);
49 if ('Unauthenticated.' !== $response->message) {
50 wp_send_json_success($response, 200);
51 } else {
52 wp_send_json_error(
53 'The token is invalid',
54 400
55 );
56 }
57 }
58
59 public static function fetchContactLists($requestParams) {
60 if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
61 wp_send_json_error(__('Token expired', 'bit-form'), 401);
62 }
63
64 $inputJSON = file_get_contents('php://input');
65 $requestParams = json_decode($inputJSON);
66
67 if (empty($requestParams->access_token)) {
68 wp_send_json_error(
69 __(
70 'Requested parameter is empty',
71 'bit-form'
72 ),
73 400
74 );
75 }
76 $apiEndpoints = self::$baseUrl . 'lists';
77
78 $requestParams = [
79 'Authorization' => "Bearer {$requestParams->access_token}",
80 'Accept' => 'application/json',
81 ];
82
83 $response = HttpHelper::get($apiEndpoints, null, $requestParams);
84
85 if ('Unauthenticated.' !== $response->message) {
86 wp_send_json_success($response, 200);
87 } else {
88 wp_send_json_error(
89 'The token is invalid',
90 400
91 );
92 }
93 }
94
95 public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) {
96 $integrationDetails = json_decode($integrationData->integration_details);
97 $access_token = $integrationDetails->access_token;
98 $listId = $integrationDetails->listId;
99 $mainAction = $integrationDetails->mainAction;
100 $fieldMap = $integrationDetails->field_map;
101
102 if (
103 empty($mainAction)
104 || empty($access_token)
105 ) {
106 return new WP_Error('REQ_FIELD_EMPTY', __('module, fields are required for SendFox api', 'bit-form'));
107 }
108 $recordApiHelper = new RecordApiHelper($access_token, $this->integrationID, $logID, $entryID);
109 $sendFoxApiResponse = $recordApiHelper->execute(
110 $listId,
111 $mainAction,
112 $fieldValues,
113 $fieldMap,
114 $access_token,
115 $integrationDetails
116 );
117
118 if (is_wp_error($sendFoxApiResponse)) {
119 return $sendFoxApiResponse;
120 }
121 return $sendFoxApiResponse;
122 }
123 }
124