public function isValid($value) { $region = new Zend_Locale($this->_locale); $region = $region->getRegion(); if (false === ($isValid = parent::isValid($value))) { $isValid = parent::isValid($region . $value); } return $isValid; }
/** * Validate payment method information object * * @param Mage_Payment_Model_Info $info * @return Mage_Payment_Model_Abstract */ public function validate() { /** * to validate payment method is allowed for billing country or not */ $errorMsg = ''; $paymentInfo = $this->getInfoInstance(); // check if Electronic signature $codeElectronicSignature = $this->getConfigData('electronic_signature'); if ($codeElectronicSignature == 0) { $iban = new Zend_Validate_Iban(); if (!$iban->isValid($paymentInfo->getAdditionalInformation('cc_iban'))) { $errorMsg = Mage::helper('payment')->__('Iban is not correct, please enter a valid Iban.'); } // variable pour la fonction empty $var1 = $paymentInfo->getAdditionalInformation('cc_firstname'); $var2 = $paymentInfo->getAdditionalInformation('cc_lastname'); $var3 = $paymentInfo->getAdditionalInformation('cc_code_bic'); $var4 = $paymentInfo->getAdditionalInformation('cc_bank_name'); if (empty($var1)) { $errorMsg = Mage::helper('payment')->__('Firstname is mandatory.'); } if (empty($var2)) { $errorMsg = Mage::helper('payment')->__('Lastname is mandatory.'); } if (empty($var3)) { $errorMsg = Mage::helper('payment')->__('Code BIC is not correct, please enter a valid Code BIC.'); } if (empty($var4)) { $errorMsg = Mage::helper('payment')->__('Bank name is not correct, please enter a valid Bank name.'); } if ($errorMsg) { Mage::throwException($errorMsg); } } return $this; }
/** * validates iban and (optional) bic data * * @param $country - the country for the iban * @param $iban - the iban to validate * @param $bic - the bic if given * * @return bool - true if the iban data are valid, false otherwise */ protected function validateIban($country, $iban, $bic) { $country = strtoupper(trim($country)); $result = true; if ('DE' != $country && 'NL' != $country) { $result = false; $this->messages[] = $this->getDataHelper()->__('Country not supported for IBAN'); } $validator = new Zend_Validate_Iban(); if (!$validator->isValid($iban)) { $result = false; $this->messages[] = $this->getDataHelper()->__('Invalid IBAN provided'); } if ('NL' == $country && 11 < strlen(trim($bic))) { $result = false; $this->messages[] = $this->getDataHelper()->__('invalid BIC provided'); } return $result; }
public function testIbanNotSupported() { $validator = new Zend_Validate_Iban('en_US'); $this->assertFalse($validator->isValid('AT611904300234573201')); }