Completed
Push — master ( 56a686...736967 )
by Oleksandr
15s queued 11s
created

addAccountInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 17
rs 9.9
c 1
b 0
f 0
cc 1
nc 1
nop 2
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\Client\Heidelpay\Mapper;
9
10
use Generated\Shared\Transfer\HeidelpayDirectDebitAccountTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...ectDebitAccountTransfer 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\HeidelpayDirectDebitRegistrationTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...bitRegistrationTransfer 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 Generated\Shared\Transfer\HeidelpayResponseErrorTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...ayResponseErrorTransfer 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...
13
use Heidelpay\PhpPaymentApi\Response;
14
15
class DirectDebitRegistrationResponseMapper implements DirectDebitRegistrationResponseMapperInterface
16
{
17
    protected const API_RESPONSE_ERROR_CODE_KEY = 'code';
18
    protected const API_RESPONSE_ERROR_MESSAGE_KEY = 'message';
19
20
    /**
21
     * @param \Heidelpay\PhpPaymentApi\Response $apiResponseObject
22
     * @param \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer $directDebitRegistrationTransfer
23
     *
24
     * @return \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer
25
     */
26
    public function mapApiResponseToDirectDebitRegistrationResponseTransfer(
27
        Response $apiResponseObject,
28
        HeidelpayDirectDebitRegistrationTransfer $directDebitRegistrationTransfer
29
    ): HeidelpayDirectDebitRegistrationTransfer {
30
        $directDebitRegistrationTransfer = $this->addAccountInfo($apiResponseObject, $directDebitRegistrationTransfer);
31
        $directDebitRegistrationTransfer = $this->addError($apiResponseObject, $directDebitRegistrationTransfer);
32
        $directDebitRegistrationTransfer = $this->addIdentification($apiResponseObject, $directDebitRegistrationTransfer);
33
34
        return $directDebitRegistrationTransfer;
35
    }
36
37
    /**
38
     * @param \Heidelpay\PhpPaymentApi\Response $apiResponseObject
39
     * @param \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer $directDebitRegistrationTransfer
40
     *
41
     * @return \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer
42
     */
43
    protected function addAccountInfo(
44
        Response $apiResponseObject,
45
        HeidelpayDirectDebitRegistrationTransfer $directDebitRegistrationTransfer
46
    ): HeidelpayDirectDebitRegistrationTransfer {
47
        $accountInfo = $apiResponseObject->getAccount();
48
        $directDebitAccountTransfer = (new HeidelpayDirectDebitAccountTransfer())
49
            ->setAccountHolder($accountInfo->getHolder())
50
            ->setAccountBankName($accountInfo->getBankName())
51
            ->setAccountNumber($accountInfo->getNumber())
52
            ->setAccountCountry($accountInfo->getCountry())
53
            ->setAccountBic($accountInfo->getBic())
54
            ->setAccountIban($accountInfo->getIban())
55
            ->setAccountIdentification($accountInfo->getIdentification());
56
57
        $directDebitRegistrationTransfer->setAccountInfo($directDebitAccountTransfer);
58
59
        return $directDebitRegistrationTransfer;
60
    }
61
62
    /**
63
     * @param \Heidelpay\PhpPaymentApi\Response $apiResponse
64
     * @param \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer $directDebitRegistrationTransfer
65
     *
66
     * @return \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer
67
     */
68
    protected function addError(
69
        Response $apiResponse,
70
        HeidelpayDirectDebitRegistrationTransfer $directDebitRegistrationTransfer
71
    ): HeidelpayDirectDebitRegistrationTransfer {
72
        if (!$apiResponse->isError()) {
73
            return $directDebitRegistrationTransfer;
74
        }
75
76
        $errorResponse = $apiResponse->getError();
77
        $directDebitRegistrationTransfer
78
            ->setIsError(true)
79
            ->setError(
80
                (new HeidelpayResponseErrorTransfer())
81
                    ->setCode($errorResponse[static::API_RESPONSE_ERROR_CODE_KEY])
82
                    ->setInternalMessage($errorResponse[static::API_RESPONSE_ERROR_MESSAGE_KEY])
83
            );
84
85
        return $directDebitRegistrationTransfer;
86
    }
87
88
    /**
89
     * @param \Heidelpay\PhpPaymentApi\Response $apiResponse
90
     * @param \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer $directDebitRegistrationTransfer
91
     *
92
     * @return \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer
93
     */
94
    protected function addIdentification(
95
        Response $apiResponse,
96
        HeidelpayDirectDebitRegistrationTransfer $directDebitRegistrationTransfer
97
    ): HeidelpayDirectDebitRegistrationTransfer {
98
        $directDebitRegistrationTransfer
99
            ->setRegistrationUniqueId($apiResponse->getIdentification()->getUniqueId())
100
            ->setTransactionId($apiResponse->getIdentification()->getTransactionId());
101
102
        return $directDebitRegistrationTransfer;
103
    }
104
}
105