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

79 lines 2.6 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\Getgist;
4
5 use BitCode\BitForm\Core\Util\ApiResponse as UtilApiResponse;
6 use BitCode\BitForm\Core\Util\HttpHelper;
7
8 class RecordApiHelper
9 {
10 private $_defaultHeader;
11
12 private $_logResponse;
13
14 private $logID;
15
16 private $entryId;
17
18 public function __construct($api_key, $integId, $logID, $entryID)
19 {
20 $this->_defaultHeader['Content-Type'] = 'application/json';
21 $this->_defaultHeader['Authorization'] = "Bearer $api_key";
22 $this->_logResponse = new UtilApiResponse();
23 $this->logID = $logID;
24 $this->entryId = $entryID;
25 }
26
27 public function createContact($data)
28 {
29 $data = \is_string($data) ? $data : wp_json_encode((object)$data);
30 $insertRecordEndpoint = 'https://api.getgist.com/contacts';
31 return HttpHelper::post($insertRecordEndpoint, $data, $this->_defaultHeader);
32 }
33
34 public function generateReqDataFromFieldMap($data, $fieldMap, $integrationDetails)
35 {
36 $dataFinal = [];
37
38 foreach ($fieldMap as $value) {
39 $triggerValue = $value->formField;
40 $actionValue = $value->getgistFormField;
41 if ('custom' === $triggerValue) {
42 $dataFinal[$actionValue] = $value->customValue;
43 } elseif (!is_null($data[$triggerValue])) {
44 $dataFinal[$actionValue] = $data[$triggerValue];
45 }
46 }
47
48 if (property_exists($integrationDetails, 'user_type') && property_exists($integrationDetails, 'userId') && 'User' === $integrationDetails->user_type) {
49 $dataFinal['user_id'] = $integrationDetails->userId;
50 }
51
52 if ($integrationDetails->actions) {
53 if (property_exists($integrationDetails->actions, 'tags') && $integrationDetails->actions->tags) {
54 $dataFinal['tags'] = explode(',', $integrationDetails->tags);
55 }
56 }
57 return $dataFinal;
58 }
59
60 public function execute($integId, $fieldValues, $fieldMap, $integrationDetails, $formId)
61 {
62 $finalData = $this->generateReqDataFromFieldMap($fieldValues, $fieldMap, $integrationDetails);
63 $apiResponse = $this->createContact($finalData);
64
65 $entryDetails = [
66 'form_id' => $formId,
67 'entry_id' => $this->entryId,
68 'fieldValues' => $fieldValues,
69 ];
70
71 if (!property_exists($apiResponse, 'contact') || property_exists($apiResponse, 'errors')) {
72 $this->_logResponse->apiResponse($this->logID, $integId, ['type' => 'contact', 'type_name' => 'contact_add'], 'errors', $apiResponse, $entryDetails);
73 } else {
74 $this->_logResponse->apiResponse($this->logID, $integId, ['type' => 'contact', 'type_name' => 'contact_add'], 'success', $apiResponse, $entryDetails);
75 }
76 return $apiResponse;
77 }
78 }
79