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\QuoteTransfer; |
|
|
|
|
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()); |
|
|
|
|
82
|
|
|
$computopPaymentTransfer->setAmount($quoteTransfer->getTotals()->getGrandTotal()); |
|
|
|
|
83
|
|
|
$computopPaymentTransfer->setCurrency($this->store->getCurrencyIsoCode()); |
|
|
|
|
84
|
|
|
$computopPaymentTransfer->setResponse(ComputopConfig::RESPONSE_ENCRYPT_TYPE); |
|
|
|
|
85
|
|
|
$computopPaymentTransfer->setClientIp($this->getClientIp()); |
|
|
|
|
86
|
|
|
$computopPaymentTransfer->setReqId($this->computopApiService->generateReqIdFromQuoteTransfer($quoteTransfer)); |
|
|
|
|
87
|
|
|
$computopPaymentTransfer->setUrlFailure( |
|
|
|
|
88
|
|
|
$this->getAbsoluteUrl($this->application->path(ComputopControllerProvider::FAILURE_PATH_NAME)) |
|
|
|
|
89
|
|
|
); |
90
|
|
|
$computopPaymentTransfer->setShippingZip($this->getZipCode($quoteTransfer)); |
|
|
|
|
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
|
|
|
|
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