public function testCreate()
 {
     $specification = $this->getMockBuilder('Magento\\Payment\\Model\\Checks\\SpecificationInterface')->disableOriginalConstructor()->setMethods([])->getMock();
     $specificationMapping = [self::SPECIFICATION_KEY => $specification];
     $expectedComposite = $this->getMockBuilder('Magento\\Payment\\Model\\Checks\\Composite')->disableOriginalConstructor()->setMethods([])->getMock();
     $modelFactory = new SpecificationFactory($this->_compositeFactory, $specificationMapping);
     $this->_compositeFactory->expects($this->once())->method('create')->with(['list' => $specificationMapping])->will($this->returnValue($expectedComposite));
     $this->assertEquals($expectedComposite, $modelFactory->create([self::SPECIFICATION_KEY]));
 }
Exemplo n.º 2
0
 /**
  * @param array $data
  * @param array $convertedData
  * @param array $dataToAssign
  * @param array $checks
  * @dataProvider importDataPositiveCheckDataProvider
  */
 public function testImportDataPositiveCheck(array $data, array $convertedData, array $dataToAssign, array $checks)
 {
     $quoteId = 1;
     $storeId = 1;
     $paymentMethod = $this->getMock(MethodInterface::class);
     $quote = $this->getMockBuilder(Quote::class)->disableOriginalConstructor()->getMock();
     $methodSpecification = $this->getMockBuilder(Composite::class)->disableOriginalConstructor()->getMock();
     $quote->expects(static::once())->method('getId')->willReturn($quoteId);
     $this->model->setQuote($quote);
     $this->model->setMethodInstance($paymentMethod);
     $this->eventManager->expects(static::once())->method('dispatch')->with('sales_quote_payment_import_data_before', ['payment' => $this->model, 'input' => new DataObject($convertedData)]);
     $quote->expects(static::once())->method('getStoreId')->willReturn($storeId);
     $quote->expects(static::once())->method('collectTotals');
     $this->specificationFactory->expects(static::once())->method('create')->with($checks)->willReturn($methodSpecification);
     $paymentMethod->expects(static::once())->method('isAvailable')->with($quote)->willReturn(true);
     $methodSpecification->expects(static::once())->method('isApplicable')->with($paymentMethod, $quote)->willReturn(true);
     $paymentMethod->expects(static::once())->method('assignData')->with(new DataObject($dataToAssign));
     $paymentMethod->expects(static::once())->method('validate');
     $this->model->importData($data);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 /**
  * Import data array to payment method object,
  * Method calls quote totals collect because payment method availability
  * can be related to quote totals
  *
  * @param array $data
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 public function importData(array $data)
 {
     $data = new \Magento\Framework\Object($data);
     $this->_eventManager->dispatch($this->_eventPrefix . '_import_data_before', array($this->_eventObject => $this, 'input' => $data));
     $this->setMethod($data->getMethod());
     $method = $this->getMethodInstance();
     /**
      * Payment availability related with quote totals.
      * We have to recollect quote totals before checking
      */
     $this->getQuote()->collectTotals();
     if (!$method->isAvailable($this->getQuote()) || !$this->methodSpecificationFactory->create($data->getChecks())->isApplicable($method, $this->getQuote())) {
         throw new \Magento\Framework\Model\Exception(__('The requested Payment Method is not available.'));
     }
     $method->assignData($data);
     /*
      * validating the payment data
      */
     $method->validate();
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Check payment method model
  *
  * @param \Magento\Payment\Model\MethodInterface $method
  * @param \Magento\Sales\Model\Quote $quote
  * @return bool
  */
 protected function _canUseMethod($method, \Magento\Sales\Model\Quote $quote)
 {
     return $this->methodSpecificationFactory->create(array(AbstractMethod::CHECK_USE_FOR_COUNTRY, AbstractMethod::CHECK_USE_FOR_CURRENCY, AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX))->isApplicable($method, $quote);
 }
Exemplo n.º 6
0
 /**
  * Check payment method model
  *
  * @param \Magento\Payment\Model\MethodInterface $method
  * @param \Magento\Quote\Api\Data\CartInterface $quote
  * @return bool
  */
 protected function _canUseMethod($method, \Magento\Quote\Api\Data\CartInterface $quote)
 {
     return $this->methodSpecificationFactory->create([AbstractMethod::CHECK_USE_FOR_COUNTRY, AbstractMethod::CHECK_USE_FOR_CURRENCY, AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX])->isApplicable($method, $quote);
 }