objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $this->cache = $this->objectManager->create('\Magento\Framework\App\CacheInterface'); } public function loadCustomerErpCache($email) { return $this->cache->load(self::CACHE_TOKEN . $email); } public function setLogHelper($logHelper) { $this->logHelper = $logHelper; } private function createPostDataForLogin($email, $password) { return array( "userEmail" => $email, "password" => $password ); } private function getMessageDto($status, $code, $message, $body) { return array( "status" => $status, "code" => $code, "message" => $message, "body" => $body, ); } private function createCustomerCache($body){ return json_encode(array( "token" => $body["token"], "userId" => $body["data"]["userId"], "userEmail" => $body["data"]["userEmail"], "firstName" => $body["data"]["firstName"], "lastName" => $body["data"]["lastName"], )); } public function loginAdmin() { // $response = $this->post( // self::API_LOGIN_URL, // array( // "userEmail" => self::ADMIN_EMAIL, // "password" => self::ADMIN_PASSWORD // ) // ); // if ($response) { // $body = null; // if ($response->getBody()){ // $body = json_decode($response->getBody()->getContents(), true); // } // if ($response->getStatusCode() == 200) { // $this->cache->save($this->createCustomerCache($body), self::CACHE_TOKEN . self::ADMIN_EMAIL, array(), null); // } // } // $response->getBody()->rewind(); //return $response; } public function login($email, $password) { $data = $this->createPostDataForLogin($email, $password); $response = $this->post(self::API_LOGIN_URL, $data); if ($response->getStatusCode() == 200) { $body = null; if ($response->getBody()){ $body = json_decode($response->getBody()->getContents(), true); } $this->cache->save($this->createCustomerCache($body), self::CACHE_TOKEN . $email, array(), null); } $response->getBody()->rewind(); return $response; } public function createPostDataForAddCustomer($email, $firstName, $lastName, $password) { $raw_data_str = '{"urlAPI":"/api/user/data-save","data":{"firstName":"","lastName":"","password":"","orgId":"","type":"staff_of_partner","signature":null,"tels":[],"emails":[{"email":""}],"skypes":[],"group":"","positions":[null],"countryId":"","address1":"","address2":"","cityId":"","stateId":"","zipCode":"","postCode":"","notes":{"content":""},"shipTo":"0","billTo":"0","accessPortal":"1"}}'; $post_data = json_decode($raw_data_str, true); $post_data["data"]["emails"][0]["email"] = $email; $post_data["data"]["firstName"] = $firstName; $post_data["data"]["lastName"] = $lastName; $post_data["data"]["password"] = $password; return $post_data; } public function createCustomer($email, $firstName, $lastName, $password) { //$customer_cache = $this->cache->load(self::CACHE_TOKEN . self::ADMIN_EMAIL); // if (!empty($customer_cache)) { // $customer_cache = json_decode($customer_cache, true); // $this->setToken($customer_cache["token"]); // } $token = self::ADMIN_TOKEN; $this->setToken($token); $data = $this->createPostDataForAddCustomer($email, $firstName, $lastName, $password); $response = $this->post(self::API_TRANSFER_POST_DATA, $data); return $response; } public function setPassword($id, $password, $token) { $this->setToken($token); $data = array( "password" => $password ); $response = $this->post(self::API_SET_PASSWORD."/".$id, $data); return $response; } public function sendMailForgotPassword($email) { $data = array( "email" => $email ); $response = $this->post(self::API_FORGOT_PASSWORD, $data); return $response; } }