/**
  * Processor constructor.
  *
  * @param EventDispatcherInterface $dispatcher
  * @param LoggerInterface $logger
  * @param Factory $factory
  * @param OperationManager $operationManager ,
  * @param VendorManager $vendorManager
  * @param VendorInterface $operator
  *
  * @throws \HiPay\Wallet\Mirakl\Exception\ValidationFailedException
  */
 public function __construct(EventDispatcherInterface $dispatcher, LoggerInterface $logger, Factory $factory, OperationManager $operationManager, VendorManager $vendorManager, VendorInterface $operator)
 {
     parent::__construct($dispatcher, $logger, $factory);
     $this->operationManager = $operationManager;
     $this->vendorManager = $vendorManager;
     ModelValidator::validate($operator, 'Operator');
     $this->operator = $operator;
 }
 /**
  * Validate the model before sending it
  * Use ModelValidator.
  */
 public function validate()
 {
     ModelValidator::validate($this);
 }
 /**
  * Register wallets into HiPay.
  *
  * @param $miraklData
  *
  * @return VendorInterface[] an array of vendor to save
  */
 public function registerWallets($miraklData)
 {
     $vendorCollection = array();
     foreach ($miraklData as $vendorData) {
         $this->logger->debug('Shop id : {shopId}', array('shopId' => $vendorData['shop_id']));
         try {
             //Vendor recording
             $email = $vendorData['contact_informations']['email'];
             $miraklId = $vendorData['shop_id'];
             $vendor = $this->vendorManager->findByMiraklId($miraklId);
             if (!$vendor) {
                 if (!$this->hasWallet($email)) {
                     //Wallet create (call to HiPay)
                     $walletInfo = $this->createWallet($vendorData);
                     $this->logger->info('[OK] Created wallet for : ' . $vendorData['shop_id'], array('shopId' => $vendorData['shop_id']));
                 } else {
                     //Fetch the wallet id from HiPay
                     $walletInfo = $this->hipay->getWalletInfo($email);
                 }
                 $vendor = $this->createVendor($email, $walletInfo->getUserAccountld(), $walletInfo->getUserSpaceld(), $walletInfo->getIdentified(), $vendorData['shop_id'], $vendorData);
             } elseif ($vendor->getEmail() !== $email) {
                 $this->logger->warning('The e-mail has changed in Mirakl (' . $email . ') but cannot be updated in HiPay Wallet (' . $vendor->getEmail() . ').', array('shopId' => $miraklId));
             }
             $previousValues = $this->getImmutableValues($vendor);
             //Put more data into the vendor
             $this->vendorManager->update($vendor, $vendorData);
             if (!$this->vendorManager->isValid($vendor)) {
                 throw new InvalidVendorException($vendor);
             }
             ModelValidator::validate($vendor);
             ModelValidator::checkImmutability($vendor, $previousValues);
             $vendorCollection[$vendor->getMiraklId()] = $vendor;
             $this->logger->info('[OK] The vendor is treated');
         } catch (DispatchableException $e) {
             $this->handleException($e, 'warning', array('shopId' => $vendorData['shop_id']));
         }
     }
     return $vendorCollection;
 }
 /**
  * @return HiPayInterface
  */
 public function getHiPay()
 {
     ModelValidator::validate($this->hiPayConfiguration);
     return new HiPay($this->hiPayConfiguration->getBaseSoapUrl(), $this->hiPayConfiguration->getBaseRestUrl(), $this->hiPayConfiguration->getWebServiceLogin(), $this->hiPayConfiguration->getWebServicePassword(), $this->hiPayConfiguration->getEntity(), $this->hiPayConfiguration->getLocale(), $this->hiPayConfiguration->getTimezone(), $this->hiPayConfiguration->getOptions());
 }
 /**
  * Validate an operation
  *
  * @param OperationInterface $operation
  *
  * @return bool
  */
 public function isOperationValid(OperationInterface $operation)
 {
     try {
         if ($this->operationManager->findByMiraklIdAndPaymentVoucherNumber($operation->getMiraklId(), $operation->getPaymentVoucher())) {
             throw new AlreadyCreatedOperationException($operation);
         }
         if (!$this->operationManager->isValid($operation)) {
             throw new InvalidOperationException($operation);
         }
         ModelValidator::validate($operation);
     } catch (Exception $e) {
         $this->handleException($e);
         return false;
     }
     return true;
 }