Passed
Push — feature/eco-2521/eco-2522-suit... ( ca0ff5 )
by Ruslan
05:57
created

AbstractMapper::getAddressData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 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\ComputopEasyCreditPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...syCreditPaymentTransfer 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\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...
13
use Silex\Application;
14
use Spryker\Shared\Kernel\Transfer\TransferInterface;
15
use SprykerEco\Service\ComputopApi\ComputopApiServiceInterface;
16
use SprykerEco\Shared\Computop\Config\ComputopApiConfig;
17
use SprykerEco\Yves\Computop\ComputopConfig;
18
use SprykerEco\Yves\Computop\ComputopConfigInterface;
19
use SprykerEco\Yves\Computop\Dependency\ComputopToStoreInterface;
20
use SprykerEco\Yves\Computop\Plugin\Provider\ComputopControllerProvider;
21
22
abstract class AbstractMapper implements MapperInterface
23
{
24
    /**
25
     * @var \SprykerEco\Service\ComputopApi\ComputopApiServiceInterface
26
     */
27
    protected $computopApiService;
28
29
    /**
30
     * @var \Silex\Application
31
     */
32
    protected $application;
33
34
    /**
35
     * @var \SprykerEco\Yves\Computop\Dependency\ComputopToStoreInterface
36
     */
37
    protected $store;
38
39
    /**
40
     * @var \SprykerEco\Yves\Computop\ComputopConfigInterface
41
     */
42
    protected $config;
43
44
    /**
45
     * @var array
46
     */
47
    protected $decryptedValues;
48
49
    /**
50
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
51
     *
52
     * @return \Spryker\Shared\Kernel\Transfer\TransferInterface
53
     */
54
    abstract protected function createTransferWithUnencryptedValues(QuoteTransfer $quoteTransfer);
55
56
    /**
57
     * @param \SprykerEco\Service\ComputopApi\ComputopApiServiceInterface $computopApiService
58
     * @param \Silex\Application $application
59
     * @param \SprykerEco\Yves\Computop\Dependency\ComputopToStoreInterface $store
60
     * @param \SprykerEco\Yves\Computop\ComputopConfigInterface $config
61
     */
62
    public function __construct(
63
        ComputopApiServiceInterface $computopApiService,
64
        Application $application,
65
        ComputopToStoreInterface $store,
66
        ComputopConfigInterface $config
67
    ) {
68
        $this->computopApiService = $computopApiService;
69
        $this->application = $application;
70
        $this->store = $store;
71
        $this->config = $config;
72
    }
73
74
    /**
75
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
76
     *
77
     * @return \Spryker\Shared\Kernel\Transfer\TransferInterface
78
     */
79
    public function createComputopPaymentTransfer(QuoteTransfer $quoteTransfer)
80
    {
81
        $computopPaymentTransfer = $this->createTransferWithUnencryptedValues($quoteTransfer);
82
        $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

82
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
83
                                  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...
83
        $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

83
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
84
                                  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...
84
        $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

84
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
85
                                  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...
85
        $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

85
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
86
                                  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...
86
        $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

86
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
87
                                  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...
87
        $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

87
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
88
                                  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...
88
        $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

88
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
89
                                  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...
89
            $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

89
            $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...
90
        );
91
92
        $addressData = $this->getAddressData($quoteTransfer);
93
94
        $computopPaymentTransfer->setShippingZip($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_ZIP]);
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

94
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
95
                                  setShippingZip($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_ZIP]);

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...
95
        $computopPaymentTransfer->setShippingCity($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_CITY]);
0 ignored issues
show
Bug introduced by
The method setShippingCity() 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

95
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
96
                                  setShippingCity($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_CITY]);

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...
96
        $computopPaymentTransfer->setShippingStreet($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET]);
0 ignored issues
show
Bug introduced by
The method setShippingStreet() 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

96
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
97
                                  setShippingStreet($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET]);

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...
97
        $computopPaymentTransfer->setShippingStreetNumber($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET_NUMBER]);
0 ignored issues
show
Bug introduced by
The method setShippingStreetNumber() 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

