66
77namespace BitCode \FI \Actions \Bento ;
88
9- use BitCode \FI \Log \LogHandler ;
109use BitCode \FI \Core \Util \Common ;
1110use BitCode \FI \Core \Util \HttpHelper ;
11+ use BitCode \FI \Log \LogHandler ;
1212
1313/**
1414 * Provide functionality for Record insert, upsert
@@ -19,8 +19,6 @@ class RecordApiHelper
1919
2020 private $ integrationId ;
2121
22- private $ apiUrl ;
23-
2422 private $ defaultHeader ;
2523
2624 private $ siteUUID ;
@@ -29,10 +27,6 @@ class RecordApiHelper
2927
3028 private $ secretKey ;
3129
32- private $ type ;
33-
34- private $ typeName ;
35-
3630 public function __construct (
3731 $ integrationDetails ,
3832 $ integId ,
@@ -45,28 +39,19 @@ public function __construct(
4539 $ this ->siteUUID = $ siteUUID ;
4640 $ this ->publishableKey = $ publishableKey ;
4741 $ this ->secretKey = $ secretKey ;
48- $ this ->apiUrl = 'https://app.bentonow.com/api/v1/fetch/ ' ;
49-
50- $ this ->defaultHeader = [
51- 'Authorization ' => 'Basic ' . base64_encode ("{$ publishableKey }: {$ secretKey }" ),
52- 'Accept ' => 'application/json ' ,
53- 'Content-Type ' => 'application/json '
54- ];
42+ $ this ->defaultHeader = BentoHelper::setHeaders ($ publishableKey , $ secretKey );
5543 }
5644
5745 public function addPeople ($ finalData )
5846 {
59- $ this ->type = 'User ' ;
60- $ this ->typeName = 'Create User ' ;
61-
6247 if (empty ($ finalData ['email ' ])) {
6348 return ['success ' => false , 'message ' => __ ('Required field Email is empty ' , 'bit-integrations ' ), 'code ' => 400 ];
6449 }
6550
6651 $ email = $ finalData ['email ' ];
6752 unset($ finalData ['email ' ]);
6853
69- $ apiEndpoint = "{ $ this -> apiUrl } subscribers?site_uuid= { $ this ->siteUUID }" ;
54+ $ apiEndpoint = BentoHelper:: setEndpoint ( ' subscribers ' , $ this ->siteUUID ) ;
7055 $ response = HttpHelper::post ($ apiEndpoint , wp_json_encode (['email ' => $ email ]), $ this ->defaultHeader );
7156
7257 if (!BentoHelper::checkResponseCode ()) {
@@ -89,9 +74,6 @@ public function addPeople($finalData)
8974
9075 public function addEvent ($ finalData )
9176 {
92- $ this ->type = 'User ' ;
93- $ this ->typeName = 'Create User ' ;
94-
9577 if (empty ($ finalData ['email ' ]) || empty ($ finalData ['type ' ])) {
9678 return ['success ' => false , 'message ' => __ ('Required field Email is empty ' , 'bit-integrations ' ), 'code ' => 400 ];
9779 }
@@ -122,11 +104,15 @@ public function execute($fieldValues, $fieldMap, $action)
122104
123105 switch ($ action ) {
124106 case 'add_people ' :
107+ $ type = 'People ' ;
108+ $ typeName = 'Add People ' ;
125109 $ apiResponse = $ this ->addPeople ($ finalData );
126110 $ logStatus = (!BentoHelper::checkResponseCode () || empty ($ apiResponse ->data )) ? 'error ' : 'success ' ;
127111
128112 break ;
129113 case 'add_event ' :
114+ $ type = 'Event ' ;
115+ $ typeName = 'Add Event ' ;
130116 $ apiResponse = $ this ->addEvent ($ finalData );
131117 $ logStatus = (!BentoHelper::checkResponseCode () || empty ($ apiResponse ->results )) ? 'error ' : 'success ' ;
132118
@@ -136,7 +122,7 @@ public function execute($fieldValues, $fieldMap, $action)
136122 break ;
137123 }
138124
139- LogHandler::save ($ this ->integrationId , wp_json_encode (['type ' => $ this -> type , 'type_name ' => $ this -> typeName ]), $ logStatus , wp_json_encode ($ apiResponse ));
125+ LogHandler::save ($ this ->integrationId , wp_json_encode (['type ' => $ type , 'type_name ' => $ typeName ]), $ logStatus , wp_json_encode ($ apiResponse ));
140126
141127 return $ apiResponse ;
142128 }
0 commit comments