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

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