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\Converter; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\CrefoPayApiErrorResponseTransfer; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\CrefoPayApiResponseTransfer; |
|
|
|
|
12
|
|
|
use SprykerEco\Zed\CrefoPayApi\CrefoPayApiConfig; |
13
|
|
|
use SprykerEco\Zed\CrefoPayApi\Dependency\External\Guzzle\Response\CrefoPayApiGuzzleResponseInterface; |
14
|
|
|
use SprykerEco\Zed\CrefoPayApi\Dependency\Service\CrefoPayApiToUtilEncodingServiceInterface; |
15
|
|
|
|
16
|
|
|
abstract class AbstractConverter implements CrefoPayApiConverterInterface |
17
|
|
|
{ |
18
|
|
|
protected const EXTERNAL_ERROR_MESSAGE = 'CrefoPay service temporarily unavailable.'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var \SprykerEco\Zed\CrefoPayApi\Dependency\Service\CrefoPayApiToUtilEncodingServiceInterface |
22
|
|
|
*/ |
23
|
|
|
protected $encodingService; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \SprykerEco\Zed\CrefoPayApi\CrefoPayApiConfig |
27
|
|
|
*/ |
28
|
|
|
protected $config; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param \Generated\Shared\Transfer\CrefoPayApiResponseTransfer $responseTransfer |
32
|
|
|
* @param array $responseData |
33
|
|
|
* |
34
|
|
|
* @return \Generated\Shared\Transfer\CrefoPayApiResponseTransfer |
35
|
|
|
*/ |
36
|
|
|
abstract protected function updateResponseTransferWithApiCallResponse( |
37
|
|
|
CrefoPayApiResponseTransfer $responseTransfer, |
38
|
|
|
array $responseData |
39
|
|
|
): CrefoPayApiResponseTransfer; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param \SprykerEco\Zed\CrefoPayApi\Dependency\Service\CrefoPayApiToUtilEncodingServiceInterface $encodingService |
43
|
|
|
* @param \SprykerEco\Zed\CrefoPayApi\CrefoPayApiConfig $config |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
CrefoPayApiToUtilEncodingServiceInterface $encodingService, |
47
|
|
|
CrefoPayApiConfig $config |
48
|
|
|
) { |
49
|
|
|
$this->encodingService = $encodingService; |
50
|
|
|
$this->config = $config; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param \SprykerEco\Zed\CrefoPayApi\Dependency\External\Guzzle\Response\CrefoPayApiGuzzleResponseInterface $response |
55
|
|
|
* @param bool $isSuccess |
56
|
|
|
* |
57
|
|
|
* @return \Generated\Shared\Transfer\CrefoPayApiResponseTransfer |
58
|
|
|
*/ |
59
|
|
|
public function convertToResponseTransfer( |
60
|
|
|
CrefoPayApiGuzzleResponseInterface $response, |
61
|
|
|
bool $isSuccess = true |
62
|
|
|
): CrefoPayApiResponseTransfer { |
63
|
|
|
$responseData = $this->encodingService->decodeJson($response->getResponseBody(), true); |
64
|
|
|
|
65
|
|
|
if (!$isSuccess || !$this->isResultCodeSuccess($responseData)) { |
|
|
|
|
66
|
|
|
return $this->createResponseTransferWithError($responseData); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$responseTransfer = $this->createSuccessResponseTransfer(); |
70
|
|
|
$responseTransfer = $this->updateResponseTransferWithApiCallResponse($responseTransfer, $responseData); |
|
|
|
|
71
|
|
|
|
72
|
|
|
return $responseTransfer; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param array $responseData |
77
|
|
|
* |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
|
|
protected function isResultCodeSuccess(array $responseData): bool |
81
|
|
|
{ |
82
|
|
|
if ($responseData === null) { |
|
|
|
|
83
|
|
|
return false; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$resultCode = $responseData[$this->config->getApiResponseFieldResultCode()]; |
87
|
|
|
|
88
|
|
|
return isset($resultCode) && ($resultCode === 0 || $resultCode === 1); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param array|null $responseData |
93
|
|
|
* |
94
|
|
|
* @return \Generated\Shared\Transfer\CrefoPayApiResponseTransfer |
95
|
|
|
*/ |
96
|
|
|
protected function createResponseTransferWithError(?array $responseData): CrefoPayApiResponseTransfer |
97
|
|
|
{ |
98
|
|
|
$errorTransfer = (new CrefoPayApiErrorResponseTransfer()) |
99
|
|
|
->setMessage(static::EXTERNAL_ERROR_MESSAGE) |
100
|
|
|
->setErrorType($this->config->getApiErrorTypeExternal()); |
101
|
|
|
|
102
|
|
|
if ($responseData !== null) { |
|
|
|
|
103
|
|
|
$errorTransfer->fromArray($responseData, true); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return (new CrefoPayApiResponseTransfer()) |
107
|
|
|
->setIsSuccess(false) |
108
|
|
|
->setError($errorTransfer); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return \Generated\Shared\Transfer\CrefoPayApiResponseTransfer |
113
|
|
|
*/ |
114
|
|
|
protected function createSuccessResponseTransfer(): CrefoPayApiResponseTransfer |
115
|
|
|
{ |
116
|
|
|
return (new CrefoPayApiResponseTransfer()) |
117
|
|
|
->setIsSuccess(true); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
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