Skip to content

Commit 955cc64

Browse files
committed
MAGETWO-53865: [GITHUB#4741] CC Model doesn't assigns cc data passed in additional_data field
1 parent 04795a6 commit 955cc64

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
*/
66
namespace Magento\Payment\Model\Method;
77

8+
use Magento\Framework\DataObject;
9+
use Magento\Quote\Api\Data\PaymentInterface;
10+
use Magento\Quote\Model\Quote\Payment;
11+
812
/**
913
* @method \Magento\Quote\Api\Data\PaymentMethodExtensionInterface getExtensionAttributes()
1014
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
* @deprecated
1116
*/
1217
class Cc extends \Magento\Payment\Model\Method\AbstractMethod
1318
{
@@ -237,6 +242,40 @@ protected function _validateExpDate($expYear, $expMonth)
237242
return true;
238243
}
239244

245+
/**
246+
* Assign data to info model instance
247+
*
248+
* @param \Magento\Framework\DataObject|mixed $data
249+
* @return $this
250+
* @throws \Magento\Framework\Exception\LocalizedException
251+
*/
252+
public function assignData(\Magento\Framework\DataObject $data)
253+
{
254+
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
255+
if (!is_object($additionalData)) {
256+
$additionalData = new DataObject($additionalData ?: []);
257+
}
258+
259+
/** @var DataObject $info */
260+
$info = $this->getInfoInstance();
261+
$info->addData(
262+
[
263+
'cc_type' => $additionalData->getCcType(),
264+
'cc_owner' => $additionalData->getCcOwner(),
265+
'cc_last_4' => substr($additionalData->getCcNumber(), -4),
266+
'cc_number' => $additionalData->getCcNumber(),
267+
'cc_cid' => $additionalData->getCcCid(),
268+
'cc_exp_month' => $additionalData->getCcExpMonth(),
269+
'cc_exp_year' => $additionalData->getCcExpYear(),
270+
'cc_ss_issue' => $additionalData->getCcSsIssue(),
271+
'cc_ss_start_month' => $additionalData->getCcSsStartMonth(),
272+
'cc_ss_start_year' => $additionalData->getCcSsStartYear()
273+
]
274+
);
275+
276+
return $this;
277+
}
278+
240279
/**
241280
* @param string $type
242281
* @return bool
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Test\Unit\Model\Method;
7+
8+
use Magento\Framework\DataObject;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Payment\Model\Method\Cc;
11+
use Magento\Quote\Api\Data\PaymentInterface;
12+
use Magento\Quote\Model\Quote\Payment;
13+
14+
class CcTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @var Cc
18+
*/
19+
private $ccModel;
20+
21+
public function setUp()
22+
{
23+
$objectManager = new ObjectManager($this);
24+
$this->ccModel = $objectManager->getObject(Cc::class);
25+
}
26+
27+
public function testAssignData()
28+
{
29+
$additionalData = [
30+
'cc_type' => 'VI',
31+
'cc_owner' => 'Bruce',
32+
'cc_number' => '41111111111111',
33+
'cc_cid' => '42',
34+
'cc_exp_month' => '02',
35+
'cc_exp_year' => '30',
36+
'cc_ss_issue' => '9',
37+
'cc_ss_start_month' => '01',
38+
'cc_ss_start_year' => '30'
39+
];
40+
41+
$inputData = new DataObject(
42+
[
43+
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData
44+
]
45+
);
46+
47+
$payment = $this->getMockBuilder(Payment::class)
48+
->disableOriginalConstructor()
49+
->getMock();
50+
51+
$expectedData = [
52+
'cc_type' => 'VI',
53+
'cc_owner' => 'Bruce',
54+
'cc_last_4' => '1111',
55+
'cc_number' => '41111111111111',
56+
'cc_cid' => '42',
57+
'cc_exp_month' => '02',
58+
'cc_exp_year' => '30',
59+
'cc_ss_issue' => '9',
60+
'cc_ss_start_month' => '01',
61+
'cc_ss_start_year' => '30'
62+
];
63+
64+
$payment->expects(static::once())
65+
->method('addData')
66+
->with(
67+
$expectedData
68+
);
69+
70+
$this->ccModel->setInfoInstance($payment);
71+
$this->ccModel->assignData($inputData);
72+
}
73+
}

0 commit comments

Comments
 (0)