/**
  * InvalidOperation constructor.
  *
  * @param OperationInterface $operation
  * @param string             $message
  * @param int                $code
  * @param Exception          $previous
  */
 public function __construct($operation, $message = '', $code = 0, Exception $previous = null)
 {
     $this->operation = $operation;
     $miraklId = $operation->getMiraklId() ?: 'operateur';
     parent::__construct($message ?: "This operation is invalid [{$miraklId}, {$operation->getAmount()}\n                , {$operation->getCycleDate()->format('Y-m-d')}]", $code, $previous);
 }
 protected function getData(OperationInterface $operation)
 {
     return array('miraklId' => $operation->getMiraklId(), 'amount' => round($operation->getAmount(), 2), 'hipayId' => $operation->getHipayId(), 'cycleDate' => $operation->getCycleDate()->format('Y-m-d'), 'cycleDateTime' => $operation->getCycleDate()->format('Y-m-d H:i:s'), 'cycleTime' => $operation->getCycleDate()->format('H:i:s'), 'date' => date('Y-m-d'), 'datetime' => date('Y-m-d H:i:s'), 'time' => date('H:i:s'));
 }
 /**
  * Return the right vendor for an operation
  *
  * @param OperationInterface $operation
  *
  * @return VendorInterface|null
  */
 protected function getVendor(OperationInterface $operation)
 {
     if ($operation->getMiraklId()) {
         return $this->vendorManager->findByMiraklId($operation->getMiraklId());
     }
     return $this->operator;
 }
 /**
  * AlreadyCreatedOperationException constructor.
  *
  * @param OperationInterface $operation
  * @param string             $message
  * @param int                $code
  * @param Exception          $previous
  */
 public function __construct($operation, $message = '', $code = 0, Exception $previous = null)
 {
     $this->operation = $operation;
     $miraklId = $operation->getMiraklId() ?: 'operateur';
     parent::__construct($message ?: "An operation for {$miraklId} is already\n            created for the payment voucher {$operation->getPaymentVoucher()}", $code, $previous);
 }
 /**
  * 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;
 }