@@ -25,10 +25,14 @@ class RecordApiHelper
2525
2626 private $ _actions ;
2727
28+ private $ _isMailerLiteV2 ;
29+
2830 public function __construct ($ auth_token , $ integrationDetails , $ integId , $ actions , $ version )
2931 {
3032 $ this ->_integrationDetails = $ integrationDetails ;
3133 $ this ->_integrationID = $ integId ;
34+ $ this ->_isMailerLiteV2 = (bool ) ('v2 ' === $ version );
35+
3236 if ('v2 ' === $ version ) {
3337 $ this ->_baseUrl = 'https://connect.mailerlite.com/api/ ' ;
3438 $ this ->_defaultHeader = [
@@ -94,10 +98,9 @@ public function addSubscriber($auth_token, $groupIds, $type, $finalData)
9498
9599 $ email = $ finalData ['email ' ];
96100 $ splitGroupIds = !empty ($ groupIds ) ? explode (', ' , $ groupIds ) : [];
97- $ isMailerLiteV2 = $ this ->_baseUrl === 'https://connect.mailerlite.com/api/ ' ;
98101 $ apiEndpoint = $ this ->_baseUrl . 'subscribers ' ;
99102
100- $ requestParams = self ::prepareRequestParams ($ finalData , $ type , $ isMailerLiteV2 );
103+ $ requestParams = self ::prepareRequestParams ($ finalData , $ type , $ this -> _isMailerLiteV2 );
101104
102105 $ isExist = $ this ->existSubscriber ($ auth_token , $ email );
103106 $ response = null ;
@@ -110,10 +113,10 @@ public function addSubscriber($auth_token, $groupIds, $type, $finalData)
110113 ];
111114 }
112115
113- self ::handleDoubleOptIn ($ this , $ auth_token , $ requestParams , $ isMailerLiteV2 );
116+ self ::handleDoubleOptIn ($ this , $ auth_token , $ requestParams , $ this -> _isMailerLiteV2 );
114117
115118 if (!empty ($ splitGroupIds )) {
116- return self ::sendToGroups ($ this , $ splitGroupIds , $ requestParams , $ isMailerLiteV2 );
119+ return self ::sendToGroups ($ this , $ splitGroupIds , $ requestParams , $ this -> _isMailerLiteV2 );
117120 }
118121
119122 if ($ isExist ) {
@@ -128,6 +131,14 @@ public function addSubscriber($auth_token, $groupIds, $type, $finalData)
128131
129132 public function deleteSubscriber ($ auth_token , $ finalData )
130133 {
134+ if (!$ this ->_isMailerLiteV2 ) {
135+ return [
136+ 'success ' => false ,
137+ 'message ' => __ ('This action is not supported for Classic accounts. ' , 'bit-integrations ' ),
138+ 'code ' => 400
139+ ];
140+ }
141+
131142 if (empty ($ finalData ['email ' ])) {
132143 return [
133144 'success ' => false ,
@@ -136,7 +147,6 @@ public function deleteSubscriber($auth_token, $finalData)
136147 ];
137148 }
138149
139- // $isMailerLiteV2 = $this->_baseUrl === 'https://connect.mailerlite.com/api/';
140150 $ subscriberId = $ this ->existSubscriber ($ auth_token , $ finalData ['email ' ]);
141151
142152 if (empty ($ subscriberId )) {
0 commit comments