Segue um exemplo mais detalhado, onde é feito a autenticação e consumo do endpoint para criar um boleto.
php
$config = [
"client_id" => "Client_Id_...",
"client_secret" => "Client_Secret_..."
];
$autorizacao = base64_encode($config["client_id"] . ":" . $config["client_secret"]);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://cobrancas-h.api.efipay.com.br/v1/authorize',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{"grant_type": "client_credentials"}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Basic ' . $autorizacao
),
));
$returnAuth = json_decode(curl_exec($curl), true);
$access_token = $returnAuth['access_token'];
curl_close($curl);
echo "
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://cobrancas-h.api.efipay.com.br/v1/charge/one-step',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"items": [
{
"name": "Teste Gn",
"amount": 1,
"value": 500
}
],
"payment": {
"banking_billet": {
"expire_at": "2024-12-10",
"customer": {
"name": "Gorbadoc Oldbuck",
"cpf": "94271564656",
"email": "[email protected]"
}
}
}
}',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $returnAuth['access_token'],
'Content-Type: application/json'
),
));
$responseBillet = curl_exec($curl);
curl_close($curl);
echo "
$config = [
"client_id" => "Client_Id_...",
"client_secret" => "Client_Secret_..."
];
$autorizacao = base64_encode($config["client_id"] . ":" . $config["client_secret"]);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://cobrancas-h.api.efipay.com.br/v1/authorize',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{"grant_type": "client_credentials"}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Basic ' . $autorizacao
),
));
$returnAuth = json_decode(curl_exec($curl), true);
$access_token = $returnAuth['access_token'];
curl_close($curl);
echo "
";";
var_dump($returnAuth);
echo "
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://cobrancas-h.api.efipay.com.br/v1/charge/one-step',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"items": [
{
"name": "Teste Gn",
"amount": 1,
"value": 500
}
],
"payment": {
"banking_billet": {
"expire_at": "2024-12-10",
"customer": {
"name": "Gorbadoc Oldbuck",
"cpf": "94271564656",
"email": "[email protected]"
}
}
}
}',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $returnAuth['access_token'],
'Content-Type: application/json'
),
));
$responseBillet = curl_exec($curl);
curl_close($curl);
echo "
";";
var_dump($responseBillet);
echo "