Conditions | 13 |
Paths | 11 |
Total Lines | 114 |
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 |
||
50 | public function preparePage() |
||
51 | { |
||
52 | $this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager); |
||
53 | $this->P->cb_pagetype = 'content'; |
||
54 | |||
55 | $sLogData = ''; |
||
56 | |||
57 | $iId = \filter_input(INPUT_POST, 'custom', FILTER_SANITIZE_NUMBER_INT); |
||
58 | |||
59 | $queryBuilder = $this->dbal->createQueryBuilder(); |
||
60 | $queryBuilder |
||
61 | ->select('*') |
||
62 | ->from('orders') |
||
63 | ->where('o_id = ?') |
||
64 | ->andWhere('o_paymentmethod = \'paypal\'') |
||
65 | ->andWhere('o_paymentcompleted = \'n\'') |
||
66 | ->setParameter(0, $iId) |
||
67 | ; |
||
68 | $statement = $queryBuilder->execute(); |
||
69 | |||
70 | if ($statement->rowCount() == 1) { |
||
71 | $aOrder = $statement->fetch(); |
||
72 | $fGesamtbrutto = $this->helperShop->calculateTotalFromDB($aOrder); |
||
73 | |||
74 | $postdata = ''; |
||
75 | |||
76 | foreach ($_POST as $i => $v) { |
||
77 | $postdata .= $i . '=' . urlencode($v) . '&'; |
||
78 | } |
||
79 | $postdata .= 'cmd=_notify-validate'; |
||
80 | $web = parse_url($this->config->getShop('paypal')['url']); |
||
81 | |||
82 | if ($web['scheme'] === 'https') { |
||
83 | $web['port'] = 443; |
||
84 | $ssl = 'ssl://'; |
||
85 | } else { |
||
86 | $web['port'] = 80; |
||
87 | $ssl = ''; |
||
88 | } |
||
89 | $fp = @fsockopen($ssl . $web['host'], $web['port'], $errnum, $errstr, 30); |
||
90 | |||
91 | if ($fp) { |
||
92 | fwrite($fp, 'POST ' . $web['path'] . " HTTP/1.1\r\n"); |
||
93 | fwrite($fp, 'Host: ' . $web['host'] . "\r\n"); |
||
94 | fwrite($fp, "Content-type: application/x-www-form-urlencoded\r\n"); |
||
95 | fwrite($fp, 'Content-length: ' . strlen($postdata) . "\r\n"); |
||
96 | fwrite($fp, "Connection: close\r\n\r\n"); |
||
97 | fwrite($fp, $postdata . "\r\n\r\n"); |
||
98 | |||
99 | $info = []; |
||
100 | while (!feof($fp)) { |
||
101 | $info[] = fgets($fp, 1024); |
||
102 | } |
||
103 | fclose($fp); |
||
104 | $info = implode(',', $info); |
||
105 | if (!(strpos($info, 'VERIFIED') === false)) { |
||
106 | |||
107 | $sLogData .= '-- new entry - '.date($this->config->getCore('locale_format_date_time')) . " --\n\n"; |
||
108 | $sLogData .= "W00T!\n\n"; |
||
109 | $sLogData .= \HaaseIT\Toolbox\Tools::debug($_REQUEST, '', true, true) . "\n\n"; |
||
110 | |||
111 | // Check if the transaction id has been used before |
||
112 | $queryBuilder = $this->dbal->createQueryBuilder(); |
||
113 | $queryBuilder |
||
114 | ->select('o_paypal_tx') |
||
115 | ->from('orders') |
||
116 | ->where('o_paypal_tx = ?') |
||
117 | ->setParameter(0, filter_input(INPUT_POST, 'txn_id')); |
||
118 | $statement = $queryBuilder->execute(); |
||
119 | |||
120 | if ($statement->rowCount() === 0) { |
||
121 | if ( |
||
122 | filter_input(INPUT_POST, 'payment_status') === 'Completed' |
||
123 | && filter_input(INPUT_POST, 'mc_gross') == number_format($fGesamtbrutto, 2, '.', '') |
||
124 | && filter_input(INPUT_POST, 'custom') == $aOrder['o_id'] |
||
125 | && filter_input(INPUT_POST, 'mc_currency') == $this->config->getShop('paypal')['currency_id'] |
||
126 | && filter_input(INPUT_POST, 'business') == $this->config->getShop('paypal')['business'] |
||
127 | ) { |
||
128 | $queryBuilder = $this->dbal->createQueryBuilder(); |
||
129 | $queryBuilder |
||
130 | ->update('orders') |
||
131 | ->set('o_paypal_tx', '?') |
||
132 | ->set('o_paymentcompleted', 'y') |
||
133 | ->setParameter(0, filter_input(INPUT_POST, 'txn_id')) |
||
134 | ->where('o_id = ?') |
||
135 | ->setParameter(1, $iId); |
||
136 | $queryBuilder->execute(); |
||
137 | |||
138 | $sLogData .= '-- Alles ok. Zahlung erfolgreich. TXNID: ' . $_REQUEST['txn_id'] . " --\n\n"; |
||
139 | } else { |
||
140 | $sLogData .= "-- In my country we have problem; Problem is evaluation. Throw the data down the log!\n"; |
||
141 | $sLogData .= 'mc_gross: ' . $_REQUEST['mc_gross'] . ' - number_format($fGesamtbrutto, 2, \'.\', \'\'): ' . number_format($fGesamtbrutto, |
||
142 | 2, '.', '') . "\n"; |
||
143 | $sLogData .= 'custom: ' . $_REQUEST['custom'] . ' - $aOrder[\'o_id\']: ' . $aOrder['o_id'] . "\n"; |
||
144 | $sLogData .= 'payment_status: ' . $_REQUEST['payment_status'] . "\n"; |
||
145 | $sLogData .= 'mc_currency: ' . $_REQUEST['mc_currency'] . ' - HelperConfig::$shop["paypal"]["currency_id"]: ' . $this->config->getShop('paypal')['currency_id'] . "\n"; |
||
146 | $sLogData .= 'business: ' . $_REQUEST['receiver_email'] . ' - HelperConfig::$shop["paypal"]["business"]: ' . $this->config->getShop('paypal')['business'] . "\n\n"; |
||
147 | } |
||
148 | } else { |
||
149 | // INVALID LOGGING ERROR |
||
150 | $sLogData .= '-- new entry - ' . date($this->config->getCore('locale_format_date_time')) . " --\n\nPHAIL\n\n"; |
||
151 | $sLogData .= '!!! JEMAND HAT EINE ALTE TXN_ID BENUTZT: ' . $_REQUEST['txn_id'] . " !!!\n\n"; |
||
152 | $sLogData .= "!!! INVALID !!!\n\n"; |
||
153 | } |
||
154 | } else { |
||
155 | $sLogData .= '-- new entry - ' . date($this->config->getCore('locale_format_date_time')) . " --\n\nPHAIL - Transaktion fehlgeschlagen. TXNID: " . $_REQUEST['txn_id'] . "\n" . $info . "\n\n"; |
||
156 | } |
||
157 | |||
158 | file_put_contents(PATH_LOGS . FILE_PAYPALLOG, $sLogData, FILE_APPEND); |
||
159 | } |
||
160 | } |
||
161 | |||
162 | $this->helper->terminateScript(); |
||
163 | } |
||
164 | } |
||
165 |