Skip to content

Commit 67f25b8

Browse files
committed
Merge branch 'MAGETWO-52359' into MPI-PR
2 parents 4de236b + 08cda66 commit 67f25b8

File tree

3 files changed

+204
-10
lines changed

3 files changed

+204
-10
lines changed

app/code/Magento/Braintree/view/adminhtml/web/js/vault.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
define([
88
'jquery',
99
'uiComponent',
10-
'Magento_Ui/js/modal/alert',
11-
'Magento_Checkout/js/model/full-screen-loader'
12-
], function ($, Class, alert, fullScreenLoader) {
10+
'Magento_Ui/js/modal/alert'
11+
], function ($, Class, alert) {
1312
'use strict';
1413

1514
return Class.extend({
@@ -84,7 +83,7 @@ define([
8483
submitOrder: function () {
8584
this.$selector.validate().form();
8685
this.$selector.trigger('afterValidate.beforeSubmit');
87-
fullScreenLoader.stopLoader();
86+
$('body').trigger('processStop');
8887

8988
// validate parent form
9089
if (this.$selector.validate().errorList.length) {
@@ -106,7 +105,7 @@ define([
106105
getPaymentMethodNonce: function () {
107106
var self = this;
108107

109-
fullScreenLoader.startLoader();
108+
$('body').trigger('processStart');
110109

111110
$.get(self.nonceUrl, {
112111
'public_hash': self.publicHash
@@ -115,10 +114,9 @@ define([
115114
self.placeOrder();
116115
}).fail(function (response) {
117116
var failed = JSON.parse(response.responseText);
118-
119117
self.error(failed.message);
120118
}).always(function () {
121-
fullScreenLoader.stopLoader();
119+
$('body').trigger('processStop');
122120
});
123121
},
124122

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public function getQuote()
145145
*/
146146
public function importData(array $data)
147147
{
148+
$data = $this->convertPaymentData($data);
148149
$data = new \Magento\Framework\DataObject($data);
149150
$this->_eventManager->dispatch(
150151
$this->_eventPrefix . '_import_data_before',
@@ -177,6 +178,37 @@ public function importData(array $data)
177178
return $this;
178179
}
179180

181+
/**
182+
* Converts request to payment data
183+
*
184+
* @param array $rawData
185+
* @return array
186+
*/
187+
private function convertPaymentData(array $rawData)
188+
{
189+
$paymentData = [
190+
PaymentInterface::KEY_METHOD => null,
191+
PaymentInterface::KEY_PO_NUMBER => null,
192+
PaymentInterface::KEY_ADDITIONAL_DATA => [],
193+
'checks' => []
194+
];
195+
196+
foreach (array_keys($rawData) as $requestKey) {
197+
if (!array_key_exists($requestKey, $paymentData)) {
198+
$paymentData[PaymentInterface::KEY_ADDITIONAL_DATA][$requestKey] = $rawData[$requestKey];
199+
} elseif ($requestKey === PaymentInterface::KEY_ADDITIONAL_DATA) {
200+
$paymentData[PaymentInterface::KEY_ADDITIONAL_DATA] = array_merge(
201+
$paymentData[PaymentInterface::KEY_ADDITIONAL_DATA],
202+
(array) $rawData[$requestKey]
203+
);
204+
} else {
205+
$paymentData[$requestKey] = $rawData[$requestKey];
206+
}
207+
}
208+
209+
return $paymentData;
210+
}
211+
180212
/**
181213
* Prepare object for save
182214
*
@@ -226,7 +258,7 @@ public function getOrderPlaceRedirectUrl()
226258
public function getMethodInstance()
227259
{
228260
$method = parent::getMethodInstance();
229-
$method->setStore($this->getQuote()->getStore()->getStoreId());
261+
$method->setStore($this->getQuote()->getStoreId());
230262
return $method;
231263
}
232264

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

Lines changed: 166 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
*/
66
namespace Magento\Quote\Test\Unit\Model\Quote;
77

8+
use Magento\Framework\DataObject;
9+
use Magento\Framework\Event\ManagerInterface;
10+
use Magento\Payment\Model\Checks\Composite;
11+
use Magento\Payment\Model\Checks\SpecificationFactory;
12+
use Magento\Payment\Model\MethodInterface;
13+
use Magento\Quote\Api\Data\PaymentInterface;
14+
use Magento\Quote\Model\Quote;
815
use \Magento\Quote\Model\Quote\Payment;
916

1017
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
@@ -16,11 +23,31 @@ class PaymentTest extends \PHPUnit_Framework_TestCase
1623
*/
1724
private $model;
1825

26+
/**
27+
* @var \PHPUnit_Framework_MockObject_MockObject|SpecificationFactory
28+
*/
29+
private $specificationFactory;
30+
31+
/**
32+
* @var \PHPUnit_Framework_MockObject_MockObject|ManagerInterface
33+
*/
34+
private $eventManager;
35+
1936
protected function setUp()
2037
{
2138
$objectManager = new ObjectManager($this);
39+
$this->specificationFactory = $this->getMockBuilder(
40+
SpecificationFactory::class
41+
)->disableOriginalConstructor()
42+
->getMock();
43+
$this->eventManager = $this->getMock(ManagerInterface::class);
44+
2245
$this->model = $objectManager->getObject(
23-
'\Magento\Quote\Model\Quote\Payment'
46+
Payment::class,
47+
[
48+
'methodSpecificationFactory' => $this->specificationFactory,
49+
'eventDispatcher' => $this->eventManager
50+
]
2451
);
2552
}
2653

@@ -32,7 +59,7 @@ protected function setUp()
3259
public function testGetCcExpYearReturnsValidValue($databaseValue, $expectedValue)
3360
{
3461
$this->model->setData('cc_exp_year', $databaseValue);
35-
$this->assertEquals($expectedValue, $this->model->getCcExpYear());
62+
static::assertEquals($expectedValue, $this->model->getCcExpYear());
3663
}
3764

3865
/**
@@ -47,4 +74,141 @@ public function yearValueDataProvider()
4774
[1939, 1939],
4875
];
4976
}
77+
78+
/**
79+
* @param array $data
80+
* @param array $convertedData
81+
* @param array $dataToAssign
82+
* @param array $checks
83+
* @dataProvider importDataPositiveCheckDataProvider
84+
*/
85+
public function testImportDataPositiveCheck(
86+
array $data,
87+
array $convertedData,
88+
array $dataToAssign,
89+
array $checks
90+
) {
91+
$quoteId = 1;
92+
$storeId = 1;
93+
94+
$paymentMethod = $this->getMock(MethodInterface::class);
95+
$quote = $this->getMockBuilder(Quote::class)
96+
->disableOriginalConstructor()
97+
->getMock();
98+
$methodSpecification = $this->getMockBuilder(Composite::class)
99+
->disableOriginalConstructor()
100+
->getMock();
101+
102+
$quote->expects(static::once())
103+
->method('getId')
104+
->willReturn($quoteId);
105+
106+
$this->model->setQuote($quote);
107+
$this->model->setMethodInstance($paymentMethod);
108+
$this->eventManager->expects(static::once())
109+
->method('dispatch')
110+
->with(
111+
'sales_quote_payment_import_data_before',
112+
[
113+
'payment' => $this->model,
114+
'input' => new DataObject($convertedData)
115+
]
116+
);
117+
$quote->expects(static::once())
118+
->method('getStoreId')
119+
->willReturn($storeId);
120+
121+
$quote->expects(static::once())
122+
->method('collectTotals');
123+
124+
$this->specificationFactory->expects(static::once())
125+
->method('create')
126+
->with($checks)
127+
->willReturn($methodSpecification);
128+
129+
$paymentMethod->expects(static::once())
130+
->method('isAvailable')
131+
->with($quote)
132+
->willReturn(true);
133+
$methodSpecification->expects(static::once())
134+
->method('isApplicable')
135+
->with($paymentMethod, $quote)
136+
->willReturn(true);
137+
138+
$paymentMethod->expects(static::once())
139+
->method('assignData')
140+
->with(new DataObject($dataToAssign));
141+
$paymentMethod->expects(static::once())
142+
->method('validate');
143+
144+
$this->model->importData($data);
145+
}
146+
147+
/**
148+
* @return array
149+
*/
150+
public function importDataPositiveCheckDataProvider()
151+
{
152+
return [
153+
[
154+
[
155+
PaymentInterface::KEY_METHOD => 'payment_method_code',
156+
'cc_number' => '1111',
157+
'cc_type' => 'VI',
158+
'cc_owner' => 'John Doe'
159+
],
160+
[
161+
PaymentInterface::KEY_METHOD => 'payment_method_code',
162+
PaymentInterface::KEY_PO_NUMBER => null,
163+
PaymentInterface::KEY_ADDITIONAL_DATA => [
164+
'cc_number' => '1111',
165+
'cc_type' => 'VI',
166+
'cc_owner' => 'John Doe'
167+
],
168+
'checks' => []
169+
],
170+
[
171+
PaymentInterface::KEY_METHOD => 'payment_method_code',
172+
PaymentInterface::KEY_PO_NUMBER => null,
173+
PaymentInterface::KEY_ADDITIONAL_DATA => [
174+
'cc_number' => '1111',
175+
'cc_type' => 'VI',
176+
'cc_owner' => 'John Doe'
177+
],
178+
'checks' => []
179+
],
180+
[]
181+
],
182+
[
183+
[
184+
PaymentInterface::KEY_METHOD => 'payment_method_code',
185+
'cc_number' => '1111',
186+
'cc_type' => 'VI',
187+
'cc_owner' => 'John Doe',
188+
'checks' => ['check_code1', 'check_code2']
189+
],
190+
[
191+
PaymentInterface::KEY_METHOD => 'payment_method_code',
192+
PaymentInterface::KEY_PO_NUMBER => null,
193+
PaymentInterface::KEY_ADDITIONAL_DATA => [
194+
'cc_number' => '1111',
195+
'cc_type' => 'VI',
196+
'cc_owner' => 'John Doe'
197+
],
198+
'checks' => ['check_code1', 'check_code2']
199+
],
200+
[
201+
PaymentInterface::KEY_METHOD => 'payment_method_code',
202+
PaymentInterface::KEY_PO_NUMBER => null,
203+
PaymentInterface::KEY_ADDITIONAL_DATA => [
204+
'cc_number' => '1111',
205+
'cc_type' => 'VI',
206+
'cc_owner' => 'John Doe'
207+
],
208+
'checks' => ['check_code1', 'check_code2']
209+
],
210+
['check_code1', 'check_code2']
211+
]
212+
];
213+
}
50214
}

0 commit comments

Comments
 (0)