UnknownSec Bypass
403
:
/
mnt
/
lmsestudio-instance-vol002
/
lms_27405516f63f
/
app
/
Services
/
Hires
/ [
drwxr-xr-x
]
Menu
Upload
Mass depes
Mass delete
Terminal
Info server
About
name :
HireServices.php
<?php namespace EstudioLMS\Services\Hires; use EstudioLMS\Cart\Cart; use EstudioLMS\Events\FreeDone; use EstudioLMS\Events\PagseguroDone; use EstudioLMS\Events\PaypalDone; use EstudioLMS\Repositories\Courses\Course\CourseRepository; use EstudioLMS\Repositories\Environment\HiredCourseRepository; use EstudioLMS\Repositories\Financial\HireDetailRepository; use EstudioLMS\Repositories\Financial\HireHeaderRepository; use EstudioLMS\Services\Admin\ConfigurationServices; use Illuminate\Contracts\Auth\Guard; use Omnipay\Common\GatewayFactory; use Omnipay\PayPal\Message\ExpressCompletePurchaseRequest; use PHPSC\PagSeguro\Customer\Address; use PHPSC\PagSeguro\Items\Item; use PHPSC\PagSeguro\Purchases\Transactions\Locator; use PHPSC\PagSeguro\Requests\Checkout\CheckoutService; use PHPSC\PagSeguro\Shipping\Shipping; use Symfony\Component\HttpFoundation\Session\SessionInterface; /** * Class HireServices * @package EstudioLMS\Services\Hires */ class HireServices { /** * @var HiredCourseRepository */ private $hiredCourse; /** * @var Guard */ private $auth; /** * @var SessionInterface */ private $session; /** * @var CourseRepository */ private $course; /** * @var Cart */ private $cart; /** * @var HireHeaderRepository */ private $header; /** * @var HireDetailRepository */ private $detail; /** * @var Locator */ private $locator; /** * @var ConfigurationServices */ private $configurationServices; /** * HireServices constructor. * @param HiredCourseRepository $hiredCourse * @param SessionInterface $session * @param Guard $auth * @param CourseRepository $course * @param Cart $cart * @param HireHeaderRepository $header * @param HireDetailRepository $detail * @param Locator $locator * @param ConfigurationServices $configurationServices */ public function __construct( HiredCourseRepository $hiredCourse, SessionInterface $session, Guard $auth, CourseRepository $course, Cart $cart, HireHeaderRepository $header, HireDetailRepository $detail, Locator $locator, ConfigurationServices $configurationServices ) { $this->hiredCourse = $hiredCourse; $this->auth = $auth; $this->session = $session; $this->course = $course; $this->cart = $cart; $this->header = $header; $this->detail = $detail; $this->locator = $locator; $this->configurationServices = $configurationServices; } /** * @param $data * @return bool */ public function freeCourse($data) { $course = $this->course->with(['plans.duration'])->find($data['course_id']); $planId = (int)$course->plans->first()->id; $planDuration = (int)$course->plans->first()->duration->duration; $hasFreeCourse = $this->hiredCourse ->orderBy('created_at', 'DESC') ->findWhere( [ [ 'user_id', '=', $this->auth->user()['id'] ], [ 'course_id', '=', $data['course_id'] ] ] ) ->first(); $renew = false; if (count($hasFreeCourse)) { if ($hasFreeCourse['status'] == 10) { $renew = true; } else { return false; } } $header = [ 'user_id' => $this->auth->user()['id'], 'gateway_id' => 'FreeCourse', 'payment_code' => uniqid(""), 'gross_amount' => 0, 'fee_amount' => 0, 'net_amount' => 0, 'status' => 3 ]; $createHeader = $this->header->create($header); $startDate = date('Y-m-d H:i:s'); $addDate = '+' . $planDuration . ' months'; $endDate = date('Y-m-d 23:59:59', strtotime($addDate, strtotime($startDate))); $detail = [ 'hire_headers_id' => $createHeader['id'], 'status' => 3, 'course_id' => $data['course_id'], 'start' => $startDate, 'end' => $endDate, 'gross_amount' => 0, 'fee_amount' => 0, 'net_amount' => 0, 'plan_id' => $planId ]; $this->detail->create($detail); $hiredCourse = [ 'user_id' => $this->auth->user()['id'], 'course_id' => $data['course_id'], 'plan_id' => $data['select_plan'], 'hire_headers_id' => $createHeader['id'], 'status' => 3, 'start' => $startDate, 'end' => $endDate, 'is_free' => true ]; if($renew) { $this->hiredCourse->update($hiredCourse, $hasFreeCourse->id); } else { $this->hiredCourse->create($hiredCourse); } $hiredCourse = $this->header ->with(['user', 'details.plan.duration', 'details.course']) ->find($createHeader['id']); \Event::fire(new FreeDone($hiredCourse)); return true; } /** * @param CheckoutService $checkoutService * @return string */ public function checkoutPagSeguro(CheckoutService $checkoutService) { $checkout = $checkoutService->createCheckoutBuilder(); $cart = $this->session->get('cart'); $itemName = str_slug($cart->get('name'), ' '); if (strlen($cart->get('name')) > 50) { $itemName = substr($itemName, 0, 49); } $checkout->addItem( new Item( $cart->get('course_id'), $itemName . ' - ' . $cart->get('plan') . ' @@' . $cart->get('plan_id'), (($cart->get('price') + $cart->get('extra_amount')) - $cart->get('discount')), 1, $cart->get('shipping_price') ) ); $redirectUrl = \URL::to('/') . '/cart/result/wait'; $notificationtUrl = \URL::to('/') . '/gateway/pagseguro'; $checkout->setRedirectTo($redirectUrl); $checkout->setNotificationURL($notificationtUrl); if ($cart->getShippingCode() == 4014) $shippingCode = 2; elseif ($cart->getShippingCode() == 4510) { $shippingCode = 1; } else { $shippingCode = 3; } $hasShipping = $this->course->with(['material'])->find($cart->get('course_id'))->material->published; if ($hasShipping) { $addr = $this->auth->user()['address']; $address = new Address($addr->state, $addr->city, $addr->zip_code, $addr->neighborhood, $addr->street, $addr->number, $addr->complement); $shipping = new Shipping($shippingCode, $address, $cart->get('shipping_price')); $checkout->setShipping($shipping); } $checkout->setReference($this->auth->user()['email']); try { $response = $checkoutService->checkout($checkout->getCheckout()); } catch (\Exception $e) { $cart->destroy(); return false; } /*$code = $response->getCode(); return $code;*/ //dd($response); return $response->getRedirectionUrl(); } /** * @param $transaction_id */ public function completePagseguro($transaction_id) { $cart = $this->session->get('cart'); $data = $this->locator->getByCode($transaction_id); $hiredCourse = $this->header ->with(['user', 'details.course']) ->findByField('payment_code', $data->getDetails()->getCode()) ->first(); $hasShipping = $this->course->with(['material'])->find($cart->get('course_id'))->material->published; $shippingCode = 0; $shippingCost = 0.00; if ($hasShipping) { if ($data->getShipping()->getType() == 1) { $shippingCode = 4510; } elseif ($data->getShipping()->getType() == 2) { $shippingCode = 4014; } else { $shippingCode = 1; } $shippingCost = $data->getShipping()->getCost(); } if (count($hiredCourse) <= 0) { $header = [ 'user_id' => $this->auth->user()['id'], 'gateway_id' => 'PagSeguro', 'payment_code' => $data->getDetails()->getCode(), 'gross_amount' => (($cart->getGrossAmount() + $cart->getShippingAmount()) - $cart->getDiscountAmount()), 'discount_amount' => $cart->getDiscountAmount(), 'fee_amount' => $data->getPayment()->getFeeAmount(), 'shipping_amount' => $shippingCost, 'extra_amount' => $cart->getExtraAmount(), 'net_amount' => $cart->getGrossAmount() - ($cart->getDiscountAmount() + $data->getPayment()->getFeeAmount()), 'shipping_type' => $shippingCode, 'status' => \GatHelper::translateGatewayStatus( 'PagSeguro', $data->getDetails()->getStatus() ) ]; $createHeader = $this->header->create($header); foreach ($data->getItems() as $item) { $course = $this->course->with(['plans', 'plans.duration', 'material'])->find($item->getId()); $planId = (int)substr($item->getDescription(), strpos($item->getDescription(), "@@") + 2); $plan = $course['plans']->where('id', $planId)->first(); $startDate = date('Y-m-d'); $addDate = '+' . $plan['duration']['duration'] . ' months'; $endDate = date('Y-m-d', strtotime($addDate, strtotime($startDate))); /* Detalhe da Transação */ $detail = [ 'hire_headers_id' => $createHeader['id'], 'status' => \GatHelper::translateGatewayStatus( 'PagSeguro', $data->getDetails()->getStatus() ), 'course_id' => $item->getId(), 'plan_id' => $planId, 'start' => $startDate, 'end' => $endDate, 'gross_amount' => ($cart->getGrossAmount()), 'discount_amount' => $cart->getDiscountAmount(), 'fee_amount' => $createHeader['fee_amount'], 'extra_amount' => $cart->getExtraAmount(), 'net_amount' => $cart->getGrossAmount() - ($cart->getDiscountAmount() + $createHeader['fee_amount']) ]; $this->detail->create($detail); /* Cursos contratados do Aluno */ $hiredCourse = [ 'user_id' => $this->auth->user()['id'], 'course_id' => $item->getId(), 'plan_id' => $planId, 'hire_headers_id' => $createHeader['id'], 'status' => \GatHelper::translateGatewayStatus( 'PagSeguro', $data->getDetails()->getStatus() ), 'start' => $startDate, 'end' => $endDate, 'is_free' => false ]; $renew = $this->hiredCourse->findWhere([ ['user_id', '=', $this->auth->user()['id']], ['course_id', '=', $cart->get('course_id')] ])->first(); if ($renew) { $this->hiredCourse->update($hiredCourse, $renew['id']); } else { $this->hiredCourse->create($hiredCourse); } } $hiredCourse = $this->header ->with(['user', 'details.plan.duration', 'details.course']) ->findByField('payment_code', $data->getDetails()->getCode()) ->first(); \Event::fire(new PagseguroDone('waiting', $hiredCourse)); } if (!is_null($cart)) { $cart->destroy(); } } /** * @return mixed */ public function checkoutPaypal() { $gatewayFactory = new GatewayFactory; $gateway = $gatewayFactory->create('PayPal_Express'); //$gateway = $gatewayFactory->create('PayPal_Pro'); $config = $this->configurationServices->paypalConfiguration(); $gateway->setUsername($config['email']); $gateway->setPassword($config['password']); $gateway->setSignature($config['token']); $gateway->setTestMode($config['sandbox'] == 1 ? true : false); $cart = $this->session->get('cart'); $paypal_setitems[] = [ 'name' => $cart->get('name'), 'quantity' => 1, 'price' => ($cart->get('price') + $cart->get('extra_amount')) ]; if ($cart->getDiscountAmount() > 0) { $paypal_setitems[] = [ 'name' => 'Cupom de Desconto', 'quantity' => 1, 'price' => $cart->getDiscountAmount() * -1 ]; } /* * O problema de parcelamento está nessa parte do código, pois o package omnipay/paypal está enviando o request * de forma equivocada. * * Pode ser visto e comprovado, seguindo: * - ExpressGateway @purchase * - ExpressAuthorizeRequest @getData * * É necessário uma mudança no package para que haja uma classe que trate o Purchase Request, assim como trata o * Authorization Request, definindo corretamente os parâmetros necessários para compra. * * Isso aberta no github https://github.com/thephpleague/omnipay-paypal/issues/210 * * Resolvemos o problema, criando nosso fork do pacote citado e alterando conforme a necessidade exigia. */ # Send response to PP $response = $gateway->purchase( [ 'amount' => (($cart->getGrossAmount() + $cart->getShippingAmount()) - $cart->getDiscountAmount()), 'returnUrl' => route('checkout.paypal.success'), 'cancelUrl' => route('cart.list'), 'currency' => 'BRL', ]) ->setItems($paypal_setitems) ->setShippingAmount($cart->getShippingAmount()) //->getData(); ->send(); //dd($response); return $response; } /** * @return mixed */ public function completePayPal() { $gatewayFactory = new GatewayFactory; $gateway = $gatewayFactory->create('PayPal_Express'); $config = $this->configurationServices->paypalConfiguration(); $gateway->setUsername($config['email']); $gateway->setPassword($config['password']); $gateway->setSignature($config['token']); $gateway->setTestMode($config['sandbox']); $cart = $this->session->get('cart'); $paypal_setitems[] = [ 'name' => $cart->get('name'), 'quantity' => 1, 'price' => ($cart->get('price') + $cart->get('extra_amount')) ]; if ($cart->getDiscountAmount() > 0) { $paypal_setitems[] = [ 'name' => 'Cupom de Desconto', 'quantity' => 1, 'price' => $cart->getDiscountAmount() * -1 ]; } /** * Testar esse método para enviar corretamente os requests quando for definido parcelamento */ /*$complete = new ExpressCompletePurchaseRequest(); $complete->setUsername($config['email']); $complete->setPassword($config['password']); $complete->setSignature($config['token']); $complete->setTestMode($config['sandbox']); $complete->setAmount(($cart->getGrossAmount() + $cart->getShippingAmount()) - $cart->getDiscountAmount()); $complete->setReturnUrl(route('checkout.paypal.success')); $complete->setCancelUrl(route('cart.list')); $complete->setCurrency('BRL'); $complete->setShippingAmount($cart->getShippingAmount()); $complete->setItems($paypal_setitems); $response = $complete->send(); $paypalResponse = $response->getData();*/ # Send response to PP $response = $gateway->completePurchase( [ 'amount' => (($cart->getGrossAmount() + $cart->getShippingAmount()) - $cart->getDiscountAmount()), 'returnUrl' => route('checkout.paypal.success'), 'cancelUrl' => route('cart.list'), 'currency' => 'BRL', ]) ->setShippingAmount($cart->getShippingAmount()) ->setItems($paypal_setitems) ->send(); $paypalResponse = $response->getData(); // this is the raw response object $errorMsg = null; if (isset($paypalResponse['PAYMENTINFO_0_ACK']) && $paypalResponse['PAYMENTINFO_0_ACK'] === 'Success') { /* Cabeçalho da Transação */ $header = [ 'user_id' => $this->auth->user()['id'], 'gateway_id' => 'PayPal', 'payment_code' => $paypalResponse['PAYMENTINFO_0_TRANSACTIONID'], 'gross_amount' => (($cart->getGrossAmount() + $cart->getShippingAmount()) - $cart->getDiscountAmount()), 'discount_amount' => $cart->getDiscountAmount(), 'fee_amount' => $paypalResponse['PAYMENTINFO_0_FEEAMT'], 'shipping_amount' => $cart->getShippingAmount(), 'extra_amount' => $cart->getExtraAmount(), 'net_amount' => $cart->getGrossAmount() - ($cart->getDiscountAmount() + $paypalResponse['PAYMENTINFO_0_FEEAMT']), 'shipping_type' => $cart->getShippingCode(), 'status' => \GatHelper::translateGatewayStatus( 'PayPal', $paypalResponse['PAYMENTINFO_0_PAYMENTSTATUS'] ) ]; $createHeader = $this->header->create($header); $course = $this->course->with(['plans', 'plans.duration', 'material'])->find($cart->get('course_id')); $planId = $cart->get('plan_id'); $plan = $course['plans']->where('id', (int)$planId)->first(); $startDate = date('Y-m-d'); $addDate = '+' . $plan['duration']['duration'] . ' months'; $endDate = date('Y-m-d', strtotime($addDate, strtotime($startDate))); /* Detalhe da Transação */ $detail = [ 'hire_headers_id' => $createHeader['id'], 'status' => \GatHelper::translateGatewayStatus( 'PayPal', $paypalResponse['PAYMENTINFO_0_PAYMENTSTATUS'] ), 'course_id' => $cart->get('course_id'), 'plan_id' => $planId, 'start' => $startDate, 'end' => $endDate, 'gross_amount' => ($cart->getGrossAmount()), 'discount_amount' => $cart->getDiscountAmount(), 'fee_amount' => $createHeader['fee_amount'], 'extra_amount' => $cart->getExtraAmount(), 'net_amount' => $cart->getGrossAmount() - ($cart->getDiscountAmount() + $createHeader['fee_amount']) ]; $this->detail->create($detail); /* Cursos contratados do Aluno */ $hiredCourse = [ 'user_id' => $this->auth->user()['id'], 'course_id' => $cart->get('course_id'), 'plan_id' => $cart->get('plan_id'), 'hire_headers_id' => $createHeader['id'], 'status' => \GatHelper::translateGatewayStatus( 'PayPal', $paypalResponse['PAYMENTINFO_0_PAYMENTSTATUS'] ), 'start' => $startDate, 'end' => $endDate, 'is_free' => false ]; $renew = $this->hiredCourse->findWhere([ ['user_id', '=', $this->auth->user()['id']], ['course_id', '=', $cart->get('course_id')] ])->first(); if ($renew) { $this->hiredCourse->update($hiredCourse, $renew['id']); } else { $this->hiredCourse->create($hiredCourse); } $hiredCourse = $this->header ->with(['user', 'details.plan.duration', 'details.course']) ->findByField('payment_code', $paypalResponse['PAYMENTINFO_0_TRANSACTIONID']) ->first(); \Event::fire(new PaypalDone('aproved', $hiredCourse)); $cart->destroy(); return $errorMsg; } else { $deniedInfo = [ 'status' => 7, 'user' => [ 'email' => $this->auth->user()->email, 'name' => $this->auth->user()->name ] ]; \Event::fire(new PaypalDone('denied', $deniedInfo)); $cart->destroy(); return $errorMsg = $paypalResponse['L_ERRORCODE0'] . ' - ' . $paypalResponse['L_LONGMESSAGE0']; } } /** * Verifica se um curso do carrinho está ativo na conta do usuário logado; * Caso o curso esteja ativo, o mesmo é removido do carrinho, evitando que o usuário compre um curso que já está comprado e ativo. * @param $cart * @return mixed */ public function checkHiredCourses($cart) { $result = []; $hasCourse = $this->hiredCourse->findWhere( [ [ 'user_id', '=', $this->auth->user()['id'] ], [ 'course_id', '=', $cart->get('course_id') ], [ 'end', '>', date('Y-m-d H:i:s') ], [ 'status', '<=', 4 ] ] ); if (count($hasCourse->all()) > 0) { $result[0] = ['id' => $cart->get('course_id'), 'course' => $cart->get('name')]; $cart->destroy(); $this->session->set('cart', $cart); } return $result; } }
Copyright © 2026 - UnknownSec