Skip to content

Commit 7132a37

Browse files
committed
MAGETWO-38902: Payment\Gateway update
- removed redundant code - Create NullCommand - Data adapters extended - added payment gateway context assertions
1 parent 724285e commit 7132a37

File tree

17 files changed

+289
-173
lines changed

17 files changed

+289
-173
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Block;
7+
8+
use Magento\Framework\Phrase;
9+
use Magento\Framework\View\Element\Template\Context;
10+
use Magento\Payment\Gateway\ConfigInterface;
11+
12+
class ConfigurableInfo extends \Magento\Payment\Block\Info
13+
{
14+
/**
15+
* @var ConfigInterface
16+
*/
17+
private $config;
18+
19+
/**
20+
* @param Context $context
21+
* @param ConfigInterface $config
22+
* @param array $data
23+
*/
24+
public function __construct(
25+
Context $context,
26+
ConfigInterface $config,
27+
array $data = []
28+
) {
29+
parent::__construct($context, $data);
30+
$this->config = $config;
31+
32+
if (isset($data['pathPattern'])) {
33+
$this->config->setPathPattern($data['pathPattern']);
34+
}
35+
36+
if (isset($data['pathPattern'])) {
37+
$this->config->setMethodCode($data['methodCode']);
38+
}
39+
}
40+
41+
/**
42+
* Prepare PayPal-specific payment information
43+
*
44+
* @param \Magento\Framework\Object|array|null $transport
45+
* @return \Magento\Framework\Object
46+
*/
47+
protected function _prepareSpecificInformation($transport = null)
48+
{
49+
$transport = parent::_prepareSpecificInformation($transport);
50+
$payment = $this->getInfo();
51+
$fieldsToStore = explode(',', (string)$this->config->getValue('paymentInfoKeys'));
52+
if ($this->getIsSecureMode()) {
53+
$fieldsToStore = array_diff(
54+
$fieldsToStore,
55+
explode(',', (string)$this->config->getValue('privateInfoKeys'))
56+
);
57+
}
58+
59+
foreach ($fieldsToStore as $field) {
60+
if ($payment->getAdditionalInformation($field) !== null) {
61+
$transport->setData(
62+
(string)$this->getLabel($field),
63+
(string)$this->getValueView(
64+
$field,
65+
$payment->getAdditionalInformation($field)
66+
)
67+
);
68+
}
69+
}
70+
71+
return $transport;
72+
}
73+
74+
/**
75+
* Returns label
76+
*
77+
* @param string $field
78+
* @return string | Phrase
79+
*/
80+
protected function getLabel($field)
81+
{
82+
return $field;
83+
}
84+
85+
/**
86+
* Returns value view
87+
*
88+
* @param string $field
89+
* @param string $value
90+
* @return string | Phrase
91+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
92+
*/
93+
protected function getValueView($field, $value)
94+
{
95+
return $value;
96+
}
97+
}

