vendredi 29 novembre 2019

mercadopago Fix Payment Gateway Issue

ShoppingcartController.php:- middleware('auth'); View()->share('classBody', 'shopping-cart'); $this->productRepository = $productRepository; $this->addressRepository = $addressRepository; View()->share('menuCart', true); } public function index() { SDK::setClientId("2080473907061160"); SDK::setClientSecret("DYju8iZXB6qli9GRI62VwiSFYe9AvSjf"); SDK::setAccessToken("TEST-5707324772516829-092412-d2598a4ac035e78f2a4dfffbf74648e1-293324417"); SDK::setAccessToken("APP_USR-2080473907061160-092412-dbf5e910b023e44f194553d0d90a7b15-293324417"); $ids = []; $addresses = []; $setting = null; $cart = session('items', []); foreach($cart as $item){ $ids[] = $item['id']; } $products = $this->productRepository->findWhereIn('id', $ids); $products = $this->productRepository->inject($products); $cards = array(); $setting = getSettingInstance(); if(auth()->check()){ $addresses = $this->addressRepository->findWhere(['user_id' => auth()->user()->id]); if(isset(auth()->user()->mercadopago_customer_id) && !empty(auth()->user()->mercadopago_customer_id)){ echo "hello"; exit(); $customer = MercadoPago\Customer::find_by_id(auth()->user()->mercadopago_customer_id); $cards = $customer->cards(); } } $crossSelling = $this->productRepository->crossSelling($ids); return view('shopping_cart.index', compact('products', 'cart', 'addresses', 'setting', 'crossSelling','cards')); } public function add() { $post = request()->all(); $product = $this->productRepository->find($post['id']); if(! $product){ return response()->json(['status' => 'failed', 'message' => 'Producto no encontrado o no es válido']); } $items = session('items', []); if(array_key_exists($product->id, $items)){ $items[$product->id]['qty'] = (int)$items[$product->id]['qty'] + (int)$post['qty']; $items[$product->id]['variant'] = $post['variant']; }else{ $items[$product->id] = [ 'id' => $product->id, 'qty' => $post['qty'], 'variant' => $post['variant'] ]; } session()->put('items', $items); return response()->json(['status' => 'ok']); } public function add2() { $post = request()->all(); $product = $this->productRepository->find($post['id']); if(! $product){ return response()->json(['status' => 'failed', 'message' => 'Producto no encontrado o no es válido']); } $items = session('items', []); if(array_key_exists($product->id, $items)){ $items[$product->id]['qty'] = (int)$items[$product->id]['qty'] + (int)$post['qty']; $items[$product->id]['variant'] = $post['variant']; }else{ $items[$product->id] = [ 'id' => $product->id, 'qty' => $post['qty'], 'variant' => $post['variant'] ]; } session()->put('items', $items); return response()->json(['status' => 'ok']); } function delete($id){ $product = $this->productRepository->find($id); if(! $product){ return response()->json(['status' => 'failed', 'message' => 'Producto no encontrado o no es válido']); } $items = session('items', []); if(array_key_exists($product->id, $items)){ unset($items[$product->id]); } session()->put('items', $items); request()->session()->flash('alert_success', "El producto ha sido eliminado del carrito"); return response()->redirectTo(route('web.cart.index')); } function update(){ $cart = request()->all(); $items = session('items', []); foreach($cart as $id => $product){ if(array_key_exists($id, $items)){ $items[$id]['qty'] = (int)$product['qty']; $items[$id]['variant'] = $product['variant']; } } session()->put('items', $items); request()->session()->flash('alert_success', "EL carrito ha sido actualizado con éxito"); return response()->redirectTo(route('web.cart.index')); } public function save(){ $post = request()->all(); $products = (array_key_exists('productos', $post)) ? $post['productos'] : []; $dispatch = (array_key_exists('dispatch', $post)) ? $post['dispatch'] : null; $address = (array_key_exists('address', $post)) ? $post['address'] : null; $date_delivery = (array_key_exists('date_delivery', $post)) ? $post['date_delivery'] :null; $schedule = (array_key_exists('schedule', $post)) ? $post['schedule'] : null; $payment = (array_key_exists('payment', $post)) ? $post['payment'] : null; $paymentMethodId = (array_key_exists('paymentMethodId', $post)) ? $post['paymentMethodId'] : null; $token = (array_key_exists('token', $post)) ? $post['token'] : null; $payType = (array_key_exists('payType', $post)) ? $post['payType'] : null; $installments = (array_key_exists('installments', $post)) ? $post['installments'] : null; $issuerId = (array_key_exists('issuerId', $post)) ? $post['issuerId'] : null; $notes = (array_key_exists('notes', $post)) ? $post['notes'] : null; if(count($products) === 0){ request()->session()->flash('alert_success', "No se encontraron productos en el carrito, por favor intente nuevamente"); return response()->redirectTo(route('web.cart.index')); } if(! $dispatch){ request()->session()->flash('alert_success', "Tipo de despacho no es válido, por favor intente nuevamente "); return response()->redirectTo(route('web.cart.index')); } if((int)$dispatch === 1 && ! $address){ request()->session()->flash('alert_success', "Ops! Te faltó seleccionar una dirección de envío"); return response()->redirectTo(route('web.cart.index')); } if((int)$dispatch === 1 && ! $date_delivery){ request()->session()->flash('alert_success', "Ops! Te faltó seleccionar el día de entrega"); return response()->redirectTo(route('web.cart.index')); } if((int)$dispatch === 1 && ! $schedule){ request()->session()->flash('alert_success', "Ops! Te faltó seleccionar la franja horaria de entrega"); return response()->redirectTo(route('web.cart.index')); } if(! $payment){ request()->session()->flash('alert_success', "EL Tipo de pago no es válida, por favor intente nuevamente "); return response()->redirectTo(route('web.cart.index')); } // echo $payment;die; if(! in_array($payment, ['cash', 'mercado-pago'])){ request()->session()->flash('alert_error', "Por favor, seleccione un método de pago válido"); return response()->redirectTo(route('web.cart.index')); }else if($payment == 'mercado-pago' && (! $issuerId || ! $installments)){ request()->session()->flash('alert_success', "No pudimos traer la información de cuotas para tu tarjeta, por favor intenta nuevamente o hablanos por chat."); return response()->redirectTo(route('web.cart.index')); } $items = []; foreach($products as $product){ $id = $product['product']; if(array_key_exists($id, $items)){ $items[$id]['qty'] = (int)$product['qty']; $items[$id]['variant'] = $product['variant']; }else{ $items[$id] = [ 'id' => $id, 'qty' => $product['qty'], 'variant' => $product['variant'] ]; } } session()->put('items', $items); session()->put('order_request', [ 'address' => $address, 'dispatch' => $dispatch, 'date_delivery' => $date_delivery, 'schedule' => $schedule, 'payment' => $payment, 'paymentMethodId' => $paymentMethodId, 'installments' => $installments, 'installments' => $installments, 'issuer_id' => $issuerId, 'token' => $token, 'payType' => $payType, 'notes' => $notes, ]); return response()->redirectTo(route('account.checkout.process')); // return response()->redirectTo(route('account.checkout.confirmation')); } }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire