| Conditions | 8 |
| Paths | 180 |
| Total Lines | 80 |
| Code Lines | 54 |
| 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 |
||
| 43 | public function payment($invoice, Request $request) |
||
| 44 | { |
||
| 45 | |||
| 46 | //Input items of form |
||
| 47 | $input = Input::all(); |
||
| 48 | |||
| 49 | $success = true; |
||
| 50 | $error = 'Payment Failed'; |
||
| 51 | $rzp_key = ApiKey::where('id', 1)->value('rzp_key'); |
||
| 52 | $rzp_secret = ApiKey::where('id', 1)->value('rzp_secret'); |
||
| 53 | |||
| 54 | $api = new Api($rzp_key, $rzp_secret); |
||
| 55 | $payment = $api->payment->fetch($input['razorpay_payment_id']); |
||
| 56 | |||
| 57 | if (count($input) && !empty($input['razorpay_payment_id'])) { //Verify Razorpay Payment Id and Signature |
||
| 58 | |||
| 59 | //Fetch payment information by razorpay_payment_id |
||
| 60 | try { |
||
| 61 | $response = $api->payment->fetch($input['razorpay_payment_id']); |
||
| 62 | // $api->utility->verifyPaymentSignature($attributes); |
||
| 63 | } catch (SignatureVerificationError $e) { |
||
| 64 | $success = false; |
||
| 65 | $error = 'Razorpay Error : '.$e->getMessage(); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | $country = \Auth::user()->country; |
||
| 69 | |||
| 70 | if ($country != 'IN') { |
||
| 71 | $state = State::where('state_subdivision_code', $stateCode)->pluck('state_subdivision_name')->first(); |
||
|
|
|||
| 72 | } else { |
||
| 73 | $state = TaxByState::where('state_code', \Auth::user()->state)->pluck('state')->first(); |
||
| 74 | } |
||
| 75 | $invoice = Invoice::where('id', $invoice)->first(); |
||
| 76 | |||
| 77 | if ($success === true) { |
||
| 78 | try { |
||
| 79 | //Change order Status as Success if payment is Successful |
||
| 80 | $control = new \App\Http\Controllers\Order\RenewController(); |
||
| 81 | |||
| 82 | if ($control->checkRenew() === false) { |
||
| 83 | $checkout_controller = new \App\Http\Controllers\Front\CheckoutController(); |
||
| 84 | |||
| 85 | $checkout_controller->checkoutAction($invoice); |
||
| 86 | |||
| 87 | $order = Order::where('invoice_id', $invoice->id)->first(); |
||
| 88 | $invoiceItem = InvoiceItem::where('invoice_id', $invoice->id)->first(); |
||
| 89 | $date1 = new DateTime($order->created_at); |
||
| 90 | $tz = \Auth::user()->timezone()->first()->name; |
||
| 91 | $date1->setTimezone(new DateTimeZone($tz)); |
||
| 92 | $date = $date1->format('M j, Y, g:i a '); |
||
| 93 | $product = Product::where('id', $order->product)->select('id', 'name')->first(); |
||
| 94 | |||
| 95 | \Cart::clear(); |
||
| 96 | $status = 'success'; |
||
| 97 | $message = view('themes.default1.front.postPaymentTemplate', compact('invoice','date','order', |
||
| 98 | 'product','invoiceItem'))->render(); |
||
| 99 | \Session::forget('items'); |
||
| 100 | } else { |
||
| 101 | $control->successRenew($invoice); |
||
| 102 | $payment = new \App\Http\Controllers\Order\InvoiceController(); |
||
| 103 | $payment->postRazorpayPayment($invoice->id, $invoice->grand_total); |
||
| 104 | |||
| 105 | $invoiceItem = InvoiceItem::where('invoice_id', $invoice->id)->first(); |
||
| 106 | $product = Product::where('name', $invoiceItem->product_name)->first(); |
||
| 107 | $date1 = new DateTime($invoiceItem->created_at); |
||
| 108 | |||
| 109 | $tz = \Auth::user()->timezone()->first()->name; |
||
| 110 | |||
| 111 | $date1->setTimezone(new DateTimeZone($tz)); |
||
| 112 | $date = $date1->format('M j, Y, g:i a '); |
||
| 113 | |||
| 114 | \Cart::clear(); |
||
| 115 | $status = 'success'; |
||
| 116 | |||
| 117 | $message =view('themes.default1.front.postRenewTemplate', compact('invoice','date','order', |
||
| 118 | 'product','invoiceItem'))->render(); |
||
| 119 | } |
||
| 120 | return redirect()->back()->with($status, $message); |
||
| 121 | } catch (\Exception $ex) { |
||
| 122 | throw new \Exception($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); |
||
| 123 | } |
||
| 127 |