Ejemplo n.º 1
0
 /**
  * @param Customer $customer
  * @param $password
  * @return bool
  */
 public function subscribeCustomer(Customer $customer, $password)
 {
     $em = $this->entityManager;
     $galittProvider = $this->galittProvider;
     $hashPassword = $galittProvider->hashPassword($password);
     try {
         $alreadyRegistered = $galittProvider->getCustomer($customer->getEmail());
     } catch (\Exception $e) {
         $this->logger->error(sprintf('An error occured while trying to get a Galitt customer with email (%s) via the getCustomer webservice. Request failed with message : "%s"', $customer->getEmail(), $e->getMessage()));
         return false;
     }
     $accentCards = array();
     if ($alreadyRegistered) {
         try {
             $passwordGalitt = $galittProvider->getPasswordCustomer($customer->getEmail());
         } catch (\Exception $e) {
             $this->logger->error(sprintf('An error occured while trying to get a password Galitt customer with email (%s) via the getPasswordCustomer webservice. Request failed with message : "%s"', $customer->getEmail(), $e->getMessage()));
             return false;
         }
         if ($passwordGalitt != $hashPassword) {
             try {
                 if (!$galittProvider->updatePassword($customer->getEmail(), $hashPassword, $passwordGalitt)) {
                     return false;
                 }
             } catch (\Exception $e) {
                 $this->logger->error(sprintf('An error occured while trying to update a password Galitt customer with parameters (Email : %s, Password : %s, PasswordGalitt : %s) via the updatePassword webservice. Request failed with message : "%s"', $customer->getEmail(), $hashPassword, $passwordGalitt, $e->getMessage()));
                 return false;
             }
         }
         $customer->setPassword(null);
         $customer->setLoyalty(1);
         if ($customer->getTempCardNumber()) {
             $this->addAccentCard($customer, $customer->getTempCardNumber());
             $customer->setTempCardNumber(null);
         }
         $em->persist($customer);
         $em->flush();
         return true;
     } else {
         try {
             $galittProvider->setAccountFidelity($customer, $password, $customer->getTempCardNumber() ?: null);
             $customer->setPassword(null);
             $customer->setLoyalty(1);
             if ($customer->getTempCardNumber()) {
                 $this->addAccentCard($customer, $customer->getTempCardNumber());
                 $customer->setTempCardNumber(null);
             }
             $em->persist($customer);
             $em->flush();
             return true;
         } catch (\Exception $e) {
             $this->logger->error(sprintf('An error occured while trying to create a customer (id : %s, email : %s) account on Galitt via the setAccountFidelity webservice. Request failed with message : "%s"', $customer->getId(), $customer->getEmail(), $e->getMessage()));
             return false;
         }
     }
 }