| Conditions | 15 |
| Paths | 108 |
| Total Lines | 103 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 194 | public function gatewayNotify($gatewaysLogPath) |
||
| 195 | { |
||
| 196 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 197 | $commandsHandler = new Oledrion\CommandsHandler($db); |
||
| 198 | // Get from bank |
||
| 199 | $authority = $_GET['au']; |
||
| 200 | $status = $_GET['rs']; |
||
| 201 | $cmd_id = \Xmf\Request::getInt('cmd_id', 0, 'GET'); |
||
| 202 | $cmd_total = \Xmf\Request::getInt('cmd_total', 0, 'GET'); |
||
| 203 | // Set soap |
||
| 204 | $url = $this->getDialogURL(); |
||
| 205 | if (extension_loaded('soap')) { |
||
| 206 | $soapclient = new \SoapClient($url); |
||
| 207 | } else { |
||
| 208 | require_once __DIR__ . '/nusoap.php'; |
||
| 209 | $soapclient = new \SoapClient($url, 'wsdl'); |
||
| 210 | } |
||
| 211 | // here we update our database |
||
| 212 | $save_ok = 0; |
||
| 213 | if ($authority) { |
||
| 214 | $save_ok = 1; |
||
| 215 | } |
||
| 216 | // doing |
||
| 217 | if ((0 == $status) && $save_ok) { |
||
| 218 | if ((!$soapclient) || ($err = $soapclient->getError())) { |
||
| 219 | // this is unsucccessfull connection |
||
| 220 | $commande = null; |
||
| 221 | $commande = $commandsHandler->get($cmd_id); |
||
| 222 | if (is_object($commande)) { |
||
| 223 | $commandsHandler->setOrderFailed($commande); |
||
| 224 | $user_log = 'خطا در پرداخت - خطا در ارتباط با بانک'; |
||
| 225 | } else { |
||
| 226 | $commandsHandler->setFraudulentOrder($commande); |
||
| 227 | $user_log = 'خطا در ارتباط با بانک - اطلاعات پرداخت شما نا معتبر است'; |
||
| 228 | } |
||
| 229 | } else { |
||
| 230 | //$status = 1; |
||
| 231 | $params = [ |
||
| 232 | 'pin' => $this->getParsianMid(), |
||
| 233 | 'authority' => $authority, |
||
| 234 | 'status' => $status, |
||
| 235 | ]; |
||
| 236 | $sendParams = [$params]; |
||
| 237 | $res = $soapclient->call('PinPaymentEnquiry', $sendParams); |
||
| 238 | $status = $res['status']; |
||
| 239 | if (0 == $status) { |
||
| 240 | // this is a succcessfull payment |
||
| 241 | // we update our DataBase |
||
| 242 | $commande = null; |
||
| 243 | $commande = $commandsHandler->get($cmd_id); |
||
| 244 | if (is_object($commande)) { |
||
| 245 | if ($cmd_total == (int)$commande->getVar('cmd_total')) { |
||
| 246 | $commandsHandler->validateOrder($commande); |
||
| 247 | $user_log = 'پرداخت شما با موفقیت انجام شد. محصول برای شما ارسال می شود'; |
||
| 248 | } else { |
||
| 249 | $commandsHandler->setFraudulentOrder($commande); |
||
| 250 | $user_log = 'اطلاعات پرداخت شما نا معتبر است'; |
||
| 251 | } |
||
| 252 | } |
||
| 253 | $log .= "VERIFIED\t"; |
||
| 254 | } else { |
||
| 255 | // this is a UNsucccessfull payment |
||
| 256 | // we update our DataBase |
||
| 257 | $commande = null; |
||
| 258 | $commande = $commandsHandler->get($cmd_id); |
||
| 259 | if (is_object($commande)) { |
||
| 260 | $commandsHandler->setOrderFailed($commande); |
||
| 261 | $user_log = 'خطا در پرداخت - وضعیت این پرداخت صحیح نیست'; |
||
| 262 | } else { |
||
| 263 | $commandsHandler->setFraudulentOrder($commande); |
||
| 264 | $user_log = 'وضعیت این پرداخت صحیح نیست - اطلاعات پرداخت شما نا معتبر است'; |
||
| 265 | } |
||
| 266 | $log .= "$status\n"; |
||
| 267 | } |
||
| 268 | } |
||
| 269 | } else { |
||
| 270 | // this is a UNsucccessfull payment |
||
| 271 | $commande = null; |
||
| 272 | $commande = $commandsHandler->get($cmd_id); |
||
| 273 | if (is_object($commande)) { |
||
| 274 | $commandsHandler->setOrderFailed($commande); |
||
| 275 | $user_log = 'خطا در پرداخت - این پرداخت نا معتبر است'; |
||
| 276 | } else { |
||
| 277 | $commandsHandler->setFraudulentOrder($commande); |
||
| 278 | $user_log = 'این پرداخت نا معتبر است - اطلاعات پرداخت شما نا معتبر است'; |
||
| 279 | } |
||
| 280 | $log .= "$status\n"; |
||
| 281 | } |
||
| 282 | |||
| 283 | // Ecriture dans le fichier log |
||
| 284 | $fp = fopen($gatewaysLogPath, 'ab'); |
||
| 285 | if ($fp) { |
||
| 286 | fwrite($fp, str_repeat('-', 120) . "\n"); |
||
| 287 | fwrite($fp, date('d/m/Y H:i:s') . "\n"); |
||
| 288 | if (isset($status)) { |
||
| 289 | fwrite($fp, 'Transaction : ' . $status . "\n"); |
||
| 290 | } |
||
| 291 | fwrite($fp, 'Result : ' . $log . "\n"); |
||
| 292 | fwrite($fp, 'Peyment note : ' . $user_log . "\n"); |
||
| 293 | fclose($fp); |
||
| 294 | } |
||
| 295 | |||
| 296 | return $user_log; |
||
| 297 | } |
||
| 299 |