/**
     * Check if customer group can use the payment method
     *
     * @param Varien_Event_Observer $observer
     * @return bool
     */
    public function methodIsAvailable(Varien_Event_Observer $observer)
    {
        $paymentMethodInstance = $observer->getMethodInstance();
        /* @var $paymentMethodInstance Mage_Payment_Model_Method_Abstract */
        $result = $observer->getResult();

        $customer = Mage::helper('customer')->getCustomer();
        /* @var $customer Mage_Customer_Model_Customer */

        if ($paymentMethodInstance instanceof Mage_Paypal_Model_Standard) {
            $customerGroupConfig = Mage::getStoreConfig('paypal/wps/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD);
        } elseif ($paymentMethodInstance instanceof Mage_Paypal_Model_Express) {
            $customerGroupConfig = Mage::getStoreConfig('paypal/express/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD);
        } elseif ($paymentMethodInstance instanceof Mage_GoogleCheckout_Model_Payment) {
            $customerGroupConfig = Mage::getStoreConfig('google/checkout/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD);
        } else {
            $customerGroupConfig = $paymentMethodInstance->getConfigData(self::XML_CUSTOMER_GROUP_CONFIG_FIELD);
        }
        if (!empty($customerGroupConfig)) {
            $methodCustomerGroups = explode(',', $customerGroupConfig);
            if (count($methodCustomerGroups) > 0) {
                if (!in_array($customer->getGroupId(), $methodCustomerGroups)) {
                    $result->isAvailable = false;
                }
            }
        }
        return true;
    }
Exemple #2
0
 /**
  * Check if customer group can use the payment method
  *
  * @param Varien_Event_Observer $observer
  * @return bool
  */
 public function methodIsAvailable(Varien_Event_Observer $observer)
 {
     /* @var $paymentMethodInstance Mage_Payment_Model_Method_Abstract */
     $paymentMethodInstance = $observer->getMethodInstance();
     /* @var $customer Mage_Customer_Model_Customer */
     if (Mage::app()->getStore()->isAdmin()) {
         $customer = Mage::getSingleton('adminhtml/session_quote')->getCustomer();
     } else {
         $customer = Mage::getSingleton('customer/session')->getCustomer();
     }
     if ($paymentMethodInstance instanceof Mage_Paypal_Model_Standard) {
         $customerGroupConfig = Mage::getStoreConfig('paypal/wps/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD);
     } elseif ($paymentMethodInstance instanceof Mage_Paypal_Model_Express) {
         $customerGroupConfig = Mage::getStoreConfig('paypal/express/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD);
     } elseif ($paymentMethodInstance instanceof Mage_GoogleCheckout_Model_Payment) {
         // VK: this won't work
         $customerGroupConfig = Mage::getStoreConfig('google/checkout/' . self::XML_CUSTOMER_GROUP_CONFIG_FIELD);
     } else {
         $customerGroupConfig = $paymentMethodInstance->getConfigData(self::XML_CUSTOMER_GROUP_CONFIG_FIELD);
     }
     if ($customerGroupConfig) {
         $customerGroupsAllowed = explode(',', $customerGroupConfig);
         $observer->getResult()->isAvailable = in_array($customer->getGroupId(), $customerGroupsAllowed);
     }
 }
Exemple #3
0
 public function disableMethod(Varien_Event_Observer $observer)
 {
     $moduleName = "Raveinfosys_Linkpoint";
     if ('linkpoint' == $observer->getMethodInstance()->getCode()) {
         if (!Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $moduleName)) {
             //nothing here, as module is ENABLE
         } else {
             $observer->getResult()->isAvailable = false;
         }
     }
 }
 /**
  * @param string $filterClass
  * @param Varien_Event_Observer $observer
  * @return void
  */
 protected function _addFilter($filterClass, Varien_Event_Observer $observer)
 {
     $quote = $observer->getQuote();
     $result = $observer->getResult();
     // stdClass with property "isAvailable"
     $paymentMethodInstance = $observer->getMethodInstance();
     /* @var $paymentMethodInstance Mage_Payment_Model_Method_Abstract */
     $customerGroupFilter = Mage::getModel($filterClass);
     $customerGroupFilter->setResult($result);
     $customerGroupFilter->setMethodInstance($paymentMethodInstance);
     $customerGroupFilter->setQuote($quote);
     $customerGroupFilter->filter();
 }
 /**
  * Check if customer group can use the payment method
  *
  * @param Varien_Event_Observer $observer
  * @return bool
  */
 public function methodIsAvailable(Varien_Event_Observer $observer)
 {
     if (Mage::getStoreConfigFlag(self::PAYMENT_SSO_ACTIVE) && Mage::getSingleton('customer/session')->isLoggedIn()) {
         $paymentMethodInstance = $observer->getMethodInstance();
         /* @var $paymentMethodInstance Mage_Payment_Model_Method_Abstract */
         $result = $observer->getResult();
         $targetGroup = Mage::getModel('customer/group');
         $targetGroup->load(Mage::getSingleton('customer/session')->getCustomerGroupId());
         if ($paymentMethodInstance->getCode() != 'wallet' && $targetGroup->getData('customer_group_code') == 'Stelo') {
             $result->isAvailable = false;
         }
         return true;
     }
 }
 /**
  * @event payment_method_is_active
  * @param Varien_Event_Observer $observer
  * @return $this
  */
 public function isPaymentMethodActive(Varien_Event_Observer $observer)
 {
     /** @var Mage_Sales_Model_Quote $quote */
     /** @noinspection PhpUndefinedMethodInspection */
     $quote = $observer->getQuote();
     if (!$quote) {
         return $this;
     }
     if (!$this->isQuoteAdyenSubscription($quote)) {
         return $this;
     }
     /** @var Mage_Payment_Model_Method_Abstract $methodInstance */
     /** @noinspection PhpUndefinedMethodInspection */
     $methodInstance = $observer->getMethodInstance();
     $methodInstance->setMode('subscription');
     /**
      * The method canCreateContractTypeRecurring returns true for:
      * Inital Payments:   checks for setting in Admin Panel: payment/adyen_abstract/recurringtypes
      *                    if RECURRING or ONECLICK,RECURRING is set
      * Stored cards/sepa: checks recurring_type in BA agreement_data.
      *                    if RECURRING or ONECLICK,RECURRING is set
      *
      * For instances that allow ONECLICK (ONECLICK,RECURRING) we need to set the mode to RECURRING.
      */
     // You need to do a recurring transaction for subscriptions
     if (method_exists($methodInstance, 'setCustomerInteraction')) {
         /** @var $methodInstance Adyen_Payment_Model_Adyen_Oneclick */
         $methodInstance->setCustomerInteraction(false);
     }
     // check if payment method is selected in config
     $selectedSubscriptionPaymentMethods = Mage::helper('adyen_subscription/config')->getSelectedSubscriptionPaymentMethods();
     // check if payment method is in the key
     $code = $methodInstance->getCode();
     // Set method to unavailable and check below if it is possible to use
     $observer->getResult()->isAvailable = false;
     /*
      * Check if payment method is in selectedPaymentMethods and
      * validate if payment method is available for Adyen subscription
      */
     if (array_key_exists($code, $selectedSubscriptionPaymentMethods) && method_exists($methodInstance, 'canCreateAdyenSubscription') && $methodInstance->canCreateAdyenSubscription()) {
         $observer->getResult()->isAvailable = true;
     }
     //@todo move paymen specific logic to Adyen_Payments module, this causes tight coupling.
     // restrict MAESTRO payment method for creditcards because MEASTRO does not support Recurring
     if ($code == "adyen_cc") {
         $types = $methodInstance->getAvailableCCTypes();
         if (isset($types['SM'])) {
             unset($types['SM']);
             $methodInstance->setAvailableCCypes($types);
         }
     }
     /*
      * For ONECLCIK payment check if it is allowed by selectedPaymentMethods configuration
      */
     if ($code != "adyen_oneclick" && strpos($code, 'adyen_oneclick') !== false) {
         $recurringDetails = $methodInstance->getRecurringDetails();
         if (isset($recurringDetails['variant'])) {
             //@todo move the available credit cards to the config, one location where all the credit cards are specified
             $creditcards = array('visa', 'mc', 'amex', 'discover', 'diners', 'maestro', 'jcb', 'elo', 'Hipercard');
             if (in_array($recurringDetails['variant'], $creditcards) && isset($selectedSubscriptionPaymentMethods['adyen_cc'])) {
                 $observer->getResult()->isAvailable = true;
             } elseif ($recurringDetails['variant'] == "sepadirectdebit" && isset($selectedSubscriptionPaymentMethods['adyen_sepa'])) {
                 $observer->getResult()->isAvailable = true;
             } elseif ($recurringDetails['variant'] == "paypal" && isset($selectedSubscriptionPaymentMethods['adyen_hpp_paypal'])) {
                 $observer->getResult()->isAvailable = true;
             } elseif ($recurringDetails['variant'] == "directEbanking" && isset($selectedSubscriptionPaymentMethods['adyen_hpp_directEbanking'])) {
                 $observer->getResult()->isAvailable = true;
             }
         }
     }
     if (Mage::app()->getRequest()->getParam('subscription')) {
         if (!method_exists($methodInstance, 'isBillingAgreement') || !$methodInstance->isBillingAgreement()) {
             $observer->getResult()->isAvailable = false;
         }
     }
     return $this;
 }