97
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
98
                                  setShippingStreetNumber($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET_NUMBER]);

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...
98
        $computopPaymentTransfer->setShippingCountryCode($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_COUNTRY_CODE]);
0 ignored issues
show
Bug introduced by
The method setShippingCountryCode() 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

98
        $computopPaymentTransfer->/** @scrutinizer ignore-call */ 
99
                                  setShippingCountryCode($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_COUNTRY_CODE]);

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...
99
100
        return $computopPaymentTransfer;
101
    }
102
103
    /**
104
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
105
     *
106
     * @return string
107
     */
108
    protected function generateTransId(QuoteTransfer $quoteTransfer)
109
    {
110
        return $this->computopApiService->generateTransId($quoteTransfer);
111
    }
112
113
    /**
114
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
115
     * @param int $limit
116
     *
117
     * @return string
118
     */
119
    protected function getLimitedTransId(QuoteTransfer $quoteTransfer, $limit)
120
    {
121
        return substr($this->generateTransId($quoteTransfer), 0, $limit);
122
    }
123
124
    /**
125
     * @param string $path
126
     *
127
     * @return string
128
     */
129
    protected function getAbsoluteUrl($path)
130
    {
131
        return $this->config->getBaseUrlSsl() . $path;
132
    }
133
134
    /**
135
     * @return string
136
     */
137
    protected function getClientIp()
138
    {
139
        return $this->application['request']->getClientIp();
140
    }
141
142
    /**
143
     * @param string $url
144
     * @param array $queryData
145
     *
146
     * @return string
147
     */
148
    protected function getActionUrl($url, $queryData)
149
    {
150
        return $url . '?' . http_build_query($queryData);
151
    }
152
153
    /**
154
     * @param string $merchantId
155
     * @param string $data
156
     * @param int $length
157
     *
158
     * @return array
159
     */
160
    protected function getQueryParameters($merchantId, $data, $length)
161
    {
162
        $queryData = [
163
            ComputopApiConfig::MERCHANT_ID => $merchantId,
164
            ComputopApiConfig::DATA => $data,
165
            ComputopApiConfig::LENGTH => $length,
166
            ComputopApiConfig::URL_BACK => $this->getAbsoluteUrl(
167
                $this->application->path($this->config->getCallbackFailureRedirectPath())
168
            ),
169
        ];
170
171
        return $queryData;
172
    }
173
174
    /**
175
     * @param \Spryker\Shared\Kernel\Transfer\TransferInterface $computopPaymentTransfer
176
     *
177
     * @return \Generated\Shared\Transfer\ComputopApiRequestTransfer
178
     */
179
    protected function createRequestTransfer(TransferInterface $computopPaymentTransfer)
180
    {
181
        return (new ComputopApiRequestTransfer())
182
            ->fromArray($computopPaymentTransfer->toArray(), true);
183
    }
184
185
    /**
186
     * @param string $method
187
     *
188
     * @return string
189
     */
190
    protected function getCaptureType(string $method): string
191
    {
192
        $paymentMethodsCaptureTypes = $this->config->getPaymentMethodsCaptureTypes();
193
194
        return $paymentMethodsCaptureTypes[$method] ?? '';
195
    }
196
197
    /**
198
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
199
     *
200
     * @return array
201
     */
202
    protected function getAddressData(QuoteTransfer $quoteTransfer): array
203
    {
204
        $addressTransfer = $quoteTransfer->getBillingSameAsShipping() ? $quoteTransfer->getBillingAddress() : $quoteTransfer->getShippingAddress();
205
206
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_ZIP] = $addressTransfer->getZipCode();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$addressData was never initialized. Although not strictly required by PHP, it is generally a good practice to add $addressData = array(); before regardless.
Loading history...
207
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_CITY] = $addressTransfer->getCity();
208
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET] = $addressTransfer->getAddress1();
209
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET_NUMBER] = $addressTransfer->getAddress2();
210
        $addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_COUNTRY_CODE] = $addressTransfer->getIso2Code();
211
212
        return $addressData;
213
    }
214
}
215