Example #1
0
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage WrongClass class doesn't implement \Magento\Payment\Model\MethodInterface
  */
 public function testWrongTypeException()
 {
     $className = 'WrongClass';
     $methodMock = $this->getMock($className, [], [], '', false);
     $this->_objectManagerMock->expects($this->once())->method('create')->with($className, [])->will($this->returnValue($methodMock));
     $this->_factory->create($className);
 }
Example #2
0
 /**
  * @param bool $isActive
  * @dataProvider getActiveMethodsDataProvider
  */
 public function testGetActiveMethods($isActive)
 {
     $abstractMethod = $this->getMockBuilder('Magento\\Payment\\Model\\Method\\AbstractMethod')->disableOriginalConstructor()->setMethods(['setId', 'setStore', 'getConfigData'])->getMock();
     $this->scopeConfig->expects($this->once())->method('getValue')->with('payment', ScopeInterface::SCOPE_STORE, null)->will($this->returnValue($this->paymentMethodsList));
     $this->paymentMethodFactory->expects($this->once())->method('create')->with($this->paymentMethodsList['active_method']['model'])->will($this->returnValue($abstractMethod));
     $abstractMethod->expects($this->any())->method('setId')->with('active_method')->will($this->returnValue($abstractMethod));
     $abstractMethod->expects($this->any())->method('setStore')->with(null);
     $abstractMethod->expects($this->any())->method('getConfigData')->with('active', $this->isNull())->will($this->returnValue($isActive));
     $this->assertEquals($isActive ? ['active_method' => $abstractMethod] : [], $this->config->getActiveMethods());
 }
Example #3
0
 /**
  * Retrieve active system payments
  *
  * @return array
  */
 public function getActiveMethods()
 {
     $methods = [];
     foreach ($this->_scopeConfig->getValue('payment', ScopeInterface::SCOPE_STORE, null) as $code => $data) {
         if (isset($data['active']) && (bool) $data['active'] && isset($data['model'])) {
             /** @var AbstractMethod|null $methodModel Actually it's wrong interface */
             $methodModel = $this->_paymentMethodFactory->create($data['model']);
             $methodModel->setId($code)->setStore(null);
             if ($methodModel->getConfigData('active', null)) {
                 $methods[$code] = $methodModel;
             }
         }
     }
     return $methods;
 }
Example #4
0
 /**
  * Get and sort available payment methods for specified or current store
  *
  * @param null|string|bool|int $store
  * @param Quote|null $quote
  * @return AbstractMethod[]
  */
 public function getStoreMethods($store = null, $quote = null)
 {
     $res = [];
     $methods = $this->getPaymentMethods();
     foreach (array_keys($methods) as $code) {
         $model = $this->scopeConfig->getValue($this->getMethodModelConfigName($code), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
         if (!$model) {
             continue;
         }
         /** @var AbstractMethod $methodInstance */
         $methodInstance = $this->_methodFactory->create($model);
         $methodInstance->setStore($store);
         if (!$methodInstance->isAvailable($quote)) {
             /* if the payment method cannot be used at this time */
             continue;
         }
         $res[] = $methodInstance;
     }
     @uasort($res, function (MethodInterface $a, MethodInterface $b) {
         if ((int) $a->getConfigData('sort_order') < (int) $b->getConfigData('sort_order')) {
             return -1;
         }
         if ((int) $a->getConfigData('sort_order') > (int) $b->getConfigData('sort_order')) {
             return 1;
         }
         return 0;
     });
     return $res;
 }
Example #5
0
 /**
  * Get and sort available payment methods for specified or current store
  *
  * Array structure:
  *  $index => \Magento\Framework\Simplexml\Element
  *
  * @param null|string|bool|int|Store $store
  * @param Quote|null $quote
  * @return array
  */
 public function getStoreMethods($store = null, $quote = null)
 {
     $res = array();
     $methods = $this->getPaymentMethods();
     uasort($methods, array($this, '_sortMethods'));
     foreach ($methods as $code => $methodConfig) {
         $prefix = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/';
         if (!($model = $this->_scopeConfig->getValue($prefix . 'model', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store))) {
             continue;
         }
         $methodInstance = $this->_methodFactory->create($model);
         if (!$methodInstance) {
             continue;
         }
         $methodInstance->setStore($store);
         if (!$methodInstance->isAvailable($quote)) {
             /* if the payment method cannot be used at this time */
             continue;
         }
         $sortOrder = (int) $methodInstance->getConfigData('sort_order', $store);
         $methodInstance->setSortOrder($sortOrder);
         $res[] = $methodInstance;
     }
     return $res;
 }
Example #6
0
 /**
  * set payment specific request data
  *
  * @param \WirecardCEE_QPay_FrontendClient $init
  * @param \Magento\Checkout\Model\Cart $cart
  */
 protected function setAdditionalRequestData($init, $cart)
 {
     if (!$this->_dataHelper->getConfigData('options/paymenttypesortorder')) {
         return;
     }
     $blacklist = ['wirecard_checkoutpage_ccardmoto', 'wirecard_checkoutpage_invoiceb2b'];
     $map = ['TRUSTLY' => 'INSTANTBANK'];
     $paymenttypes = array();
     /* read all payment methods, regardless whether they are active or not */
     foreach ($this->_scopeConfig->getValue('payment', ScopeInterface::SCOPE_STORE, null) as $paymentCode => $data) {
         if (isset($data['model']) && isset($data['sort_order']) && $data['sort_order'] != 0) {
             /** @var AbstractPayment $paymentModel */
             if ($paymentCode == $this->getCode()) {
                 continue;
             }
             if (!preg_match('/^wirecard_checkoutpage/i', $paymentCode)) {
                 continue;
             }
             if (in_array($paymentCode, $blacklist)) {
                 continue;
             }
             /** @var AbstractMethod|null $methodModel Actually it's wrong interface */
             $paymentModel = $this->_paymentMethodFactory->create($data['model']);
             $paymentModel->setId($paymentCode);
             $paymentModel->setStore(null);
             $paymenttype = $paymentModel->getPaymentMethod();
             if (isset($map[$paymentModel->getPaymentMethod()])) {
                 $paymenttype = $map[$paymentModel->getPaymentMethod()];
             }
             $paymenttypes[$paymenttype] = $paymentModel->getConfigData('sort_order');
         }
     }
     if (count($paymenttypes)) {
         asort($paymenttypes);
         $init->setPaymenttypeSortOrder(array_keys($paymenttypes));
     }
 }