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\CrefoPayApi\Business\Response\Converter; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\CrefoPayApiErrorResponseTransfer; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\CrefoPayApiResponseTransfer; |
|
|
|
|
12
|
|
|
use SprykerEco\Zed\CrefoPayApi\Business\Response\Mapper\CrefoPayApiResponseMapperInterface; |
13
|
|
|
use SprykerEco\Zed\CrefoPayApi\Business\Response\Validator\CrefoPayApiResponseValidatorInterface; |
14
|
|
|
use SprykerEco\Zed\CrefoPayApi\Dependency\External\Guzzle\Response\CrefoPayApiGuzzleResponseInterface; |
15
|
|
|
use SprykerEco\Zed\CrefoPayApi\Dependency\Service\CrefoPayApiToUtilEncodingServiceInterface; |
16
|
|
|
|
17
|
|
|
class CrefoPayApiResponseConverter implements CrefoPayApiResponseConverterInterface |
18
|
|
|
{ |
19
|
|
|
protected const API_ERROR_TYPE_EXTERNAL = 'EXTERNAL'; |
20
|
|
|
protected const EXTERNAL_ERROR_MESSAGE = 'CrefoPay service temporarily unavailable.'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \SprykerEco\Zed\CrefoPayApi\Dependency\Service\CrefoPayApiToUtilEncodingServiceInterface |
24
|
|
|
*/ |
25
|
|
|
protected $encodingService; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \SprykerEco\Zed\CrefoPayApi\Business\Response\Mapper\CrefoPayApiResponseMapperInterface |
29
|
|
|
*/ |
30
|
|
|
protected $responseMapper; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \SprykerEco\Zed\CrefoPayApi\Business\Response\Validator\CrefoPayApiResponseValidatorInterface |
34
|
|
|
*/ |
35
|
|
|
protected $responseValidator; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param \SprykerEco\Zed\CrefoPayApi\Dependency\Service\CrefoPayApiToUtilEncodingServiceInterface $encodingService |
39
|
|
|
* @param \SprykerEco\Zed\CrefoPayApi\Business\Response\Mapper\CrefoPayApiResponseMapperInterface $responseMapper |
40
|
|
|
* @param \SprykerEco\Zed\CrefoPayApi\Business\Response\Validator\CrefoPayApiResponseValidatorInterface $responseValidator |
41
|
|
|
*/ |
42
|
|
|
public function __construct( |
43
|
|
|
CrefoPayApiToUtilEncodingServiceInterface $encodingService, |
44
|
|
|
CrefoPayApiResponseMapperInterface $responseMapper, |
45
|
|
|
CrefoPayApiResponseValidatorInterface $responseValidator |
46
|
|
|
) { |
47
|
|
|
$this->encodingService = $encodingService; |
48
|
|
|
$this->responseMapper = $responseMapper; |
49
|
|
|
$this->responseValidator = $responseValidator; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param \SprykerEco\Zed\CrefoPayApi\Dependency\External\Guzzle\Response\CrefoPayApiGuzzleResponseInterface $response |
54
|
|
|
* @param bool $isSuccess |
55
|
|
|
* |
56
|
|
|
* @return \Generated\Shared\Transfer\CrefoPayApiResponseTransfer |
57
|
|
|
*/ |
58
|
|
|
public function convertToResponseTransfer( |
59
|
|
|
CrefoPayApiGuzzleResponseInterface $response, |
60
|
|
|
bool $isSuccess = true |
61
|
|
|
): CrefoPayApiResponseTransfer { |
62
|
|
|
$responseData = $this->encodingService->decodeJson($response->getResponseBody(), true); |
63
|
|
|
$responseTransfer = $this->createResponseTransfer($isSuccess); |
64
|
|
|
|
65
|
|
|
if (!$isSuccess || !$this->responseValidator->validateResponse($response, $responseData)) { |
66
|
|
|
return $this->updateResponseTransferWithError($responseTransfer, $responseData); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $this->responseMapper |
70
|
|
|
->mapResponseDataToResponseTransfer($responseData, $responseTransfer); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param \Generated\Shared\Transfer\CrefoPayApiResponseTransfer $responseTransfer |
75
|
|
|
* @param array|null $responseData |
76
|
|
|
* |
77
|
|
|
* @return \Generated\Shared\Transfer\CrefoPayApiResponseTransfer |
78
|
|
|
*/ |
79
|
|
|
protected function updateResponseTransferWithError( |
80
|
|
|
CrefoPayApiResponseTransfer $responseTransfer, |
81
|
|
|
?array $responseData |
82
|
|
|
): CrefoPayApiResponseTransfer { |
83
|
|
|
$errorTransfer = (new CrefoPayApiErrorResponseTransfer()) |
84
|
|
|
->setMessage(static::EXTERNAL_ERROR_MESSAGE) |
85
|
|
|
->setErrorType(static::API_ERROR_TYPE_EXTERNAL); |
86
|
|
|
|
87
|
|
|
if ($responseData !== null) { |
|
|
|
|
88
|
|
|
$errorTransfer->fromArray($responseData, true); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $responseTransfer |
92
|
|
|
->setIsSuccess(false) |
93
|
|
|
->setError($errorTransfer); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param bool $isSuccess |
98
|
|
|
* |
99
|
|
|
* @return \Generated\Shared\Transfer\CrefoPayApiResponseTransfer |
100
|
|
|
*/ |
101
|
|
|
protected function createResponseTransfer(bool $isSuccess): CrefoPayApiResponseTransfer |
102
|
|
|
{ |
103
|
|
|
return (new CrefoPayApiResponseTransfer()) |
104
|
|
|
->setIsSuccess($isSuccess); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
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