Clipper On Line • Ver Tópico - Gateway de Pagamentos

Gateway de Pagamentos

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

Moderador: Moderadores

 

Gateway de Pagamentos

Mensagempor ctoas » 18 Mai 2021 15:26

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
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
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 de usuário

ctoas
Usuário Nível 2

Usuário Nível 2
 
Mensagens: 52
Data de registro: 09 Mai 2005 16:22
Cidade/Estado: São Paulo
Curtiu: 5 vezes
Mens.Curtidas: 1 vez

Gateway de Pagamentos

Mensagempor Itamar M. Lins Jr. » 18 Mai 2021 15:31

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.
Avatar de usuário

Itamar M. Lins Jr.
Colaborador

Colaborador
 
Mensagens: 6927
Data de registro: 30 Mai 2007 11:31
Cidade/Estado: Ilheus Bahia
Curtiu: 309 vezes
Mens.Curtidas: 503 vezes

Gateway de Pagamentos

Mensagempor Itamar M. Lins Jr. » 18 Mai 2021 15:34

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

Saudações,
Itamar M. Lins Jr.
Avatar de usuário

Itamar M. Lins Jr.
Colaborador

Colaborador
 
Mensagens: 6927
Data de registro: 30 Mai 2007 11:31
Cidade/Estado: Ilheus Bahia
Curtiu: 309 vezes
Mens.Curtidas: 503 vezes

Gateway de Pagamentos

Mensagempor ctoas » 18 Mai 2021 15:43

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 de usuário

ctoas
Usuário Nível 2

Usuário Nível 2
 
Mensagens: 52
Data de registro: 09 Mai 2005 16:22
Cidade/Estado: São Paulo
Curtiu: 5 vezes
Mens.Curtidas: 1 vez

Gateway de Pagamentos

Mensagempor Itamar M. Lins Jr. » 18 Mai 2021 15:51

Olá!
Ativar SSL no Harbour.
#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.
Avatar de usuário

Itamar M. Lins Jr.
Colaborador

Colaborador
 
Mensagens: 6927
Data de registro: 30 Mai 2007 11:31
Cidade/Estado: Ilheus Bahia
Curtiu: 309 vezes
Mens.Curtidas: 503 vezes

Gateway de Pagamentos

Mensagempor ctoas » 18 Mai 2021 16:19

Olá...

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

Não tenho aqui nem no xharbour e nem no BCC...
Avatar de usuário

ctoas
Usuário Nível 2

Usuário Nível 2
 
Mensagens: 52
Data de registro: 09 Mai 2005 16:22
Cidade/Estado: São Paulo
Curtiu: 5 vezes
Mens.Curtidas: 1 vez

Gateway de Pagamentos

Mensagempor Itamar M. Lins Jr. » 18 Mai 2021 16:59

Olá!
Pois é moço! Por isso perguntei.
No xHarbour não sei como é.
Teste isso ai.
  
     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.
Avatar de usuário

Itamar M. Lins Jr.
Colaborador

Colaborador
 
Mensagens: 6927
Data de registro: 30 Mai 2007 11:31
Cidade/Estado: Ilheus Bahia
Curtiu: 309 vezes
Mens.Curtidas: 503 vezes

Gateway de Pagamentos

Mensagempor JoséQuintas » 18 Mai 2021 18:16

É Windows?
Usa MSXML da Microsoft e pronto.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg, multithread, dbfcdx, ADO+MySql, PNotepad
"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 de usuário

JoséQuintas
Membro Master

Membro Master
 
Mensagens: 18015
Data de registro: 26 Fev 2007 11:59
Cidade/Estado: São Paulo-SP
Curtiu: 15 vezes
Mens.Curtidas: 1206 vezes

Gateway de Pagamentos

Mensagempor Itamar M. Lins Jr. » 18 Mai 2021 18:32

Olá!
#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.
Avatar de usuário

Itamar M. Lins Jr.
Colaborador

Colaborador
 
Mensagens: 6927
Data de registro: 30 Mai 2007 11:31
Cidade/Estado: Ilheus Bahia
Curtiu: 309 vezes
Mens.Curtidas: 503 vezes

Gateway de Pagamentos

Mensagempor ctoas » 18 Mai 2021 18:58

Obrigado por enquanto Itamar.

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

Ate agora tudo que tentei nada deu certo.... sempre erro 60 do curl
Avatar de usuário

ctoas
Usuário Nível 2

Usuário Nível 2
 
Mensagens: 52
Data de registro: 09 Mai 2005 16:22
Cidade/Estado: São Paulo
Curtiu: 5 vezes
Mens.Curtidas: 1 vez

Gateway de Pagamentos

Mensagempor Itamar M. Lins Jr. » 18 Mai 2021 19:02

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.
Avatar de usuário

Itamar M. Lins Jr.
Colaborador

Colaborador
 
Mensagens: 6927
Data de registro: 30 Mai 2007 11:31
Cidade/Estado: Ilheus Bahia
Curtiu: 309 vezes
Mens.Curtidas: 503 vezes

Gateway de Pagamentos

Mensagempor Itamar M. Lins Jr. » 18 Mai 2021 19:20

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.
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.
Avatar de usuário

Itamar M. Lins Jr.
Colaborador

Colaborador
 
Mensagens: 6927
Data de registro: 30 Mai 2007 11:31
Cidade/Estado: Ilheus Bahia
Curtiu: 309 vezes
Mens.Curtidas: 503 vezes

Gateway de Pagamentos

Mensagempor ctoas » 18 Mai 2021 19:44

Olá.

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

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 de usuário

ctoas
Usuário Nível 2

Usuário Nível 2
 
Mensagens: 52
Data de registro: 09 Mai 2005 16:22
Cidade/Estado: São Paulo
Curtiu: 5 vezes
Mens.Curtidas: 1 vez

Gateway de Pagamentos

Mensagempor ctoas » 18 Mai 2021 20:09

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 de usuário

ctoas
Usuário Nível 2

Usuário Nível 2
 
Mensagens: 52
Data de registro: 09 Mai 2005 16:22
Cidade/Estado: São Paulo
Curtiu: 5 vezes
Mens.Curtidas: 1 vez

Gateway de Pagamentos

Mensagempor Itamar M. Lins Jr. » 18 Mai 2021 22:58

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.
Avatar de usuário

Itamar M. Lins Jr.
Colaborador

Colaborador
 
Mensagens: 6927
Data de registro: 30 Mai 2007 11:31
Cidade/Estado: Ilheus Bahia
Curtiu: 309 vezes
Mens.Curtidas: 503 vezes

Próximo



Retornar para FiveWin

Quem está online

Usuários vendo este fórum: Google [Bot] e 11 visitantes


Ola Amigo, espero que meu site e forum tem lhe beneficiado, com exemplos e dicas de programacao.
Entao divulgue o link da Doacao abaixo para seus amigos e redes sociais ou faça uma doacao para o site forum...
MUITO OBRIGADO PELA SUA DOACAO!
Faça uma doação para o forum
cron
v
Olá visitante, seja bem-vindo ao Fórum Clipper On Line!
Efetue o seu login ou faça o seu Registro