|
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\AfterPay\Business\Api\Adapter\ApiCall; |
|
9
|
|
|
|
|
10
|
|
|
use Spryker\Shared\Log\LoggerTrait; |
|
11
|
|
|
use SprykerEco\Zed\AfterPay\AfterPayConfig; |
|
12
|
|
|
use SprykerEco\Zed\AfterPay\Business\Api\Adapter\Client\ClientInterface; |
|
13
|
|
|
use SprykerEco\Zed\AfterPay\Business\Exception\ApiHttpRequestException; |
|
14
|
|
|
|
|
15
|
|
|
class ApiStatusCall implements ApiStatusCallInterface |
|
16
|
|
|
{ |
|
17
|
|
|
use LoggerTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var int |
|
21
|
|
|
*/ |
|
22
|
|
|
public const RESPONSE_STATUS_NOT_AVAILABLE = 503; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var \SprykerEco\Zed\AfterPay\Business\Api\Adapter\Client\ClientInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $client; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var \SprykerEco\Zed\AfterPay\AfterPayConfig |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $config; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param \SprykerEco\Zed\AfterPay\Business\Api\Adapter\Client\ClientInterface $client |
|
36
|
|
|
* @param \SprykerEco\Zed\AfterPay\AfterPayConfig $config |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct( |
|
39
|
|
|
ClientInterface $client, |
|
40
|
|
|
AfterPayConfig $config |
|
41
|
|
|
) { |
|
42
|
|
|
$this->client = $client; |
|
43
|
|
|
$this->config = $config; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return int |
|
48
|
|
|
*/ |
|
49
|
|
|
public function execute(): int |
|
50
|
|
|
{ |
|
51
|
|
|
try { |
|
52
|
|
|
$jsonResponse = $this->client->getStatus( |
|
53
|
|
|
$this->config->getStatusApiEndpointUrl(), |
|
54
|
|
|
); |
|
55
|
|
|
} catch (ApiHttpRequestException $apiHttpRequestException) { |
|
56
|
|
|
$this->logApiException($apiHttpRequestException); |
|
57
|
|
|
$jsonResponse = static::RESPONSE_STATUS_NOT_AVAILABLE; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $jsonResponse; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param \SprykerEco\Zed\AfterPay\Business\Exception\ApiHttpRequestException $apiHttpRequestException |
|
65
|
|
|
* |
|
66
|
|
|
* @return void |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function logApiException(ApiHttpRequestException $apiHttpRequestException): void |
|
69
|
|
|
{ |
|
70
|
|
|
$this->getLogger()->error( |
|
71
|
|
|
$apiHttpRequestException->getMessage(), |
|
72
|
|
|
['exception' => $apiHttpRequestException], |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|