Passed
Push — feature/eco-2521/eco-2522-suit... ( ca0ff5...cfa5b3 )
by Ruslan
02:36
created

AbstractMapper   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 180
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 40
dl 0
loc 180
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getActionUrl() 0 3 1
A getClientIp() 0 3 1
A generateTransId() 0 3 1
A getQueryParameters() 0 12 1
A getCaptureType() 0 5 1
A createRequestTransfer() 0 4 1
A createComputopPaymentTransfer() 0 15 1
A getZipCode() 0 7 2
A getLimitedTransId() 0 3 1
A getAbsoluteUrl() 0 3 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\Yves\Computop\Mapper\Init;
9
10
use Generated\Shared\Transfer\ComputopApiRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...putopApiRequestTransfer 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\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer 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 Silex\Application;
13
use Spryker\Shared\Kernel\Transfer\TransferInterface;
14
use SprykerEco\Service\ComputopApi\ComputopApiServiceInterface;
15
use SprykerEco\Shared\Computop\Config\ComputopApiConfig;
16
use SprykerEco\Yves\Computop\ComputopConfig;
17
use SprykerEco\Yves\Computop\ComputopConfigInterface;
18
use SprykerEco\Yves\Computop\Dependency\ComputopToStoreInterface;
19
use SprykerEco\Yves\Computop\Plugin\Provider\ComputopControllerProvider;
20
21
abstract class AbstractMapper implements MapperInterface
22
{
23
    /**
24
     * @var \SprykerEco\Service\ComputopApi\ComputopApiServiceInterface
25
     */
26
    protected $computopApiService;
27
28
    /**
29
     * @var \Silex\Application
30
     */
31
    protected $application;
32
33
    /**
34
     * @var \SprykerEco\Yves\Computop\Dependency\ComputopToStoreInterface
35
     */
36
    protected $store;
37
38
    /**
39
     * @var \SprykerEco\Yves\Computop\ComputopConfigInterface
40
     */
41
    protected $config;
42
43
    /**
44
     * @var array
45
     */
46
    protected $decryptedValues;
47
48
    /**
49
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
50
     *
51
     * @return \Spryker\Shared\Kernel\Transfer\TransferInterface
52
     */
53
    abstract protected function createTransferWithUnencryptedValues(QuoteTransfer $quoteTransfer);
54
55
    /**
56
     * @param \SprykerEco\Service\ComputopApi\ComputopApiServiceInterface $computopApiService
57
     * @param \Silex\Application $application
58
     * @param \SprykerEco\Yves\Computop\Dependency\ComputopToStoreInterface $store
59
     * @param \SprykerEco\Yves\Computop\ComputopConfigInterface $config
60
     */
61
    public function __construct(
62
        ComputopApiServiceInterface $computopApiService,
63
        Application $application,
64
        ComputopToStoreInterface $store,
65
        ComputopConfigInterface $config
66
    ) {
67
        $this->computopApiService = $computopApiService;
68
        $this->application = $application;
69
        $this->store = $store;
70
        $this->config = $config;
71
    }
72
73
    /**
74
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
75
     *
76
     * @return \Spryker\Shared\Kernel\Transfer\TransferInterface
77
     */
78
    public function createComputopPaymentTransfer(QuoteTransfer $quoteTransfer)
79
    {
80
        $computopPaymentTransfer = $this->createTransferWithUnencryptedValues($quoteTransfer);
81
        $computopPaymentTransfer->setMerchantId($this->config->getMerchantId());
0 ignored issues
show
Bug introduced by
The method setMerchantId() does not exist on Spryker\Shared\Kernel\Transfer\TransferInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
82
                                  setMerchantId($this->config->getMerchantId());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
        $computopPaymentTransfer->setAmount($quoteTransfer->getTotals()->getGrandTotal());
0 ignored issues
show
Bug introduced by
The method setAmount() does not exist on Spryker\Shared\Kernel\Transfer\TransferInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

82
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
83
                                  setAmount($quoteTransfer->getTotals()->getGrandTotal());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
        $computopPaymentTransfer->setCurrency($this->store->getCurrencyIsoCode());
0 ignored issues
show
Bug introduced by
The method setCurrency() does not exist on Spryker\Shared\Kernel\Transfer\TransferInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
84
                                  setCurrency($this->store->getCurrencyIsoCode());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
        $computopPaymentTransfer->setResponse(ComputopConfig::RESPONSE_ENCRYPT_TYPE);
0 ignored issues
show
Bug introduced by
The method setResponse() does not exist on Spryker\Shared\Kernel\Transfer\TransferInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
85
                                  setResponse(ComputopConfig::RESPONSE_ENCRYPT_TYPE);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
85
        $computopPaymentTransfer->setClientIp($this->getClientIp());
0 ignored issues
show
Bug introduced by
The method setClientIp() does not exist on Spryker\Shared\Kernel\Transfer\TransferInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
86
                                  setClientIp($this->getClientIp());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
86
        $computopPaymentTransfer->setReqId($this->computopApiService->generateReqIdFromQuoteTransfer($quoteTransfer));
0 ignored issues
show
Bug introduced by
The method setReqId() does not exist on Spryker\Shared\Kernel\Transfer\TransferInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
87
                                  setReqId($this->computopApiService->generateReqIdFromQuoteTransfer($quoteTransfer));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
        $computopPaymentTransfer->setUrlFailure(
0 ignored issues
show
Bug introduced by
The method setUrlFailure() does not exist on Spryker\Shared\Kernel\Transfer\TransferInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
88
                                  setUrlFailure(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
            $this->getAbsoluteUrl($this->application->path(ComputopControllerProvider::FAILURE_PATH_NAME))
0 ignored issues
show
Bug introduced by
The method path() does not exist on Silex\Application. Did you maybe mean patch()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

88
            $this->getAbsoluteUrl($this->application->/** @scrutinizer ignore-call */ path(ComputopControllerProvider::FAILURE_PATH_NAME))

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
        );
90
        $computopPaymentTransfer->setShippingZip($this->getZipCode($quoteTransfer));
0 ignored issues
show
Bug introduced by
The method setShippingZip() does not exist on Spryker\Shared\Kernel\Transfer\TransferInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
91
                                  setShippingZip($this->getZipCode($quoteTransfer));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
92
        return $computopPaymentTransfer;
93
    }
94
95
    /**
96
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
97
     *
98
     * @return string
99
     */
100
    protected function generateTransId(QuoteTransfer $quoteTransfer)
101
    {
102
        return $this->computopApiService->generateTransId($quoteTransfer);
103
    }
104
105
    /**
106
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
107
     * @param int $limit
108
     *
109
     * @return string
110
     */
111
    protected function getLimitedTransId(QuoteTransfer $quoteTransfer, $limit)
112
    {
113
        return substr($this->generateTransId($quoteTransfer), 0, $limit);
114
    }
115
116
    /**
117
     * @param string $path
118
     *
119
     * @return string
120
     */
121
    protected function getAbsoluteUrl($path)
122
    {
123
        return $this->config->getBaseUrlSsl() . $path;
124
    }
125
126
    /**
127
     * @return string
128
     */
129
    protected function getClientIp()
130
    {
131
        return $this->application['request']->getClientIp();
132
    }
133
134
    /**
135
     * @param string $url
136
     * @param array $queryData
137
     *
138
     * @return string
139
     */
140
    protected function getActionUrl($url, $queryData)
141
    {
142
        return $url . '?' . http_build_query($queryData);
143
    }
144
145
    /**
146
     * @param string $merchantId
147
     * @param string $data
148
     * @param int $length
149
     *
150
     * @return array
151
     */
152
    protected function getQueryParameters($merchantId, $data, $length)
153
    {
154
        $queryData = [
155
            ComputopApiConfig::MERCHANT_ID => $merchantId,
156
            ComputopApiConfig::DATA => $data,
157
            ComputopApiConfig::LENGTH => $length,
158
            ComputopApiConfig::URL_BACK => $this->getAbsoluteUrl(
159
                $this->application->path($this->config->getCallbackFailureRedirectPath())
160
            ),
161
        ];
162
163
        return $queryData;
164
    }
165
166
    /**
167
     * @param \Spryker\Shared\Kernel\Transfer\TransferInterface $computopPaymentTransfer
168
     *
169
     * @return \Generated\Shared\Transfer\ComputopApiRequestTransfer
170
     */
171
    protected function createRequestTransfer(TransferInterface $computopPaymentTransfer)
172
    {
173
        return (new ComputopApiRequestTransfer())
174
            ->fromArray($computopPaymentTransfer->toArray(), true);
175
    }
176
177
    /**
178
     * @param string $method
179
     *
180
     * @return string
181
     */
182
    protected function getCaptureType(string $method): string
183
    {
184
        $paymentMethodsCaptureTypes = $this->config->getPaymentMethodsCaptureTypes();
185
186
        return $paymentMethodsCaptureTypes[$method] ?? '';
187
    }
188
189
    /**
190
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
191
     *
192
     * @return string
193
     */
194
    protected function getZipCode(QuoteTransfer $quoteTransfer): string
195
    {
196
        if ($quoteTransfer->getBillingSameAsShipping()) {
197
            return $quoteTransfer->getBillingAddress()->getZipCode();
198
        }
199
200
        return $quoteTransfer->getShippingAddress()->getZipCode();
201
    }
202
}
203