Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 277 |
|
0.00% |
0 / 16 |
CRAP | |
0.00% |
0 / 1 |
| InstancyService | |
0.00% |
0 / 277 |
|
0.00% |
0 / 16 |
6006 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| createUser | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
156 | |||
| updateUser | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
182 | |||
| userFieldData | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| paymentTypes | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| updateMemebrship | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
90 | |||
| renewMemebrship | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
90 | |||
| membershipDetails | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| userMembershipDetails | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| GenerateSessionID | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
6 | |||
| authenticateUser | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
42 | |||
| createInstancyUserViaHttp | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
2 | |||
| validateUser | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
110 | |||
| createUserInstancy | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 | |||
| callInstacncyApi | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
12 | |||
| makeUrl | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Services; |
| 4 | |
| 5 | use Illuminate\Http\Request; |
| 6 | use App\Http\Models\Auth\User; |
| 7 | use Illuminate\Support\Facades\Http; |
| 8 | |
| 9 | class InstancyService |
| 10 | { |
| 11 | private $astr_key; |
| 12 | |
| 13 | private $parameters; |
| 14 | |
| 15 | private $url; |
| 16 | |
| 17 | private $action; |
| 18 | |
| 19 | private $site_group_id; |
| 20 | |
| 21 | private $isProd; |
| 22 | |
| 23 | public function __construct() |
| 24 | { |
| 25 | $this->astr_key = env('ASTRKEY'); |
| 26 | $this->url = env('INSTANCYURL'); |
| 27 | $this->site_group_id = env('SITE_GROUP_ID'); |
| 28 | $this->parameters = []; |
| 29 | $this->action = ''; |
| 30 | $this->isProd = env('APP_ENV') === 'production'; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Function to create a instancy user |
| 35 | */ |
| 36 | public function createUser(object $request) |
| 37 | { |
| 38 | $this->action = 'CreateUser'; |
| 39 | $parametersArray = [ |
| 40 | 'Request' => [ |
| 41 | '@SiteID' => '388', |
| 42 | 'UserDetails' => [ |
| 43 | '#GroupID' => $this->site_group_id, |
| 44 | '#First_Name' => (isset($request->First_Name)) ? $request->First_Name : '', |
| 45 | '#Gender' => (isset($request->Gender)) ? $request->Gender : '', |
| 46 | '#Last_Name' => (isset($request->Last_Name)) ? $request->Last_Name : '', |
| 47 | '#User_name' => (isset($request->User_name)) ? $request->User_name : '', |
| 48 | '#Email' => (isset($request->Email)) ? $request->Email : '', |
| 49 | '#Password' => (isset($request->Password)) ? $request->Password : '', |
| 50 | '#Mobile_Number' => (isset($request->Mobile_Number)) ? $request->Mobile_Number : '', |
| 51 | '#Job_title' => (isset($request->Job_title)) ? $request->Job_title : '', |
| 52 | '#Company_Name' => (isset($request->Company_Name)) ? $request->Company_Name : '', |
| 53 | '#MembershipDurationID' => (isset($request->MembershipDurationID)) ? $request->MembershipDurationID : 30, |
| 54 | '#PaymentType' => (isset($request->PaymentType)) ? $request->PaymentType : '', |
| 55 | ], |
| 56 | ], |
| 57 | ]; |
| 58 | |
| 59 | $xml = new ArrayToXML(); |
| 60 | $this->parameters = $xml->buildXML($parametersArray); |
| 61 | |
| 62 | return $this->callInstacncyApi(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Function to update a instancy user |
| 67 | */ |
| 68 | public function updateUser(Request $request) |
| 69 | { |
| 70 | $this->action = 'UpdateUser'; |
| 71 | $parametersArray = [ |
| 72 | 'Request' => [ |
| 73 | '@SiteID' => $this->site_group_id, |
| 74 | 'UserDetails' => [ |
| 75 | '#UserID' => $request->UserID, // 3043 for manojpatel |
| 76 | '#GroupID' => $this->site_group_id, |
| 77 | '#First_Name' => (isset($request->First_Name)) ? $request->First_Name : '', |
| 78 | '#Gender' => (isset($request->Gender)) ? $request->Gender : '', |
| 79 | '#Last_Name' => (isset($request->Last_Name)) ? $request->Last_Name : '', |
| 80 | '#User_name' => (isset($request->User_name)) ? $request->User_name : '', |
| 81 | '#Email' => (isset($request->Email)) ? $request->Email : '', |
| 82 | '#Password' => (isset($request->Password)) ? $request->Password : '', |
| 83 | '#Mobile_Number' => (isset($request->Mobile_Number)) ? $request->Mobile_Number : '', |
| 84 | '#Job_title' => (isset($request->Job_title)) ? $request->Job_title : '', |
| 85 | '#Company_Name' => (isset($request->Company_Name)) ? $request->Company_Name : '', |
| 86 | '#MembershipDurationID' => (isset($request->MembershipDurationID)) ? $request->MembershipDurationID : 30, |
| 87 | '#PaymentType' => (isset($request->PaymentType)) ? $request->PaymentType : '', |
| 88 | '#Status' => (isset($request->Status)) ? $request->Status : '', |
| 89 | ], |
| 90 | ], |
| 91 | ]; |
| 92 | |
| 93 | $xml = new ArrayToXML(); |
| 94 | $this->parameters = $xml->buildXML($parametersArray); |
| 95 | |
| 96 | return $this->callInstacncyApi(); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * function to get the user fields details |
| 101 | */ |
| 102 | public function userFieldData(Request $request) |
| 103 | { |
| 104 | $this->action = 'UserFieldsData'; |
| 105 | $parametersArray = [ |
| 106 | 'Request' => [ |
| 107 | '@SiteID' => $this->site_group_id, |
| 108 | |
| 109 | ], |
| 110 | 'UserFieldsData' => [], |
| 111 | ]; |
| 112 | |
| 113 | $xml = new ArrayToXML(); |
| 114 | $this->parameters = $xml->buildXML($parametersArray); |
| 115 | |
| 116 | return $this->callInstacncyApi(); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * function to get the payment types |
| 121 | */ |
| 122 | public function paymentTypes(Request $request) |
| 123 | { |
| 124 | $this->action = 'PaymentTypes'; |
| 125 | $parametersArray = [ |
| 126 | 'Request' => [ |
| 127 | '@SiteID' => $this->site_group_id, |
| 128 | ], |
| 129 | 'PaymentTypes' => [], |
| 130 | ]; |
| 131 | |
| 132 | $xml = new ArrayToXML(); |
| 133 | $this->parameters = $xml->buildXML($parametersArray); |
| 134 | |
| 135 | return $this->callInstacncyApi(); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Function to update a instancy user |
| 140 | */ |
| 141 | public function updateMemebrship(Request $request) |
| 142 | { |
| 143 | $this->action = 'UpdateMemebrship'; |
| 144 | $parametersArray = [ |
| 145 | 'Request' => [ |
| 146 | '@SiteID' => $this->site_group_id, |
| 147 | 'UpdateMemebrship' => [ |
| 148 | '#MembershipID' => $request->MembershipID, // 3043 for manojpatel |
| 149 | '#DurationName' => $request->DurationName, |
| 150 | '#UserID' => (isset($request->UserID)) ? $request->UserID : '', |
| 151 | '#ExpiryDate' => (isset($request->ExpiryDate)) ? $request->ExpiryDate : '', |
| 152 | '#MembershipDurationID' => (isset($request->MembershipDurationID)) ? $request->MembershipDurationID : '', |
| 153 | '#RecurringProfileID' => (isset($request->RecurringProfileID)) ? $request->RecurringProfileID : '', |
| 154 | '#Paymentmode' => (isset($request->Paymentmode)) ? $request->Paymentmode : '', |
| 155 | '#Notes' => (isset($request->Notes)) ? $request->Notes : '', |
| 156 | '#StartDate' => (isset($request->StartDate)) ? $request->StartDate : '', |
| 157 | '#Amount' => (isset($request->Amount)) ? $request->Amount : '', |
| 158 | ], |
| 159 | ], |
| 160 | ]; |
| 161 | |
| 162 | $xml = new ArrayToXML(); |
| 163 | $this->parameters = $xml->buildXML($parametersArray); |
| 164 | |
| 165 | return $this->callInstacncyApi(); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Function to renew a instancy membership for the user |
| 170 | */ |
| 171 | public function renewMemebrship(Request $request) |
| 172 | { |
| 173 | $this->action = 'RenewMemebrship'; |
| 174 | $parametersArray = [ |
| 175 | 'Request' => [ |
| 176 | '@SiteID' => $this->site_group_id, |
| 177 | 'RenewMemebrship' => [ |
| 178 | '#MembershipID' => $request->MembershipID, // 3043 for manojpatel |
| 179 | '#DurationName' => $request->DurationName, |
| 180 | '#UserID' => (isset($request->UserID)) ? $request->UserID : '', |
| 181 | '#ExpiryDate' => (isset($request->ExpiryDate)) ? $request->ExpiryDate : '', |
| 182 | '#MembershipDurationID' => (isset($request->MembershipDurationID)) ? $request->MembershipDurationID : '', |
| 183 | '#RecurringProfileID' => (isset($request->RecurringProfileID)) ? $request->RecurringProfileID : '', |
| 184 | '#Paymentmode' => (isset($request->Paymentmode)) ? $request->Paymentmode : '', |
| 185 | '#Notes' => (isset($request->Notes)) ? $request->Notes : '', |
| 186 | '#StartDate' => (isset($request->StartDate)) ? $request->StartDate : '', |
| 187 | '#Amount' => (isset($request->Amount)) ? $request->Amount : '', |
| 188 | ], |
| 189 | ], |
| 190 | ]; |
| 191 | |
| 192 | $xml = new ArrayToXML(); |
| 193 | $this->parameters = $xml->buildXML($parametersArray); |
| 194 | |
| 195 | return $this->callInstacncyApi(); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * function to get the membership details |
| 200 | */ |
| 201 | public function membershipDetails(Request $request) |
| 202 | { |
| 203 | $this->action = 'MembershipDetails'; |
| 204 | $parametersArray = [ |
| 205 | 'Request' => [ |
| 206 | '@SiteID' => $this->site_group_id, |
| 207 | ], |
| 208 | 'MembershipDetails' => [], |
| 209 | ]; |
| 210 | |
| 211 | $xml = new ArrayToXML(); |
| 212 | $this->parameters = $xml->buildXML($parametersArray); |
| 213 | |
| 214 | return $this->callInstacncyApi(); |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * function to get the user membership details |
| 219 | */ |
| 220 | public function userMembershipDetails(Request $request) |
| 221 | { |
| 222 | $this->action = 'UserMembershipDetails'; |
| 223 | $parametersArray = [ |
| 224 | 'Request' => [ |
| 225 | '@SiteID' => $this->site_group_id, |
| 226 | ], |
| 227 | 'UserMembershipDetails' => [ |
| 228 | 'UserID' => $request->UserID, |
| 229 | ], |
| 230 | ]; |
| 231 | |
| 232 | $xml = new ArrayToXML(); |
| 233 | $this->parameters = $xml->buildXML($parametersArray); |
| 234 | |
| 235 | return $this->callInstacncyApi(); |
| 236 | } |
| 237 | |
| 238 | public function GenerateSessionID($email) |
| 239 | { |
| 240 | $astrKey = $this->isProd ? 'B6F95CD1-600A-421F-9528-39DF7130ABE0' : '7CD8EDD1-3495-4232-9C63-0238B0FA0C8C'; |
| 241 | |
| 242 | $curl = curl_init(); |
| 243 | curl_setopt_array($curl, [ |
| 244 | CURLOPT_URL => 'https://ondemand-master-admin.vengreso.com/instancyservice.asmx/AuthenticateUser', |
| 245 | CURLOPT_RETURNTRANSFER => true, |
| 246 | CURLOPT_ENCODING => '', |
| 247 | CURLOPT_MAXREDIRS => 10, |
| 248 | CURLOPT_TIMEOUT => 0, |
| 249 | CURLOPT_FOLLOWLOCATION => true, |
| 250 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 251 | CURLOPT_CUSTOMREQUEST => 'POST', |
| 252 | CURLOPT_POSTFIELDS => 'astrKey='.$astrKey.'&astrXML=%3C%3Fxml%20version%3D\'1.0\'%20encoding%3D\'iso-8859-1\'%3F%3E%3CInstancyWrapper%3E%3CRequest%20SiteID%3D\'374\'%3E%3CUserDetails%3E%20%3CUserID%3E%3C!%5BCDATA%5B-1%5D%5D%3E%3C%2FUserID%3E%3CEmail%3E%3C!%5BCDATA%5B'.$email.'%5D%5D%3E%3C%2FEmail%3E%3CPassword%3E%3C!%5BCDATA%5B17%245I%24jaFq%40%5D%5D%3E%3C%2FPassword%3E%3C%2FUserDetails%3E%3C%2FRequest%3E%3C%2FInstancyWrapper%3E', CURLOPT_HTTPHEADER => [ |
| 253 | 'Content-Type: application/x-www-form-urlencoded', |
| 254 | 'Cookie: ASP.NET_SessionId=fuhbkztcn41q4vteeipt5jmr', |
| 255 | ], |
| 256 | ]); |
| 257 | $response = curl_exec($curl); |
| 258 | curl_close($curl); |
| 259 | |
| 260 | return $response; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Function to renew a instancy membership for the user |
| 265 | */ |
| 266 | public function authenticateUser(Request $request) |
| 267 | { |
| 268 | $email = urlencode($request['Email']); |
| 269 | $response = $this->GenerateSessionID($email); |
| 270 | |
| 271 | if (str_contains($response, 'Invalid User ID') || str_contains($response, 'Invalid Client ID') || str_contains($response, 'There is no row') |
| 272 | || str_contains($response, 'Error') |
| 273 | ) { |
| 274 | $user = User::where('email', $request['Email'])->first(); |
| 275 | $First_Name = $user['first_name']; |
| 276 | $Last_Name = $user['last_name']; |
| 277 | |
| 278 | $curl = curl_init(); |
| 279 | curl_setopt_array($curl, [ |
| 280 | CURLOPT_URL => 'https://ondemand-admin.vengreso.com/InstancyService.asmx/CreateUser', |
| 281 | CURLOPT_RETURNTRANSFER => true, |
| 282 | CURLOPT_ENCODING => '', |
| 283 | CURLOPT_MAXREDIRS => 10, |
| 284 | CURLOPT_TIMEOUT => 0, |
| 285 | CURLOPT_FOLLOWLOCATION => true, |
| 286 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 287 | CURLOPT_CUSTOMREQUEST => 'POST', |
| 288 | CURLOPT_POSTFIELDS => 'astrKey=22A9838A-2196-47ED-8126-4321B7A07EF1&astrXML=%3C%3Fxml%20version%3D\'1.0\'%20encoding%3D\'iso-8859-1\'%3F%3E%3CInstancyWrapper%3E%3CRequest%20SiteID%3D\'388\'%3E%3CUserDetails%3E%3CGroupID%3E%3C!%5BCDATA%5B388%5D%5D%3E%3C%2FGroupID%3E%3CFirst_Name%3E%3C!%5BCDATA%5B'.$First_Name.'%5D%5D%3E%3C%2FFirst_Name%3E%3CGender%3E%3C!%5BCDATA%5B1%5D%5D%3E%3C%2FGender%3E%3CLast_Name%3E%3C!%5BCDATA%5B'.$Last_Name.'%5D%5D%3E%3C%2FLast_Name%3E%3CUser_name%3E%3C!%5BCDATA%5B'.$email.'%5D%5D%3E%3C%2FUser_name%3E%3CEmail%3E%3C!%5BCDATA%5B'.$email.'%5D%5D%3E%3C%2FEmail%3E%3CPassword%3E%3C!%5BCDATA%5B17$5I$jaFq@%5D%5D%3E%3C%2FPassword%3E%3CMobile_Number%3E%3C!%5BCDATA%5B12344433%5D%5D%3E%3C%2FMobile_Number%3E%3CJob_title%3EManager%3C%2FJob_title%3E%3CCompany_Name%3Eve%3C%2FCompany_Name%3E%3CMembershipDurationID%3E%3C!%5BCDATA%5B30%5D%5D%3E%3C%2FMembershipDurationID%3E%3CPaymentType%3E%3C!%5BCDATA%5BCredit%20Card%5D%5D%3E%3C%2FPaymentType%3E%20%0A%3C%2FUserDetails%3E%3C%2FRequest%3E%3C%2FInstancyWrapper%3E', |
| 289 | CURLOPT_HTTPHEADER => [ |
| 290 | 'Content-Type: application/x-www-form-urlencoded', |
| 291 | 'Cookie: ASP.NET_SessionId=z1kdzfdinrjc01n3poj2ast3', |
| 292 | ], |
| 293 | ]); |
| 294 | |
| 295 | $responseCreate = curl_exec($curl); |
| 296 | curl_close($curl); |
| 297 | |
| 298 | if (str_contains($responseCreate, 'Success')) { |
| 299 | $response = $this->GenerateSessionID($email); |
| 300 | return $response; |
| 301 | } |
| 302 | return $responseCreate; |
| 303 | } else { |
| 304 | return $response; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Create Instancy User |
| 310 | * |
| 311 | * |
| 312 | * @return mixed |
| 313 | */ |
| 314 | public function createInstancyUserViaHttp(string $email) |
| 315 | { |
| 316 | $user = User::where('email', $email)->first(); |
| 317 | $First_Name = $user['first_name']; |
| 318 | $Last_Name = $user['last_name']; |
| 319 | |
| 320 | $curl = curl_init(); |
| 321 | |
| 322 | curl_setopt_array($curl, [ |
| 323 | CURLOPT_URL => 'https://ondemand-admin.vengreso.com/InstancyService.asmx/CreateUser', |
| 324 | CURLOPT_RETURNTRANSFER => true, |
| 325 | CURLOPT_ENCODING => '', |
| 326 | CURLOPT_MAXREDIRS => 10, |
| 327 | CURLOPT_TIMEOUT => 0, |
| 328 | CURLOPT_FOLLOWLOCATION => true, |
| 329 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 330 | CURLOPT_CUSTOMREQUEST => 'POST', |
| 331 | CURLOPT_POSTFIELDS => 'astrKey=22A9838A-2196-47ED-8126-4321B7A07EF1&astrXML=%3C%3Fxml%20version%3D\'1.0\'%20encoding%3D\'iso-8859-1\'%3F%3E%3CInstancyWrapper%3E%3CRequest%20SiteID%3D\'388\'%3E%3CUserDetails%3E%3CGroupID%3E%3C!%5BCDATA%5B388%5D%5D%3E%3C%2FGroupID%3E%3CFirst_Name%3E%3C!%5BCDATA%5B'.$First_Name.'%5D%5D%3E%3C%2FFirst_Name%3E%3CGender%3E%3C!%5BCDATA%5B1%5D%5D%3E%3C%2FGender%3E%3CLast_Name%3E%3C!%5BCDATA%5B'.$Last_Name.'%5D%5D%3E%3C%2FLast_Name%3E%3CUser_name%3E%3C!%5BCDATA%5B'.$email.'%5D%5D%3E%3C%2FUser_name%3E%3CEmail%3E%3C!%5BCDATA%5B'.$email.'%5D%5D%3E%3C%2FEmail%3E%3CPassword%3E%3C!%5BCDATA%5B17$5I$jaFq@%5D%5D%3E%3C%2FPassword%3E%3CMobile_Number%3E%3C!%5BCDATA%5B12344433%5D%5D%3E%3C%2FMobile_Number%3E%3CJob_title%3EManager%3C%2FJob_title%3E%3CCompany_Name%3Eve%3C%2FCompany_Name%3E%3CMembershipDurationID%3E%3C!%5BCDATA%5B30%5D%5D%3E%3C%2FMembershipDurationID%3E%3CPaymentType%3E%3C!%5BCDATA%5BCredit%20Card%5D%5D%3E%3C%2FPaymentType%3E%20%0A%3C%2FUserDetails%3E%3C%2FRequest%3E%3C%2FInstancyWrapper%3E', |
| 332 | CURLOPT_HTTPHEADER => [ |
| 333 | 'Content-Type: application/x-www-form-urlencoded', |
| 334 | 'Cookie: ASP.NET_SessionId=z1kdzfdinrjc01n3poj2ast3', |
| 335 | ], |
| 336 | ]); |
| 337 | |
| 338 | $response = curl_exec($curl); |
| 339 | curl_close($curl); |
| 340 | |
| 341 | return $response; |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Determine if the user has been created on Instancy |
| 346 | */ |
| 347 | public function validateUser(Request $request): bool |
| 348 | { |
| 349 | $email = urlencode($request['Email']); |
| 350 | $response = $this->GenerateSessionID($email); |
| 351 | |
| 352 | if (str_contains($response, 'Invalid User ID') || str_contains($response, 'Invalid Client ID') || str_contains($response, 'There is no row') |
| 353 | || str_contains($response, 'Error') |
| 354 | ) { |
| 355 | return false; |
| 356 | } |
| 357 | |
| 358 | $astrKey = $this->isProd ? 'B6F95CD1-600A-421F-9528-39DF7130ABE0' : '7CD8EDD1-3495-4232-9C63-0238B0FA0C8C'; |
| 359 | |
| 360 | $curl = curl_init(); |
| 361 | curl_setopt_array($curl, [ |
| 362 | CURLOPT_URL => 'https://ondemand-master-admin.vengreso.com/instancyservice.asmx/GetUserInfoByEmailForAllSites', |
| 363 | CURLOPT_RETURNTRANSFER => true, |
| 364 | CURLOPT_ENCODING => '', |
| 365 | CURLOPT_MAXREDIRS => 10, |
| 366 | CURLOPT_TIMEOUT => 0, |
| 367 | CURLOPT_FOLLOWLOCATION => true, |
| 368 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 369 | CURLOPT_CUSTOMREQUEST => 'POST', |
| 370 | CURLOPT_POSTFIELDS => 'astrKey='.$astrKey.'&astrXML=%3C%3Fxml%20version%3D\'1.0\'%20encoding%3D\'iso-8859-1\'%3F%3E%3CInstancyWrapper%3E%3CRequest%20SiteID%3D\'374\'%3E%3CUserDetails%3E%20%3CUserID%3E%3C!%5BCDATA%5B-1%5D%5D%3E%3C%2FUserID%3E%3CEmail%3E%3C!%5BCDATA%5B'.$email.'%5D%5D%3E%3C%2FEmail%3E%3CPassword%3E%3C!%5BCDATA%5B17%245I%24jaFq%40%5D%5D%3E%3C%2FPassword%3E%3C%2FUserDetails%3E%3C%2FRequest%3E%3C%2FInstancyWrapper%3E', CURLOPT_HTTPHEADER => [ |
| 371 | 'Content-Type: application/x-www-form-urlencoded', |
| 372 | 'Cookie: ASP.NET_SessionId=fuhbkztcn41q4vteeipt5jmr', |
| 373 | ], |
| 374 | ]); |
| 375 | $response = curl_exec($curl); |
| 376 | curl_close($curl); |
| 377 | |
| 378 | if (str_contains($response, 'Invalid User ID') || str_contains($response, 'Invalid Client ID') || str_contains($response, 'There is no row') |
| 379 | || str_contains($response, 'Error') |
| 380 | ) { |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | return true; |
| 385 | } |
| 386 | |
| 387 | public function createUserInstancy($request) |
| 388 | { |
| 389 | $this->action = 'CreateUser'; |
| 390 | $parametersArray = [ |
| 391 | 'Request' => [ |
| 392 | '@SiteID' => '388', |
| 393 | 'UserDetails' => [ |
| 394 | '#First_Name' => (isset($request['First_Name'])) ? $request['First_Name'] : '', |
| 395 | '#Last_Name' => (isset($request['Last_Name'])) ? $request['Last_Name'] : '', |
| 396 | '#User_name' => (isset($request['User_name'])) ? $request['User_name'] : '', |
| 397 | '#Email' => (isset($request['Email'])) ? $request['Email'] : '', |
| 398 | '#Password' => (isset($request['Password'])) ? $request['Password'] : '', |
| 399 | |
| 400 | ], |
| 401 | ], |
| 402 | ]; |
| 403 | |
| 404 | $xml = new ArrayToXML(); |
| 405 | $this->parameters = $xml->buildXML($parametersArray); |
| 406 | |
| 407 | return $this->callInstacncyApi(); |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Call the common api call through the curl |
| 412 | */ |
| 413 | public function callInstacncyApi() |
| 414 | { |
| 415 | $url = $this->makeUrl(); |
| 416 | $params = [ |
| 417 | 'astrKey' => $this->astr_key, |
| 418 | 'astrXML' => $this->parameters, |
| 419 | ]; |
| 420 | |
| 421 | $curl = curl_init($url); |
| 422 | curl_setopt($curl, CURLOPT_POST, true); |
| 423 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
| 424 | curl_setopt($curl, CURLOPT_HTTPHEADER, [ |
| 425 | 'Content-Type: application/json', |
| 426 | ]); |
| 427 | curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); |
| 428 | $curlResponse = curl_exec($curl); |
| 429 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
| 430 | curl_close($curl); |
| 431 | |
| 432 | $processed = json_decode($curlResponse, true); |
| 433 | |
| 434 | $xml_data = (isset($processed['d'])) ? $processed['d'] : ''; |
| 435 | $array = ''; |
| 436 | if ($xml_data) { |
| 437 | $xml = simplexml_load_string($xml_data, 'SimpleXMLElement', LIBXML_NOCDATA); |
| 438 | $json = json_encode($xml); |
| 439 | $array = json_decode($json, true); |
| 440 | } |
| 441 | |
| 442 | return $array; |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Function to make the api url with action |
| 447 | */ |
| 448 | public function makeUrl() |
| 449 | { |
| 450 | $url = $this->url.'/'.$this->action; |
| 451 | |
| 452 | return $url; |
| 453 | } |
| 454 | } |