1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\AuthorizenetAcceptjs\Gateway\Command;
use Exception;
use Magento\Payment\Gateway\Command\CommandException;
use Magento\Payment\Gateway\Command\ResultInterface;
use Magento\Payment\Gateway\CommandInterface;
use Magento\Payment\Gateway\Http\ClientInterface;
use Magento\Payment\Gateway\Http\TransferFactoryInterface;
use Magento\Payment\Gateway\Request\BuilderInterface;
use Magento\Payment\Gateway\Validator\ValidatorInterface;
use Psr\Log\LoggerInterface;
use Magento\Payment\Gateway\Command\Result\ArrayResult;
/**
* Makes a request to the gateway and returns results
*/
class GatewayQueryCommand implements CommandInterface
{
/**
* @var BuilderInterface
*/
private $requestBuilder;
/**
* @var TransferFactoryInterface
*/
private $transferFactory;
/**
* @var ClientInterface
*/
private $client;
/**
* @var ValidatorInterface
*/
private $validator;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @param BuilderInterface $requestBuilder
* @param TransferFactoryInterface $transferFactory
* @param ClientInterface $client
* @param LoggerInterface $logger
* @param ValidatorInterface $validator
*/
public function __construct(
BuilderInterface $requestBuilder,
TransferFactoryInterface $transferFactory,
ClientInterface $client,
LoggerInterface $logger,
ValidatorInterface $validator
) {
$this->requestBuilder = $requestBuilder;
$this->transferFactory = $transferFactory;
$this->client = $client;
$this->validator = $validator;
$this->logger = $logger;
}
/**
* @inheritdoc
*
* @throws Exception
*/
public function execute(array $commandSubject): ResultInterface
{
$transferO = $this->transferFactory->create(
$this->requestBuilder->build($commandSubject)
);
try {
$response = $this->client->placeRequest($transferO);
} catch (Exception $e) {
$this->logger->critical($e);
throw new CommandException(__('There was an error while trying to process the request.'));
}
$result = $this->validator->validate(
array_merge($commandSubject, ['response' => $response])
);
if (!$result->isValid()) {
throw new CommandException(__('There was an error while trying to process the request.'));
}
return new ArrayResult($response);
}
}