Skip to content

Commit 9c3137c

Browse files
committed
Merge pull request #350 from magento-mpi/MAGETWO-38191
MAGETWO-38191: Contribute payment service API to mainline
2 parents f4bcca8 + 85dabe3 commit 9c3137c

File tree

111 files changed

+4815
-435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+4815
-435
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@ protected function setUp()
2323

2424
public function testGetInstructions()
2525
{
26-
$method = $this->getMock(
27-
'Magento\Payment\Model\MethodInterface',
28-
['getConfigData', 'getCode', 'getFormBlockType', 'getTitle'],
29-
[],
30-
'',
31-
false
32-
);
26+
$method = $this->getMockBuilder('Magento\Payment\Model\MethodInterface')
27+
->getMockForAbstractClass();
28+
3329
$method->expects($this->once())
3430
->method('getConfigData')
3531
->willReturn('instructions');

app/code/Magento/OfflinePayments/Test/Unit/Model/ObserverTest.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@ public function testBeforeOrderPaymentSaveWithInstructions($methodCode)
4343
$payment->expects($this->once())
4444
->method('setAdditionalInformation')
4545
->with('instructions', 'payment configuration');
46-
$method = $this->getMock(
47-
'Magento\Payment\Model\MethodInterface',
48-
['getInstructions', 'getFormBlockType', 'getTitle', 'getCode'],
49-
[],
50-
'',
51-
false
52-
);
46+
$method = $this->getMockBuilder('\Magento\OfflinePayments\Model\Banktransfer')
47+
->disableOriginalConstructor()
48+
->getMock();
49+
5350
$method->expects($this->once())
5451
->method('getInstructions')
5552
->willReturn('payment configuration');
@@ -96,13 +93,9 @@ public function testBeforeOrderPaymentSaveWithCheckmo()
9693
]
9794
);
9895

99-
$method = $this->getMock(
100-
'Magento\Payment\Model\MethodInterface',
101-
['getPayableTo', 'getMailingAddress', 'getFormBlockType', 'getTitle', 'getCode'],
102-
[],
103-
'',
104-
false
105-
);
96+
$method = $this->getMockBuilder('Magento\OfflinePayments\Model\Checkmo')
97+
->disableOriginalConstructor()
98+
->getMock();
10699
$method->expects($this->once())
107100
->method('getPayableTo')
108101
->willReturn('payable to');

app/code/Magento/Payment/Block/Transparent/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function getCgiUrl()
168168
*/
169169
public function getMethodConfigData($fieldName)
170170
{
171-
return $this->getMethod()->getConfigInterface()->getConfigValue($fieldName);
171+
return $this->getMethod()->getConfigInterface()->getValue($fieldName);
172172
}
173173

