Skip to content

Commit

Permalink
Fixing webhook check and creation (#148)
Browse files Browse the repository at this point in the history
* fixing webhook check and creation

* removing comment
  • Loading branch information
luiznfeio authored Feb 8, 2023
1 parent 3e75da5 commit fc89a90
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions modules/addons/NFEioServiceInvoices/lib/Legacy/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,20 @@ function gnfe_issue_nfe($postfields) {
$_storageKey = Addon::I()->configuration()->storageKey;
$storage = new Storage($_storageKey);

logModuleCall('NFEioServiceInvoices', 'gnfe_issue_nfe - gnfe_webhook_id', $gnfe_webhook_id, $webhook_url);

if ($gnfe_webhook_id) {
$check_webhook = $this->gnfe_check_webhook($gnfe_webhook_id);

if ($check_webhook == null)
{
return (object) ['message' => 'Erro ao checar a existência de um webhook já cadastrado'];
}

if ($check_webhook == "ERRO 400" || $check_webhook == "ERRO 404")
{
$gnfe_webhook_id = null;
}
}

logModuleCall('NFEioServiceInvoices', 'gnfe_issue_nfe - check_webhook', $check_webhook);

if ($gnfe_webhook_id and (string) $check_webhook['hooks']['url'] !== (string) $webhook_url) {
$delete_webhook = $this->gnfe_delete_webhook($gnfe_webhook_id);

Expand All @@ -290,6 +292,8 @@ function gnfe_issue_nfe($postfields) {
if (!$gnfe_webhook_id) {
$create_webhook = $this->gnfe_create_webhook($webhook_url);

logModuleCall('NFEioServiceInvoices', 'gnfe_issue_nfe - gnfe_create_webhook', $create_webhook, $webhook_url);

if ($create_webhook == null)
{
return (object) ['message' => 'Erro ao criar novo webhook'];
Expand All @@ -299,7 +303,6 @@ function gnfe_issue_nfe($postfields) {

$storage->set('webhook_id', $create_webhook['hooks']['id']);
$storage->set('webhook_secret', $create_webhook['hooks']['secret']);
logModuleCall($_storageKey, 'webhook_id', $create_webhook);
}
}

Expand Down Expand Up @@ -688,6 +691,11 @@ function gnfe_check_webhook($id) {
{
return json_decode($response, true);
}
elseif ($info['http_code'] == 400 || $info['http_code'] == 404)
{
logModuleCall('NFEioServiceInvoices', 'gnfe_check_webhook', $id, "ERRO " . $info['http_code']);
return "ERRO " . $info['http_code'];
}
else {
logModuleCall('NFEioServiceInvoices', 'gnfe_check_webhook', $id, $info['http_code']);
}
Expand Down

0 comments on commit fc89a90

Please sign in to comment.