app/code/Magento/Payment/Block/Info/Cc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ protected function _prepareSpecificInformation($transport = null)
101101
if ($this->getInfo()->getCcLast4()) {
102102
$data[(string)__('Credit Card Number')] = sprintf('xxxx-%s', $this->getInfo()->getCcLast4());
103103
}
104+
104105
if (!$this->getIsSecureMode()) {
105106
if ($ccSsIssue = $this->getInfo()->getCcSsIssue()) {
106107
$data[(string)__('Switch/Solo/Maestro Issue Number')] = $ccSsIssue;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Gateway\Command;
7+
8+
use Magento\Payment\Gateway\Command;
9+
use Magento\Payment\Gateway\CommandInterface;
10+
11+
class NullCommand implements CommandInterface
12+
{
13+
/**
14+
* Null command. Does nothing. Stable.
15+
*
16+
* @param array $commandSubject
17+
*
18+
* @return null|Command\ResultInterface
19+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
20+
*/
21+
public function execute(array $commandSubject)
22+
{
23+
return null;
24+
}
25+
}

app/code/Magento/Payment/Gateway/Config/Config.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,36 @@ class Config implements ConfigInterface
3535
*/
3636
public function __construct(
3737
ScopeConfigInterface $scopeConfig,
38-
$methodCode,
38+
$methodCode = '',
3939
$pathPattern = self::DEFAULT_PATH_PATTERN
4040
) {
4141
$this->scopeConfig = $scopeConfig;
4242
$this->methodCode = $methodCode;
4343
$this->pathPattern = $pathPattern;
4444
}
4545

46+
/**
47+
* Sets method code
48+
*
49+
* @param string $methodCode
50+
* @return void
51+
*/
52+
public function setMethodCode($methodCode)
53+
{
54+
$this->methodCode = $methodCode;
55+
}
56+
57+
/**
58+
* Sets path pattern
59+
*
60+
* @param string $pathPattern
61+
* @return void
62+
*/
63+
public function setPathPattern($pathPattern)
64+
{
65+
$this->pathPattern = $pathPattern;
66+
}
67+
4668
/**
4769
* Retrieve information from payment configuration
4870
*

app/code/Magento/Payment/Gateway/ConfigInterface.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,20 @@ interface ConfigInterface
1616
* @return mixed
1717
*/
1818
public function getValue($field, $storeId = null);
19+
20+
/**
21+
* Sets method code
22+
*
23+
* @param string $methodCode
24+
* @return void
25+
*/
26+
public function setMethodCode($methodCode);
27+
28+
/**
29+
* Sets path pattern
30+
*
31+
* @param string $pathPattern
32+
* @return void
33+
*/
34+
public function setPathPattern($pathPattern);
1935
}

app/code/Magento/Payment/Gateway/Data/AddressAdapterInterface.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,6 @@ public function getCustomerId();
9494
*/
9595
public function getEmail();
9696

97-
/**
98-
* Returns street
99-
*
100-
* @return string
101-
*/
102-
public function getStreet();
103-
104-
/**
105-
* Returns region
106-
*
107-
* @return string
108-
*/
109-
public function getRegion();
110-
11197
/**
11298
* Returns name prefix
11399
*

app/code/Magento/Payment/Gateway/Data/Order/AddressAdapter.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,6 @@ public function getEmail()
148148
return $this->address->getEmail();
149149
}
150150

151-
/**
152-
* Returns street
153-
*
154-
* @return string[]
155-
*/
156-
public function getStreet()
157-
{
158-
return $this->address->getStreet();
159-
}
160-
161-
/**
162-
* Returns region
163-
*
164-
* @return string
165-
*/
166-
public function getRegion()
167-
{
168-
return $this->address->getRegion();
169-
}
170-
171151
/**
172152
* Returns name prefix
173153
*

app/code/Magento/Payment/Gateway/Data/Order/OrderAdapter.php

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -110,48 +110,6 @@ public function getId()
110110
return $this->order->getEntityId();
111111
}
112112

113-
/**
114-
* Returns order increment id
115-
*
116-
* @return string
117-
*
118-
*/
119-
public function getIncrementId()
120-
{
121-
return $this->order->getIncrementId();
122-
}
123-
124-
/**
125-
* Returns quote id
126-
*
127-
* @return int
128-
*/
129-
public function getQuoteId()
130-
{
131-
return $this->order->getQuoteId();
132-
}
133-
134-
/**
135-
* Returns order grand total
136-
*
137-
* @return float
138-
*/
139-
public function getGrandTotal()
140-
{
141-
return $this->order->getGrandTotal();
142-
}
143-
144-
/**
145-
* Returns base currency code
146-
*
147-
* @return string
148-
*/
149-
public function getBaseCurrencyCode()
150-
{
151-
return $this->order->getBaseCurrencyCode();
152-
153-
}
154-
155113
/**
156114
* Returns order grand total amount
157115
*

app/code/Magento/Payment/Gateway/Data/OrderAdapterInterface.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,40 +59,10 @@ public function getStoreId();
5959
*/
6060
public function getId();
6161

62-
/**
63-
* Returns order increment id
64-
*
65-
* @return string
66-
*
67-
*/
68-
public function getIncrementId();
69-
70-
/**
71-
* Returns quote id
72-
*
73-
* @return int
74-
*/
75-
public function getQuoteId();
76-
77-
/**
78-
* Returns order grand total
79-
*
80-
* @return float
81-
*/
82-
public function getGrandTotal();
83-
84-
/**
85-
* Returns base currency code
86-
*
87-
* @return string
88-
*/
89-
public function getBaseCurrencyCode();
90-
9162
/**
9263
* Returns order grand total amount
9364
*
9465
* @return float
9566
*/
9667
public function getGrandTotalAmount();
97-
9868
}

app/code/Magento/Payment/Gateway/Data/Quote/AddressAdapter.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,6 @@ public function getEmail()
148148
return $this->address->getEmail();
149149
}
150150

151-
/**
152-
* Returns street
153-
*
154-
* @return string[]
155-
*/
156-
public function getStreet()
157-
{
158-
return $this->address->getStreet();
159-
}
160-
161-
/**
162-
* Returns region
163-
*
164-
* @return string
165-
*/
166-
public function getRegion()
167-
{
168-
return $this->address->getRegion();
169-
}
170-
171151
/**
172152
* Returns name prefix
173153
*

0 commit comments

Comments
 (0)