Att.
Marcelo A. L. Carli
Marília/SP
Capital Nacional do Alimento ®
https://malc-informatica.ueniweb.com
Insta: @malcarli25
Email / Skype: marceloalcarli@gmail.com
Código: Selecionar todos
/*****************************************************************************
* SISTEMA : ROTINA EVENTUAL *
* PROGRAMA : DEMO.PRG *
* OBJETIVO : Boleto por Api - Sicoob *
* AUTOR : Marcelo Antonio Lázzaro Carli *
* DATA : 23.02.2024 *
* ULT. ALT.: 27.02.2024 *
*****************************************************************************/
#include 'minigui.ch'
Function Main()
REQUEST HB_LANG_PT
REQUEST HB_CODEPAGE_PTISO
REQUEST HB_CODEPAGE_PT850
HB_LangSelect([PT])
Set Navigation Extended
DEFINE WINDOW f_BoletosApi AT 165 , 299 WIDTH 650 HEIGHT 300 TITLE "Boleto por Api - Sicoob" MAIN
DEFINE BUTTON Button_1
ROW 210
COL 20
WIDTH 110
HEIGHT 28
ACTION {|| fEnvia(1)}
CAPTION "Enviar Boletos"
FONTNAME 'Arial'
END BUTTON
DEFINE BUTTON Button_2
ROW 210
COL 210
WIDTH 110
HEIGHT 28
ACTION {|| fEnvia(2)}
CAPTION "Consultar Boleto"
FONTNAME 'Arial'
END BUTTON
DEFINE BUTTON Button_3
ROW 210
COL 480
WIDTH 110
HEIGHT 28
ACTION {|| f_BoletosApi.Release}
CAPTION "Sair"
FONTNAME 'Arial'
END BUTTON
END WINDOW
f_BoletosApi.Center
f_BoletosApi.Activate
Return (Nil)
Static Procedure fEnvia(nTipo)
Local oSoap, cUrl:= cRetorno:= cChave:= cBoleto:= cCliente:= [], cMetodo:= [POST], nAmbiente:= 1 // 1 Produção 2 - testes
HB_SETCODEPAGE([PTISO])
If nTipo == 1 // emitir boleto
If nAmbiente == 1 // Produção
cUrl := [https://api.sicoob.com.br/cobranca-bancaria/v2/boletos]
Else
cUrl := [https://sandbox.sicoob.com.br/sicoob/sandbox/cobranca-bancaria/v2/boletos]
Endif
Else // consultar boleto
cMetodo:= [GET]
If nAmbiente == 1 // Produção
* cUrl := [https://api.sicoob.com.br/cobranca-bancaria/v2/boletos?numeroContrato={{153672}}&modalidade=1&nossoNumero=10264]
cUrl := [https://api.sicoob.com.br/cobranca-bancaria/v2/boletos?numeroContrato=153672&modalidade=1&nossoNumero=10264]
* cUrl := [https://api.sicoob.com.br/cobranca-bancaria/v2/boletos?numeroContrato={{153672}}&modalidade=1&nossoNumero=102642]
Else
cUrl := [https://sandbox.sicoob.com.br/sicoob/sandbox/cobranca-bancaria/v2/boletos?numeroContrato={{numContrato}}&modalidade=1&nossoNumero=integer]
Endif
Endif
cChave := [Bearer 946700d1-6a91-4b6a-845e-9999] // chave sicoob não é esta por segurança
cCliente:= [946700d1-6a91-4b6a-845e-9999993] // não é esta por segurança
cBoleto:= '{ "numeroContrato": 153672,' + hb_OsNewLine() + ;
'"modalidade": 1,' + hb_OsNewLine() + ;
'"numeroContaCorrente": 0,' + hb_OsNewLine() + ;
'"especieDocumento": "DM",' + hb_OsNewLine() + ;
'"dataEmissao": "2024-09-20T00:00:00-03:00",' + hb_OsNewLine() + ;
'"nossoNumero": 2588658,' + hb_OsNewLine() + ;
'"seuNumero": "1235512",' + hb_OsNewLine() + ;
'"identificacaoBoletoEmpresa": "4562",' + hb_OsNewLine() + ;
'"identificacaoEmissaoBoleto": 1,' + hb_OsNewLine() + ;
'"identificacaoDistribuicaoBoleto": 1,' + hb_OsNewLine() + ;
'"valor": 156.23,' + hb_OsNewLine() + ;
'"dataVencimento": "2024-09-20T00:00:00-03:00",' + hb_OsNewLine() + ;
'"dataLimitePagamento": "2024-09-20T00:00:00-03:00",' + hb_OsNewLine() + ;
'"valorAbatimento": 1,' + hb_OsNewLine() + ;
'"tipoDesconto": 1,' + hb_OsNewLine() + ;
'"dataPrimeiroDesconto": "2024-09-20T00:00:00-03:00",' + hb_OsNewLine() + ;
'"valorPrimeiroDesconto": 1,' + hb_OsNewLine() + ;
'"dataSegundoDesconto": "2024-09-20T00:00:00-03:00",' + hb_OsNewLine() + ;
'"valorSegundoDesconto": 0,' + hb_OsNewLine() + ;
'"dataTerceiroDesconto": "2024-09-20T00:00:00-03:00",' + hb_OsNewLine() + ;
'"valorTerceiroDesconto": 0,' + hb_OsNewLine() + ;
'"tipoMulta": 0,' + hb_OsNewLine() + ;
'"dataMulta": "2024-09-20T00:00:00-03:00",' + hb_OsNewLine() + ;
'"valorMulta": 5,' + hb_OsNewLine() + ;
'"tipoJurosMora": 2,' + hb_OsNewLine() + ;
'"dataJurosMora": "2024-09-20T00:00:00-03:00",' + hb_OsNewLine() + ;
'"valorJurosMora": 4,' + hb_OsNewLine() + ;
'"numeroParcela": 1,' + hb_OsNewLine() + ;
'"aceite": false,' + hb_OsNewLine() + ;
'"codigoNegativacao": 2,' + hb_OsNewLine() + ;
'"numeroDiasNegativacao": 60,' + hb_OsNewLine() + ;
'"codigoProtesto": 1,' + hb_OsNewLine() + ;
'"numeroDiasProtesto": 30,' + hb_OsNewLine() + ;
'"pagador": { "numeroCpfCnpj": "98765432185",' + hb_OsNewLine() + ;
'"nome": "Marcelo dos Santos",' + hb_OsNewLine() + ;
'"endereco": "Rua 87 Quadra 1 Lote 1 casa 1",' + hb_OsNewLine() + ;
'"bairro": "Santa Rosa",' + hb_OsNewLine() + ;
'"cidade": "Luziânia",' + hb_OsNewLine() + ;
'"cep": "72320000",' + hb_OsNewLine() + ;
'"uf": "DF",' + hb_OsNewLine() + ;
'"email": [ "pagador@dominio.com.br" ] },' + hb_OsNewLine() + ;
'"beneficiarioFinal": { "numeroCpfCnpj": "98784978699",' + hb_OsNewLine() + ;
'"nome": "Lucas de Lima" },' + hb_OsNewLine() + ;
'"mensagensInstrucao": { "tipoInstrucao": 1,' + hb_OsNewLine() + ;
'"mensagens": [ "Descrição da Instrução 1",' + hb_OsNewLine() + ;
'"Descrição da Instrução 2",' + hb_OsNewLine() + ;
'"Descrição da Instrução 3",' + hb_OsNewLine() + ;
'"Descrição da Instrução 4",' + hb_OsNewLine() + ;
'"Descrição da Instrução 5" ] },' + hb_OsNewLine() + ;
'"gerarPdf": true,' + hb_OsNewLine() + ;
'"rateioCreditos": [ { "numeroBanco": 756,' + hb_OsNewLine() + ;
'"numeroAgencia": 4027,' + hb_OsNewLine() + ;
'"numeroContaCorrente": 0,' + hb_OsNewLine() + ;
'"contaPrincipal": true,' + hb_OsNewLine() + ;
'"codigoTipoValorRateio": 1,' + hb_OsNewLine() + ;
'"valorRateio": 156.23,' + hb_OsNewLine() + ;
'"codigoTipoCalculoRateio": 1,' + hb_OsNewLine() + ;
'"numeroCpfCnpjTitular": "98765432185",' + hb_OsNewLine() + ;
'"nomeTitular": "Marcelo dos Santos",' + hb_OsNewLine() + ;
'"codigoFinalidadeTed": 10,' + hb_OsNewLine() + ;
'"codigoTipoContaDestinoTed": "CC",' + hb_OsNewLine() + ;
'"quantidadeDiasFloat": 1,' + hb_OsNewLine() + ;
'"dataFloatCredito": "2020-12-30" } ],' + hb_OsNewLine() + ;
'"codigoCadastrarPIX": 1 }'
BEGIN SEQUENCE WITH __BreakBlock()
oSoap:= Win_OleCreateObject([MSXML2.ServerXMLHTTP.6.0])
oSoap:SetTimeouts(30000, 30000, 30000, 30000)
oSoap:Open(cMetodo, cUrl, .F.)
oSoap:SetRequestHeader([Authorization], cChave)
oSoap:SetRequestHeader([client_id], cCliente)
oSoap:SetRequestHeader([Content-Type], [application/json; charset=utf-8])
oSoap:SetRequestHeader([Accept], [application/json])
oSoap:SetRequestHeader([cache-control], [no-cache])
oSoap:Send(cBoleto)
cRetorno:= oSoap:Responsetext()
END SEQUENCE
* aReturn := {=>}
* cteste:= hb_jsondecode(cRetorno, @aReturn)
hb_MemoWrit([retorno.txt], cRetorno)
If hb_At([resultado], cRetorno) # 0
MsgInfo([Sucesso: ] + cRetorno)
Else
MsgExclamation([Aconteceu um erro: ] + hb_OsNewLine() + cRetorno, [Entre em contato com o Suporte])
Endif
HB_SETCODEPAGE([PT850])
Return (Nil)

