|
| 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 | +} |
0 commit comments