Skip to content

Commit 98ae1ef

Browse files
committed
Merge remote-tracking branch 'mpi/MDVA-293' into MDVA-293
2 parents 1eeb82b + 6d601d7 commit 98ae1ef

File tree

25 files changed

+722
-181
lines changed

25 files changed

+722
-181
lines changed

app/code/Magento/Braintree/Model/PaymentMethod.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use \Braintree_Exception;
1111
use \Braintree_Transaction;
1212
use \Braintree_Result_Successful;
13+
use Magento\Framework\DataObject;
1314
use Magento\Framework\Exception\LocalizedException;
1415
use Magento\Sales\Model\Order\Payment\Transaction;
1516
use Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\CollectionFactory as TransactionCollectionFactory;
@@ -254,15 +255,29 @@ public function __construct(
254255
*/
255256
public function assignData(\Magento\Framework\DataObject $data)
256257
{
257-
parent::assignData($data);
258+
$additionalData = $data->getAdditionalData();
259+
260+
if (!is_array($data->getAdditionalData())) {
261+
return $this;
262+
}
263+
$additionalData = new DataObject($additionalData);
264+
258265
$infoInstance = $this->getInfoInstance();
259266
if ($this->getConfigData('fraudprotection') > 0) {
260-
$infoInstance->setAdditionalInformation('device_data', $data->getData('device_data'));
267+
$infoInstance->setAdditionalInformation('device_data', $additionalData->getData('device_data'));
261268
}
262-
$infoInstance->setAdditionalInformation('cc_last4', $data->getData('cc_last4'));
263-
$infoInstance->setAdditionalInformation('cc_token', $data->getCcToken());
264-
$infoInstance->setAdditionalInformation('payment_method_nonce', $data->getPaymentMethodNonce());
265-
$infoInstance->setAdditionalInformation('store_in_vault', $data->getStoreInVault());
269+
270+
$infoInstance->setAdditionalInformation('cc_last4', $additionalData->getData('cc_last4'));
271+
$infoInstance->setAdditionalInformation('cc_token', $additionalData->getData('cc_token'));
272+
$infoInstance->setAdditionalInformation(
273+
'payment_method_nonce',
274+
$additionalData->getData('payment_method_nonce')
275+
);
276+
277+
$infoInstance->setCcLast4($additionalData->getData('cc_last4'));
278+
$infoInstance->setCcType($additionalData->getData('cc_type'));
279+
$infoInstance->setCcExpMonth($additionalData->getData('cc_exp_month'));
280+
$infoInstance->setCcExpYear($additionalData->getData('cc_exp_year'));
266281
return $this;
267282
}
268283

app/code/Magento/Braintree/Model/PaymentMethod/PayPal.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use \Braintree_Exception;
1111
use \Braintree_Transaction;
1212
use \Braintree_Result_Successful;
13+
use Magento\Framework\DataObject;
1314
use Magento\Framework\Exception\LocalizedException;
1415
use Magento\Braintree\Model\PaymentMethod;
1516
use Magento\Payment\Model\InfoInterface;
@@ -152,8 +153,18 @@ public function getConfigData($field, $storeId = null)
152153
*/
153154
public function assignData(\Magento\Framework\DataObject $data)
154155
{
156+
$additionalData = $data->getAdditionalData();
157+
158+
if (!is_array($data->getAdditionalData())) {
159+
return $this;
160+
}
161+
$additionalData = new DataObject($additionalData);
162+
155163
$infoInstance = $this->getInfoInstance();
156-
$infoInstance->setAdditionalInformation('payment_method_nonce', $data->getPaymentMethodNonce());
164+
$infoInstance->setAdditionalInformation(
165+
'payment_method_nonce',
166+
$additionalData->getData('payment_method_nonce')
167+
);
157168
return $this;
158169
}
159170

app/code/Magento/Braintree/Test/Unit/Model/PaymentMethod/PayPalTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,12 @@ public function testAssignData()
230230
$paymentMethodNonce = 'nonce';
231231
$storeInVault = true;
232232
$data = [
233-
'cc_last4' => $ccLast4,
234-
'cc_token' => $ccToken,
235-
'payment_method_nonce' => $paymentMethodNonce,
236-
'store_in_vault' => $storeInVault,
233+
'additional_data' => [
234+
'cc_last4' => $ccLast4,
235+
'cc_token' => $ccToken,
236+
'payment_method_nonce' => $paymentMethodNonce,
237+
'store_in_vault' => $storeInVault
238+
]
237239
];
238240
$data = new \Magento\Framework\DataObject($data);
239241
$this->model->setInfoInstance($this->infoInstanceMock);

app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php

Lines changed: 44 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use Magento\Braintree\Model\PaymentMethod;
1010
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
11+
use Magento\Payment\Model\InfoInterface;
12+
use Magento\Quote\Model\Quote\Payment;
1113
use Magento\Sales\Model\Order\Payment\Transaction;
1214
use \Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\CollectionFactory as TransactionCollectionFactory;
1315
use Magento\Framework\Exception\LocalizedException;
@@ -62,7 +64,7 @@ class PaymentMethodTest extends \PHPUnit_Framework_TestCase
6264
protected $registryMock;
6365

6466
/**
65-
* @var \Magento\Payment\Model\InfoInterface|\PHPUnit_Framework_MockObject_MockObject
67+
* @var Payment|\PHPUnit_Framework_MockObject_MockObject
6668
*/
6769
protected $infoInstanceMock;
6870

@@ -200,29 +202,25 @@ protected function setUp()
200202
'orderRepository' => $this->orderRepository
201203
]
202204
);
203-
$this->infoInstanceMock = $this->getMockForAbstractClass(
204-
'\Magento\Payment\Model\InfoInterface',
205-
[],
206-
'',
207-
false,
208-
false,
209-
false,
210-
[
211-
'setCcType',
212-
'setCcOwner',
213-
'setCcLast4',
214-
'setCcNumber',
215-
'setCcCid',
216-
'setCcExpMonth',
217-
'setCcExpYear',
218-
'setCcSsIssue',
219-
'setCcSsStartMonth',
220-
'setCcSsStartYear',
221-
'getOrder',
222-
'getQuote',
223-
'getCcType',
224-
]
225-
);
205+
$this->infoInstanceMock = $this->getMockBuilder(InfoInterface::class)
206+
->disableOriginalConstructor()
207+
->setMethods(
208+
[
209+
'setCcType',
210+
'setCcOwner',
211+
'setCcLast4',
212+
'setCcNumber',
213+
'setCcCid',
214+
'setCcExpMonth',
215+
'setCcExpYear',
216+
'setCcSsIssue',
217+
'setCcSsStartMonth',
218+
'setCcSsStartYear',
219+
'getOrder',
220+
'getQuote',
221+
'getCcType'
222+
]
223+
)->getMockForAbstractClass();
226224
$this->productMetaDataMock->expects($this->any())
227225
->method('getEdition')
228226
->willReturn('Community Edition');
@@ -234,7 +232,6 @@ protected function setUp()
234232
public function testAssignData()
235233
{
236234
$ccType = 'VI';
237-
$ccOwner = 'John Doe';
238235
$ccExpMonth = '10';
239236
$ccExpYear = '2020';
240237

@@ -244,15 +241,16 @@ public function testAssignData()
244241
$storeInVault = true;
245242
$deviceData = 'mobile';
246243
$data = [
247-
'cc_type' => $ccType,
248-
'cc_owner' => $ccOwner,
249-
'cc_exp_month' => $ccExpMonth,
250-
'cc_exp_year' => $ccExpYear,
251-
'cc_last4' => $ccLast4,
252-
'cc_token' => $ccToken,
253-
'payment_method_nonce' => $paymentMethodNonce,
254-
'store_in_vault' => $storeInVault,
255-
'device_data' => $deviceData,
244+
'additional_data' => [
245+
'cc_type' => $ccType,
246+
'cc_exp_month' => $ccExpMonth,
247+
'cc_exp_year' => $ccExpYear,
248+
'cc_last4' => $ccLast4,
249+
'cc_token' => $ccToken,
250+
'payment_method_nonce' => $paymentMethodNonce,
251+
'store_in_vault' => $storeInVault,
252+
'device_data' => $deviceData
253+
]
256254
];
257255
$data = new \Magento\Framework\DataObject($data);
258256
$this->model->setInfoInstance($this->infoInstanceMock);
@@ -265,21 +263,9 @@ public function testAssignData()
265263
->method('setCcType')
266264
->with($ccType)
267265
->willReturnSelf();
268-
$this->infoInstanceMock->expects($this->once())
269-
->method('setCcOwner')
270-
->with($ccOwner)
271-
->willReturnSelf();
272266
$this->infoInstanceMock->expects($this->once())
273267
->method('setCcLast4')
274-
->with(false)
275-
->willReturnSelf();
276-
$this->infoInstanceMock->expects($this->once())
277-
->method('setCcNumber')
278-
->with(null)
279-
->willReturnSelf();
280-
$this->infoInstanceMock->expects($this->once())
281-
->method('setCcCid')
282-
->with(null)
268+
->with($ccLast4)
283269
->willReturnSelf();
284270
$this->infoInstanceMock->expects($this->once())
285271
->method('setCcExpMonth')
@@ -289,34 +275,19 @@ public function testAssignData()
289275
->method('setCcExpYear')
290276
->with($ccExpYear)
291277
->willReturnSelf();
292-
$this->infoInstanceMock->expects($this->once())
293-
->method('setCcSsIssue')
294-
->with(null)
295-
->willReturnSelf();
296-
$this->infoInstanceMock->expects($this->once())
297-
->method('setCcSsStartMonth')
298-
->with(null)
299-
->willReturnSelf();
300-
$this->infoInstanceMock->expects($this->once())
301-
->method('setCcSsStartYear')
302-
->with(null)
303-
->willReturnSelf();
304278

305-
$this->infoInstanceMock->expects($this->at(10))
279+
$this->infoInstanceMock->expects($this->atLeastOnce())
306280
->method('setAdditionalInformation')
307-
->with('device_data', $deviceData);
308-
$this->infoInstanceMock->expects($this->at(11))
309-
->method('setAdditionalInformation')
310-
->with('cc_last4', $ccLast4);
311-
$this->infoInstanceMock->expects($this->at(12))
312-
->method('setAdditionalInformation')
313-
->with('cc_token', $ccToken);
314-
$this->infoInstanceMock->expects($this->at(13))
315-
->method('setAdditionalInformation')
316-
->with('payment_method_nonce', $paymentMethodNonce);
317-
$this->infoInstanceMock->expects($this->at(14))
318-
->method('setAdditionalInformation')
319-
->with('store_in_vault', $storeInVault);
281+
->willReturnMap(
282+
[
283+
['device_data', $deviceData],
284+
['cc_last4', $ccLast4],
285+
['cc_token', $ccToken],
286+
['payment_method_nonce', $paymentMethodNonce],
287+
['store_in_vault', $storeInVault]
288+
]
289+
);
290+
320291
$this->model->assignData($data);
321292
}
322293

