Gateway de Pagamentos

Discussão sobre a biblioteca Fivewin - O Clipper para Windows.

Moderador: Moderadores

Avatar do usuário
ctoas
Usuário Nível 2
Usuário Nível 2
Mensagens: 52
Registrado em: 09 Mai 2005 16:22
Localização: São Paulo
Contato:

Gateway de Pagamentos

Mensagem por ctoas »

Olá amigos!

Preciso integrar o gateway de pagamento da Gerencianet (www.gerencianet.com.br) para geração de boletos de cobrança. Acontece que estou tendo problemas com o uso da CURL.

Alguém já fez esta integração? Poderia dar uma força?

Segue exemplo da API em C

Código: Selecionar todos

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
  curl_easy_setopt(curl, CURLOPT_URL, "https://sandbox.gerencianet.com.br/v1/charge");
  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
  struct curl_slist *headers = NULL;
  headers = curl_slist_append(headers, "Authorization: {{Authorization}}");
  headers = curl_slist_append(headers, "Content-Type: application/json");
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  const char *data = "{\n  \"items\": [\n    {\n      \"name\": \"item\",\n      \"value\": 500,\n      \"amount\": 1\n    }\n  ]\n}";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
  res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
E este é o teste que fiz usando o xHarbour

Código: Selecionar todos

FUNCTION GERENCIANET()

	cURL := CURL_EASY_INIT()
	
	IF !EMPTY(cURL)
	
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_CUSTOMREQUEST, "POST")
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_URL, "https://sandbox.gerencianet.com.br/v1/charge")
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_RETURNTRANSFER, .T.)
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_ENCODING, "")
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_MAXREDIRS, 10)
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_TIMEOUT, 0)
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_FOLLOWLOCATION, .T.)
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_HTTP_VERSION, "CURL_HTTP_VERSION_1_1")
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_POSTFIELDS, {"grant_type","client_credentials"})		
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_POSTFIELDS, {'"items": [{"name": "item","value": 500,"amount": 1}]'})
		
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_HTTPHEADER, {'Authorization: [{"Client_Id_1c055bbc11805306ad56442e71f4f6b771536fc2","Client_Secret_2884bd0e7ef116a1cfaeca5624b1725394644608"}]'})
		CURL_EASY_SETOPT(cURL, HB_CURLOPT_HTTPHEADER, {'Content-Type: application/json'})
		
		nCURLERR := CURL_EASY_PERFORM(cURL)
		
		IF ncurlErr > 0
			? "Curl Error: "+str(ncurlErr)
		ELSE
			? "PASSOU"
		ENDIF
	
	ENDIF
	
	CURL_EASY_CLEANUP( cURL )

RETURN NIL
Quando executo teste que fiz, retorna o erro 60
Este erro está relacionado ao cURL configurado em seu servidor (ou computador) estar exigindo um certificado (https/ssl) local
Sei que é possível também executar o codigo C direto, mas não faço idéia de como.


Agradeço desde já a atenção e ajuda
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Gateway de Pagamentos

Mensagem por Itamar M. Lins Jr. »

Olá!
Tem exemplo usando o Curl via linha de comando ?
Pq na internet tem muitos exemplos que usam o programa curl pela linha de comando.

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Gateway de Pagamentos

Mensagem por Itamar M. Lins Jr. »

Olá!
Outra coisa.
É xHarbour ou Harbour ?
Precisa ativar SSL antes. Vc viu isso ?

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
ctoas
Usuário Nível 2
Usuário Nível 2
Mensagens: 52
Registrado em: 09 Mai 2005 16:22
Localização: São Paulo
Contato:

Gateway de Pagamentos

Mensagem por ctoas »

Olá Itamar.

