PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
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 / Rapidmail / RecordApiHelper.php

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

93 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\Rapidmail;
4
5 use BitCode\BitForm\Core\Util\ApiResponse as UtilApiResponse;
6 use BitCode\BitForm\Core\Util\HttpHelper;
7
8 /**
9 * Provide functionality for Record insert,upsert
10 */
11 class RecordApiHelper
12 {
13 protected $_defaultHeader;
14 public static $apiBaseUri = 'https://apiv3.emailsys.net/v1';
15
16 private $integrationDetails;
17
18 private $logID;
19
20 private $_logResponse;
21
22 private $_entryID;
23
24 public function __construct($integrationDetails, $username, $password, $logID, $entryID)
25 {
26 $this->integrationDetails = $integrationDetails;
27 $this->_defaultHeader = [
28 'Authorization' => 'Basic ' . base64_encode("$username:$password"),
29 'Accept' => '*/*',
30 'Content-Type' => 'application/json',
31 'verify' => false
32 ];
33 $this->_logResponse = new UtilApiResponse();
34 $this->logID = $logID;
35 $this->_entryID = $entryID;
36 }
37
38 public function insertRecipientRecord($data)
39 {
40 $insertRecordEndpoint = self::$apiBaseUri . '/recipients';
41 $data = \is_string($data) ? $data : wp_json_encode((object)$data);
42 $response = HttpHelper::post($insertRecordEndpoint, $data, $this->_defaultHeader);
43 return $response;
44 }
45
46 public function generateReqDataFromFieldMap($data, $fieldMap)
47 {
48 $dataFinal = [];
49
50 foreach ($fieldMap as $value) {
51 $triggerValue = $value->formField;
52 $actionValue = $value->rapidmailFormField;
53 if ('custom' === $triggerValue) {
54 $dataFinal[$actionValue] = $value->customValue;
55 } elseif (!is_null($data[$triggerValue])) {
56 if (strtotime($data[$triggerValue])) {
57 $dataFinal[$actionValue] = gmdate('Y-m-d', strtotime($data[$triggerValue]));
58 } else {
59 $dataFinal[$actionValue] = $data[$triggerValue];
60 }
61 }
62 }
63
64 $selectedRecipientList = $this->integrationDetails->recipient_id;
65 if ($this->integrationDetails->actions) {
66 if (property_exists($this->integrationDetails->actions, 'send_activationmail') && $this->integrationDetails->actions->send_activationmail) {
67 $dataFinal['send_activationmail'] = 'yes';
68 }
69 }
70 $dataFinal['recipientlist_id'] = (int)$selectedRecipientList;
71 return $dataFinal;
72 }
73
74 public function executeRecordApi($integId, $defaultConf, $recipientLists, $fieldValues, $fieldMap, $actions, $formId)
75 {
76 $finalData = $this->generateReqDataFromFieldMap($fieldValues, $fieldMap);
77 $apiResponse = $this->insertRecipientRecord($finalData);
78
79 $entryDetails = [
80 'formId' => $formId,
81 'entryId' => $this->_entryID,
82 'fieldValues' => $fieldValues
83 ];
84
85 if (!property_exists($apiResponse, 'recipientlist_id')) {
86 $this->_logResponse->apiResponse($this->logID, $integId, ['type' => 'recipient', 'type_name' => 'add'], 'errors', $apiResponse, $entryDetails);
87 } else {
88 $this->_logResponse->apiResponse($this->logID, $integId, ['type' => 'recipient', 'type_name' => 'add'], 'success', $apiResponse, $entryDetails);
89 }
90 return $apiResponse;
91 }
92 }
93