Exemplo n.º 1
0
 public function check(BankAccountNormalized $bankAccount)
 {
     $checks = $this->fetch($bankAccount->getSortCode());
     $numChecks = count($checks);
     if (1 === $numChecks) {
         $check = $checks[0];
         if (14 === $check[2] && self::MOD11 === $check[0]) {
             if ($this->applySingleModulus($bankAccount, $check, 1)) {
                 return true;
             }
             return $this->applySingleModulus($bankAccount, $check, 2);
         }
         return $this->applySingleModulus($bankAccount, $check, 1);
     } elseif (2 === $numChecks) {
         if (2 === $checks[0][2] && 9 === $checks[1][2]) {
             // Exception 2 & 9
             $chars = (string) $bankAccount;
             if ('0' !== $chars[self::A]) {
                 if ('9' === $chars[self::G]) {
                     $checks[0][1] = [0, 0, 0, 0, 0, 0, 0, 0, 8, 7, 10, 9, 3, 1];
                 } else {
                     $checks[0][1] = [0, 0, 1, 2, 5, 3, 6, 4, 8, 7, 10, 9, 3, 1];
                 }
             }
             return $this->applyDoubleOrModulus($bankAccount, $checks[0], $checks[1]);
         }
         if (10 === $checks[0][2] && 11 === $checks[1][2]) {
             // Exception 10 & 11
             return $this->applyDoubleOrModulus($bankAccount, $checks[0], $checks[1]);
         }
         if (12 === $checks[0][2] && 13 === $checks[1][2]) {
             // Exception 12 & 13
             // Where there is a 12 in the exception column for the first
             // check for a sorting code and a 13 in the exception column for
             // the second check for the same sorting code, if either check
             // is successful the account number is deemed valid.
             return $this->applyDoubleOrModulus($bankAccount, $checks[0], $checks[1]);
         }
         if (6 === $checks[0][2] && 6 === $checks[1][2]) {
             // If a = 4, 5, 6, 7 or 8, and g and h are the same, the
             // accounts are for a foreign currency and the checks cannot be
             // used.
             $chars = (string) $bankAccount;
             if ($chars[self::G] === $chars[self::H] && 4 <= $chars[self::A] && 8 >= $chars[self::A]) {
                 return true;
             }
         }
         return $this->applyDoubleAndModulus($bankAccount, $checks[0], $checks[1]);
     } else {
         throw CannotValidateException::createFromBankAccount($bankAccount);
     }
 }
Exemplo n.º 2
0
 /** @return BankAccountInterface */
 public function normalize(BankAccountInterface $bankAccount)
 {
     foreach ($this->normalizers as $normalizer) {
         if ($normalizer->supports($bankAccount)) {
             return $normalizer->normalize($bankAccount);
         }
     }
     return BankAccountNormalized::createFromBankAccount($bankAccount);
 }
Exemplo n.º 3
0
 private function normalizeBankAccount(BankAccountInterface $account)
 {
     if ($this->normalizer->supports($account)) {
         return $this->normalizer->normalize($account);
     }
     return BankAccountNormalized::createFromBankAccount($account);
 }