generalResponseValidator = $generalResponseValidator; $this->subjectReader = $subjectReader; } /** * @inheritdoc */ public function validate(array $validationSubject): ResultInterface { $result = $this->generalResponseValidator->validate($validationSubject); if (!$result->isValid()) { $response = $this->subjectReader->readResponseObject($validationSubject); if ($this->isErrorAcceptable($response->errors)) { $result = $this->createResult(true, [__('Transaction is cancelled offline.')]); } } return $result; } /** * Checks if error collection has an acceptable error code. * * @param ErrorCollection $errorCollection * @return bool */ private function isErrorAcceptable(ErrorCollection $errorCollection): bool { $errors = $errorCollection->deepAll(); // there is should be only one acceptable error if (count($errors) > 1) { return false; } /** @var Validation $error */ $error = array_pop($errors); return (int)$error->code === self::$acceptableTransactionCode; } }