Skip to content

Commit 3c66c19

Browse files
committed
Merge pull request #306 from magento-mpi/MAGETWO-32004
[MPI] Sprint & bugfixes
2 parents fb8412d + 9121811 commit 3c66c19

File tree

10 files changed

+180
-17
lines changed

10 files changed

+180
-17
lines changed

app/code/Magento/OfflinePayments/Block/Form/AbstractInstruction.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ abstract class AbstractInstruction extends \Magento\Payment\Block\Form
2020
/**
2121
* Get instructions text from config
2222
*
23-
* @return string
23+
* @return null|string
2424
*/
2525
public function getInstructions()
2626
{
2727
if ($this->_instructions === null) {
28-
$this->_instructions = $this->getMethod()->getInstructions();
28+
/** @var \Magento\Payment\Model\Method\AbstractMethod $method */
29+
$method = $this->getMethod();
30+
$this->_instructions = $method->getConfigData('instructions');
2931
}
3032
return $this->_instructions;
3133
}

app/code/Magento/OfflinePayments/Test/Unit/Block/Form/AbstractInstructionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public function testGetInstructions()
2525
{
2626
$method = $this->getMock(
2727
'Magento\Payment\Model\MethodInterface',
28-
['getInstructions', 'getCode', 'getFormBlockType', 'getTitle'],
28+
['getConfigData', 'getCode', 'getFormBlockType', 'getTitle'],
2929
[],
3030
'',
3131
false
3232
);
3333
$method->expects($this->once())
34-
->method('getInstructions')
34+
->method('getConfigData')
3535
->willReturn('instructions');
3636
$this->_model->setData('method', $method);
3737

app/code/Magento/Payment/Model/Method/AbstractMethod.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,6 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl
207207
*/
208208
protected $_scopeConfig;
209209

210-
/**
211-
* Core event manager proxy
212-
*
213-
* @var \Magento\Framework\Event\ManagerInterface
214-
*/
215-
protected $_eventManager;
216-
217210
/**
218211
* @var \Psr\Log\LoggerInterface
219212
*/
@@ -252,7 +245,6 @@ public function __construct(
252245
);
253246
$this->_paymentData = $paymentData;
254247
$this->_scopeConfig = $scopeConfig;
255-
$this->_eventManager = $context->getEventDispatcher();
256248
$this->logger = $context->getLogger();
257249
$this->initializeData($data);
258250
}
@@ -765,6 +757,17 @@ public function getTitle()
765757
return $this->getConfigData('title');
766758
}
767759

760+
/**
761+
* Retrieve fraud message if exists
762+
*
763+
* @return string
764+
* @throws \Magento\Framework\Exception\LocalizedException
765+
*/
766+
public function getFraudMessage()
767+
{
768+
return $this->getInfoInstance()->getAdditionalInformation('fraud_msg');
769+
}
770+
768771
/**
769772
* Retrieve information from payment configuration
770773
*
@@ -819,18 +822,33 @@ public function prepareSave()
819822
public function isAvailable($quote = null)
820823
{
821824
$checkResult = new \StdClass();
822-
$isActive = (bool)(int)$this->getConfigData('active', $quote ? $quote->getStoreId() : null);
825+
$isActive = $this->isActive($quote ? $quote->getStoreId() : null);
823826
$checkResult->isAvailable = $isActive;
824827
$checkResult->isDeniedInConfig = !$isActive;
825828
// for future use in observers
826829
$this->_eventManager->dispatch(
827830
'payment_method_is_active',
828-
['result' => $checkResult, 'method_instance' => $this, 'quote' => $quote]
831+
[
832+
'result' => $checkResult,
833+
'method_instance' => $this,
834+
'quote' => $quote
835+
]
829836
);
830837

831838
return $checkResult->isAvailable;
832839
}
833840

841+
/**
842+
* Is active
843+
*
844+
* @param int|null $storeId
845+
* @return bool
846+
*/
847+
public function isActive($storeId = null)
848+
{
849+
return (bool)(int)$this->getConfigData('active', $storeId);
850+
}
851+
834852
/**
835853
* Method that will be executed instead of authorize or capture
836854
* if flag isInitializeNeeded set to true

app/code/Magento/Payment/Model/Method/Free.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function isAvailable($quote = null)
103103
* @param \Magento\Quote\Model\Quote|null $quote
104104
* @return bool
105105
*/
106-
public function isActive($quote = null)
106+
public function isAvailableInConfig($quote = null)
107107
{
108108
return parent::isAvailable($quote);
109109
}