Todos os exemplos possíveis em diversas linguagens estão no Postman (https://documenter.getpostman.com/view/ ... 4/TW71kRme).

Com relação ao SSL, já imaginava, já que o erro fala de certificado de segurança, mas como ativa-lo ?

Estou usando xHarbour...

Obrigado
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Gateway de Pagamentos

Mensagem por Itamar M. Lins Jr. »

Olá!
Ativar SSL no Harbour.

Código: Selecionar todos

#require "hbtip"
#require "hbssl"
#require "hbcurl"

REQUEST __HBEXTERN__HBSSL__
Function main
? "Tip_SSL: ", tip_SSL()

   IF hb_AScan( curl_version_info()[ HB_CURLVERINFO_PROTOCOLS ], "https",,, .T. ) == 0
      ? "Error: Requires libcurl 7.20.0 or newer, built with TLS/SSL and HTTPS protocol support"
      RETURN
   ENDIF
Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
ctoas
Usuário Nível 2
Usuário Nível 2
Mensagens: 52
Registrado em: 09 Mai 2005 16:22
Localização: São Paulo
Contato:

Gateway de Pagamentos

Mensagem por ctoas »

Olá...

Onde consigo as libs "hbtip", "hbssl" e "hbcurl" ?

Não tenho aqui nem no xharbour e nem no BCC...
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Gateway de Pagamentos

Mensagem por Itamar M. Lins Jr. »

Olá!
Pois é moço! Por isso perguntei.
No xHarbour não sei como é.
Teste isso ai.

Código: Selecionar todos

  
     info := curl_easy_getinfo( curl, HB_CURLINFO_SSL_ENGINES, @tmp )
      ? "SSL ENGINES: ", tmp, Len( info )
      FOR tmp := 1 TO Len( info )
         ?? info[ tmp ] + " "
      NEXT
Me parece que o cURL tem o SSL próprio.

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Gateway de Pagamentos

Mensagem por JoséQuintas »

É Windows?
Usa MSXML da Microsoft e pronto.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Gateway de Pagamentos

Mensagem por Itamar M. Lins Jr. »

Olá!

Código: Selecionar todos

#include "hbcurl.ch"

Function main
gerencianet()
return nil

FUNCTION GERENCIANET()

   cURL := CURL_EASY_INIT()
   
   IF !EMPTY(cURL)
      ? CURL_EASY_SETOPT(cURL, HB_CURLOPT_VERBOSE,.T.)
      ? CURL_EASY_SETOPT(cURL, HB_CURLOPT_CUSTOMREQUEST, "POST")
      
      ? CURL_EASY_SETOPT(cURL, HB_CURLOPT_URL, "https://sandbox.gerencianet.com.br/v1/charge")
      ? curl_easy_setopt(curl, HB_CURLOPT_FOLLOWLOCATION, "1L")
      ? curl_easy_setopt(cURL, HB_CURLOPT_PROTOCOLS, HB_CURLPROTO_HTTPS)

      ? CURL_EASY_SETOPT(cURL, HB_CURLOPT_POSTFIELDS, {"grant_type","client_credentials"})      
      ? CURL_EASY_SETOPT(cURL, HB_CURLOPT_POSTFIELDS, {'"items": [{"name": "item","value": 500,"amount": 1}]'})
      ? "POSTFIELDS"
      ? CURL_EASY_SETOPT(cURL, HB_CURLOPT_HTTPHEADER, {'Authorization:[{"Client_Id_1c055bbc11805306ad56442e71f4f6b771536fc2","Client_Secret_2884bd0e7ef116a1cfaeca5624b1725394644608"}]'})
      ? "HTTPHEADER 1"
      ? CURL_EASY_SETOPT(cURL, HB_CURLOPT_HTTPHEADER, {'Content-Type: application/json'})
      ? "HTTPHEADER 2"
      //? curl_easy_setopt(cURL, HB_CURLOPT_POSTFIELDS, data)
      nCURLERR := CURL_EASY_PERFORM(cURL)
      
      IF ncurlErr > 0
         ? "Curl Error: "+str(ncurlErr)
      ELSE
         ? "PASSOU"
      ENDIF
   
   ENDIF
   
   CURL_EASY_CLEANUP( cURL )

RETURN NIL
Screenshot_20210518_183130.png
Só deu pra ir até ai.
Coloque o link dos exemplos novamente mas use a TAG para URL.

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
ctoas
Usuário Nível 2
Usuário Nível 2
Mensagens: 52
Registrado em: 09 Mai 2005 16:22
Localização: São Paulo
Contato:

Gateway de Pagamentos

Mensagem por ctoas »

Obrigado por enquanto Itamar.

Segue o link.
https://documenter.getpostman.com/view/ ... 4/TW71kRme

Ate agora tudo que tentei nada deu certo.... sempre erro 60 do curl
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Gateway de Pagamentos

Mensagem por Itamar M. Lins Jr. »

Olá!
Estava vendo lá no forum do Linares(fivewin).
O padrão lá é Harbour, pq o pessoal fica usando xHarbour ? não migraram para Harbour ?
Os exemplos dele para MOD_HARBOUR, Linux, ele usa o Harbour.

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Gateway de Pagamentos

Mensagem por Itamar M. Lins Jr. »

Olá!
Tente usar o exe curl linha de comando(cmd)
https://curl.se/windows/
Eu não entendo nada disso... 0,001%
Olhando algum exemplo, consigo entender mas esses do link, não entendi.
Coloca o produto comprado, mais o CPF do cliente para emitir um boleto. Foi mais ou menos isso que entendi.
Agora como passa os paramentos é que estou tentando entender.

Código: Selecionar todos

curl --location --request POST 'https://sandbox.gerencianet.com.br/v1/carnet' \
--header 'Authorization: {{Authorization}}' \
--header 'Content-Type: application/json' \
--data-raw '{
  "items": [
    {
      "name": "Meu Produto",
      "value": 7500,
      "amount": 1
    }
  ],
  "customer": {
    "name": "Gorbadoc Oldbuck",
    "cpf": "94271564656",
    "phone_number": "5144916523"
  },
  "expire_at": "2018-12-20",
  "configurations": {
        "fine": 200,
        "interest": 33
      },
  "message": "Este é um espaço de até 80 caracteres para informar algo a seu cliente",
  "repeats": 5,
  "split_items": false
}'
Como converter isso para o Harbour eu não sei.

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
ctoas
Usuário Nível 2
Usuário Nível 2
Mensagens: 52
Registrado em: 09 Mai 2005 16:22
Localização: São Paulo
Contato:

