Ejemplo n.º 1
0
 /**
  * @param Payone_Core_Model_Config $config
  * @param string $methodType
  *
  * @return int
  */
 public function getMethodId($config, $methodType)
 {
     if ($methodType) {
         $methods = $config->getPayment()->getMethodsByType($methodType);
         if (!empty($methods)) {
             /** @var Payone_Core_Model_Config_Payment_Method $method */
             foreach ($methods as $method) {
                 $id = $method->getScope() === 'websites' ? Mage::app()->getWebsite()->getId() : Mage::app()->getStore()->getStoreId();
                 if ($method->getScopeId() === $id) {
                     return $method->getId();
                 }
             }
             $error = $this->__('PayOne: could not match config scope with any of the active methods');
         } else {
             $error = $this->__('PayOne: could not find an enabled config for mapping: %s', $methodType);
         }
     } else {
         $error = $this->__('PayOne: method type not set in the called class');
     }
     ShopgateLogger::getInstance()->log($error, ShopgateLogger::LOGTYPE_ERROR);
     return false;
 }
 /**
  * @param Payone_Core_Model_Config $config
  * @return Payone_Settings_Data_ConfigFile_Abstract|Payone_Settings_Data_ConfigFile_Shop_ClearingTypes
  */
 protected function generateSettingsClearingtypes(Payone_Core_Model_Config $config)
 {
     /** @var $clearingTypes Payone_Settings_Data_ConfigFile_Shop_ClearingTypes */
     $clearingTypes = $this->getSettingsClass('shop_clearingTypes');
     $payment = $config->getPayment();
     $clearingTypesArray = array();
     foreach ($payment->getMethods() as $paymentMethod) {
         /** @var $paymentMethod Payone_Core_Model_Config_Payment_Method */
         /** @var $paymentMethodConfig Payone_Settings_Data_ConfigFile_PaymentMethod_Abstract */
         $paymentMethodConfig = $this->getPaymentMethodClass($paymentMethod->getCode());
         foreach ($paymentMethod->toArray() as $key => $value) {
             if ($key === 'enabled') {
                 $key = 'active';
             }
             $setterName = 'set' . uc_words($key, '');
             if (method_exists($paymentMethodConfig, $setterName)) {
                 $paymentMethodConfig->{$setterName}($value);
             }
         }
         $allowedCountries = $paymentMethod->getAllowedCountries();
         if (method_exists($paymentMethodConfig, 'setCountries')) {
             $paymentMethodConfig->setCountries(implode(',', $allowedCountries));
         }
         if (method_exists($paymentMethodConfig, 'setAuthorization')) {
             $paymentMethodConfig->setAuthorization($paymentMethod->getRequestType());
         }
         $paymentMethodConfig->setTitle($paymentMethod->getName());
         if ($paymentMethod->getTypes() !== NULL && $paymentMethod->getTypes() !== false) {
             $types = $paymentMethod->getTypes();
             if (is_array($types)) {
                 $types = implode(',', $types);
             }
             if ($paymentMethodConfig instanceof Payone_Settings_Data_ConfigFile_PaymentMethod_Creditcard) {
                 /**@var $paymentMethodConfig Payone_Settings_Data_ConfigFile_PaymentMethod_Creditcard */
                 $paymentMethodConfig->setCvc2($paymentMethod->getCheckCvc());
             }
             $paymentMethodConfig->setTypes($types);
         }
         if ($paymentMethodConfig instanceof Payone_Settings_Data_ConfigFile_PaymentMethod_Financing) {
             /** @var Payone_Settings_Data_ConfigFile_PaymentMethod_Financing $paymentMethodConfig */
             $klarnaConfigs = $paymentMethod->getKlarnaConfig();
             $klarnaConfigArray = array();
             if (is_array($klarnaConfigs)) {
                 foreach ($klarnaConfigs as $klarnaConfig) {
                     $attributeCountry = '';
                     if (is_array($klarnaConfig)) {
                         if (array_key_exists('countries', $klarnaConfig)) {
                             $attributeCountry = implode(',', $klarnaConfig['countries']);
                         }
                     }
                     $attributeArray = array('countries' => $attributeCountry);
                     $configArray = array('value' => array_key_exists('klarna_store_id', $klarnaConfig) ? $klarnaConfig['klarna_store_id'] : '', 'attribute' => $attributeArray);
                     array_push($klarnaConfigArray, $configArray);
                 }
             }
             $paymentMethodConfig->setKlarnaConfig($klarnaConfigArray);
         }
         $feeConfigs = $paymentMethod->getFeeConfig();
         $feeConfigArray = array();
         if (is_array($feeConfigs)) {
             foreach ($feeConfigs as $feeConfig) {
                 $attributeCountry = $attributeShippingMethod = '';
                 if (is_array($feeConfig)) {
                     if (array_key_exists('countries', $feeConfig)) {
                         $attributeCountry = array_shift($feeConfig['countries']);
                     }
                     if (array_key_exists('shipping_method', $feeConfig)) {
                         $attributeShippingMethod = array_shift($feeConfig['shipping_method']);
                     }
                 }
                 $attributeArray = array('country' => $attributeCountry, 'shipping_method' => $attributeShippingMethod);
                 $configArray = array('value' => $feeConfig['fee_config'], 'attribute' => $attributeArray);
                 array_push($feeConfigArray, $configArray);
             }
         }
         $paymentMethodConfig->setFeeConfig($feeConfigArray);
         array_push($clearingTypesArray, $paymentMethodConfig);
     }
     $clearingTypes->setClearingtypes($clearingTypesArray);
     return $clearingTypes;
 }