From c4b05133865d3556ba7f8b3c8d687951f752b501 Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Thu, 6 Jun 2024 05:50:36 +0800 Subject: [PATCH] Attempt to re-enable paymongo webhook if found disabled #801 --- .../ProcessLatePaymongoTransactionsCommand.php | 16 ++++++++++++++-- src/Service/PayMongoConnector.php | 5 +++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Command/ProcessLatePaymongoTransactionsCommand.php b/src/Command/ProcessLatePaymongoTransactionsCommand.php index f3bc0312..8bdc66ca 100644 --- a/src/Command/ProcessLatePaymongoTransactionsCommand.php +++ b/src/Command/ProcessLatePaymongoTransactionsCommand.php @@ -55,9 +55,21 @@ class ProcessLatePaymongoTransactionsCommand extends Command return 0; } else { - $output->writeln('Webhook is disabled! Logging event and proceeding...'); + $output->writeln('Webhook is disabled! Logging event and attempting to re-enable...'); - $this->paymongo->log('WEBHOOK', "[]", json_encode($webhook['response'], JSON_PRETTY_PRINT), 'webhook'); + // attempt re-enabling of webhook + $result = $this->paymongo->enableWebhook($this->webhook_id); + if ($result['success'] && $result['response']['data']['attributes']['status'] ?? null === 'enabled') { + $output->writeln('Webhook ' . $this->webhook_id . ' re-enabled!'); + + // log event + $this->paymongo->log('WEBHOOK RE-ENABLED', "[]", json_encode($result['response'], JSON_PRETTY_PRINT), 'webhook'); + } else { + $output->writeln('Webhook ' . $this->webhook_id . ' could not be re-enabled.'); + + // log event + $this->paymongo->log('WEBHOOK FAILURE', "[]", json_encode($result['response'], JSON_PRETTY_PRINT), 'webhook'); + } } } diff --git a/src/Service/PayMongoConnector.php b/src/Service/PayMongoConnector.php index 25f380ca..3abafc22 100644 --- a/src/Service/PayMongoConnector.php +++ b/src/Service/PayMongoConnector.php @@ -79,6 +79,11 @@ class PayMongoConnector return $this->doRequest('/v1/webhooks/'. $id, 'GET'); } + public function enableWebhook($id) + { + return $this->doRequest('/v1/webhooks/' . $id . '/enable', 'POST'); + } + protected function generateHash() { return base64_encode($this->secret_key);