/**
  * Validates Request
  *
  * @param       Request                 $request        Request for validation
  *
  * @throws      ValidationException                     Request data is invalid
  */
 protected function validateRequest(Request $request)
 {
     $validationErrors = array();
     if (strlen($request->getApiMethod()) == 0) {
         $validationErrors[] = 'Request api method is empty';
     }
     if (strlen($request->getEndPoint()) == 0 && strlen($request->getEndPointGroup()) === 0) {
         $validationErrors[] = 'Request end point is empty and request end point group is empty. Set one of them.';
     }
     if (strlen($request->getEndPoint()) > 0 && strlen($request->getEndPointGroup()) > 0) {
         $validationErrors[] = 'Request end point was set and request end point group was set. Set only one of them.';
     }
     if (count($request->getRequestFields()) === 0) {
         $validationErrors[] = 'Request data is empty';
     }
     if (!Validator::validateByRule($request->getGatewayUrl(), Validator::URL, false)) {
         $validationErrors[] = 'Gateway url does not valid in Request';
     }
     if (!empty($validationErrors)) {
         throw new ValidationException("Some Request fields are invalid:\n" . implode(";\n", $validationErrors));
     }
 }
 /**
  * Add query config data to PaynetEasy payment transaction
  *
  * @param       PaymentTransaction      $paynetTransaction      PaynetEasy payment transaction
  * @param       string                  $redirectUrl            Url for final payment processing
  */
 protected function addQueryConfigData(PaymentTransaction $paynetTransaction, $redirectUrl = null)
 {
     $paynetTransaction->getQueryConfig()->setEndPoint($this->paymentConfig['end_point'])->setLogin($this->paymentConfig['login'])->setSigningKey($this->paymentConfig['signing_key'])->setGatewayMode($this->paymentConfig['gateway_mode'])->setGatewayUrlSandbox($this->paymentConfig['sandbox_gateway'])->setGatewayUrlProduction($this->paymentConfig['production_gateway']);
     if (Validator::validateByRule($redirectUrl, Validator::URL, false)) {
         $paynetTransaction->getQueryConfig()->setRedirectUrl($redirectUrl)->setCallbackUrl($redirectUrl);
     }
 }
 /**
  * Validates payment transaction before request constructing
  *
  * @param       PaymentTransaction      $paymentTransaction        Payment transaction for validation
  */
 protected function validatePaymentTransaction(PaymentTransaction $paymentTransaction)
 {
     $this->validateQueryConfig($paymentTransaction);
     $errorMessage = '';
     $missedFields = array();
     $invalidFields = array();
     foreach (static::$requestFieldsDefinition as $fieldDescription) {
         list($fieldName, $propertyPath, $isFieldRequired, $validationRule) = $fieldDescription;
         $fieldValue = PropertyAccessor::getValue($paymentTransaction, $propertyPath, false);
         if (!empty($fieldValue)) {
             try {
                 Validator::validateByRule($fieldValue, $validationRule);
             } catch (ValidationException $e) {
                 $invalidFields[] = "Field '{$fieldName}' from property path '{$propertyPath}', {$e->getMessage()}.";
             }
         } elseif ($isFieldRequired) {
             $missedFields[] = "Field '{$fieldName}' from property path '{$propertyPath}' missed or empty.";
         }
     }
     if (!empty($missedFields)) {
         $errorMessage .= "Some required fields missed or empty in PaymentTransaction: \n" . implode("\n", $missedFields) . "\n";
     }
     if (!empty($invalidFields)) {
         $errorMessage .= "Some fields invalid in PaymentTransaction: \n" . implode("\n", $invalidFields) . "\n";
     }
     if (!empty($errorMessage)) {
         throw new ValidationException($errorMessage);
     }
 }