Skip to content

Commit 0545e93

Browse files
✨feat: Added endpoint and example to get receipts Pix
1 parent f07257d commit 0545e93

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/**
4+
* Detailed endpoint documentation
5+
* https://dev.efipay.com.br/docs/api-pix/endpoints-exclusivos-efi#solicitar-download-extrato-conciliação
6+
*/
7+
8+
$autoload = realpath(__DIR__ . "/../../../vendor/autoload.php");
9+
if (!file_exists($autoload)) {
10+
die("Autoload file not found or on path <code>$autoload</code>.");
11+
}
12+
require_once $autoload;
13+
14+
use Efi\Exception\EfiException;
15+
use Efi\EfiPay;
16+
17+
$optionsFile = __DIR__ . "/../../credentials/options.php";
18+
if (!file_exists($optionsFile)) {
19+
die("Options file not found or on path <code>$options</code>.");
20+
}
21+
$options = include $optionsFile;
22+
23+
$params = [
24+
"e2eid" => "E0000000000000000000000000000"
25+
// "txid" => "0000000000000000000000000000000"
26+
// "idEnvio" => "0000000000000000000000000000000"
27+
// "rtrId" => "D0000000000000000000000000000"
28+
];
29+
30+
try {
31+
$api = new EfiPay($options);
32+
$response = $api->pixGetReceipt($params);
33+
34+
if (isset($options["responseHeaders"]) && $options["responseHeaders"] && is_array($response->body)) {
35+
print_r("<pre>" . json_encode($response->body, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "</pre>");
36+
print_r("<pre>" . json_encode($response->headers, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "</pre>");
37+
} else if (is_array($response)) {
38+
print_r("<pre>" . json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "</pre>");
39+
} else {
40+
// Pegar o nome do arquivo do cabeçalho Content-Disposition
41+
$filename = 'comprovante.pdf'; // valor padrão
42+
if (isset($response->headers['Content-Disposition'])) {
43+
preg_match('/filename="([^"]+)"/', $response->headers['Content-Disposition'][0], $matches);
44+
if (isset($matches[1])) {
45+
$filename = $matches[1];
46+
}
47+
}
48+
49+
$pdf = ($response->body) ? $response->body : $response;
50+
51+
// Enviar cabeçalhos para o navegador
52+
header('Content-Type: application/pdf');
53+
header('Content-Disposition: inline; filename="' . $filename . '"');
54+
header('Content-Length: ' . strlen($pdf));
55+
56+
// Enviar o conteúdo do PDF
57+
echo $pdf;
58+
exit;
59+
}
60+
61+
} catch (EfiException $e) {
62+
print_r($e->code . "<br>");
63+
print_r($e->error . "<br>");
64+
print_r($e->errorDescription) . "<br>";
65+
if (isset($options["responseHeaders"]) && $options["responseHeaders"]) {
66+
print_r("<pre>" . json_encode($e->headers, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "</pre>");
67+
}
68+
} catch (Exception $e) {
69+
print_r($e->getMessage());
70+
}

src/Efi/EfiPay.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
* @method object listAccountConfig()
8888
* @method object medList(array $params)
8989
* @method object medDefense(array $params, array $body)
90+
* @method object pixGetReceipt(array $params)
9091
* @method object pixCreateDueCharge(array $params, array $body)
9192
* @method object pixUpdateDueCharge(array $params, array $body)
9293
* @method object pixDetailDueCharge(array $params)

src/Efi/Endpoints/Pix.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
"route" => "/v2/gn/infracoes/:idInfracao/defesa",
270270
"method" => "post",
271271
"scope" => "gn.infractions.write"
272+
],
273+
"pixGetReceipt" => [
274+
"route" => "/v2/gn/pix/comprovantes",
275+
"method" => "get",
276+
"scope" => "gn.receipts.read"
272277
]
273278
]
274279
];

0 commit comments

Comments
 (0)