/**
  * Get the javascript to send the shipping method form via ajax.
  *
  * $shippingPaneSelector and $confirmationPaneSelector are jquery selectors pointing to the pane element surrounding the shipping method and
  * confirmation forms.
  *
  * Customweb.ExternalCheckout.submit() can be used to submit the shipping method form manually.
  *
  * @param string $shippingPaneSelector
  * @param string $confirmationPaneSelector
  * @return string
  */
 protected final function getAjaxJavascript($shippingPaneSelector, $confirmationPaneSelector)
 {
     $jqueryVariableName = 'j' . Customweb_Util_Rand::getRandomString(30);
     $javascript = Customweb_Core_Util_Class::readResource('Customweb_Payment_ExternalCheckout', 'ExternalCheckout.js') . "\n\n";
     $variables = array('jQueryNameSpace' => $jqueryVariableName);
     foreach ($variables as $variableName => $value) {
         $javascript = str_replace('____' . $variableName . '____', $value, $javascript);
     }
     $javascript .= Customweb_Util_JavaScript::getLoadJQueryCode('1.10.2', $jqueryVariableName, 'function() { Customweb.ExternalCheckout.init("' . $shippingPaneSelector . '", "' . $confirmationPaneSelector . '"); }') . "\n\n";
     return $javascript;
 }
Exemplo n.º 2
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();
 }
    protected function getPollingJs($transaction)
    {
        //@formatter:off
        $pollingFunction = '
			(function cwStatusChecker() {
				if(typeof window.jQuery == "undefined") {
					window.jQuery = cwJQuery;
				}
			    setTimeout(function() {
			        window.jQuery.ajax({
			            url: "' . $this->getUrl($this->getControllerName(), 'check', array('cw_transaction_id' => $transaction->getExternalTransactionId(), self::HASH_PARAMETER => $transaction->getSecuritySignature($this->getControllerName() . 'check'))) . '",
			            type: "POST",
			            success: function(data) {
			                if(data.status == "complete") {
			            		window.location.replace(data.redirect);
			            		return;
			            	}
			            	cwStatusChecker();			            	
			            },
			            error: function(request, message, code) {
			            	cwStatusChecker();	
			            },
			            dataType: "json",
			           	cache: false,
			            timeout: 30000
			        })
			    },  2000);
			})';
        //@formatter:on
        $jQuerySnippet = Customweb_Util_JavaScript::getLoadJQueryCode(null, 'cwJQuery', $pollingFunction);
        return '<script type="text/javascript">' . $jQuerySnippet . '</script>';
    }