174174
/**
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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\Framework\ObjectManager\TMap;
9+
use Magento\Payment\Gateway\CommandInterface;
10+
use Magento\Framework\Exception\NotFoundException;
11+
12+
class CommandPool implements CommandPoolInterface
13+
{
14+
/**
15+
* @var CommandInterface[]
16+
*/
17+
private $commands;
18+
19+
/**
20+
* @param TMap $commands
21+
*/
22+
public function __construct(
23+
TMap $commands
24+
) {
25+
$this->commands = $commands;
26+
}
27+
28+
/**
29+
* Retrieves operation
30+
*
31+
* @param string $commandCode
32+
* @return CommandInterface
33+
* @throws NotFoundException
34+
*/
35+
public function get($commandCode)
36+
{
37+
if (!isset($this->commands[$commandCode])) {
38+
throw new NotFoundException(__('Command %1 does not exist.', $commandCode));
39+
}
40+
41+
return $this->commands[$commandCode];
42+
}
43+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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\Framework\Exception\NotFoundException;
9+
use Magento\Payment\Gateway\CommandInterface;
10+
11+
interface CommandPoolInterface
12+
{
13+
/**
14+
* Retrieves operation
15+
*
16+
* @param string $commandCode
17+
* @return CommandInterface
18+
* @throws NotFoundException
19+
*/
20+
public function get($commandCode);
21+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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\CommandInterface;
9+
use Magento\Payment\Gateway\Http\ClientInterface;
10+
use Magento\Payment\Gateway\Request;
11+
use Magento\Payment\Gateway\Response;
12+
13+
class GatewayCommand implements CommandInterface
14+
{
15+
/**
16+
* @var \Magento\Payment\Gateway\Request\BuilderInterface
17+
*/
18+
private $requestBuilder;
19+
20+
/**
21+
* @var \Magento\Payment\Gateway\Http\TransferBuilderInterface
22+
*/
23+
private $transferBuilder;
24+
25+
/**
26+
* @var \Magento\Payment\Gateway\Http\ClientInterface
27+
*/
28+
private $gateway;
29+
30+
/**
31+
* @var \Magento\Payment\Gateway\Response\HandlerInterface
32+
*/
33+
private $responseHandler;
34+
35+
/**
36+
* @param \Magento\Payment\Gateway\Request\BuilderInterface $requestBuilder
37+
* @param \Magento\Payment\Gateway\Http\TransferBuilderInterface $transferBuilder
38+
* @param \Magento\Payment\Gateway\Http\ClientInterface $gateway
39+
* @param \Magento\Payment\Gateway\Response\HandlerInterface $responseHandler
40+
*/
41+
public function __construct(
42+
\Magento\Payment\Gateway\Request\BuilderInterface $requestBuilder,
43+
\Magento\Payment\Gateway\Http\TransferBuilderInterface $transferBuilder,
44+
ClientInterface $gateway,
45+
\Magento\Payment\Gateway\Response\HandlerInterface $responseHandler
46+
) {
47+
48+
$this->requestBuilder = $requestBuilder;
49+
$this->transferBuilder = $transferBuilder;
50+
$this->gateway = $gateway;
51+
$this->responseHandler = $responseHandler;
52+
}
53+
54+
/**
55+
* Executes command basing on business object
56+
*
57+
* @param array $commandSubject
58+
* @return void
59+
*/
60+
public function execute(array $commandSubject)
61+
{
62+
// @TODO implement exceptions catching
63+
$transferO = $this->transferBuilder->build(
64+
$this->requestBuilder->build($commandSubject)
65+
);
66+
67+
$response = $this->gateway->placeRequest($transferO);
68+
69+
$this->responseHandler->handle(
70+
$commandSubject,
71+
$response
72+
);
73+
}
74+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Gateway;
7+
8+
interface CommandInterface
9+
{
10+
/**
11+
* Executes command basing on business object
12+
*
13+
* @param array $commandSubject
14+
* @return void
15+
*/
16+
public function execute(array $commandSubject);
17+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Gateway\Config;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Payment\Gateway\ConfigInterface;
10+
use Magento\Store\Model\ScopeInterface;
11+
12+
class Config implements ConfigInterface
13+
{
14+
const DEFAULT_PATH_PATTERN = 'payment/%s/%s';
15+
16+
/**
17+
* @var ScopeConfigInterface
18+
*/
19+
private $scopeConfig;
20+
21+
/**
22+
* @var string
23+
*/
24+
private $methodCode;
25+
26+
/**
27+
* @var string
28+
*/
29+
private $pathPattern;
30+
31+
/**
32+
* @param ScopeConfigInterface $scopeConfig
33+
* @param string $methodCode
34+
* @param string $pathPattern
35+
*/
36+
public function __construct(
37+
ScopeConfigInterface $scopeConfig,
38+
$methodCode,
39+
$pathPattern = self::DEFAULT_PATH_PATTERN
40+
) {
41+
$this->scopeConfig = $scopeConfig;
42+
$this->methodCode = $methodCode;
43+
$this->pathPattern = $pathPattern;
44+
}
45+
46+
/**
47+
* Retrieve information from payment configuration
48+
*
49+
* @param string $field
50+
* @param int|null $storeId
51+
*
52+
* @return mixed
53+
*/
54+
public function getValue($field, $storeId = null)
55+
{
56+
return $this->scopeConfig->getValue(
57+
sprintf($this->pathPattern, $this->methodCode, $field),
58+
ScopeInterface::SCOPE_STORE,
59+
$storeId
60+
);
61+
}
62+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Gateway\Config;
7+
8+
use Magento\Payment\Gateway\ConfigInterface;
9+
10+
class ConfigValueHandler implements ValueHandlerInterface
11+
{
12+
/**
13+
* @var \Magento\Payment\Gateway\ConfigInterface
14+
*/
15+
private $configInterface;
16+
17+
/**
18+
* @param \Magento\Payment\Gateway\ConfigInterface $configInterface
19+
*/
20+
public function __construct(
21+
ConfigInterface $configInterface
22+
) {
23+
$this->configInterface = $configInterface;
24+
}
25+
26+
/**
27+
* Retrieve method configured value
28+
*
29+
* @param string $field
30+
* @param int|null $storeId
31+
*
32+
* @return mixed
33+
*/
34+
public function handle($field, $storeId = null)
35+
{
36+
return $this->configInterface->getValue($field, $storeId);
37+
}
38+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Gateway\Config;
7+
8+
interface ValueHandlerInterface
9+
{
10+
/**
11+
* Retrieve method configured value
12+
*
13+
* @param string $field
14+
* @param int|null $storeId
15+
*
16+
* @return mixed
17+
*/
18+
public function handle($field, $storeId = null);
19+
}

0 commit comments

Comments
 (0)