UnknownSec Bypass
403
:
/
mnt
/
lmsestudio-instance-vol002
/
lms_2ae1a8506d80
/
app
/
Services
/
Hires
/ [
drwxr-xr-x
]
Menu
Upload
Mass depes
Mass delete
Terminal
Info server
About
name :
BoletoService.php
<?php namespace EstudioLMS\Services\Hires; use App; use Carbon\Carbon; use Eduardokum\LaravelBoleto\Boleto\Pessoa; use Eduardokum\LaravelBoleto\Util; use EstudioLMS\Cart\Cart; use EstudioLMS\Events\BoletoDone; use EstudioLMS\Helpers\Helpers; use EstudioLMS\Http\Controllers\Cart\CheckoutController; use EstudioLMS\Repositories\Courses\Course\CourseRepository; use EstudioLMS\Repositories\Environment\HiredCourseRepository; use EstudioLMS\Repositories\Financial\BillingRepository; use EstudioLMS\Repositories\Financial\HireDetailRepository; use EstudioLMS\Repositories\Financial\HireHeaderRepository; use EstudioLMS\Services\Admin\ConfigurationServices; use Illuminate\Contracts\Auth\Guard; use Symfony\Component\HttpFoundation\Session\SessionInterface; /** * Class BoletoService * @package EstudioLMS\Services\Hires */ class BoletoService { /** * @var HiredCourseRepository */ private $hiredCourse; /** * @var SessionInterface */ private $session; /** * @var Guard */ private $auth; /** * @var CourseRepository */ private $course; /** * @var Cart */ private $cart; /** * @var HireHeaderRepository */ private $header; /** * @var HireDetailRepository */ private $detail; /** * @var ConfigurationServices */ private $configurationServices; /** * @var BillingRepository */ private $billingRepository; /** * BoletoService constructor. * @param HiredCourseRepository $hiredCourse * @param SessionInterface $session * @param Guard $auth * @param CourseRepository $course * @param Cart $cart * @param HireHeaderRepository $header * @param HireDetailRepository $detail * @param ConfigurationServices $configurationServices * @param BillingRepository $billingRepository */ public function __construct( HiredCourseRepository $hiredCourse, SessionInterface $session, Guard $auth, CourseRepository $course, Cart $cart, HireHeaderRepository $header, HireDetailRepository $detail, ConfigurationServices $configurationServices, BillingRepository $billingRepository ) { $this->hiredCourse = $hiredCourse; $this->session = $session; $this->auth = $auth; $this->course = $course; $this->cart = $cart; $this->header = $header; $this->detail = $detail; $this->configurationServices = $configurationServices; $this->billingRepository = $billingRepository; } /** * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function payWithBoleto() { $user = $this->auth->user(); if (empty($user->address->street) || empty($user->cpf)) { //return redirect()->route('cart.checkout')->with('addError', 'Endereço ou CPF não cadastrados'); return redirect()->route('checkout.shipping'); } $cart = $this->session->get('cart'); $fee = 0.00; $header = [ 'user_id' => $this->auth->user()['id'], 'gateway_id' => 'Boleto', 'payment_code' => strtoupper(md5(uniqid(rand(), true))), 'gross_amount' => (($cart->getGrossAmount() + $cart->getShippingAmount()) - $cart->getDiscountAmount()), 'discount_amount' => $cart->getDiscountAmount(), 'fee_amount' => $fee, 'shipping_amount' => $cart->getShippingAmount(), 'extra_amount' => $cart->getExtraAmount(), 'net_amount' => $cart->getGrossAmount() - ($cart->getDiscountAmount() + $fee), 'shipping_type' => $cart->getShippingCode(), 'status' => \GatHelper::translateGatewayStatus( 'boleto', 1 ) ]; $createHeader = $this->header->create($header); $course = $this->course->with(['plans', 'plans.duration', 'material'])->find($cart->get('course_id')); $planId = (int)$cart->get('plan_id'); $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' => $createHeader['status'], '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' => $planId, 'hire_headers_id' => $createHeader['id'], 'status' => $createHeader['status'], '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); } $headerId = $createHeader['id']; $payCode = $createHeader['payment_code']; $this->billing($headerId); $success = true; $installment = 1; $hiredCourse = $this->header ->with(['user', 'details.plan.duration', 'details.course']) ->find($headerId); \Event::fire(new BoletoDone($hiredCourse)); //return view('cart.result_boleto', compact('success', 'headerId', 'payCode', 'installment')); return redirect()->action('Cart\CheckoutController@result_boleto', compact('payCode', 'installment', 'success')); } /* * Irá registrar todas os boletos referentes a contratação do aluno. */ /** * @param $hireHeaderId */ public function billing($hireHeaderId) { // Configurações do Boleto $boletoConf = $this->configurationServices->boletoConfiguration(); // Registro financeiro da contratação $hired = $this->header->find($hireHeaderId); /* * TODO: * Verificar a situação de quando há matricula, se a mesma tem que ser somada ou debitada do total * do curso e refazer os cálculos. * * Se houver matrícula, a primeira parcela deve ser o valor da matrícula. */ // Número de Parcelas $installments = $hired->detail->course->gateways->find(3)->pivot->installments; // Valor total da contratação $installment_value = $hired->gross_amount / $installments; // Nosso número atual $ourNumber = $this->billingRepository->lastOurNumber()['ourNumber']; $dueDate = Carbon::now()->addDays(5); //$fee = $boletoConf->bank_fee; $fee = 0.00; for ($i = 1; $i <= $installments; $i++) { $ourNumber += 1; $billing = [ 'hire_header_id' => $hireHeaderId, 'due_date' => $dueDate, 'installment' => $i, 'net_amount' => $installment_value, 'fee_amount' => $fee, 'our_number' => $ourNumber, 'our_number_boleto' => null, 'paid_in' => null, 'billing_status_id' => 1, ]; $this->billingRepository->create($billing); // Próximo vencimento $dueDate = $dueDate->addMonth(1); } } /** * @summary Métdo para emissão de boleto. * * @param $payCode Código do Pagamento. * @param int $installment Número da Parcela. * @return string Boleto a ser impresso/enviado. * @throws \Exception */ public function makeBillet($payCode, $installment = 1) { // Configurações Administrativas $config = $this->configurationServices->configuration(); // Configurações do Boleto $boletoConf = $this->configurationServices->boletoConfiguration(); // Registro financeiro da contratação $hired = $this->header->findByField('payment_code', $payCode)->first(); // Criação dos objetos beneficiário e aluno, para utilização do pacote de geração de boletos $beneficiario = new Pessoa([ 'nome' => $config->site_name, 'endereco' => $config->street . ' ,' . $config->number, 'cep' => $config->zip_code, 'uf' => $config->state, 'cidade' => $config->city, 'documento' => $config->cpf_cnpj, ]); $aluno = new Pessoa([ 'nome' => $hired->user->name, 'endereco' => $hired->user->address->street . ' ,' . $hired->user->address->number, 'bairro' => $hired->user->address->neighborhood, 'cep' => $hired->user->address->zip_code, 'uf' => $hired->user->address->state, 'cidade' => $hired->user->address->city, 'documento' => $hired->user->address->cpf, ]); $billing = $this->billingRepository->findWhere( [ ['hire_header_id', '=', $hired->id], ['installment', '=', $installment] ] )->first(); $dueDate = Carbon::createFromFormat('Y-m-d H:i:s', $billing->due_date); $descriptionLine_1 = $boletoConf->description_line_1; if ($boletoConf->bank_fee > 0) { $fee = Helpers::formatValue($boletoConf->bank_fee); $descriptionLine_1 = 'Está sendo cobrado a taxa de emissão bancária de R$ ' . $fee; } $msgAssesment = $boletoConf->instructions_line_1; $msgInterest = $boletoConf->instructions_line_2; if ($boletoConf->assessment > 0) { $assessment = Helpers::formatValue((($billing->net_amount + $boletoConf->bank_fee) * ($boletoConf->assessment / 100))); $msgAssesment = 'Após ' . $boletoConf->interest_after . ' dia(s) do vencimento cobrar multa de R$ ' . $assessment; $interest = Helpers::formatValue((($billing->net_amount + $boletoConf->bank_fee) * ($boletoConf->interest / 100))); $msgInterest = 'Cobrar mora diária de R$ ' . $interest; } $boletoArray = [ //'logo' => 'path/para/o/logo', // Logo da empresa 'dataVencimento' => $dueDate, 'valor' => $billing->net_amount + $boletoConf->bank_fee, 'multa' => $boletoConf->assessment, // porcento 'juros' => $boletoConf->interest, // porcento ao mes 'juros_apos' => $boletoConf->interest_after, // juros e multa após 'diasProtesto' => false, // protestar após, se for necessário 'numero' => str_pad($billing->our_number, 8, '0', STR_PAD_LEFT), // Compoẽ o nosso número 'numeroDocumento' => str_pad($billing->our_number, 8, '0', STR_PAD_LEFT), 'pagador' => $aluno, // Objeto PessoaContract 'beneficiario' => $beneficiario, // Objeto PessoaContract 'agencia' => $boletoConf->agency, // BB, Bradesco, CEF, HSBC, Itáu 'agenciaDv' => $boletoConf->agency_dv, // se possuir 'conta' => $boletoConf->account, // BB, Bradesco, CEF, HSBC, Itáu, Santander 'contaDv' => $boletoConf->account_dv, // Bradesco, HSBC, Itáu 'carteira' => $boletoConf->wallet, // BB, Bradesco, CEF, HSBC, Itáu, Santander 'convenio' => $boletoConf->agreement, // BB 'variacaoCarteira' => $boletoConf->wallet_variation, // BB 'range' => $boletoConf->range, // HSBC 'codigoCliente' => $boletoConf->customer_code, // Bradesco, CEF, Santander 'ios' => $boletoConf->ios, // Santander 'descricaoDemonstrativo' => [ $descriptionLine_1, $boletoConf->description_line_2, $boletoConf->description_line_3, $boletoConf->description_line_4, $boletoConf->description_line_5, ], // máximo de 5 'instrucoes' => [ $msgAssesment, $msgInterest, $boletoConf->instructions_line_3, $boletoConf->instructions_line_4, $boletoConf->instructions_line_5, ], // máximo de 5 'aceite' => $boletoConf->acceptance, 'especieDoc' => $boletoConf->doc_species, ]; $boleto = null; switch ($boletoConf->bank) { case '001': $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Bb($boletoArray); break; case 033: $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Santander($boletoArray); break; case 104: $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Caixa($boletoArray); break; case 237: $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Bradesco($boletoArray); break; case 341: $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Itau($boletoArray); break; case 399: $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Hsbc($boletoArray); break; } return $boleto->renderHTML(); } /** * @param $payCode * @param int $installment * @throws \Exception */ public function fakeRetorno($payCode, $installment = 1) { // Configurações Administrativas $config = $this->configurationServices->configuration(); // Configurações do Boleto $boletoConf = $this->configurationServices->boletoConfiguration(); // Registro financeiro da contratação $hired = $this->header->findByField('payment_code', $payCode)->first(); // Criação dos objetos beneficiário e aluno, para utilização do pacote de geração de boletos $beneficiario = new Pessoa([ 'nome' => $config->site_name, 'endereco' => $config->street . ' ,' . $config->number, 'cep' => $config->zip_code, 'uf' => $config->state, 'cidade' => $config->city, 'documento' => $config->cpf_cnpj, ]); $aluno = new Pessoa([ 'nome' => $hired->user->name, 'endereco' => $hired->user->address->street . ' ,' . $hired->user->address->number, 'bairro' => $hired->user->address->neighborhood, 'cep' => $hired->user->address->zip_code, 'uf' => $hired->user->address->state, 'cidade' => $hired->user->address->city, 'documento' => $hired->user->address->cpf, ]); $billing = $this->billingRepository->findWhere( [ ['hire_header_id', '=', $hired->id], ['installment', '=', $installment] ] )->first(); $dueDate = Carbon::createFromFormat('Y-m-d H:i:s', $billing->due_date); $boletoArray = [ //'logo' => 'path/para/o/logo', // Logo da empresa 'dataVencimento' => $dueDate, 'valor' => $billing->net_amount + $boletoConf->bank_fee, 'multa' => $boletoConf->assessment, // porcento 'juros' => $boletoConf->interest, // porcento ao mes 'juros_apos' => $boletoConf->interest_after, // juros e multa após 'diasProtesto' => false, // protestar após, se for necessário 'numero' => str_pad($billing->our_number, 8, '0', STR_PAD_LEFT), // Compoẽ o nosso número //'numeroDocumento' => str_pad($billing->our_number, 8, '0', STR_PAD_LEFT), 'pagador' => $aluno, // Objeto PessoaContract 'beneficiario' => $beneficiario, // Objeto PessoaContract 'agencia' => $boletoConf->agency, // BB, Bradesco, CEF, HSBC, Itáu 'agenciaDv' => $boletoConf->agency_dv, // se possuir 'conta' => $boletoConf->account, // BB, Bradesco, CEF, HSBC, Itáu, Santander 'contaDv' => $boletoConf->account_dv, // Bradesco, HSBC, Itáu 'carteira' => $boletoConf->wallet, // BB, Bradesco, CEF, HSBC, Itáu, Santander 'convenio' => $boletoConf->agreement, // BB 'variacaoCarteira' => $boletoConf->wallet_variation, // BB 'range' => $boletoConf->range, // HSBC 'codigoCliente' => $boletoConf->customer_code, // Bradesco, CEF, Santander 'ios' => $boletoConf->ios, // Santander 'descricaoDemonstrativo' => [ $boletoConf->description_line_1, $boletoConf->description_line_2, $boletoConf->description_line_3, $boletoConf->description_line_4, $boletoConf->description_line_5, ], // máximo de 5 'instrucoes' => [ $boletoConf->instructions_line_1, $boletoConf->instructions_line_2, $boletoConf->instructions_line_3, $boletoConf->instructions_line_4, $boletoConf->instructions_line_5, ], // máximo de 5 'aceite' => $boletoConf->acceptance, 'especieDoc' => $boletoConf->doc_species, ]; $bank = ''; switch ($boletoConf->bank) { case '001': $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Bb($boletoArray); break; case 033: $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Santander($boletoArray); break; case 104: $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Caixa($boletoArray); break; case 237: $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Bradesco($boletoArray); break; case 341: $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Itau($boletoArray); break; case 399: $boleto = new \Eduardokum\LaravelBoleto\Boleto\Banco\Hsbc($boletoArray); break; } $remessaArray = [ 'agencia' => $boletoConf->agency, // BB, Bradesco, CEF, HSBC, Itáu 'agenciaDv' => $boletoConf->agency_dv, // se possuir 'conta' => $boletoConf->account, // BB, Bradesco, CEF, HSBC, Itáu, Santander 'contaDv' => $boletoConf->account_dv, // Bradesco, HSBC, Itáu 'carteira' => $boletoConf->wallet, // BB, Bradesco, CEF, HSBC, Itáu, Santander 'convenio' => $boletoConf->agreement, // BB 'range' => $boletoConf->range, // HSBC 'codigoCliente' => $boletoConf->customer_code, // Bradesco, CEF, Santander 'variacaoCarteira' => $boletoConf->wallet_variation, // BB 'beneficiario' => $beneficiario, // Dados do beneficiário ]; /*$remessa = new \Eduardokum\LaravelBoleto\Cnab\Remessa\Banco\Itau($remessaArray); $remessa->addBoleto($boleto); $txtRemessa = $remessa->gerar(); $file = App::storagePath().'/resources/remessas/REMTESTE002.REM'; \File::put($file, $txtRemessa); echo 'FIM';*/ $file = App::storagePath() . '/resources/remessas/REMTESTE002.REM'; $txtRetorno = Util::criarRetornoFake($file, '10'); $ret = App::storagePath() . '/resources/returns/RETTESTE002.RET'; \File::put($ret, $txtRetorno); echo 'FIM'; } }
Copyright © 2026 - UnknownSec