PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / -3.0.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v-3.0.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 / MailPoet / RecordApiHelper.php

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

86 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * ZohoRecruit Record Api
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\MailPoet;
9
10 use BitCode\BitForm\Core\Util\ApiResponse as UtilApiResponse;
11 use MailPoet\API\MP\v1\APIException;
12
13 /**
14 * Provide functionality for Record insert,upsert
15 */
16 class RecordApiHelper
17 {
18 private $_integrationID;
19
20 private $_logID;
21
22 private $_logResponse;
23
24 private $_entryID;
25
26 public function __construct($integId, $logID, $entryID)
27 {
28 $this->_integrationID = $integId;
29 $this->_logID = $logID;
30 $this->_logResponse = new UtilApiResponse();
31 $this->_entryID = $entryID;
32 }
33
34 public function insertRecord($subscriber, $lists)
35 {
36 if (class_exists(\MailPoet\API\API::class)) {
37 $mailpoet_api = \MailPoet\API\API::MP('v1');
38 try {
39 $response = $mailpoet_api->addSubscriber($subscriber, $lists);
40 $response = [
41 'success'=> true,
42 'id' => $response['id']
43 ];
44 } catch (APIException $e) {
45 $response = [
46 'success' => false,
47 'code' => $e->getCode(),
48 'message' => $e->getMessage()
49 ];
50 }
51 return $response;
52 }
53 }
54
55 public function executeRecordApi($fieldValues, $fieldMap, $lists, $formId)
56 {
57 $fieldData = [];
58
59 foreach ($fieldMap as $fieldKey => $fieldPair) {
60 if (!empty($fieldPair->mailPoetField)) {
61 if ('custom' === $fieldPair->formField && isset($fieldPair->customValue)) {
62 $fieldData[$fieldPair->mailPoetField] = $fieldPair->customValue;
63 } else {
64 $fieldData[$fieldPair->mailPoetField] = $fieldValues[$fieldPair->formField];
65 }
66 }
67 }
68
69 $recordApiResponse = $this->insertRecord($fieldData, $lists);
70
71 $entryDetails = [
72 'formId' => $formId,
73 'entryId' => $this->_entryID,
74 'fieldValues' => $fieldValues
75 ];
76
77 if ($recordApiResponse['success']) {
78 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'insert'], 'success', $recordApiResponse, $entryDetails);
79 } else {
80 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'insert'], 'error', $recordApiResponse, $entryDetails);
81 }
82
83 return $recordApiResponse;
84 }
85 }
86