Skip to content

Commit

Permalink
Update openFinance.php
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelo-machado-gn authored Aug 29, 2023
1 parent 035d1b9 commit b90fb98
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions callback/efi/openFinance.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
function validateWebhook($gatewayParams)
{



if ($gatewayParams['mtls'] != 'on' && isset($_GET['hmac'])) {
$hmac = $_GET['hmac'];
$hash = hash('sha256', $gatewayParams['clientIdProd']);
$hash = hash('sha256',$gatewayParams['clientIdProd']);
if ($hmac != $hash) {
header('HTTP/1.1 403 Forbidden');
die("Não foi possível receber a notificação de pagamento do Open Finance.");
Expand All @@ -25,12 +25,12 @@ function validateWebhook($gatewayParams)
function handleWebhook($gatewayParams)
{

$postData = json_decode(file_get_contents('php://input'));
$ofPaymentData = json_decode(file_get_contents('php://input'));
$logFile = __DIR__ . '/log.txt'; // caminho completo para o arquivo de log



$logString = date('Y-m-d H:i:s') . ' - ' . json_encode($postData) . "\n"; // string formatada com a data atual e os dados do array em formato JSON
$logString = date('Y-m-d H:i:s') . ' - ' . json_encode($ofPaymentData) . "\n"; // string formatada com a data atual e os dados do array em formato JSON

// abre o arquivo em modo de escrita, acrescentando os dados ao final do arquivo, se ele já existir
$fileHandle = fopen($logFile, 'a');
Expand All @@ -42,16 +42,10 @@ function handleWebhook($gatewayParams)
fwrite($fileHandle, $logString);
fclose($fileHandle);

if (isset($postData->evento) && isset($postData->data_criacao)) {
if (!isset($ofPaymentData->identificadorPagamento) ) {
header('HTTP/1.0 200 OK');
exit();
}

$ofPaymentData = $postData;

if (empty($ofPaymentData)) {
showException('Exception', array('Pagamento Open Finance não recebido pelo Webhook.'));
} else {
echo "webhook processado com sucesso";
}else {
header('HTTP/1.0 200 OK');

$tableName = 'tblefiopenfinance';
Expand Down

0 comments on commit b90fb98

Please sign in to comment.