app/code/Magento/Payment/Model/MethodList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote
5555
if (!$isFreeAdded) {
5656
/** @var \Magento\Payment\Model\Method\Free $freeMethod */
5757
$freeMethod = $this->paymentHelper->getMethodInstance(Free::PAYMENT_METHOD_FREE_CODE);
58-
if ($freeMethod->isActive()) {
58+
if ($freeMethod->isAvailableInConfig()) {
5959
$freeMethod->setInfoInstance($quote->getPayment());
6060
$methods[] = $freeMethod;
6161
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Test\Unit\Model\Method\AbstractMethod;
7+
8+
/**
9+
* Class Stub
10+
*
11+
* Stub for \Magento\Payment\Model\Method\AbstractMethod
12+
*/
13+
class Stub extends \Magento\Payment\Model\Method\AbstractMethod
14+
{
15+
const STUB_CODE = 'stub-code';
16+
17+
/**
18+
* @return string
19+
*/
20+
public function getCode()
21+
{
22+
return static::STUB_CODE;
23+
}
24+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Test\Unit\Model\Method;
7+
8+
use Magento\Store\Model\ScopeInterface;
9+
use Magento\Payment\Test\Unit\Model\Method\AbstractMethod\Stub;
10+
11+
/**
12+
* Class AbstractMethodTest
13+
*
14+
* Test for class \Magento\Payment\Model\Method\AbstractMethod
15+
*/
16+
class AbstractMethodTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @var \Magento\Payment\Model\Method\AbstractMethod
20+
*/
21+
protected $payment;
22+
23+
/**
24+
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
protected $scopeConfigMock;
27+
28+
/**
29+
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
protected $eventManagerMock;
32+
33+
/**
34+
* @var \Magento\Quote\Api\Data\CartInterface|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
protected $quoteMock;
37+
38+
protected function setUp()
39+
{
40+
$this->scopeConfigMock = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')
41+
->setMethods(['getValue'])
42+
->getMockForAbstractClass();
43+
$this->eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface')
44+
->setMethods(['dispatch'])
45+
->getMockForAbstractClass();
46+
$this->quoteMock = $this->getMockBuilder('Magento\Quote\Api\Data\CartInterface')
47+
->setMethods(['getStoreId'])
48+
->getMockForAbstractClass();
49+
$contextMock = $this->getMockBuilder('Magento\Framework\Model\Context')
50+
->disableOriginalConstructor()
51+
->setMethods(['getEventDispatcher'])
52+
->getMock();
53+
54+
$contextMock->expects($this->once())
55+
->method('getEventDispatcher')
56+
->willReturn($this->eventManagerMock);
57+
58+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
59+
60+
$this->payment = $helper->getObject(
61+
'Magento\Payment\Test\Unit\Model\Method\AbstractMethod\Stub',
62+
[
63+
'scopeConfig' => $this->scopeConfigMock,
64+
'context' => $contextMock
65+
]
66+
);
67+
}
68+
69+
/**
70+
* @param bool $result
71+
*
72+
* @dataProvider dataProviderForTestIsAvailable
73+
*/
74+
public function testIsAvailable($result)
75+
{
76+
$storeId = 15;
77+
$this->quoteMock->expects($this->once())
78+
->method('getStoreId')
79+
->willReturn($storeId);
80+
81+
$this->scopeConfigMock->expects($this->once())
82+
->method('getValue')
83+
->with(
84+
'payment/' . Stub::STUB_CODE . '/active',
85+
ScopeInterface::SCOPE_STORE,
86+
$storeId
87+
)->willReturn($result);
88+
89+
$this->eventManagerMock->expects($this->once())
90+
->method('dispatch')
91+
->with(
92+
$this->equalTo('payment_method_is_active'),
93+
$this->countOf(3)
94+
);
95+
96+
$this->assertEquals($result, $this->payment->isAvailable($this->quoteMock));
97+
}
98+
99+
/**
100+
* @return array
101+
*/
102+
public function dataProviderForTestIsAvailable()
103+
{
104+
return [
105+
[
106+
'result' => true
107+
],
108+
[
109+
'result' => false
110+
],
111+
];
112+
}
113+
}

app/code/Magento/Payment/view/frontend/templates/transparent/iframe.phtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ $params = $block->getParams();
1818
window.top.location="<?php echo $block->escapeXssInUrl($params['redirect_parent']) ?>";
1919
<?php elseif (isset($params['error_msg'])): ?>
2020
window.top.alert(<?php echo $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($params['error_msg']) ?>);
21+
var require = window.top.require;
22+
require(['jquery'], function($) {
23+
$('#opc-review').trigger('hideAjaxLoader');
24+
});
2125
<?php elseif (isset($params['order_success'])): ?>
2226
window.top.location = "<?php echo $params['order_success'] ?>";
2327
<?php else: ?>

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
414414
$this->customerManagement->populateCustomerInfo($quote);
415415
}
416416
$addresses = [];
417+
$quote->reserveOrderId();
417418
if ($quote->isVirtual()) {
418419
$this->dataObjectHelper->mergeDataObjects(
419420
'\Magento\Sales\Api\Data\OrderInterface',

app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,8 @@ protected function getQuote(
824824
'getId',
825825
'getCustomer',
826826
'getAllItems',
827-
'getPayment'
827+
'getPayment',
828+
'reserveOrderId'
828829
],
829830
[],
830831
'',

0 commit comments

Comments
 (0)