Passed
Push — feature/eco-574/eco-2266-check... ( efd21d )
by Aleksey
08:13
created

buildValidateBankAccountResponseTransfer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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 Generated\Shared\Transfer\AfterpayValidateBankAccountRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...kAccountRequestTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Generated\Shared\Transfer\AfterpayValidateBankAccountResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...AccountResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use SprykerEco\Shared\Afterpay\AfterpayApiRequestConfig;
13
use SprykerEco\Zed\Afterpay\AfterpayConfig;
14
use SprykerEco\Zed\Afterpay\Business\Api\Adapter\Client\ClientInterface;
15
use SprykerEco\Zed\Afterpay\Business\Api\Adapter\Converter\TransferToCamelCaseArrayConverterInterface;
16
use SprykerEco\Zed\Afterpay\Business\Exception\ApiHttpRequestException;
17
use SprykerEco\Zed\Afterpay\Dependency\Service\AfterpayToUtilEncodingInterface;
18
19
class ValidateBankAccountCall extends AbstractApiCall implements ValidateBankAccountCallInterface
20
{
21
    /**
22
     * @var \SprykerEco\Zed\Afterpay\Business\Api\Adapter\Client\ClientInterface
23
     */
24
    protected $client;
25
26
    /**
27
     * @var \SprykerEco\Zed\Afterpay\Dependency\Service\AfterpayToUtilTextInterface
28
     */
29
    protected $utilText;
30
31
    /**
32
     * @var \SprykerEco\Zed\Afterpay\AfterpayConfig
33
     */
34
    protected $config;
35
36
    /**
37
     * @param \SprykerEco\Zed\Afterpay\Business\Api\Adapter\Client\ClientInterface $client
38
     * @param \SprykerEco\Zed\Afterpay\Business\Api\Adapter\Converter\TransferToCamelCaseArrayConverterInterface $transferConverter
39
     * @param \SprykerEco\Zed\Afterpay\Dependency\Service\AfterpayToUtilEncodingInterface $utilEncoding
40
     * @param \SprykerEco\Zed\Afterpay\AfterpayConfig $config
41
     */
42
    public function __construct(
43
        ClientInterface $client,
44
        TransferToCamelCaseArrayConverterInterface $transferConverter,
45
        AfterpayToUtilEncodingInterface $utilEncoding,
46
        AfterpayConfig $config
47
    ) {
48
        $this->client = $client;
49
        $this->utilEncoding = $utilEncoding;
50
        $this->config = $config;
51
        $this->transferConverter = $transferConverter;
52
    }
53
54
    /**
55
     * @param \Generated\Shared\Transfer\AfterpayValidateBankAccountRequestTransfer $validateBankAccountRequestTransfer
56
     *
57
     * @return \Generated\Shared\Transfer\AfterpayValidateBankAccountResponseTransfer
58
     */
59
    public function execute(AfterpayValidateBankAccountRequestTransfer $validateBankAccountRequestTransfer): AfterpayValidateBankAccountResponseTransfer
60
    {
61
        $jsonRequest = $this->buildJsonRequestFromTransferObject($validateBankAccountRequestTransfer);
62
63
        try {
64
            $jsonResponse = $this->client->sendPost(
65
                $this->config->getValidateBankAccountApiEndpointUrl(),
66
                $jsonRequest
67
            );
68
        } catch (ApiHttpRequestException $apiHttpRequestException) {
69
            $this->logApiException($apiHttpRequestException);
70
            $jsonResponse = '[]';
71
        }
72
73
        return $this->buildValidateBankAccountResponseTransfer($jsonResponse);
74
    }
75
76
    /**
77
     * @param string $jsonResponse
78
     *
79
     * @return \Generated\Shared\Transfer\AfterpayValidateBankAccountResponseTransfer
80
     */
81
    protected function buildValidateBankAccountResponseTransfer(string $jsonResponse): AfterpayValidateBankAccountResponseTransfer
82
    {
83
        $jsonResponseArray = $this->utilEncoding->decodeJson($jsonResponse, true);
84
85
        $responseTransfer = new AfterpayValidateBankAccountResponseTransfer();
86
        $responseTransfer->setIsValid($jsonResponseArray[AfterpayApiRequestConfig::VALIDATE_BANK_ACCOUNT_IS_VALID] ?? false);
87
88
        return $responseTransfer;
89
    }
90
}
91