mergeShippingAddress($request); Cart::addTaxes($request); $cartWithCoupon = null; $couponCode = request()->query('coupon_code'); if ($couponCode) { $coupon = Coupon::findByCode($couponCode); try { resolve(Pipeline::class) ->send($coupon) ->through($this->checkers) ->then(function ($coupon) use (&$cartWithCoupon) { Cart::applyCoupon($coupon); $cartWithCoupon = json_encode(Cart::instance()); Cart::removeCoupon(); }); } catch (Exception) { //Just suppressing the exception } } return $cartWithCoupon ?? Cart::instance(); } private function mergeShippingAddress($request) { $request->merge([ 'shipping' => $request->ship_to_a_different_address ? $request->shipping : $request->billing, ]); } }