| Conditions | 8 |
| Paths | 86 |
| Total Lines | 111 |
| Code Lines | 86 |
| 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 |
||
| 189 | public function postCheckout(Request $request) |
||
| 190 | { |
||
| 191 | $invoice_controller = new \App\Http\Controllers\Order\InvoiceController(); |
||
| 192 | $info_cont = new \App\Http\Controllers\Front\InfoController(); |
||
| 193 | $payment_method = $request->input('payment_gateway'); |
||
| 194 | \Session::put('payment_method', $payment_method); |
||
| 195 | $paynow = $this->checkregularPaymentOrRenewal($request->input('invoice_id')); |
||
| 196 | $cost = $request->input('cost'); |
||
| 197 | $state = $this->getState(); |
||
| 198 | try { |
||
| 199 | if ($paynow === false) { |
||
| 200 | /* |
||
| 201 | * Do order, invoicing etc |
||
| 202 | */ |
||
| 203 | |||
| 204 | $invoice = $invoice_controller->generateInvoice(); |
||
| 205 | |||
| 206 | $pay = $this->payment($payment_method, $status = 'pending'); |
||
| 207 | $payment_method = $pay['payment']; |
||
| 208 | $status = $pay['status']; |
||
| 209 | $invoice_no = $invoice->number; |
||
| 210 | $date = $this->getDate($invoice); |
||
| 211 | $invoiceid = $invoice->id; |
||
| 212 | $amount = $invoice->grand_total; |
||
| 213 | $url = ''; |
||
| 214 | $cart = Cart::getContent(); |
||
| 215 | $invoices = $this->invoice->find($invoiceid); |
||
| 216 | $items = new \Illuminate\Support\Collection(); |
||
| 217 | if ($invoices) { |
||
| 218 | $items = $invoice->invoiceItem()->get(); |
||
| 219 | $product = $this->product($invoiceid); |
||
| 220 | $content = Cart::getContent(); |
||
| 221 | $attributes = $this->getAttributes($content); |
||
| 222 | } |
||
| 223 | } else { |
||
| 224 | $items = new \Illuminate\Support\Collection(); |
||
| 225 | $invoiceid = $request->input('invoice_id'); |
||
| 226 | $invoice = $this->invoice->find($invoiceid); |
||
| 227 | $date = $this->getDate($invoice); |
||
| 228 | $items = $invoice->invoiceItem()->get(); |
||
| 229 | $product = $this->product($invoiceid); |
||
| 230 | $amount = $invoice->grand_total; |
||
| 231 | $content = Cart::getContent(); |
||
| 232 | $attributes = $this->getAttributes($content); |
||
| 233 | } |
||
| 234 | if (Cart::getSubTotal() != 0 || $cost > 0) { |
||
| 235 | $this->validate($request, [ |
||
| 236 | 'payment_gateway'=> 'required', |
||
| 237 | ],[ |
||
| 238 | 'payment_gateway.required'=> 'Please Select a Payment Gateway', |
||
| 239 | ]); |
||
| 240 | if ($payment_method == 'razorpay') { |
||
| 241 | $rzp_key = ApiKey::where('id', 1)->value('rzp_key'); |
||
| 242 | $rzp_secret = ApiKey::where('id', 1)->value('rzp_secret'); |
||
| 243 | $apilayer_key = ApiKey::where('id', 1)->value('apilayer_key'); |
||
| 244 | |||
| 245 | return view( |
||
| 246 | 'themes.default1.front.postCheckout', |
||
| 247 | compact( |
||
| 248 | 'amount', |
||
| 249 | 'invoice_no', |
||
| 250 | ' invoiceid', |
||
| 251 | ' payment_method', |
||
| 252 | 'phone', |
||
| 253 | 'invoice', |
||
| 254 | 'items', |
||
| 255 | 'product', |
||
| 256 | 'paynow', |
||
| 257 | 'content', |
||
| 258 | 'attributes', |
||
| 259 | 'rzp_key', |
||
| 260 | 'rzp_secret', |
||
| 261 | 'apilayer_key' |
||
| 262 | ) |
||
| 263 | ); |
||
| 264 | } else { |
||
| 265 | \Event::fire(new \App\Events\PaymentGateway(['request' => $request, 'cart' => Cart::getContent(), 'order' => $invoice])); |
||
| 266 | } |
||
| 267 | } else { |
||
| 268 | if ($paynow == false) {//Regular Payment for free Product |
||
| 269 | $action = $this->checkoutAction($invoice); |
||
| 270 | } else {//Renewal Payment for free Product |
||
| 271 | $control = new \App\Http\Controllers\Order\RenewController(); |
||
| 272 | $control->successRenew($invoice); |
||
| 273 | $payment = new \App\Http\Controllers\Order\InvoiceController(); |
||
| 274 | $payment->postRazorpayPayment($invoice->id, $invoice->grand_total); |
||
| 275 | |||
| 276 | } |
||
| 277 | |||
| 278 | // $check_product_category = $this->product($invoiceid); |
||
| 279 | $url = ''; |
||
| 280 | // if ($check_product_category->category) { |
||
| 281 | $url = view('themes.default1.front.postCheckoutTemplate', compact( |
||
| 282 | 'invoice', |
||
| 283 | 'date', |
||
| 284 | 'product', |
||
| 285 | 'items', |
||
| 286 | 'attributes', |
||
| 287 | 'state' |
||
| 288 | ))->render(); |
||
| 289 | // } |
||
| 290 | |||
| 291 | \Cart::clear(); |
||
| 292 | |||
| 293 | return redirect()->back()->with('success', $url); |
||
| 294 | } |
||
| 295 | } catch (\Exception $ex) { |
||
| 296 | app('log')->error($ex->getMessage()); |
||
| 297 | Bugsnag::notifyException($ex); |
||
| 298 | |||
| 299 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 300 | } |
||
| 356 |