app/code/Magento/OfflinePayments/Model/Purchaseorder.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ class Purchaseorder extends \Magento\Payment\Model\Method\AbstractMethod
4747
*/
4848
public function assignData(\Magento\Framework\DataObject $data)
4949
{
50-
if (!$data instanceof \Magento\Framework\DataObject) {
51-
$data = new \Magento\Framework\DataObject($data);
52-
}
53-
5450
$this->getInfoInstance()->setPoNumber($data->getPoNumber());
5551
return $this;
5652
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ protected function _initAdditionalInformation()
217217
{
218218
$additionalInfo = $this->_getData('additional_information');
219219
if (empty($this->_additionalInformation) && $additionalInfo) {
220-
if (!is_array($additionalInfo)) {
221-
$additionalInfo = unserialize($additionalInfo);
222-
}
223220
$this->_additionalInformation = $additionalInfo;
224221
}
225222
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
2121
* @SuppressWarnings(PHPMD.TooManyFields)
2222
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
23+
* @deprecated
2324
*/
2425
abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibleModel implements
2526
MethodInterface,
@@ -765,14 +766,10 @@ public function getConfigData($field, $storeId = null)
765766
* @return $this
766767
* @throws \Magento\Framework\Exception\LocalizedException
767768
* @api
769+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
768770
*/
769771
public function assignData(\Magento\Framework\DataObject $data)
770772
{
771-
if (is_array($data)) {
772-
$this->getInfoInstance()->addData($data);
773-
} elseif ($data instanceof \Magento\Framework\DataObject) {
774-
$this->getInfoInstance()->addData($data->getData());
775-
}
776773
return $this;
777774
}
778775

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,7 @@ public function assignData(\Magento\Framework\DataObject $data)
611611
'data' => $data
612612
]
613613
);
614-
615-
$this->getInfoInstance()->addData($data->getData());
614+
616615
return $this;
617616
}
618617

