简体   繁体   中英

How to get Magento Payone active payment methods?

We use Payone with our Magento shop. And we want to show our users warnings in their cart when their total amount is too large for a certain payment method.

That is why I want to check the total amount against each payment method max order value.

But somehow I can not reach the correct data.

When I try to get them by Payones config:

$methods = Mage::helper('payone_core/config')->getConfigPayment($store);

I get an object->array with all methods, but they are protected. So I can not use them in my cart module.

What is a clean way to get Payones payment methods (all active methods with their max_order_value)?

Edit:

I tried following code, but it still says:

Fatal error: Cannot access protected property Payone_Core_Model_Config_Payment::$methods in /pathToClass/CtaB2c/Helper/Data.php on line 20

class CtaB2c_Helper_Data extends Payone_Core_Helper_Config {
    public function getConfigPayment($store) {
        return parent::getConfigPayment($store);
    }

    public function showPaymentRestrictions() {
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        $store = $quote->getStoreId();
        $total = $quote->getBaseGrandTotal();
        $methods = $this->getConfigPayment($store);
        $methods = $methods->methods; //error occurs here: member has protected access

        $avaibleMethods = array();

        foreach ($methods AS $mid => $method) {
            $minTotal = $method->minOrderTotal;
            $maxTotal = $method->maxOrderTotal;

            if($minTotal <= $total && $maxTotal >= $total) {
                $avaibleMethods[$mid] = $method->code;
            }
        }

        return $avaibleMethods;
    }
}

I know, there is no check if this payment method is avaible, but actually I just want know if maxOrderTotal is bigger than payment methods max_order_total. And of course I do not need this extra function. I could call parent::getConfigPayment($store) in my function as well.

Edit 2 This is the object I get from getConfigPayment() :

object(Payone_Core_Model_Config_Payment)#<a number> (1) {
  ["methods":protected]=>
  array(6) {
    [<a number>]=>
    object(Payone_Core_Model_Config_Payment_Method)#<a number> (38) {
      ["id":protected]=>
      string(1) "a number"
      ["scope":protected]=>
      string(6) "stores"
      ["scope_id":protected]=>
      string(1) "<a number>"
      ["code":protected]=>
      string(15) "advance_payment"
      ["name":protected]=>
      string(8) "Vorkasse"
      ["sort_order":protected]=>
      string(1) "<a number>"
      ["enabled":protected]=>
      string(1) "<a number>"
      ["fee_config":protected]=>
      NULL
      ["mode":protected]=>
      string(4) "test"
      ["use_global":protected]=>
      string(1) "1"
      ["mid":protected]=>
      string(5) "<a number>"
      ["portalid":protected]=>
      string(7) "<a number>"
      ["aid":protected]=>
      string(5) "<a number>"
      ["key":protected]=>
      string(16) "<a key>"
      ["allowspecific":protected]=>
      string(1) "0"
      ["specificcountry":protected]=>
      array(0) {
      }
      ["allowedCountries":protected]=>
      array(2) {
        [0]=>
        string(2) "DE"
        [1]=>
        string(2) "AT"
      }
      ["request_type":protected]=>
      string(16) "preauthorization"
      ["invoice_transmit":protected]=>
      string(1) "0"
      ["types":protected]=>
      NULL
      ["klarna_config":protected]=>
      NULL
      ["klarna_campaign_code":protected]=>
      NULL
      ["paypal_express_image":protected]=>
      NULL
      ["check_cvc":protected]=>
      NULL
      ["check_bankaccount":protected]=>
      NULL
      ["bankaccountcheck_type":protected]=>
      NULL
      ["message_response_blocked":protected]=>
      NULL
      ["sepa_country":protected]=>
      NULL
      ["sepa_de_show_bank_data":protected]=>
      NULL
      ["sepa_mandate_enabled":protected]=>
      NULL
      ["sepa_mandate_download_enabled":protected]=>
      NULL
      ["customer_form_data_save":protected]=>
      NULL
      ["is_deleted":protected]=>
      string(1) "0"
      ["minValidityPeriod":protected]=>
      string(0) ""
      ["minOrderTotal":protected]=>
      string(1) "1"
      ["maxOrderTotal":protected]=>
      string(4) "1000"
      ["parent":protected]=>
      string(1) "<a number>"
      ["currency_convert":protected]=>
      string(1) "0"
    }

You can always extend the payone_core/config class YourNameSpace_Module_Helper_Payone extends ThePayOneNamespace_Payone_Core_Config and basically get any method to be public

class YourNameSpace_Module_Helper_Payone extends ThePayOneNamespace_Payone_Core_Config

   public function someProtectedParentMethod()
   {
       return parent::someProtectedParentMethod();
   }
}

The above will allow you to use any protected method and get the data you are after.

This is hopefully the Magento way to get information about Payones Payment methods. You should call setPaymentRestrictionNoticeMessage() somewhere in your controller.

class YourModule_Helper_Data extends Mage_Core_Helper_Abstract {
    /**
     * Returns array of methods that will not work with current max order value.
     * @return array
     */
    public function getPaymentsWithRestrictions() {
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        $store = $quote->getStoreId();
        $total = $quote->getBaseGrandTotal();

        /**
         * @var Payone_Core_Model_Config_Payment $model
         */
        $model = Mage::helper('payone_core/config')->getConfigPayment($store);
        $methods = $model->getMethods();

        $restrictedMethods = array();

        foreach ($methods AS $mid => $method) {
            /**
             * @var Payone_Core_Model_Config_Payment_Method $method
             */
            $minTotal = $method->getMinOrderTotal();
            $maxTotal = $method->getMaxOrderTotal();
            $isEnabled = $method->getEnabled();

            if($isEnabled && ($minTotal > $total || $maxTotal < $total)) {
                $restrictedMethods[$mid] = $method;
            }
        }

        return $restrictedMethods;
    }

    /**
     * Sets notification message with information about payment methods
     * that will not work.
     */
    public function setPaymentRestrictionNoticeMessage() {
        $restrictedMethodModels = $this->getPaymentsWithRestrictions();

        $restrictedMethods = array();

        foreach ($restrictedMethodModels AS $methodModel) {
            /**
             * @var Payone_Core_Model_Config_Payment_Method $methodModel
             */
            $restrictedMethods[] = $methodModel->getName();
        }

        Mage::getSingleton('core/session')->addNotice(
            Mage::helper('checkout')->__(
                'Your order value is too high for following payment methods: ' . implode(', ', $restrictedMethods)
            )
        );
    }
}

Get the Payone config in your function:

$payoneConfig = Mage::helper('payone_core/config')->getConfigPayment($storeId);

In Payone_Core_Model_Config_Payment you can find all methods which you can call on $payoneConfig , eg getAvailableMethods() . Overwrite Payone_Core_Model_Config_Payment the Magento way if you want to add more functionality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM