/** * @param Mage_Sales_Model_Quote|null $quote * @return bool */ public function isAvailable($quote = null) { if (!parent::isAvailable($quote)) { return false; } /** @var Payin7_Payments_Helper_Data $phelper */ $phelper = Mage::helper('payin7payments'); // check for a reject cookie if ($phelper->isRejectVerificationCookieSet()) { return false; } if ($quote) { // validate the platform constraints /** @var Payin7_Payments_Model_Remote_Platform_Status $remote_platform_status */ $remote_platform_status = Mage::getModel('payin7payments/remote_platform_status'); $remote_platform_status->loadData(); $remote_method_code = $this->getRemoteApiPaymentMethodCode(); $platform_is_available = $remote_platform_status->getIsPlatformAvailable() && $remote_platform_status->getIsPaymentMethodAvailable($remote_method_code); if (!$platform_is_available) { return false; } $quote_total = (double) $quote->getGrandTotal(); /** @var Payin7_Payments_Model_Remote_Platform_Config $remote_platform_config */ $remote_platform_config = Mage::getModel('payin7payments/remote_platform_config'); $remote_platform_config->loadData(); // check if the platform constraints are met $payment_method_cfg = $remote_platform_config->getPaymentMethodConfig($remote_method_code); $is_customer_disabled = isset($payment_method_cfg['is_disabled']) ? (bool) $payment_method_cfg['is_disabled'] : null; if ($is_customer_disabled) { return false; } $min_order_allowed_platform = isset($payment_method_cfg['minimum_amount']) ? (double) $payment_method_cfg['minimum_amount'] : null; $max_order_allowed_platform = isset($payment_method_cfg['maximum_amount']) ? (double) $payment_method_cfg['maximum_amount'] : null; $supported_countries = isset($payment_method_cfg['supported_countries']) ? (array) $payment_method_cfg['supported_countries'] : array(); if ($min_order_allowed_platform && $quote_total < $min_order_allowed_platform) { $this->_logger->logWarn('Order platform min not within allowed constraints (min platform allowed: ' . $min_order_allowed_platform . ', current quote: ' . $quote_total . ')'); return false; } if ($max_order_allowed_platform && $quote_total > $max_order_allowed_platform) { $this->_logger->logWarn('Order platform max not within allowed constraints (max platform allowed: ' . $max_order_allowed_platform . ', current quote: ' . $quote_total . ')'); return false; } if ($supported_countries) { $country = $quote->getBillingAddress()->getCountry(); if (!in_array($country, $supported_countries)) { $this->_logger->logWarn('Order country not supported, country: ' . $country); return false; } } // verify the minimum / maximum allowed $min_order_allowed = (double) $this->getConfigData('min_order_total'); $max_order_allowed = (double) $this->getConfigData('max_order_total'); if ($min_order_allowed && $quote_total < $min_order_allowed) { $this->_logger->logWarn('Order min not within allowed constraints (min allowed: ' . $min_order_allowed . ', current quote: ' . $quote_total . ')'); return false; } if ($max_order_allowed && $quote_total > $max_order_allowed) { $this->_logger->logWarn('Order max not within allowed constraints (max allowed: ' . $max_order_allowed . ', current quote: ' . $quote_total . ')'); return false; } // verify the shipping methods if ($this->getConfigData('specific_shipping_methods') && $quote->getShippingAddress()->getShippingMethod()) { $specific_shipping_methods = array_filter(explode(',', $this->getConfigData('specific_shipping_methods'))); if ($specific_shipping_methods) { $current_shipping_method = explode('_', $quote->getShippingAddress()->getShippingMethod()); if (!$current_shipping_method || !is_array($current_shipping_method)) { return false; } $this->_logger->logWarn('Shipping method not supported: ' . $current_shipping_method[0] . ', ' . print_r($specific_shipping_methods, true)); return in_array($current_shipping_method[0], $specific_shipping_methods); } } } return true; }