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

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

83 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Encharge Record Api
5 */
6
7 namespace BitCode\BitForm\Core\Integration\Encharge;
8
9 use BitCode\BitForm\Core\Util\ApiResponse as UtilApiResponse;
10 use BitCode\BitForm\Core\Util\HttpHelper;
11
12 /**
13 * Provide functionality for Record insert
14 */
15 class RecordApiHelper
16 {
17 private $_defaultHeader;
18 private $_integrationID;
19 private $_logID;
20 private $_logResponse;
21
22 private $entryId;
23
24 public function __construct($api_key, $integId, $logID, $entryID)
25 {
26 // wp_send_json_success($tokenDetails);
27 $this->_defaultHeader['Content-Type'] = 'application/json';
28 $this->_defaultHeader['X-Encharge-Token'] = $api_key;
29 $this->_integrationID = $integId;
30 $this->_logID = $logID;
31 $this->_logResponse = new UtilApiResponse();
32 $this->entryId = $entryID;
33 }
34
35 /**
36 * serd data to api
37 * @return json response
38 */
39 public function insertRecord($data)
40 {
41 $insertRecordEndpoint = 'https://api.encharge.io/v1/people';
42 return HttpHelper::post($insertRecordEndpoint, $data, $this->_defaultHeader);
43 }
44
45 public function executeRecordApi($fieldValues, $fieldMap, $tags, $formId)
46 {
47 $fieldData = [];
48
49 foreach ($fieldMap as $fieldKey => $fieldPair) {
50 if (!empty($fieldPair->enChargeFields)) {
51 if ('custom' === $fieldPair->formField && isset($fieldPair->customValue)) {
52 $fieldData[$fieldPair->enChargeFields] = $fieldPair->customValue;
53 } else {
54 $fieldData[$fieldPair->enChargeFields] = $fieldValues[$fieldPair->formField];
55 }
56 }
57 }
58 if (null !== $tags) {
59 $fieldData['tags'] = $tags;
60 }
61 // wp_send_json_success($fieldData);
62 $recordApiResponse = $this->insertRecord(wp_json_encode($fieldData));
63 $type = 'insert';
64
65 $entryDetails = [
66 'form_id' => $formId,
67 'entry_id' => $this->entryId,
68 'fieldValues' => $fieldValues,
69 ];
70
71 if ($recordApiResponse && isset($recordApiResponse->user)) {
72 $recordApiResponse = [
73 'status' => 'success',
74 'email' => $recordApiResponse->user->email
75 ];
76 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => $type], 'success', $recordApiResponse, $entryDetails);
77 } else {
78 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => $type], 'error', $recordApiResponse, $entryDetails);
79 }
80 return $recordApiResponse;
81 }
82 }
83