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; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\ComputopEasyCreditPaymentTransfer; |
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
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()); |
|
|
|
|
83
|
|
|
$computopPaymentTransfer->setAmount($quoteTransfer->getTotals()->getGrandTotal()); |
|
|
|
|
84
|
|
|
$computopPaymentTransfer->setCurrency($this->store->getCurrencyIsoCode()); |
|
|
|
|
85
|
|
|
$computopPaymentTransfer->setResponse(ComputopConfig::RESPONSE_ENCRYPT_TYPE); |
|
|
|
|
86
|
|
|
$computopPaymentTransfer->setClientIp($this->getClientIp()); |
|
|
|
|
87
|
|
|
$computopPaymentTransfer->setReqId($this->computopApiService->generateReqIdFromQuoteTransfer($quoteTransfer)); |
|
|
|
|
88
|
|
|
$computopPaymentTransfer->setUrlFailure( |
|
|
|
|
89
|
|
|
$this->getAbsoluteUrl($this->application->path(ComputopControllerProvider::FAILURE_PATH_NAME)) |
|
|
|
|
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
$addressData = $this->getAddressData($quoteTransfer); |
93
|
|
|
|
94
|
|
|
$computopPaymentTransfer->setShippingZip($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_ZIP]); |
|
|
|
|
95
|
|
|
$computopPaymentTransfer->setShippingCity($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_CITY]); |
|
|
|
|
96
|
|
|
$computopPaymentTransfer->setShippingStreet($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET]); |
|
|
|
|
97
|
|
|
$computopPaymentTransfer->setShippingStreetNumber($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_STREET_NUMBER]); |
|
|
|
|
98
|
|
|
$computopPaymentTransfer->setShippingCountryCode($addressData[ComputopEasyCreditPaymentTransfer::SHIPPING_COUNTRY_CODE]); |
|
|
|
|
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(); |
|
|
|
|
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
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths