'UK', 'de' => 'DE', ); public function checkConditions($cart, $method, $cart_prices) { //vmTrace('checkConditions', true); //$this->debugLog( $cart_prices['salesPrice'], 'checkConditions','debug'); $this->_currentMethod = $method; if($this->isValidLanguage() && $this->isValidAmount($cart_prices['salesPrice']) && $this->isValidProductCategories($cart) && $this->isValidIP() ) { return true; } return false; } /** * in VM, the payment is not showed if the buyer browse in another language * @return bool */ private function isValidLanguage() { return true; /*if(!$this->_currentMethod->language_restriction) { return true; } $lang = JFactory::getLanguage(); $tag = strtolower(substr($lang->get('tag'), 0, 2)); if(array_key_exists($tag, $this->languages_region) AND $this->languages_region[$tag] == $this->_currentMethod->region) { vmdebug('AMAZON checkConditions isValidLanguage false ',$tag); return true; } return false;*/ } /** * @return bool */ private function isValidCountry($virtuemart_country_id) { $countries = array(); if(!empty($this->_currentMethod->countries)) { if(!is_array($this->_currentMethod->countries)) { $countries[0] = $this->_currentMethod->countries; } else { $countries = $this->_currentMethod->countries; } } if(count($countries) == 0 || in_array($virtuemart_country_id, $countries)) { return TRUE; } return false; } /** * @return bool */ private function isValidAmount($amount) { $this->_currentMethod->min_amount = (float)str_replace(',', '.', $this->_currentMethod->min_amount); $this->_currentMethod->max_amount = (float)str_replace(',', '.', $this->_currentMethod->max_amount); $amount_cond = ($amount > 0 AND $amount >= $this->_currentMethod->min_amount AND $amount <= $this->_currentMethod->max_amount OR ($this->_currentMethod->min_amount <= $amount AND ($this->_currentMethod->max_amount == 0))); if($amount == 0 or !$amount_cond) { vmdebug('AMAZON checkConditions $amount_cond false'); return false; } return true; } /** * Exclusion of unsupported items: product categories as “not available via Amazon Payments”. * @param $cart * @return bool */ private function isValidProductCategories($cart) { if(!is_array($this->_currentMethod->exclude_categories)) { $exclude_categories[0] = $this->_currentMethod->exclude_categories; } else { $exclude_categories = $this->_currentMethod->exclude_categories; } foreach ($cart->products as $product) { if(array_intersect($exclude_categories, $product->categories)) { vmdebug('AMAZON checkConditions one of the products is not allowed to be payed via amazon ',$product); return false; } } return true; } /** * Switch for enabling / disabling Hidden Button Mode. * @return bool */ private function isValidIP() { if(empty($this->_currentMethod->ip_whitelist)) { return true; } if(!class_exists('ShopFunctions')) { require(VMPATH_ADMIN . DS . 'helpers' . DS . 'shopfunctions.php'); } $clientIp = ShopFunctions::getClientIP(); if(strpos( $this->_currentMethod->ip_whitelist,';')!==false){ $ip_whitelist = explode(";", $this->_currentMethod->ip_whitelist); } else { $ip_whitelist = explode("\n", $this->_currentMethod->ip_whitelist); } foreach($ip_whitelist as $ip){ $ip = trim($ip); if($ip==$clientIp) return true; } vmdebug('AMAZON checkConditions isValidIP false '.$clientIp, $ip_whitelist); return false; } }