/** * @param int $bank * @param int $account * @return bool * @throws ValidationTestAPIException * @throws NotInitializedTestAPIException * @throws BankNotFoundTestAPIException */ protected function isValid(Bank $bank, $account) { $isValid = kto_check_blz($bank->getBankID(), $account); switch ($isValid) { case self::NOT_INITIALIZED: throw new NotInitializedTestAPIException("LUT not initialized"); case self::BANK_NOT_FOUND: throw new BankNotFoundTestAPIException($bank->getBankID()); case self::INVALID_NULL: case self::INVALID_KTO: case self::INVALID_FALSE: return false; default: if ($isValid < 0) { throw new ValidationTestAPIException("unknown code {$isValid}"); } return true; } }
/** * @throws ValidatorESERException * @return string */ protected function getESER9() { $bankID = $this->bank->getBankID(); $account = ltrim($this->account, '0'); if (strlen($account) != 9) { throw new ValidatorESERException(); } if ($bankID[3] != 5) { throw new ValidatorESERException(); } $blzPart0 = substr($bankID, -4, 2); $blzPart1 = substr($bankID, -1); $accountPart0 = $account[0]; $t = $account[1]; $p = $account[2]; $accountTail = ltrim(substr($account, 3), '0'); $eser = $blzPart0 . $t . $blzPart1 . $accountPart0 . $p . $accountTail; return $eser; }
public function __construct(Bank $bank) { parent::__construct("bank {$bank->getBankID()} has no main agency."); $this->bank = $bank; }
/** * @throws DataBackendException * @return Agency[] * @see DataBackend::getAgenciesForBank() */ public function getAgenciesForBank(Bank $bank) { try { $stmt = $this->statementContainer->prepare("SELECT {$this->agencyAttributes} FROM {$this->prefix}agency a\n WHERE bank = :bankID AND id != :mainAgency"); $agencies = array(); $stmt->execute(array(":bankID" => $bank->getBankID(), ":mainAgency" => $bank->getMainAgency()->getID())); foreach ($stmt->fetchAll() as $agencyResult) { $agencies[] = $this->getAgencyObject($bank, $agencyResult); } $stmt->closeCursor(); return $agencies; } catch (\PDOException $e) { $stmt->closeCursor(); throw new DataBackendIOException($e->getMessage(), 0, $e); } catch (MissingAttributesDataBackendIOException $e) { $stmt->closeCursor(); throw new \LogicException($e); } }
/** * @param Bank $bank * @param String $account * @param array $results * @return String */ private function getErrorMessage(Bank $bank, $account, array $results) { $resultTranslation = array(TestAPIResult::VALID => "valid", TestAPIResult::INVALID => "invalid", TestAPIResult::ERROR => "error"); $message = "bank: {$bank->getBankID()} method: {$bank->getValidationType()} account: {$account}"; foreach ($results as $result) { $message .= " {$result->getTestAPI()->getName()}: " . $resultTranslation[$result->getResult()]; if ($result instanceof TestAPIErrorResult) { $message .= " {$result->getMessage()}"; } } return $message; }
/** * 0 - 0000000000 should always be invalid * * @param String $validatorType * @throws ClassFileIOException * @throws MissingClassException * @dataProvider provideBanks */ public function testNullIsInvalid(Bank $bank) { for ($length = 0; $length <= 10; $length++) { $account = str_pad("0", $length, "0", STR_PAD_LEFT); $this->assertFalse($bank->isValid($account), "{$bank->getBankID()}/{$bank->getValidationType()} {$account} should be invalid."); } }
/** * @param int $account * @return bool * @throws ValidationTestAPIException * @throws NotInitializedTestAPIException * @throws BankNotFoundTestAPIException */ protected function isValid(Bank $bank, $account) { $fileParam = empty($this->bankdata) ? '' : "--file={$this->bankdata}"; $cmd = "{$this->binary} {$fileParam} '{$bank->getBankID()}' '{$account}'"; exec($cmd, $out, $result); switch ($result) { case self::VALID: return true; case self::INVALID: return false; case self::BANK_NOT_FOUND: throw new BankNotFoundTestAPIException("Bank not found: {$bank->getBankID()}"); default: throw new ValidationTestAPIException("unknown code {$result}: " . implode("\n", $out)); } }