| Conditions | 9 |
| Paths | 69 |
| Total Lines | 61 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 |
||
| 40 | public function payment($invoice, Request $request) |
||
| 41 | { |
||
| 42 | $userId = Invoice::find($invoice)->user_id; |
||
| 43 | if (\Auth::user()->role != 'admin' && $userId != \Auth::user()->id) { |
||
| 44 | return errorResponse('Payment cannot be initiated. Invalid modification of data'); |
||
| 45 | } |
||
| 46 | //Input items of form |
||
| 47 | $input = $request->all(); |
||
| 48 | $error = 'Payment Failed'; |
||
| 49 | $rzp_key = ApiKey::where('id', 1)->value('rzp_key'); |
||
| 50 | $rzp_secret = ApiKey::where('id', 1)->value('rzp_secret'); |
||
| 51 | $invoice = Invoice::where('id', $invoice)->first(); |
||
| 52 | if (count($input) && ! empty($input['razorpay_payment_id'])) { //Verify Razorpay Payment Id and Signature |
||
| 53 | |||
| 54 | //Fetch payment information by razorpay_payment_id |
||
| 55 | try { |
||
| 56 | $api = new Api($rzp_key, $rzp_secret); |
||
| 57 | $payment = $api->payment->fetch($input['razorpay_payment_id']); |
||
| 58 | $response = $api->payment->fetch($input['razorpay_payment_id']); |
||
| 59 | |||
| 60 | $stateCode = \Auth::user()->state; |
||
| 61 | $state = $this->getState($stateCode); |
||
| 62 | $currency = $this->getCurrency(); |
||
| 63 | |||
| 64 | //Change order Status as Success if payment is Successful |
||
| 65 | $control = new \App\Http\Controllers\Order\RenewController(); |
||
| 66 | //After Regular Payment |
||
| 67 | if ($control->checkRenew() === false) { |
||
| 68 | $checkout_controller = new \App\Http\Controllers\Front\CheckoutController(); |
||
| 69 | $checkout_controller->checkoutAction($invoice); |
||
| 70 | $view = $this->getViewMessageAfterPayment($invoice, $state, $currency); |
||
| 71 | $status = $view['status']; |
||
| 72 | $message = $view['message']; |
||
| 73 | \Session::forget('items'); |
||
| 74 | \Session::forget('code'); |
||
| 75 | \Session::forget('codevalue'); |
||
| 76 | } else { |
||
| 77 | //Afer Renew |
||
| 78 | $control->successRenew($invoice); |
||
| 79 | $payment = new \App\Http\Controllers\Order\InvoiceController(); |
||
| 80 | $payment->postRazorpayPayment($invoice); |
||
| 81 | if ($invoice->grand_total) { |
||
| 82 | SettingsController::sendPaymentSuccessMailtoAdmin($invoice->currency, $invoice->grand_total, \Auth::user(), $invoice->invoiceItem()->first()->product_name); |
||
| 83 | } |
||
| 84 | |||
| 85 | $view = $this->getViewMessageAfterRenew($invoice, $state, $currency); |
||
| 86 | $status = $view['status']; |
||
| 87 | $message = $view['message']; |
||
| 88 | } |
||
| 89 | \Cart::removeCartCondition('Processing fee'); |
||
| 90 | |||
| 91 | return redirect('checkout')->with($status, $message); |
||
| 92 | } catch (\Razorpay\Api\Errors\SignatureVerificationError | \Razorpay\Api\Errors\BadRequestError | \Razorpay\Api\Errors\GatewayError | \Razorpay\Api\Errors\ServerError $e) { |
||
| 93 | dd($e); |
||
| 94 | SettingsController::sendFailedPaymenttoAdmin($invoice->grand_total, $e->getMessage()); |
||
| 95 | |||
| 96 | return redirect('checkout')->with('fails', 'Your Payment was declined. '.$e->getMessage().'. Please try again or try the other gateway'); |
||
| 97 | } catch (\Exception $e) { |
||
| 98 | dd($e); |
||
| 99 | |||
| 100 | return redirect('checkout')->with('fails', 'Your Payment was declined. '.$e->getMessage().'. Please try again or try the other gateway'); |
||
| 101 | } |
||
| 156 |