From 14d5c783c25e96b79c08f567ca06796d0e147e86 Mon Sep 17 00:00:00 2001 From: IsaacRL Date: Wed, 10 Jun 2026 17:17:36 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Adicionado=20e=20funcionando=20integra?= =?UTF-8?q?=C3=A7=C3=A3o=20SUBMIT=20->=20Settings=20->=20Info=20Boleto.=20?= =?UTF-8?q?Falta=20integrar=20SENHA/USER=20com=20o=20boleto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Service/GerarBoleto.php | 105 ++++++++++++++++++++++++++++++++ webform_pagamentos.module | 13 ++++ webform_pagamentos.services.yml | 3 + 3 files changed, 121 insertions(+) create mode 100644 src/Service/GerarBoleto.php create mode 100644 webform_pagamentos.services.yml diff --git a/src/Service/GerarBoleto.php b/src/Service/GerarBoleto.php new file mode 100644 index 0000000..6661ff0 --- /dev/null +++ b/src/Service/GerarBoleto.php @@ -0,0 +1,105 @@ + 8, + 'codigoFonteRecurso' => $codigoFonteRecursoSET, + 'estruturaHierarquica' => $estruturaHierarquicaSET, + 'dataVencimentoBoleto' => $dataVencimentoSET, + 'valorDocumento' => $valorDocumentoSET, + 'tipoSacado' => 'PF', + 'cpfCnpj' => $cpfCnpjSET, + 'nomeSacado' => $nomeSacadoSET, + 'codigoEmail' => $codigoEmailSET, + 'informacoesBoletoSacado' => $informacoesSacadoSET, + 'instrucoesObjetoCobranca' => $instrucoesObjetoCobrancaSET, + ); + $gerar = $boleto->gerar($data); + dd($gerar); + $id = $gerar['value']; + $obter = $boleto->obter($id); + + header('Content-type: application/pdf'); + header('Content-Disposition: attachment; filename="boleto.pdf"'); + echo base64_decode($obter['value']); +} +}; + + + + + + + + +// // Inicialização do serviço com as credenciais criadas +// // [Ambiente de DEV] = ('consumerdi','teste1') +// // [Ambiente de PRD] = solicitar credenciais em https://servicos.sti.usp.br/ws-boleto/ +// $boleto = new Boleto('usuario','senha'); +// +// /* array com campos mínimos para geração do boleto */ +// $data = array( +// 'codigoUnidadeDespesa' => 8, +// 'codigoFonteRecurso' => 32, +// 'estruturaHierarquica' => '\FFLCH\SCINFOR', +// 'dataVencimentoBoleto' => '10/11/2018', +// 'valorDocumento' => 18.20, +// 'tipoSacado' => 'PF', +// 'cpfCnpj' => '99999999999', +// 'nomeSacado' => 'Fulano', +// 'codigoEmail' => 'fulano@usp.br', +// 'informacoesBoletoSacado' => 'Qualquer informações que queira colocar', +// 'instrucoesObjetoCobranca' => 'Não receber após vencimento!', +// ); +// +// // [Método Gerar] gerar boleto +// $gerar = $boleto->gerar($data); +// if($gerar['status']) { +// $id = $gerar['value']; +// +// // [Método Situacao] resgatar informações do boleto +// print_r($boleto->situacao($id)); +// +// // [Método Obter] recupera o arquivo PDF do boleto +// // (PDF no formato binário codificado para Base64) +// $obter = $boleto->obter($codigoIDBoleto); +// +// //redirecionando os dados binarios do pdf para o browser +// header('Content-type: application/pdf'); +// header('Content-Disposition: attachment; filename="boleto.pdf"'); +// echo base64_decode($obter['value']); +// +// // [Método Cancelar] cancelar boleto +// $boleto->cancelar($id); +// } diff --git a/webform_pagamentos.module b/webform_pagamentos.module index ccab1ca..c6a51e5 100644 --- a/webform_pagamentos.module +++ b/webform_pagamentos.module @@ -204,4 +204,17 @@ function webform_pagamentos_webform_third_party_settings_form_alter(array &$form ]; } +function webform_pagamentos_webform_submission_insert(WebformSubmissionInterface $webform_submission) { + $settings = $webform_submission + ->getWebform() + ->getThirdPartySettings('webform_pagamentos'); + if (empty($settings['habilitar_boleto'])) { + return; + } + + $submission_data = $webform_submission->getData(); + + \Drupal::service('webform_pagamentos.gerar_boleto') + ->generate($settings, $webform_submission->getData()); +} diff --git a/webform_pagamentos.services.yml b/webform_pagamentos.services.yml new file mode 100644 index 0000000..3e69723 --- /dev/null +++ b/webform_pagamentos.services.yml @@ -0,0 +1,3 @@ +services: + webform_pagamentos.gerar_boleto: + class: Drupal\webform_pagamentos\Service\GerarBoleto From 39375e5c63c1f322f6de9d15148c760c89a26e73 Mon Sep 17 00:00:00 2001 From: IsaacRL Date: Thu, 11 Jun 2026 15:38:17 -0300 Subject: [PATCH 2/2] =?UTF-8?q?Adicionada=20a=20configura=C3=A7=C3=A3o=20S?= =?UTF-8?q?ENHA=20e=20USER=20sob=20COnfigura=C3=A7=C3=B5es=20>=20Web=20Ser?= =?UTF-8?q?vices,=20configura=C3=A7=C3=A3o=20de=20senha=20e=20usu=C3=A1rio?= =?UTF-8?q?=20j=C3=A1=20s=C3=A3o=20obtidas=20e=20informadas=20na=20hora=20?= =?UTF-8?q?de=20gerar=20boleto.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Form/SettingsForm.php | 59 +++++++++++++++++++++++++++++++ src/Service/GerarBoleto.php | 16 ++++++++- webform_pagamentos.links.menu.yml | 5 +++ webform_pagamentos.routing.yml | 7 ++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/Form/SettingsForm.php create mode 100644 webform_pagamentos.links.menu.yml create mode 100644 webform_pagamentos.routing.yml diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php new file mode 100644 index 0000000..92241b5 --- /dev/null +++ b/src/Form/SettingsForm.php @@ -0,0 +1,59 @@ +config('webform_pagamentos.settings'); + + $form['user'] = [ + '#type' => 'textfield', + '#title' => $this->t('Usuário'), + '#default_value' => $config->get('user'), + '#required' => FALSE, + '#attributes' => [ + 'placeholder' => $this->t('Exemplo: fflch'), + ], + ]; + + $form['password'] = [ + '#type' => 'password', + '#title' => $this->t('Senha'), + '#default_value' => $config->get('password'), + '#required' => FALSE, + ]; + + return parent::buildForm($form, $form_state); + } + + public function submitForm(array &$form, FormStateInterface $form_state): void { + + $config = $this->configFactory() + ->getEditable('webform_pagamentos.settings'); + + $config->set('user', $form_state->getValue('user')); + + // Only update password if a new one was entered. + if ($password = $form_state->getValue('password')) { + $config->set('password', $password); + } + + $config->save(); + + parent::submitForm($form, $form_state); +} + +} diff --git a/src/Service/GerarBoleto.php b/src/Service/GerarBoleto.php index 6661ff0..aa1cd17 100644 --- a/src/Service/GerarBoleto.php +++ b/src/Service/GerarBoleto.php @@ -19,6 +19,9 @@ public function generate(array $settings, array $submission_data): array { $cpfCnpjSET = $settings['cpfCnpj'] ?? ''; $numeroUspSacadoSET = $settings['numeroUspSacado'] ?? ''; + + //GUARDANDO PARA CASO PRECISE ADICIONAR INFORMAÇÕES COLOCADAS PELO USUÁRIO: + // $codigoFonteRecurso = $submission_data[$codigoFonteRecursoSET] ?? ''; // $estruturaHierarquica = $submission_data[$estruturaHierarquicaSET] ?? ''; // $dataVencimento = $submission_data[$dataVencimentoSET] ?? ''; @@ -30,7 +33,18 @@ public function generate(array $settings, array $submission_data): array { // $cpfCnpj = $submission_data[$cpfCnpjSET] ?? ''; // $numeroUspSacado = $submission_data[$numeroUspSacadoSET] ?? ''; - $boleto = new Boleto('user','senha'); + /// + ///Recupera USER E LOGIN a partir do Settings no menuzinho lá de configuração do Drupal ;) + + $config = \Drupal::config('webform_pagamentos.settings'); + $user = $config->get('user'); + $password = $config->get('password'); + + /// + /// + + + $boleto = new Boleto($user, $password); /* array com campos mínimos para geração do boleto */ $data = array( 'codigoUnidadeDespesa' => 8, diff --git a/webform_pagamentos.links.menu.yml b/webform_pagamentos.links.menu.yml new file mode 100644 index 0000000..d3888d4 --- /dev/null +++ b/webform_pagamentos.links.menu.yml @@ -0,0 +1,5 @@ +webform_pagamentos.settings: + title: 'Webform Pagamentos' + description: 'Configurações de autenticação do boleto USP' + parent: system.admin_config_services + route_name: webform_pagamentos.settings diff --git a/webform_pagamentos.routing.yml b/webform_pagamentos.routing.yml new file mode 100644 index 0000000..d5b738c --- /dev/null +++ b/webform_pagamentos.routing.yml @@ -0,0 +1,7 @@ +webform_pagamentos.settings: + path: '/admin/config/webform-pagamentos/settings' + defaults: + _form: '\Drupal\webform_pagamentos\Form\SettingsForm' + _title: 'Webform Pagamentos' + requirements: + _permission: 'administer site configuration'