This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify |
||
5 | * it under the terms of the GNU Lesser General Public License as published by |
||
6 | * the Free Software Foundation, either version 3 of the License, or |
||
7 | * (at your option) any later version. |
||
8 | * |
||
9 | * PAYONE Magento 2 Connector is distributed in the hope that it will be useful, |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
12 | * GNU Lesser General Public License for more details. |
||
13 | * |
||
14 | * You should have received a copy of the GNU Lesser General Public License |
||
15 | * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. |
||
16 | * |
||
17 | * PHP version 5 |
||
18 | * |
||
19 | * @category Payone |
||
20 | * @package Payone_Magento2_Plugin |
||
21 | * @author FATCHIP GmbH <[email protected]> |
||
22 | * @copyright 2003 - 2016 Payone GmbH |
||
23 | * @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
||
24 | * @link http://www.payone.de |
||
25 | */ |
||
26 | |||
27 | namespace Payone\Core\Model\Methods; |
||
28 | |||
29 | use Magento\Framework\Exception\LocalizedException; |
||
30 | use Magento\Payment\Model\InfoInterface; |
||
31 | use Magento\Sales\Model\Order; |
||
32 | |||
33 | /** |
||
34 | * Abstract model for all the PAYONE payment methods |
||
35 | */ |
||
36 | abstract class PayoneMethod extends BaseMethod |
||
37 | { |
||
38 | /** |
||
39 | * Returns clearingtype |
||
40 | * |
||
41 | * @return string |
||
42 | * @throws LocalizedException |
||
43 | */ |
||
44 | public function getClearingtype() |
||
45 | { |
||
46 | return $this->sClearingtype; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Returns authorization-mode |
||
51 | * preauthorization or authorization |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | public function getAuthorizationMode() |
||
56 | { |
||
57 | $sRequestType = $this->shopHelper->getConfigParam('request_type'); |
||
58 | if ($this->hasCustomConfig()) { |
||
59 | $sRequestType = $this->getCustomConfigParam('request_type'); |
||
60 | } |
||
61 | return $sRequestType; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Method handling the debit request and the response |
||
66 | * |
||
67 | * @param InfoInterface $payment |
||
68 | * @param float $amount |
||
69 | * @return void |
||
70 | * @throws LocalizedException |
||
71 | */ |
||
72 | View Code Duplication | protected function sendPayoneDebit(InfoInterface $payment, $amount) |
|
0 ignored issues
–
show
|
|||
73 | { |
||
74 | $aResponse = $this->debitRequest->sendRequest($this, $payment, $amount); |
||
75 | if ($aResponse['status'] == 'ERROR') { |
||
76 | throw new LocalizedException(__($aResponse['errorcode'].' - '.$aResponse['customermessage'])); |
||
77 | } elseif (!$aResponse) { |
||
0 ignored issues
–
show
The expression
$aResponse of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
78 | throw new LocalizedException(__('Unkown error')); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Method handling the capture request and the response |
||
84 | * |
||
85 | * @param InfoInterface $payment |
||
86 | * @param float $amount |
||
87 | * @return void |
||
88 | * @throws LocalizedException |
||
89 | */ |
||
90 | View Code Duplication | protected function sendPayoneCapture(InfoInterface $payment, $amount) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
91 | { |
||
92 | $aResponse = $this->captureRequest->sendRequest($this, $payment, $amount); |
||
93 | if ($aResponse['status'] == 'ERROR') {// request returned an error |
||
94 | throw new LocalizedException(__($aResponse['errorcode'].' - '.$aResponse['customermessage'])); |
||
95 | } elseif (!$aResponse) {// response not existing |
||
0 ignored issues
–
show
The expression
$aResponse of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
96 | throw new LocalizedException(__('Unkown error')); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Method handling the authorization request and the response |
||
102 | * |
||
103 | * @param InfoInterface $payment |
||
104 | * @param float $amount |
||
105 | * @return void |
||
106 | * @throws LocalizedException |
||
107 | */ |
||
108 | protected function sendPayoneAuthorization(InfoInterface $payment, $amount) |
||
109 | { |
||
110 | $oOrder = $payment->getOrder(); |
||
111 | $oOrder->setCanSendNewEmailFlag(false); // dont send email now, will be sent on appointed |
||
112 | $this->checkoutSession->unsPayoneRedirectUrl(); // remove redirect url from session |
||
113 | $aResponse = $this->authorizationRequest->sendRequest($this, $oOrder, $amount); |
||
114 | $this->handleResponse($aResponse); |
||
115 | if ($aResponse['status'] == 'ERROR') {// request returned an error |
||
116 | throw new LocalizedException(__($aResponse['errorcode'].' - '.$aResponse['customermessage'])); |
||
117 | } elseif ($aResponse['status'] == 'APPROVED' || $aResponse['status'] == 'REDIRECT') {// request successful |
||
118 | $payment->setTransactionId($aResponse['txid']); |
||
119 | $payment->setIsTransactionClosed(0); |
||
120 | if ($aResponse['status'] == 'REDIRECT') {// user needs to be redirected to external payment page |
||
121 | $this->checkoutSession->setPayoneRedirectUrl($aResponse['redirecturl']); |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Perform certain actions with the response |
||
128 | * |
||
129 | * @param array $aResponse |
||
130 | * @return void |
||
131 | */ |
||
132 | protected function handleResponse($aResponse) |
||
133 | { |
||
134 | // hook for certain payment methods |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Returns operationmode live or test for this payment method |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | public function getOperationMode() |
||
143 | { |
||
144 | return $this->getCustomConfigParam('mode'); |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * Return parameters specific to this payment type |
||
149 | * |
||
150 | * @param Order $oOrder |
||
151 | * @return array |
||
152 | */ |
||
153 | public function getPaymentSpecificParameters(Order $oOrder) |
||
154 | { |
||
155 | return []; // filled in child classes |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Return success url for redirect payment types |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getSuccessUrl() |
||
164 | { |
||
165 | return $this->url->getUrl('payone/onepage/returned'); |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Return cancel url for redirect payment types |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | public function getCancelUrl() |
||
174 | { |
||
175 | return $this->url->getUrl('payone/onepage/cancel'); |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * Return error url for redirect payment types |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | public function getErrorUrl() |
||
184 | { |
||
185 | return $this->url->getUrl('payone/onepage/cancel?error=1'); |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * Return if redirect urls have to be added to the authroization request |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function needsRedirectUrls() |
||
194 | { |
||
195 | return $this->blNeedsRedirectUrls; |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * Return if invoice data has to be added to the authroization request |
||
200 | * |
||
201 | * @return bool |
||
202 | */ |
||
203 | public function needsProductInfo() |
||
204 | { |
||
205 | return $this->blNeedsProductInfo; |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Get config parameter for this payment type |
||
210 | * |
||
211 | * @param string $sParam |
||
212 | * @return string |
||
213 | */ |
||
214 | public function getCustomConfigParam($sParam) |
||
215 | { |
||
216 | return $this->shopHelper->getConfigParam($sParam, $this->getCode(), 'payone_payment'); |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * Returns if global PAYONE config is used for this payment type |
||
221 | * |
||
222 | * @return bool |
||
223 | */ |
||
224 | public function hasCustomConfig() |
||
225 | { |
||
226 | if ($this->getCustomConfigParam('use_global') == '0') {// has non-global config |
||
227 | return true; |
||
228 | } |
||
229 | return false; |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * Return if this payment method is part of a group |
||
234 | * |
||
235 | * @return bool |
||
236 | */ |
||
237 | public function isGroupMethod() |
||
238 | { |
||
239 | if ($this->sGroupName === false) { |
||
240 | return false; |
||
241 | } |
||
242 | return true; |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * Returns group identifier |
||
247 | * |
||
248 | * @return string|bool |
||
249 | */ |
||
250 | public function getGroupName() |
||
251 | { |
||
252 | return $this->sGroupName; |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * Returns group identifier |
||
257 | * |
||
258 | * @return string|bool |
||
259 | */ |
||
260 | public function getSubType() |
||
261 | { |
||
262 | return $this->sSubType; |
||
263 | } |
||
264 | |||
265 | /** |
||
266 | * Return parameters specific to this payment sub type |
||
267 | * |
||
268 | * @param Order $oOrder |
||
269 | * @return array |
||
270 | */ |
||
271 | public function getSubTypeSpecificParameters(Order $oOrder) |
||
272 | { |
||
273 | return []; // filled in child classes |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * Formats the reference number if needed for this payment method |
||
278 | * Needed for Paydirekt |
||
279 | * |
||
280 | * @param string $sRefNr |
||
281 | * @return string |
||
282 | */ |
||
283 | public function formatReferenceNumber($sRefNr) |
||
284 | { |
||
285 | return $sRefNr; |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * Return max length of narrative text |
||
290 | * |
||
291 | * @return int |
||
292 | */ |
||
293 | public function getNarrativeTextMaxLength() |
||
294 | { |
||
295 | return $this->iNarrativeTextMax; |
||
296 | } |
||
297 | } |
||
298 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.