Conditions | 12 |
Paths | 585 |
Total Lines | 112 |
Code Lines | 85 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 3 | 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 |
||
111 | public function postPaymentWithStripe(Request $request) |
||
112 | { |
||
113 | $validator = Validator::make($request->all(), [ |
||
114 | ]); |
||
115 | $input = $request->all(); |
||
116 | $validation = [ |
||
117 | 'card_no' => 'required', |
||
118 | 'exp_month' => 'required', |
||
119 | 'exp_year' => 'required', |
||
120 | 'cvv' => 'required', |
||
121 | ]; |
||
122 | |||
123 | $this->validate($request, $validation); |
||
124 | $stripeSecretKey = ApiKey::pluck('stripe_secret')->first(); |
||
125 | $stripe = Stripe::make($stripeSecretKey); |
||
126 | try { |
||
127 | $invoice = \Session::get('invoice'); |
||
128 | // $invoiceTotal = \Session::get('totalToBePaid'); |
||
129 | $amount = rounding(\Cart::getTotal()); |
||
130 | if (! $amount) {//During renewal |
||
131 | $amount = rounding(\Session::get('totalToBePaid')); |
||
132 | } |
||
133 | $stripeSecretKey = ApiKey::pluck('stripe_secret')->first(); |
||
134 | $stripe = Stripe::make($stripeSecretKey); |
||
135 | $token = $stripe->tokens()->create([ |
||
136 | 'card' => [ |
||
137 | 'number' => $request->get('card_no'), |
||
138 | 'exp_month' => $request->get('exp_month'), |
||
139 | 'exp_year' => $request->get('exp_year'), |
||
140 | 'cvc' => $request->get('cvv'), |
||
141 | ], |
||
142 | ]); |
||
143 | if (! isset($token['id'])) { |
||
144 | \Session::put('error', 'The Stripe Token was not generated correctly'); |
||
145 | |||
146 | return redirect()->route('stripform'); |
||
147 | } |
||
148 | $customer = $stripe->customers()->create([ |
||
149 | 'name' => \Auth::user()->first_name.' '.\Auth::user()->last_name, |
||
150 | 'email' => \Auth::user()->email, |
||
151 | 'address' => [ |
||
152 | 'line1' => \Auth::user()->address, |
||
153 | 'postal_code' => \Auth::user()->zip, |
||
154 | 'city' => \Auth::user()->town, |
||
155 | 'state' => \Auth::user()->state, |
||
156 | 'country' => \Auth::user()->country, |
||
157 | ], |
||
158 | ]); |
||
159 | $stripeCustomerId = $customer['id']; |
||
160 | $currency = strtolower(\Auth::user()->currency); |
||
161 | $card = $stripe->cards()->create($stripeCustomerId, $token['id']); |
||
162 | $charge = $stripe->charges()->create([ |
||
163 | 'customer' => $customer['id'], |
||
164 | 'currency' => $currency, |
||
165 | 'amount' =>$amount, |
||
166 | 'description' => 'Add in wallet', |
||
167 | ]); |
||
168 | if ($charge['status'] == 'succeeded') { |
||
169 | //Change order Status as Success if payment is Successful |
||
170 | $stateCode = \Auth::user()->state; |
||
171 | $cont = new \App\Http\Controllers\RazorpayController(); |
||
172 | $state = $cont->getState($stateCode); |
||
173 | $currency = $cont->getCurrency(); |
||
174 | |||
175 | $control = new \App\Http\Controllers\Order\RenewController(); |
||
176 | //After Regular Payment |
||
177 | if ($control->checkRenew() === false) { |
||
178 | $checkout_controller = new \App\Http\Controllers\Front\CheckoutController(); |
||
179 | $checkout_controller->checkoutAction($invoice); |
||
180 | |||
181 | $view = $cont->getViewMessageAfterPayment($invoice, $state, $currency); |
||
182 | $status = $view['status']; |
||
183 | $message = $view['message']; |
||
184 | } else { |
||
185 | //Afer Renew |
||
186 | $control->successRenew($invoice); |
||
187 | $payment = new \App\Http\Controllers\Order\InvoiceController(); |
||
188 | $payment->postRazorpayPayment($invoice); |
||
189 | if ($invoice->grand_total && emailSendingStatus()) { |
||
190 | $this->sendPaymentSuccessMailtoAdmin($invoice->currency, $invoice->grand_total, \Auth::user(), $invoice->invoiceItem()->first()->product_name); |
||
191 | } |
||
192 | $view = $cont->getViewMessageAfterRenew($invoice, $state, $currency); |
||
193 | $status = $view['status']; |
||
194 | $message = $view['message']; |
||
195 | } |
||
196 | \Session::forget('items'); |
||
197 | \Session::forget('code'); |
||
198 | \Session::forget('codevalue'); |
||
199 | \Session::forget('totalToBePaid'); |
||
200 | \Session::forget('invoice'); |
||
201 | \Cart::removeCartCondition('Processing fee'); |
||
202 | |||
203 | return redirect('checkout')->with($status, $message); |
||
204 | } else { |
||
205 | return redirect('checkout')->with('fails', 'Your Payment was declined. Please try making payment with other gateway'); |
||
206 | } |
||
207 | } 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) { |
||
208 | if (emailSendingStatus()) { |
||
209 | $this->sendFailedPaymenttoAdmin($amount, $e->getMessage()); |
||
210 | } |
||
211 | |||
212 | return redirect('checkout')->with('fails', 'Your Payment was declined. '.$e->getMessage().'. Please try again or try the other gateway'); |
||
213 | } catch (\Cartalyst\Stripe\Exception\CardErrorException $e) { |
||
214 | if (emailSendingStatus()) { |
||
215 | $this->sendFailedPaymenttoAdmin($request['amount'], $e->getMessage()); |
||
216 | } |
||
217 | \Session::put('amount', $amount); |
||
218 | \Session::put('error', $e->getMessage()); |
||
219 | |||
220 | return redirect()->route('checkout'); |
||
221 | } catch (\Exception $e) { |
||
222 | return redirect('checkout')->with('fails', 'Your payment was declined. '.$e->getMessage().'. Please try again or try the other gateway.'); |
||
223 | } |
||
245 |