Last active
March 8, 2017 18:35
-
-
Save johnnyasantoss/f09c2f9ddc8bed82325acb1733e7be2b to your computer and use it in GitHub Desktop.
Um exemplo de como fazer uma chamada na API V4 de Boletos da PagueVeloz.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//dados necessários para fazer qualquer requisição | |
$email = 'emaildoclientepv@teste.com.br'; | |
$token = '0000-1234-4321-5678-9876'; | |
$dominio = 'https://sandbox.pagueveloz.com.br'; | |
//cria o token de segurança para fazer a chamada na API | |
$authToken = base64_encode($email . ':' . $token); | |
//cria um array com os headers obrigatórios | |
$cabecalho = array(); | |
$cabecalho[] = 'Accept: application/json'; | |
$cabecalho[] = 'Content-Type: application/json'; | |
$cabecalho[] = 'Authorization: Basic ' . $authToken; | |
//todas as datas devem usar ISO8601 | |
$amanhaISO = (new DateTime('tomorrow'))->format(DATE_ISO8601); | |
//cria o dto do boleto | |
$corpoRequisicao = array( | |
'Cedente' => 'Meu Cedente', | |
'CPFCNPJCedente' => "000.000.000-00", | |
'CPFCNPJSacado' => "111.111.111-11", | |
'Linha1' => "Linha 1", | |
'Sacado' => "Sacado", | |
'Valor' => 10.5, | |
'SeuNumero' => "32", | |
'Vencimento' => $amanhaISO | |
); | |
//cria o json à partir do objeto criado acima | |
$json = json_encode($corpoRequisicao); | |
$ch = curl_init(); | |
//configura o curl para fazer a requisição | |
curl_setopt($ch, CURLOPT_URL, $dominio . '/api/v4/boleto'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $cabecalho); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $json); | |
//Usamos TLS 1.2 então, verifique se você tem os requisitos para usar TLS 1.2. Isso pode ajudar: http://stackoverflow.com/questions/30145089/tls-1-2-not-working-in-curl | |
curl_setopt($ch, CURLOPT_SSLVERSION, 6); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //só em **sandbox** | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); | |
//faz o POST na API da PagueVeloz | |
$resultado = curl_exec($ch); | |
//escreve o corpo da resposta | |
echo $resultado; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment