Пример #1
0
 /**
  * Retrieve available billing agreement methods
  *
  * @param null|string|bool|int|\Magento\Store\Model\Store $store
  * @param \Magento\Quote\Model\Quote|null $quote
  * @return MethodInterface[]
  */
 public function getBillingAgreementMethods($store = null, $quote = null)
 {
     $result = [];
     foreach ($this->_paymentData->getStoreMethods($store, $quote) as $method) {
         if ($method instanceof MethodInterface) {
             $result[] = $method;
         }
     }
     return $result;
 }
Пример #2
0
 /**
  * @param \Magento\Quote\Api\Data\CartInterface $quote
  * @return \Magento\Payment\Model\MethodInterface[]
  * @api
  */
 public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote = null)
 {
     $store = $quote ? $quote->getStoreId() : null;
     $methods = [];
     foreach ($this->paymentHelper->getStoreMethods($store, $quote) as $method) {
         if ($this->_canUseMethod($method, $quote)) {
             $method->setInfoInstance($quote->getPayment());
             $methods[] = $method;
         }
     }
     return $methods;
 }
Пример #3
0
 /**
  * @param \Magento\Sales\Model\Quote $quote
  * @return \Magento\Payment\Model\MethodInterface[]
  */
 public function getAvailableMethods(\Magento\Sales\Model\Quote $quote = null)
 {
     $store = $quote ? $quote->getStoreId() : null;
     $methods = array();
     $specification = $this->methodSpecificationFactory->create(array(AbstractMethod::CHECK_ZERO_TOTAL));
     foreach ($this->paymentHelper->getStoreMethods($store, $quote) as $method) {
         if ($this->_canUseMethod($method, $quote) && $specification->isApplicable($method, $quote)) {
             $method->setInfoInstance($quote->getPayment());
             $methods[] = $method;
         }
     }
     return $methods;
 }
Пример #4
0
 /**
  * Retrieve available billing agreement methods
  *
  * @param null|string|bool|int|\Magento\Store\Model\Store $store
  * @param \Magento\Quote\Model\Quote|null $quote
  *
  * @return MethodInterface[]
  */
 public function getBillingAgreementMethods($store = null, $quote = null)
 {
     $pre = __METHOD__ . " : ";
     $this->_logger->debug($pre . 'bof');
     $result = [];
     foreach ($this->_paymentData->getStoreMethods($store, $quote) as $method) {
         if ($method instanceof MethodInterface) {
             $result[] = $method;
         }
     }
     $this->_logger->debug($pre . 'eof | result : ', $result);
     return $result;
 }
Пример #5
0
 /**
  * @param $method1 array
  * @param $method2 array
  *
  * @dataProvider getSortMethodsDataProvider
  */
 public function testSortMethods($method1, $method2)
 {
     $this->_initialConfig->expects($this->once())->method('getData')->will($this->returnValue(array(\Magento\Payment\Helper\Data::XML_PATH_PAYMENT_METHODS => array('method1' => $method1, 'method2 ' => $method2))));
     $this->_scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue('Magento\\Payment\\Model\\Method\\AbstractMethod'));
     $methodInstanceMock1 = $this->getMock('Magento\\Framework\\Object', array('isAvailable', 'getConfigData'), array(), '', false);
     $methodInstanceMock1->expects($this->any())->method('isAvailable')->will($this->returnValue(true));
     $methodInstanceMock1->expects($this->any())->method('getConfigData')->will($this->returnValue($method1['sort_order']));
     $methodInstanceMock2 = $this->getMock('Magento\\Framework\\Object', array('isAvailable', 'getConfigData'), array(), '', false);
     $methodInstanceMock2->expects($this->any())->method('isAvailable')->will($this->returnValue(true));
     $methodInstanceMock2->expects($this->any())->method('getConfigData')->will($this->returnValue($method2['sort_order']));
     $this->_methodFactory->expects($this->at(0))->method('create')->will($this->returnValue($methodInstanceMock1));
     $this->_methodFactory->expects($this->at(1))->method('create')->will($this->returnValue($methodInstanceMock2));
     $sortedMethods = $this->_helper->getStoreMethods();
     $this->assertTrue(array_shift($sortedMethods)->getSortOrder() < array_shift($sortedMethods)->getSortOrder());
 }
Пример #6
0
 /**
  * @param array $methodA
  * @param array $methodB
  *
  * @dataProvider getSortMethodsDataProvider
  */
 public function testSortMethods(array $methodA, array $methodB)
 {
     $this->initialConfig->expects($this->once())->method('getData')->will($this->returnValue([\Magento\Payment\Helper\Data::XML_PATH_PAYMENT_METHODS => [$methodA['code'] => $methodA['data'], $methodB['code'] => $methodB['data'], 'empty' => []]]));
     $this->scopeConfig->expects(new MethodInvokedAtIndex(0))->method('getValue')->with(sprintf('%s/%s/model', Data::XML_PATH_PAYMENT_METHODS, $methodA['code']))->will($this->returnValue('Magento\\Payment\\Model\\Method\\AbstractMethod'));
     $this->scopeConfig->expects(new MethodInvokedAtIndex(1))->method('getValue')->with(sprintf('%s/%s/model', Data::XML_PATH_PAYMENT_METHODS, $methodB['code']))->will($this->returnValue('Magento\\Payment\\Model\\Method\\AbstractMethod'));
     $this->scopeConfig->expects(new MethodInvokedAtIndex(2))->method('getValue')->with(sprintf('%s/%s/model', Data::XML_PATH_PAYMENT_METHODS, 'empty'))->will($this->returnValue(null));
     $methodInstanceMockA = $this->getMockBuilder('Magento\\Payment\\Model\\MethodInterface')->getMockForAbstractClass();
     $methodInstanceMockA->expects($this->any())->method('isAvailable')->will($this->returnValue(true));
     $methodInstanceMockA->expects($this->any())->method('getConfigData')->with('sort_order', null)->will($this->returnValue($methodA['data']['sort_order']));
     $methodInstanceMockB = $this->getMockBuilder('Magento\\Payment\\Model\\MethodInterface')->getMockForAbstractClass();
     $methodInstanceMockB->expects($this->any())->method('isAvailable')->will($this->returnValue(true));
     $methodInstanceMockB->expects($this->any())->method('getConfigData')->with('sort_order', null)->will($this->returnValue($methodB['data']['sort_order']));
     $this->methodFactory->expects($this->at(0))->method('create')->will($this->returnValue($methodInstanceMockA));
     $this->methodFactory->expects($this->at(1))->method('create')->will($this->returnValue($methodInstanceMockB));
     $sortedMethods = $this->helper->getStoreMethods();
     $this->assertTrue(array_shift($sortedMethods)->getConfigData('sort_order') < array_shift($sortedMethods)->getConfigData('sort_order'));
 }
Пример #7
0
 /**
  * Retrieve available billing agreement methods
  *
  * @param null|string|bool|int|\Magento\Store\Model\Store $store
  * @param \Magento\Sales\Model\Quote|null $quote
  * @return MethodInterface[]
  */
 public function getBillingAgreementMethods($store = null, $quote = null)
 {
     $result = array();
     foreach ($this->_paymentData->getStoreMethods($store, $quote) as $method) {
         if ($this->canManageBillingAgreements($method)) {
             $result[] = $method;
         }
     }
     return $result;
 }
Пример #8
0
 /**
  * @param \Magento\Quote\Api\Data\CartInterface $quote
  * @return \Magento\Payment\Model\MethodInterface[]
  * @api
  */
 public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote = null)
 {
     $store = $quote ? $quote->getStoreId() : null;
     $methods = [];
     $isFreeAdded = false;
     foreach ($this->paymentHelper->getStoreMethods($store, $quote) as $method) {
         if ($this->_canUseMethod($method, $quote)) {
             $method->setInfoInstance($quote->getPayment());
             $methods[] = $method;
             if ($method->getCode() == Free::PAYMENT_METHOD_FREE_CODE) {
                 $isFreeAdded = true;
             }
         }
     }
     if (!$isFreeAdded) {
         /** @var \Magento\Payment\Model\Method\Free $freeMethod */
         $freeMethod = $this->paymentHelper->getMethodInstance(Free::PAYMENT_METHOD_FREE_CODE);
         if ($freeMethod->isAvailableInConfig()) {
             $freeMethod->setInfoInstance($quote->getPayment());
             $methods[] = $freeMethod;
         }
     }
     return $methods;
 }
Пример #9
0
 /**
  * Retrieve available payment methods
  *
  * @return array
  */
 public function getMethods()
 {
     $methods = $this->getData('methods');
     if ($methods === null) {
         $quote = $this->getQuote();
         $store = $quote ? $quote->getStoreId() : null;
         $methods = [];
         $specification = $this->methodSpecificationFactory->create([AbstractMethod::CHECK_ZERO_TOTAL]);
         foreach ($this->_paymentHelper->getStoreMethods($store, $quote) as $method) {
             if ($this->_canUseMethod($method) && $specification->isApplicable($method, $this->getQuote())) {
                 $this->_assignMethod($method);
                 $methods[] = $method;
             }
         }
         $this->setData('methods', $methods);
     }
     return $methods;
 }