Gateway de Pagamentos

Mensagem por ctoas »

Olá.

Pelo curl.exe também não vai. Complicado isso.

Código: Selecionar todos

curl: (1) Protocol "'https" not supported or disabled in libcurl
curl: (6) Could not resolve host: \--header
curl: (6) Could not resolve host: 'Authorization
curl: (3) [globbing] nested brace in column 2
curl: (6) Could not resolve host: \--header
curl: (6) Could not resolve host: 'Content-Type
curl: (6) Could not resolve host: application
curl: (6) Could not resolve host: \--data-raw
curl: (3) [globbing] unmatched brace in column 2
curl: (6) Could not resolve host: items
curl: (3) [globbing] bad range specification in column 2
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: name
curl: (6) Could not resolve host: Meu Produto,
curl: (6) Could not resolve host: value
curl: (6) Could not resolve host: 7500,
curl: (6) Could not resolve host: amount
curl: (6) Could not resolve host: 1
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (6) Could not resolve host: customer
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: name
curl: (6) Could not resolve host: Gorbadoc Oldbuck,
curl: (6) Could not resolve host: cpf
curl: (6) Could not resolve host: 94271564656,
curl: (6) Could not resolve host: phone_number
curl: (6) Could not resolve host: 5144916523
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (6) Could not resolve host: expire_at
curl: (6) Could not resolve host: 2018-12-20,
curl: (6) Could not resolve host: configurations
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: fine
curl: (6) Could not resolve host: 200,
curl: (6) Could not resolve host: interest
curl: (6) Could not resolve host: 33
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (6) Could not resolve host: message
curl: (6) Could not resolve host: Este é um espaço de até 80 caracteres para informar algo a seu cliente,
curl: (6) Could not resolve host: repeats
curl: (6) Could not resolve host: 5,
curl: (6) Could not resolve host: split_items
curl: (3) [globbing] unmatched close brace/bracket in column 6
Avatar do usuário
ctoas
Usuário Nível 2
Usuário Nível 2
Mensagens: 52
Registrado em: 09 Mai 2005 16:22
Localização: São Paulo
Contato:

Gateway de Pagamentos

Mensagem por ctoas »

Olá Itamar!

Pelo que vi você usa Harbour, certo?

Será que funciona?

Pensei em que se funcionar, fazer um programinha em harbour só para isso. Conseguiria fazer um teste em harbour?

Obrigado!
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Gateway de Pagamentos

Mensagem por Itamar M. Lins Jr. »

Olá!
Mas como é ?
Esse é o problema. Eu não sei fazer.
Pela linha de comando só achei exemplos simples.
Tem que procurar mais ou esperar alguém com mais conhecimento ou usar C#, etc.

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Responder