Completed
Pull Request — master (#64)
by
unknown
07:24
created

PayoneGetFileMethodSender   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 36
c 1
b 0
f 0
dl 0
loc 114
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFile() 0 26 2
A setAccessDeniedError() 0 5 1
A findPaymentByFileReferenceAndCustomerId() 0 3 1
A __construct() 0 12 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Payone\Business\Payment\MethodSender;
9
10
use Generated\Shared\Transfer\PayoneGetFileTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneGetFileTransfer 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\PayoneStandardParameterTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...andardParameterTransfer 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\Payone\PayoneApiConstants;
13
use SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface;
14
use SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer;
15
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetFileResponseContainer;
16
use SprykerEco\Zed\Payone\Business\Payment\DataMapper\StandartParameterMapperInterface;
17
use SprykerEco\Zed\Payone\Business\Payment\PaymentMapperReader;
18
use SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface;
19
20
class PayoneGetFileMethodSender implements PayoneGetFileMethodSenderInterface
21
{
22
    public const ERROR_ACCESS_DENIED_MESSAGE = 'Access denied';
23
24
    /**
25
     * @var \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface
26
     */
27
    protected $executionAdapter;
28
29
    /**
30
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface
31
     */
32
    protected $queryContainer;
33
34
    /**
35
     * @var \Generated\Shared\Transfer\PayoneStandardParameterTransfer
36
     */
37
    protected $standardParameter;
38
39
    /**
40
     * @var \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface|\SprykerEco\Zed\Payone\Business\Key\HashGenerator
41
     */
42
    protected $hashGenerator;
43
44
    /**
45
     * @var \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface[]
46
     */
47
    protected $registeredMethodMappers;
48
49
    /**
50
     * @var \SprykerEco\Zed\Payone\Business\Payment\DataMapper\StandartParameterMapperInterface
51
     */
52
    protected $standartParameterMapper;
53
54
    /**
55
     * @var \SprykerEco\Zed\Payone\Business\Payment\PaymentMapperReader
56
     */
57
    protected $paymentMapperReader;
58
59
    /**
60
     * @param \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface $executionAdapter
61
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface $queryContainer
62
     * @param \Generated\Shared\Transfer\PayoneStandardParameterTransfer $standardParameter
63
     * @param \SprykerEco\Zed\Payone\Business\Payment\DataMapper\StandartParameterMapperInterface $standartParameterMapper
64
     * @param \SprykerEco\Zed\Payone\Business\Payment\PaymentMapperReader $paymentMapperReader
65
     */
66
    public function __construct(
67
        AdapterInterface $executionAdapter,
68
        PayoneQueryContainerInterface $queryContainer,
69
        PayoneStandardParameterTransfer $standardParameter,
70
        StandartParameterMapperInterface $standartParameterMapper,
71
        PaymentMapperReader $paymentMapperReader
72
    ) {
73
        $this->executionAdapter = $executionAdapter;
74
        $this->queryContainer = $queryContainer;
75
        $this->standardParameter = $standardParameter;
76
        $this->standartParameterMapper = $standartParameterMapper;
77
        $this->paymentMapperReader = $paymentMapperReader;
78
    }
79
80
    /**
81
     * @param \Generated\Shared\Transfer\PayoneGetFileTransfer $getFileTransfer
82
     *
83
     * @return \Generated\Shared\Transfer\PayoneGetFileTransfer
84
     */
85
    public function getFile(PayoneGetFileTransfer $getFileTransfer): PayoneGetFileTransfer
86
    {
87
        $responseContainer = new GetFileResponseContainer();
88
        $paymentEntity = $this->findPaymentByFileReferenceAndCustomerId(
89
            $getFileTransfer->getReference(),
90
            $getFileTransfer->getCustomerId()
91
        );
92
93
        if ($paymentEntity) {
0 ignored issues
show
introduced by
$paymentEntity is of type Orm\Zed\Payone\Persistence\SpyPaymentPayone, thus it always evaluated to true.
Loading history...
94
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
95
            $paymentMethodMapper = $this->paymentMapperReader->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
96
            $requestContainer = $paymentMethodMapper->mapGetFile($getFileTransfer);
97
            $this->standartParameterMapper->setStandardParameter($requestContainer, $this->standardParameter);
98
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
99
            $responseContainer->init($rawResponse);
100
        } else {
101
            $this->setAccessDeniedError($responseContainer);
102
        }
103
104
        $getFileTransfer->setRawResponse($responseContainer->getRawResponse());
105
        $getFileTransfer->setStatus($responseContainer->getStatus());
106
        $getFileTransfer->setErrorCode($responseContainer->getErrorcode());
107
        $getFileTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
108
        $getFileTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
109
110
        return $getFileTransfer;
111
    }
112
113
    /**
114
     * @param string $fileReference
115
     * @param int $customerId
116
     *
117
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayone 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...
118
     */
119
    protected function findPaymentByFileReferenceAndCustomerId($fileReference, $customerId)
120
    {
121
        return $this->queryContainer->createPaymentByFileReferenceAndCustomerIdQuery($fileReference, $customerId)->findOne();
122
    }
123
124
    /**
125
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer $container
126
     *
127
     * @return void
128
     */
129
    protected function setAccessDeniedError(AbstractResponseContainer $container)
130
    {
131
        $container->setStatus(PayoneApiConstants::RESPONSE_TYPE_ERROR);
132
        $container->setErrormessage(static::ERROR_ACCESS_DENIED_MESSAGE);
133
        $container->setCustomermessage(static::ERROR_ACCESS_DENIED_MESSAGE);
134
    }
135
}
136