Conditions | 7 |
Paths | 4 |
Total Lines | 68 |
Code Lines | 50 |
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 |
||
156 | public function processPayment($data, $form) |
||
157 | { |
||
158 | //save data |
||
159 | $this->write(); |
||
160 | |||
161 | //get variables |
||
162 | $isTest = $this->isTest(); |
||
163 | $order = $this->Order(); |
||
164 | //if currency has been pre-set use this |
||
165 | $currency = strtoupper($this->Amount->Currency); |
||
166 | //if amout has been pre-set, use this |
||
167 | $amount = $this->Amount->Amount; |
||
168 | $username = $this->Config()->get("username"); |
||
169 | $password = $this->Config()->get("password"); |
||
170 | if (!$username || !$password) { |
||
171 | user_error("Make sure to set a username and password."); |
||
172 | } |
||
173 | |||
174 | $xml = "<Txn>"; |
||
175 | $xml .= "<PostUsername>".$username."</PostUsername>"; |
||
176 | $xml .= "<PostPassword>".$password."</PostPassword>"; |
||
177 | $xml .= "<CardHolderName>".Convert::raw2xml($this->NameOnCard)."</CardHolderName>"; |
||
178 | $xml .= "<CardNumber>".$this->CardNumber."</CardNumber>"; |
||
179 | $xml .= "<Amount>".round($amount, 2)."</Amount>"; |
||
180 | $xml .= "<DateExpiry>".$this->ExpiryDate."</DateExpiry>"; |
||
181 | $xml .= "<Cvc2>".$this->CVVNumber."</Cvc2>"; |
||
182 | $xml .= "<Cvc2Presence>1</Cvc2Presence>"; |
||
183 | $xml .= "<InputCurrency>".Convert::raw2xml(strtoupper($currency))."</InputCurrency>"; |
||
184 | $xml .= "<TxnType>".Convert::raw2xml($this->Config()->get("type"))."</TxnType>"; |
||
185 | $xml .= "<TxnId>".$this->ID."</TxnId>"; |
||
186 | $xml .= "<MerchantReference>".$this->OrderID."</MerchantReference>"; |
||
187 | $xml .= "</Txn>"; |
||
188 | $URL = "sec.paymentexpress.com/pxpost.aspx"; |
||
189 | //echo "\n\n\n\nSENT:\n$cmdDoTxnTransaction\n\n\n\n\n$"; |
||
190 | |||
191 | $ch = curl_init(); |
||
192 | curl_setopt($ch, CURLOPT_URL, "https://".$URL); |
||
193 | curl_setopt($ch, CURLOPT_POST, 1); |
||
194 | curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); |
||
195 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
196 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //Needs to be included if no *.crt is available to verify SSL certificates |
||
197 | |||
198 | $result = curl_exec($ch); |
||
199 | curl_close($ch); |
||
200 | |||
201 | $params = new SimpleXMLElement($result); |
||
202 | $txn = $params->Transaction; |
||
203 | |||
204 | //save basic info |
||
205 | //$this->Request = Convert::raw2sql($xml); |
||
206 | $this->Response = str_replace('\n', "\n", Convert::raw2sql(print_r($params, 1))); |
||
207 | $this->Message = Convert::raw2sql($txn->CardHolderResponseText." ".$txn->CardHolderResponseDescription); |
||
208 | $this->CardNumber = Convert::raw2sql($txn->CardNumber); |
||
209 | if ( |
||
210 | $params->Success == 1 && |
||
211 | $amount == $txn->Amount && |
||
212 | $currency == $txn->CurrencyName && |
||
213 | trim($this->OrderID) == trim($txn->MerchantReference) |
||
214 | ) { |
||
215 | $this->Status = "Success"; |
||
216 | $returnObject = EcommercePayment_Success::create(); |
||
217 | } else { |
||
218 | $this->Status = "Failure"; |
||
219 | $returnObject = EcommercePayment_Failure::create(); |
||
220 | } |
||
221 | $this->write(); |
||
222 | return $returnObject; |
||
223 | } |
||
224 | |||
252 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.