Add force option to enable or disable webhook status checking, defaults to false #801

This commit is contained in:
Ramon Gutierrez 2024-05-31 18:51:55 +08:00
parent 3846ad5a43
commit 08084f682c

View file

@ -5,6 +5,7 @@ namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\ORM\EntityManagerInterface;
@ -34,24 +35,30 @@ class ProcessLatePaymongoTransactionsCommand extends Command
{
$this->setName('paymongo:checkpending')
->setDescription('Check for any late PayMongo transactions and process if needed.')
->setHelp('Check for any late PayMongo transactions and process if needed.');
->setHelp('Check for any late PayMongo transactions and process if needed.')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Ignore webhook status and process anyway.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Checking webhook status...');
$force = $input->getOption('force');
// check if webhook is disabled
$webhook = $this->paymongo->getWebhook($this->webhook_id);
// if we aren't forcing, check webhook status first
if (!$force) {
$output->writeln('Checking webhook status...');
if ($webhook['success'] && $webhook['response']['data']['attributes']['status'] === 'enabled') {
$output->writeln('<info>Webhook is enabled, no need to do anything.</info>');
// check if webhook is disabled
$webhook = $this->paymongo->getWebhook($this->webhook_id);
return 0;
} else {
$output->writeln('<comment>Webhook is disabled! Logging event and proceeding...</comment>');
if ($webhook['success'] && $webhook['response']['data']['attributes']['status'] === 'enabled') {
$output->writeln('<info>Webhook is enabled, no need to do anything.</info>');
$this->paymongo->log('WEBHOOK', "[]", json_encode($webhook['response'], JSON_PRETTY_PRINT), 'webhook');
return 0;
} else {
$output->writeln('<comment>Webhook is disabled! Logging event and proceeding...</comment>');
$this->paymongo->log('WEBHOOK', "[]", json_encode($webhook['response'], JSON_PRETTY_PRINT), 'webhook');
}
}
$output->writeln('Fetching all late pending transactions...');