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);