Skip to content

Commit 3795e4c

Browse files
committed
MAGETWO-32923: Creating Invoice
- unit test coverage - made converter not required for http clients
1 parent edd2e6a commit 3795e4c

File tree

17 files changed

+372
-65
lines changed

17 files changed

+372
-65
lines changed

app/code/Magento/Payment/Gateway/Command/CommandException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66
namespace Magento\Payment\Gateway\Command;
77

8-
class CommandException extends \Exception
8+
use Magento\Framework\Exception\LocalizedException;
9+
10+
class CommandException extends LocalizedException
911
{
1012

1113
}

app/code/Magento/Payment/Gateway/Command/GatewayCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public function execute(array $commandSubject)
8282
array_merge($commandSubject, ['response' => $response])
8383
);
8484
if (!$result->isValid()) {
85-
throw new CommandException;
85+
throw new CommandException(
86+
__(implode("\n", $result->getFailsDescription()))
87+
);
8688
}
8789
}
8890

app/code/Magento/Payment/Gateway/Helper/SubjectReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function readPayment(array $subject)
3030
* Reads amount from subject
3131
*
3232
* @param array $subject
33-
* @return int|double|string
33+
* @return mixed
3434
*/
3535
public static function readAmount(array $subject)
3636
{

app/code/Magento/Payment/Gateway/Http/Client/Soap.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Payment\Gateway\Http\Client;
77

8+
use Magento\Framework\Webapi\Soap\ClientFactory;
89
use Magento\Payment\Gateway\Http\ClientInterface;
910
use Magento\Payment\Gateway\Http\ConverterInterface;
1011
use Magento\Payment\Gateway\Http\TransferInterface;
@@ -22,15 +23,24 @@ class Soap implements ClientInterface
2223
*/
2324
private $converter;
2425

26+
/**
27+
* @var ClientFactory
28+
*/
29+
private $clientFactory;
30+
2531
/**
2632
* @param Logger $logger
33+
* @param ClientFactory $clientFactory
34+
* @param ConverterInterface | null $converter
2735
*/
2836
public function __construct(
2937
Logger $logger,
38+
ClientFactory $clientFactory,
3039
ConverterInterface $converter = null
3140
) {
3241
$this->logger = $logger;
3342
$this->converter = $converter;
43+
$this->clientFactory = $clientFactory;
3444
}
3545

3646
/**
@@ -46,16 +56,24 @@ public function placeRequest(TransferInterface $transferObject)
4656
{
4757
$this->logger->debug(['request' => $transferObject->getBody()]);
4858

49-
$client = new \SoapClient($transferObject->getClientConfig()['wsdl'], ['trace' => true]);
59+
$client = $this->clientFactory->create(
60+
$transferObject->getClientConfig()['wsdl'],
61+
['trace' => true]
62+
);
5063

5164
try {
5265
$client->__setSoapHeaders($transferObject->getHeaders());
5366

67+
$response = $client->__soapCall(
68+
$transferObject->getMethod(),
69+
[$transferObject->getBody()]
70+
);
71+
5472
$result = $this->converter
5573
? $this->converter->convert(
56-
$client->__soapCall($transferObject->getMethod(), [$transferObject->getBody()])
74+
$response
5775
)
58-
: null;
76+
: [$response];
5977

6078
$this->logger->debug(['response' => $result]);
6179
} catch (\Exception $e) {

app/code/Magento/Payment/Gateway/Http/Client/Zend.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\HTTP\ZendClient;
1010
use Magento\Payment\Gateway\Http\ClientInterface;
1111
use Magento\Payment\Gateway\Http\ConverterInterface;
12+
use Magento\Payment\Gateway\Http\TransferInterface;
1213
use Magento\Payment\Model\Method\Logger;
1314

1415
class Zend implements ClientInterface
@@ -31,7 +32,7 @@ class Zend implements ClientInterface
3132
/**
3233
* @param ZendClientFactory $clientFactory
3334
* @param Logger $logger
34-
* @param ConverterInterface $converter
35+
* @param ConverterInterface | null $converter
3536
*/
3637
public function __construct(
3738
ZendClientFactory $clientFactory,
@@ -46,7 +47,7 @@ public function __construct(
4647
/**
4748
* {inheritdoc}
4849
*/
49-
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
50+
public function placeRequest(TransferInterface $transferObject)
5051
{
5152
$log = [
5253
'request' => $transferObject->getBody(),
@@ -67,7 +68,12 @@ public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $tr
6768
$client->setParameterPost($transferObject->getBody());
6869
break;
6970
default:
70-
throw new \LogicException(sprintf('Unsupported HTTP method %s', $transferObject->getMethod()));
71+
throw new \LogicException(
72+
sprintf(
73+
'Unsupported HTTP method %s',
74+
$transferObject->getMethod()
75+
)
76+
);
7177
}
7278

7379
$client->setHeaders($transferObject->getHeaders());
@@ -79,10 +85,12 @@ public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $tr
7985

8086
$result = $this->converter
8187
? $this->converter->convert($response->getBody())
82-
: $response->getBody();
88+
: [$response->getBody()];
8389
$log['response'] = $result;
8490
} catch (\Zend_Http_Client_Exception $e) {
85-
throw new \Magento\Payment\Gateway\Http\ClientException(__($e->getMessage()));
91+
throw new \Magento\Payment\Gateway\Http\ClientException(
92+
__($e->getMessage())
93+
);
8694
} catch (\Magento\Payment\Gateway\Http\ConverterException $e) {
8795
throw $e;
8896
} finally {

app/code/Magento/Payment/Gateway/Validator/AbstractValidator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public function __construct(
3030
*/
3131
protected function createResult($isValid, array $fails = [])
3232
{
33-
return $this->resultInterfaceFactory->create(['isValid' => (bool)$isValid, 'failsDescription' => $fails]);
33+
return $this->resultInterfaceFactory->create(
34+
[
35+
'isValid' => (bool)$isValid,
36+
'failsDescription' => $fails
37+
]
38+
);
3439
}
3540
}

app/code/Magento/Payment/Gateway/Validator/CountryValidator.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,23 @@
99
use Magento\Payment\Gateway\ConfigInterface;
1010
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
1111

12-
class CountryValidator implements ValidatorInterface
12+
class CountryValidator extends AbstractValidator
1313
{
1414
/**
1515
* @var \Magento\Payment\Gateway\ConfigInterface
1616
*/
1717
private $config;
1818

1919
/**
20-
* @var ResultInterfaceFactory
21-
*/
22-
private $resultFactory;
23-
24-
/**
25-
* @param \Magento\Payment\Gateway\ConfigInterface $config
2620
* @param ResultInterfaceFactory $resultFactory
21+
* @param \Magento\Payment\Gateway\ConfigInterface $config
2722
*/
2823
public function __construct(
29-
ConfigInterface $config,
30-
ResultInterfaceFactory $resultFactory
24+
ResultInterfaceFactory $resultFactory,
25+
ConfigInterface $config
3126
) {
3227
$this->config = $config;
33-
$this->resultFactory = $resultFactory;
28+
parent::__construct($resultFactory);
3429
}
3530

3631
/**
@@ -55,10 +50,6 @@ public function validate(array $validationSubject)
5550
}
5651
}
5752

58-
return $this->resultFactory->create(
59-
[
60-
'isValid' => $isValid
61-
]
62-
);
53+
return $this->createResult($isValid);
6354
}
6455
}

app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Magento\Framework\ObjectManager\TMapFactory;
1010
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
1111

12-
class ValidatorComposite implements ValidatorInterface
12+
class ValidatorComposite extends AbstractValidator
1313
{
1414
/**
1515
* @var ValidatorInterface[] | TMap
@@ -37,7 +37,7 @@ public function __construct(
3737
'type' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'
3838
]
3939
);
40-
$this->resultFactory = $resultFactory;
40+
parent::__construct($resultFactory);
4141
}
4242

4343
/**
@@ -61,11 +61,6 @@ public function validate(array $validationSubject)
6161
}
6262
}
6363

64-
return $this->resultFactory->create(
65-
[
66-
'isValid' => $isValid,
67-
'failsDescription' => $failsDescriptionAggregate
68-
]
69-
);
64+
return $this->createResult($isValid, $failsDescriptionAggregate);
7065
}
7166
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ public function assignData($data)
580580

581581
/**
582582
* {inheritdoc}
583+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
583584
*/
584585
public function initialize($paymentAction, $stateObject)
585586
{

0 commit comments

Comments
 (0)