PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.10.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.10.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 / Acumbamail / RecordApiHelper.php

RecordApiHelper.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.10.0, at includes/Core/Integration/Acumbamail/RecordApiHelper.php

107 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Integration\Acumbamail;
4
5 use BitCode\BitForm\Core\Util\ApiResponse;
6 use BitCode\BitForm\Core\Util\HttpHelper;
7
8 /**
9 * Provide functionality for Record insert, upsert
10 */
11 class RecordApiHelper
12 {
13 private $_integrationID;
14 private $_logID;
15
16 private $_logResponse;
17
18 public function __construct($auth_token, $integId, $logID, $entryID)
19 {
20 $this->_integrationID = $integId;
21 $this->_logResponse = new ApiResponse();
22 $this->_logID = $logID;
23 }
24
25 public function addSubscriber($auth_token, $listId, $finalData)
26 {
27 $apiEndpoints = 'https://acumbamail.com/api/1/addSubscriber/';
28 $header = [
29 'Content-Type' => 'application/x-www-form-urlencoded'
30 ];
31
32 $requestParams = [
33 'auth_token' => $auth_token,
34 'list_id' => $listId,
35 'welcome_email' => 1,
36 'update_subscriber' => 1,
37 'merge_fields[EMAIL]' => $finalData['email'],
38
39 ];
40 foreach ($finalData as $key => $value) {
41 if ('email' !== $key) {
42 $requestParams['merge_fields[' . $key . ']'] = $value;
43 }
44 }
45 return HttpHelper::post($apiEndpoints, $requestParams, $header);
46 }
47
48 public function deleteSubscriber($auth_token, $listId, $finalData)
49 {
50 $apiEndpoints = 'https://acumbamail.com/api/1/deleteSubscriber/';
51
52 $header = [
53 'Content-Type' => 'application/x-www-form-urlencoded'
54 ];
55
56 $requestParams = [
57 'auth_token' => $auth_token,
58 'list_id' => $listId,
59 'email' => $finalData['email'],
60 ];
61
62 return HttpHelper::post($apiEndpoints, $requestParams, $header);
63 }
64
65 public function generateReqDataFromFieldMap($data, $fieldMap)
66 {
67 $dataFinal = [];
68
69 foreach ($fieldMap as $value) {
70 $triggerValue = $value->formField;
71 $actionValue = $value->acumbamailFormField;
72 if ('custom' === $triggerValue) {
73 $dataFinal[$actionValue] = $value->customValue;
74 } elseif (!is_null($data[$triggerValue])) {
75 $dataFinal[$actionValue] = $data[$triggerValue];
76 }
77 }
78 return $dataFinal;
79 }
80
81 public function execute(
82 $listId,
83 $mainAction,
84 $defaultDataConf,
85 $fieldValues,
86 $fieldMap,
87 $auth_token
88 ) {
89 $finalData = $this->generateReqDataFromFieldMap($fieldValues, $fieldMap);
90 $apiResponse = null;
91 $type = null;
92 if ('1' === $mainAction) {
93 $apiResponse = $this->addSubscriber($auth_token, $listId, $finalData);
94 $type = 'add subscriber';
95 } elseif ('2' === $mainAction) {
96 $apiResponse = $this->deleteSubscriber($auth_token, $listId, $finalData);
97 $type = 'delete subscriber';
98 }
99
100 if (property_exists($apiResponse, 'errors')) {
101 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => $type], 'errors', $apiResponse);
102 } else {
103 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => $type], 'success', $apiResponse);
104 }
105 return $apiResponse;
106 }
107 }