Conditions | 13 |
Paths | 600 |
Total Lines | 115 |
Code Lines | 88 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
134 | public function postPaymentWithRazorpay(Request $request) |
||
135 | { |
||
136 | $validator = Validator::make($request->all(), [ |
||
137 | ]); |
||
138 | $input = $request->all(); |
||
139 | $validation = [ |
||
140 | 'card_no' => 'required', |
||
141 | 'exp_month' => 'required', |
||
142 | 'exp_year' => 'required', |
||
143 | 'cvv' => 'required', |
||
144 | ]; |
||
145 | |||
146 | $this->validate($request, $validation); |
||
147 | $stripeSecretKey = ApiKey::pluck('stripe_secret')->first(); |
||
148 | $stripe = Stripe::make($stripeSecretKey); |
||
149 | try { |
||
150 | $invoice = \Session::get('invoice'); |
||
151 | $invoiceTotal = \Session::get('totalToBePaid'); |
||
152 | $amount = rounding(\Cart::getTotal()); |
||
153 | if (! $amount) {//During renewal |
||
154 | if (rounding($request->input('amount')) != rounding($invoiceTotal)) { |
||
155 | throw new \Exception('Invalid modification of data'); |
||
156 | } |
||
157 | $amount = rounding($request->input('amount')); |
||
158 | } |
||
159 | $stripeSecretKey = ApiKey::pluck('stripe_secret')->first(); |
||
160 | $stripe = Stripe::make($stripeSecretKey); |
||
161 | $token = $stripe->tokens()->create([ |
||
162 | 'card' => [ |
||
163 | 'number' => $request->get('card_no'), |
||
164 | 'exp_month' => $request->get('exp_month'), |
||
165 | 'exp_year' => $request->get('exp_year'), |
||
166 | 'cvc' => $request->get('cvv'), |
||
167 | ], |
||
168 | ]); |
||
169 | if (! isset($token['id'])) { |
||
170 | \Session::put('error', 'The Stripe Token was not generated correctly'); |
||
171 | |||
172 | return redirect()->route('stripform'); |
||
173 | } |
||
174 | $customer = $stripe->customers()->create([ |
||
175 | 'name' => \Auth::user()->first_name.' '.\Auth::user()->last_name, |
||
176 | 'email' => \Auth::user()->email, |
||
177 | 'address' => [ |
||
178 | 'line1' => \Auth::user()->address, |
||
179 | 'postal_code' => \Auth::user()->zip, |
||
180 | 'city' => \Auth::user()->town, |
||
181 | 'state' => \Auth::user()->state, |
||
182 | 'country' => \Auth::user()->country, |
||
183 | ], |
||
184 | ]); |
||
185 | $stripeCustomerId = $customer['id']; |
||
186 | $currency = strtolower(\Auth::user()->currency); |
||
187 | $card = $stripe->cards()->create($stripeCustomerId, $token['id']); |
||
188 | $charge = $stripe->charges()->create([ |
||
189 | 'customer' => $customer['id'], |
||
190 | 'currency' => $currency, |
||
191 | 'amount' =>$amount, |
||
192 | 'description' => 'Add in wallet', |
||
193 | ]); |
||
194 | if ($charge['status'] == 'succeeded') { |
||
195 | //Change order Status as Success if payment is Successful |
||
196 | $stateCode = \Auth::user()->state; |
||
197 | $cont = new \App\Http\Controllers\RazorpayController(); |
||
198 | $state = $cont->getState($stateCode); |
||
199 | $currency = $cont->getCurrency(); |
||
200 | |||
201 | $control = new \App\Http\Controllers\Order\RenewController(); |
||
202 | //After Regular Payment |
||
203 | if ($control->checkRenew() === false) { |
||
204 | $checkout_controller = new \App\Http\Controllers\Front\CheckoutController(); |
||
205 | $checkout_controller->checkoutAction($invoice); |
||
206 | |||
207 | $view = $cont->getViewMessageAfterPayment($invoice, $state, $currency); |
||
208 | $status = $view['status']; |
||
209 | $message = $view['message']; |
||
210 | } else { |
||
211 | //Afer Renew |
||
212 | $control->successRenew($invoice); |
||
213 | $payment = new \App\Http\Controllers\Order\InvoiceController(); |
||
214 | $payment->postRazorpayPayment($invoice); |
||
215 | if ($invoice->grand_total && emailSendingStatus()) { |
||
216 | $this->sendPaymentSuccessMailtoAdmin($invoice->currency, $invoice->grand_total, \Auth::user(), $invoice->invoiceItem()->first()->product_name); |
||
217 | } |
||
218 | $view = $cont->getViewMessageAfterRenew($invoice, $state, $currency); |
||
219 | $status = $view['status']; |
||
220 | $message = $view['message']; |
||
221 | } |
||
222 | \Session::forget('items'); |
||
223 | \Session::forget('code'); |
||
224 | \Session::forget('codevalue'); |
||
225 | \Session::forget('totalToBePaid'); |
||
226 | \Session::forget('invoice'); |
||
227 | \Cart::removeCartCondition('Processing fee'); |
||
228 | |||
229 | return redirect('checkout')->with($status, $message); |
||
230 | } else { |
||
231 | return redirect('checkout')->with('fails', 'Your Payment was declined. Please try making payment with other gateway'); |
||
232 | } |
||
233 | } catch (\Cartalyst\Stripe\Exception\ApiLimitExceededException | \Cartalyst\Stripe\Exception\BadRequestException | \Cartalyst\Stripe\Exception\MissingParameterException | \Cartalyst\Stripe\Exception\NotFoundException | \Cartalyst\Stripe\Exception\ServerErrorException | \Cartalyst\Stripe\Exception\StripeException | \Cartalyst\Stripe\Exception\UnauthorizedException $e) { |
||
234 | if (emailSendingStatus()) { |
||
235 | $this->sendFailedPaymenttoAdmin($request['amount'], $e->getMessage()); |
||
236 | } |
||
237 | |||
238 | return redirect('checkout')->with('fails', 'Your Payment was declined. '.$e->getMessage().'. Please try again or try the other gateway'); |
||
239 | } catch (\Cartalyst\Stripe\Exception\CardErrorException $e) { |
||
240 | if (emailSendingStatus()) { |
||
241 | $this->sendFailedPaymenttoAdmin($request['amount'], $e->getMessage()); |
||
242 | } |
||
243 | \Session::put('amount', $request['amount']); |
||
244 | \Session::put('error', $e->getMessage()); |
||
245 | |||
246 | return redirect()->route('checkout'); |
||
247 | } catch (\Exception $e) { |
||
248 | return redirect('checkout')->with('fails', 'Your payment was declined. '.$e->getMessage().'. Please try again or try the other gateway.'); |
||
249 | } |
||
271 |