app/code/Magento/Payment/Test/Unit/Model/InfoTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ public function ccKeysDataProvider()
9090
];
9191
}
9292

93-
9493
public function testGetMethodInstanceWithRealMethod()
9594
{
9695
$method = 'real_method';
@@ -108,7 +107,6 @@ public function testGetMethodInstanceWithRealMethod()
108107
$this->info->getMethodInstance();
109108
}
110109

111-
112110
public function testGetMethodInstanceWithUnrealMethod()
113111
{
114112
$method = 'unreal_method';
@@ -131,7 +129,6 @@ public function testGetMethodInstanceWithUnrealMethod()
131129
$this->info->getMethodInstance();
132130
}
133131

134-
135132
/**
136133
* @expectedException \Magento\Framework\Exception\LocalizedException
137134
* @expectedExceptionMessage The payment method you requested is not available.
@@ -141,8 +138,7 @@ public function testGetMethodInstanceWithNoMethod()
141138
$this->info->setData('method', false);
142139
$this->info->getMethodInstance();
143140
}
144-
145-
141+
146142
public function testGetMethodInstanceRequestedMethod()
147143
{
148144
$code = 'real_method';
@@ -251,9 +247,9 @@ public function testHasAdditionalInformation()
251247

252248
public function testInitAdditionalInformationWithUnserialize()
253249
{
254-
$data = serialize(['key1' => 'data1', 'key2' => 'data2']);
250+
$data = ['key1' => 'data1', 'key2' => 'data2'];
255251
$this->info->setData('additional_information', $data);
256252

257-
$this->assertEquals(unserialize($data), $this->info->getAdditionalInformation());
253+
$this->assertEquals($data, $this->info->getAdditionalInformation());
258254
}
259255
}

app/code/Magento/Payment/Test/Unit/Model/Method/AbstractMethodTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Payment\Test\Unit\Model\Method;
77

8+
use Magento\Framework\DataObject;
9+
use Magento\Payment\Model\InfoInterface;
10+
use Magento\Payment\Observer\AbstractDataAssignObserver;
811
use Magento\Store\Model\ScopeInterface;
912
use Magento\Payment\Test\Unit\Model\Method\AbstractMethod\Stub;
1013

@@ -65,7 +68,7 @@ protected function setUp()
6568

6669
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
6770
$this->payment = $helper->getObject(
68-
'Magento\Payment\Test\Unit\Model\Method\AbstractMethod\Stub',
71+
Stub::class,
6972
[
7073
'scopeConfig' => $this->scopeConfigMock,
7174
'context' => $contextMock,

0 commit comments

Comments
 (0)