1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\FirstData\Business\Api\ApiClient; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\FirstDataApiRequestTransfer; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\FirstDataApiResponseTransfer; |
|
|
|
|
12
|
|
|
use SprykerEco\Zed\FirstData\Business\Api\Logger\FirstDataApiLoggerInterface; |
13
|
|
|
use SprykerEco\Zed\FirstData\Business\Api\Request\Builder\FirstDataRequestBuilderInterface; |
14
|
|
|
use SprykerEco\Zed\FirstData\Business\Api\Response\Converter\FirstDataResponseConverterInterface; |
15
|
|
|
use SprykerEco\Zed\FirstData\Dependency\External\Guzzle\Exception\FirstDataGuzzleRequestException; |
16
|
|
|
use SprykerEco\Zed\FirstData\Dependency\External\Guzzle\FirstDataGuzzleHttpClientAdapterInterface; |
17
|
|
|
use SprykerEco\Zed\FirstData\FirstDataConfig; |
18
|
|
|
|
19
|
|
|
class FirstDataApiClient implements FirstDataApiClientInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var \SprykerEco\Zed\FirstData\Dependency\External\Guzzle\FirstDataGuzzleHttpClientAdapterInterface |
23
|
|
|
*/ |
24
|
|
|
protected $guzzleHttpClientAdapter; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \SprykerEco\Zed\FirstData\Business\Api\Request\Builder\FirstDataRequestBuilderInterface |
28
|
|
|
*/ |
29
|
|
|
protected $firstDataRequestBuilder; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var \SprykerEco\Zed\FirstData\Business\Api\Response\Converter\FirstDataResponseConverterInterface |
33
|
|
|
*/ |
34
|
|
|
protected $firstDataResponseConverter; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var \SprykerEco\Zed\FirstData\Business\Api\Logger\FirstDataApiLoggerInterface |
38
|
|
|
*/ |
39
|
|
|
protected $firstDataApiLogger; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var \SprykerEco\Zed\FirstData\FirstDataConfig |
43
|
|
|
*/ |
44
|
|
|
protected $firstDataConfig; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param \SprykerEco\Zed\FirstData\Dependency\External\Guzzle\FirstDataGuzzleHttpClientAdapterInterface $guzzleHttpClientAdapter |
48
|
|
|
* @param \SprykerEco\Zed\FirstData\Business\Api\Request\Builder\FirstDataRequestBuilderInterface $firstDataRequestBuilder |
49
|
|
|
* @param \SprykerEco\Zed\FirstData\Business\Api\Response\Converter\FirstDataResponseConverterInterface $firstDataResponseConverter |
50
|
|
|
* @param \SprykerEco\Zed\FirstData\Business\Api\Logger\FirstDataApiLoggerInterface $firstDataApiLogger |
51
|
|
|
* @param \SprykerEco\Zed\FirstData\FirstDataConfig $firstDataConfig |
52
|
|
|
*/ |
53
|
|
|
public function __construct( |
54
|
|
|
FirstDataGuzzleHttpClientAdapterInterface $guzzleHttpClientAdapter, |
55
|
|
|
FirstDataRequestBuilderInterface $firstDataRequestBuilder, |
56
|
|
|
FirstDataResponseConverterInterface $firstDataResponseConverter, |
57
|
|
|
FirstDataApiLoggerInterface $firstDataApiLogger, |
58
|
|
|
FirstDataConfig $firstDataConfig |
59
|
|
|
) { |
60
|
|
|
$this->guzzleHttpClientAdapter = $guzzleHttpClientAdapter; |
61
|
|
|
$this->firstDataRequestBuilder = $firstDataRequestBuilder; |
62
|
|
|
$this->firstDataResponseConverter = $firstDataResponseConverter; |
63
|
|
|
$this->firstDataApiLogger = $firstDataApiLogger; |
64
|
|
|
$this->firstDataConfig = $firstDataConfig; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param \Generated\Shared\Transfer\FirstDataApiRequestTransfer $firstDataApiRequestTransfer |
69
|
|
|
* |
70
|
|
|
* @return \Generated\Shared\Transfer\FirstDataApiResponseTransfer |
71
|
|
|
*/ |
72
|
|
|
public function performApiRequest(FirstDataApiRequestTransfer $firstDataApiRequestTransfer): FirstDataApiResponseTransfer |
73
|
|
|
{ |
74
|
|
|
$isSuccess = true; |
75
|
|
|
$firstDataHttpRequestTransfer = $this->firstDataRequestBuilder->buildRequest($firstDataApiRequestTransfer); |
76
|
|
|
|
77
|
|
|
try { |
78
|
|
|
$guzzleHttpResponse = $this->guzzleHttpClientAdapter->post( |
79
|
|
|
$this->getRequestUrl($firstDataApiRequestTransfer), |
80
|
|
|
$firstDataHttpRequestTransfer->getHeaders(), |
81
|
|
|
$firstDataHttpRequestTransfer->getBodyOrFail() |
82
|
|
|
); |
83
|
|
|
} catch (FirstDataGuzzleRequestException $requestException) { |
84
|
|
|
$isSuccess = false; |
85
|
|
|
$guzzleHttpResponse = $requestException->getResponse(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$firstDataApiResponseTransfer = $this->firstDataResponseConverter->convertToResponseTransfer($guzzleHttpResponse, $isSuccess); |
89
|
|
|
|
90
|
|
|
$this->firstDataApiLogger |
91
|
|
|
->logApiCall( |
92
|
|
|
$firstDataHttpRequestTransfer, |
93
|
|
|
$firstDataApiResponseTransfer, |
94
|
|
|
$firstDataApiRequestTransfer->getRequestType() |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
return $firstDataApiResponseTransfer; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param \Generated\Shared\Transfer\FirstDataApiRequestTransfer $firstDataApiRequestTransfer |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
protected function getRequestUrl(FirstDataApiRequestTransfer $firstDataApiRequestTransfer): string |
106
|
|
|
{ |
107
|
|
|
return sprintf( |
108
|
|
|
'%s/%s', |
109
|
|
|
$this->firstDataConfig->getApiEndpoint($firstDataApiRequestTransfer->getRequestTypeOrFail()), |
110
|
|
|
$firstDataApiRequestTransfer->getTransactionId() |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths