diff --git a/config/services.yaml b/config/services.yaml index 00085811..12c32894 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -109,6 +109,12 @@ services: arguments: $callback_url: "%env(WARRANTY_SERIAL_CALLBACK_URL)%" + App\Command\ProcessLatePaymongoTransactionsCommand: + arguments: + $em: "@doctrine.orm.entity_manager" + $paymongo: "@App\\Service\\PayMongoConnector" + $webhook_id: "%env(PAYMONGO_WEBHOOK_ID)%" + # rider tracker service App\Service\RiderTracker: arguments: diff --git a/src/Command/ProcessLatePaymongoTransactionsCommand.php b/src/Command/ProcessLatePaymongoTransactionsCommand.php index 5397a7a2..2c86d3ab 100644 --- a/src/Command/ProcessLatePaymongoTransactionsCommand.php +++ b/src/Command/ProcessLatePaymongoTransactionsCommand.php @@ -10,8 +10,6 @@ use Doctrine\ORM\EntityManagerInterface; use App\Ramcar\TransactionStatus; use App\Entity\GatewayTransaction; - -use App\Service\InsuranceConnector; use App\Service\PayMongoConnector; use DateTime; @@ -20,13 +18,14 @@ class ProcessLatePaymongoTransactionsCommand extends Command { protected $em; protected $paymongo; - protected $insurance; - public function __construct(EntityManagerInterface $em, PayMongoConnector $paymongo, InsuranceConnector $insurance) + protected $webhook_id; + + public function __construct(EntityManagerInterface $em, PayMongoConnector $paymongo, $webhook_id) { $this->em = $em; $this->paymongo = $paymongo; - $this->insurance = $insurance; + $this->webhook_id = $webhook_id; parent::__construct(); } @@ -40,6 +39,21 @@ class ProcessLatePaymongoTransactionsCommand extends Command protected function execute(InputInterface $input, OutputInterface $output) { + $output->writeln('Checking webhook status...'); + + // check if webhook is disabled + $webhook = $this->paymongo->getWebhook($this->webhook_id); + + if ($webhook['success'] && $webhook['response']['data']['attributes']['status'] === 'enabled') { + $output->writeln('Webhook is enabled, no need to do anything.'); + + return 0; + } else { + $output->writeln('Webhook is disabled! Logging event and proceeding...'); + + $this->paymongo->log('WEBHOOK', "[]", json_encode($webhook['response'], JSON_PRETTY_PRINT), 'webhook'); + } + $output->writeln('Fetching all late pending transactions...'); // set date threshold to 24 hours ago @@ -96,7 +110,7 @@ class ProcessLatePaymongoTransactionsCommand extends Command } } - $output->writeln('Done! Processed ' . $x . ' rows.'); + $output->writeln('Done! Processed ' . $x . ' rows.'); return 0; } diff --git a/src/Service/PayMongoConnector.php b/src/Service/PayMongoConnector.php index c34a94e7..25f380ca 100644 --- a/src/Service/PayMongoConnector.php +++ b/src/Service/PayMongoConnector.php @@ -74,6 +74,11 @@ class PayMongoConnector return $this->doRequest('/v1/checkout_sessions/' . $checkout_id, 'GET'); } + public function getWebhook($id) + { + return $this->doRequest('/v1/webhooks/'. $id, 'GET'); + } + protected function generateHash() { return base64_encode($this->secret_key);