Exemplo n.º 1
0
 /**
  * This method generates all the JavaScript required to
  * handle the user input as configured.
  *
  * Subclasses may override this method, but should call this method in first place.
  * The additional JS can be added by invoking the method self::appendJavaScript().
  *
  * @return string
  */
 protected function generateJavaScript()
 {
     $js = Customweb_Core_Util_Class::readResource('Customweb_Payment_Authorization_Method_CreditCard', 'CardHandler.js');
     $filteredData = array();
     foreach ($this->getCardHandler()->getCardInformationObjects() as $object) {
         $key = strtolower($object->getBrandKey());
         $filteredData[$key] = array();
         $filteredData[$key]['validators'] = $object->getValidators();
         $filteredData[$key]['lengths'] = $object->getCardNumberLengths();
         if ($object->isCvvPresentOnCard()) {
             $filteredData[$key]['cvv_length'] = $object->getCvvLength();
             $filteredData[$key]['cvv_required'] = $object->isCvvRequired();
         }
     }
     $selectedBrand = $this->getSelectedBrand();
     if ($selectedBrand === null) {
         $selectedBrand = 'null';
     }
     $brandMapping = $this->getCardHandler()->getExternalBrandMap();
     if ($brandMapping === null) {
         $brandMapping = array();
     }
     $variables = array('jQueryNameSpace' => $this->getJQueryVariableName(), 'imageBrandControlId' => self::getControlId($this->brandImageControl), 'brandDropDownControlId' => self::getControlId($this->brandDropDownControl), 'creditCardControlId' => self::getControlId($this->cardNumberControl), 'cvcControlId' => self::getControlId($this->cvcControl), 'expiryMonthControlId' => self::getControlId($this->expiryMonthControl), 'expiryYearControlId' => self::getControlId($this->expiryYearControl), 'cardHandlerNameSpace' => $this->getCardHandlerJavaScriptNameSpace(), 'brandMapping' => Customweb_Util_JavaScript::toJavaScript($brandMapping), 'cardInformation' => Customweb_Util_JavaScript::toJavaScript($filteredData), 'cardNumberPrefixMap' => Customweb_Util_JavaScript::toJavaScript($this->getCardHandler()->getCardNumberPrefixMap()), 'imageBrandSelectionActive' => self::handleBoolean($this->isImageBrandSelectionActive()), 'autoBrandSelectionActive' => self::handleBoolean($this->isAutoBrandSelectionActive()), 'brandSelectionActive' => self::handleBoolean($this->isBrandSelectionActive()), 'enhancedWithJavaScript' => $this->isEnhancedWithJavaScript(), 'selectedBrand' => $selectedBrand, 'forceCvcOptional' => self::handleBoolean($this->isForceCvcOptional()), 'expiryFieldFormat' => $this->getExpiryFieldFormat(), 'expiryControlId' => self::getControlId($this->expiryControl));
     foreach ($variables as $variableName => $value) {
         $js = str_replace('____' . $variableName . '____', $value, $js);
     }
     $this->appendJavaScript($js . "\n");
     // Add jQuery
     $this->appendJavaScript(Customweb_Util_JavaScript::getLoadJQueryCode('1.10.2', $this->getJQueryVariableName(), 'function() { ' . $this->getCardHandlerJavaScriptNameSpace() . '.init(); }'));
     return $this->getJavaScript();
 }