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 / Rapidmail / 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/Rapidmail/RecordApiHelper.php

84 lines 2.7 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 public function __construct($integrationDetails, $username, $password, $logID)
23 {
24 $this->integrationDetails = $integrationDetails;
25 $this->_defaultHeader = [
26 'Authorization' => 'Basic ' . base64_encode("$username:$password"),
27 'Accept' => '*/*',
28 'Content-Type' => 'application/json',
29 'verify' => false
30 ];
31 $this->_logResponse = new UtilApiResponse();
32 $this->logID = $logID;
33 }
34
35 public function insertRecipientRecord($data)
36 {
37 $insertRecordEndpoint = self::$apiBaseUri . '/recipients';
38 $data = \is_string($data) ? $data : wp_json_encode((object)$data);
39 $response = HttpHelper::post($insertRecordEndpoint, $data, $this->_defaultHeader);
40 return $response;
41 }
42
43 public function generateReqDataFromFieldMap($data, $fieldMap)
44 {
45 $dataFinal = [];
46
47 foreach ($fieldMap as $value) {
48 $triggerValue = $value->formField;
49 $actionValue = $value->rapidmailFormField;
50 if ('custom' === $triggerValue) {
51 $dataFinal[$actionValue] = $value->customValue;
52 } elseif (!is_null($data[$triggerValue])) {
53 if (strtotime($data[$triggerValue])) {
54 $dataFinal[$actionValue] = date('Y-m-d', strtotime($data[$triggerValue]));
55 } else {
56 $dataFinal[$actionValue] = $data[$triggerValue];
57 }
58 }
59 }
60
61 $selectedRecipientList = $this->integrationDetails->recipient_id;
62 if ($this->integrationDetails->actions) {
63 if (property_exists($this->integrationDetails->actions, 'send_activationmail') && $this->integrationDetails->actions->send_activationmail) {
64 $dataFinal['send_activationmail'] = 'yes';
65 }
66 }
67 $dataFinal['recipientlist_id'] = (int)$selectedRecipientList;
68 return $dataFinal;
69 }
70
71 public function executeRecordApi($integId, $defaultConf, $recipientLists, $fieldValues, $fieldMap, $actions)
72 {
73 $finalData = $this->generateReqDataFromFieldMap($fieldValues, $fieldMap);
74 $apiResponse = $this->insertRecipientRecord($finalData);
75
76 if (!property_exists($apiResponse, 'recipientlist_id')) {
77 $this->_logResponse->apiResponse($this->logID, $integId, ['type' => 'recipient', 'type_name' => 'add'], 'errors', $apiResponse);
78 } else {
79 $this->_logResponse->apiResponse($this->logID, $integId, ['type' => 'recipient', 'type_name' => 'add'], 'success', $apiResponse);
80 }
81 return $apiResponse;
82 }
83 }
84