PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.9.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.9.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 2.10.2 All 137 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 2.9.1, at includes/Core/Integration/Getgist/RecordApiHelper.php

70 lines 2.3 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 public function __construct($api_key, $integId, $logID)
17 {
18 $this->_defaultHeader['Content-Type'] = 'application/json';
19 $this->_defaultHeader['Authorization'] = "Bearer $api_key";
20 $this->_logResponse = new UtilApiResponse();
21 $this->logID = $logID;
22 }
23
24 public function createContact($data)
25 {
26 $data = \is_string($data) ? $data : \json_encode((object)$data);
27 $insertRecordEndpoint = 'https://api.getgist.com/contacts';
28 return HttpHelper::post($insertRecordEndpoint, $data, $this->_defaultHeader);
29 }
30
31 public function generateReqDataFromFieldMap($data, $fieldMap, $integrationDetails)
32 {
33 $dataFinal = [];
34
35 foreach ($fieldMap as $value) {
36 $triggerValue = $value->formField;
37 $actionValue = $value->getgistFormField;
38 if ('custom' === $triggerValue) {
39 $dataFinal[$actionValue] = $value->customValue;
40 } elseif (!is_null($data[$triggerValue])) {
41 $dataFinal[$actionValue] = $data[$triggerValue];
42 }
43 }
44
45 if (property_exists($integrationDetails, 'user_type') && property_exists($integrationDetails, 'userId') && 'User' === $integrationDetails->user_type) {
46 $dataFinal['user_id'] = $integrationDetails->userId;
47 }
48
49 if ($integrationDetails->actions) {
50 if (property_exists($integrationDetails->actions, 'tags') && $integrationDetails->actions->tags) {
51 $dataFinal['tags'] = explode(',', $integrationDetails->tags);
52 }
53 }
54 return $dataFinal;
55 }
56
57 public function execute($integId, $fieldValues, $fieldMap, $integrationDetails)
58 {
59 $finalData = $this->generateReqDataFromFieldMap($fieldValues, $fieldMap, $integrationDetails);
60 $apiResponse = $this->createContact($finalData);
61
62 if (!property_exists($apiResponse, 'contact') || property_exists($apiResponse, 'errors')) {
63 $this->_logResponse->apiResponse($this->logID, $integId, ['type' => 'contact', 'type_name' => 'contact_add'], 'errors', $apiResponse);
64 } else {
65 $this->_logResponse->apiResponse($this->logID, $integId, ['type' => 'contact', 'type_name' => 'contact_add'], 'success', $apiResponse);
66 }
67 return $apiResponse;
68 }
69 }
70