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

76 lines 2.0 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 public function __construct($integId, $logID, $entryID)
25 {
26 $this->_integrationID = $integId;
27 $this->_logID = $logID;
28 $this->_logResponse = new UtilApiResponse();
29 }
30
31 public function insertRecord($subscriber, $lists)
32 {
33 if (class_exists(\MailPoet\API\API::class)) {
34 $mailpoet_api = \MailPoet\API\API::MP('v1');
35 try {
36 $response = $mailpoet_api->addSubscriber($subscriber, $lists);
37 $response = [
38 'success'=> true,
39 'id' => $response['id']
40 ];
41 } catch (APIException $e) {
42 $response = [
43 'success' => false,
44 'code' => $e->getCode(),
45 'message' => $e->getMessage()
46 ];
47 }
48 return $response;
49 }
50 }
51
52 public function executeRecordApi($fieldValues, $fieldMap, $lists)
53 {
54 $fieldData = [];
55
56 foreach ($fieldMap as $fieldKey => $fieldPair) {
57 if (!empty($fieldPair->mailPoetField)) {
58 if ('custom' === $fieldPair->formField && isset($fieldPair->customValue)) {
59 $fieldData[$fieldPair->mailPoetField] = $fieldPair->customValue;
60 } else {
61 $fieldData[$fieldPair->mailPoetField] = $fieldValues[$fieldPair->formField];
62 }
63 }
64 }
65
66 $recordApiResponse = $this->insertRecord($fieldData, $lists);
67 if ($recordApiResponse['success']) {
68 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'insert'], 'success', $recordApiResponse);
69 } else {
70 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'insert'], 'error', $recordApiResponse);
71 }
72
73 return $recordApiResponse;
74 }
75 }
76