From 96a0040104b9a399a40567d344964a6bd670aba9 Mon Sep 17 00:00:00 2001 From: Ram Prakash Singh <45222925+ramth05@users.noreply.github.com> Date: Wed, 9 Dec 2020 13:03:59 +0530 Subject: [PATCH] Added delay in webhook to avoid duplicate orders (#212) --- Controller/Payment/Webhook.php | 17 +++++++++++++++++ composer.json | 2 +- etc/module.xml | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Controller/Payment/Webhook.php b/Controller/Payment/Webhook.php index 11d889e7..2915a192 100644 --- a/Controller/Payment/Webhook.php +++ b/Controller/Payment/Webhook.php @@ -249,6 +249,23 @@ protected function orderPaid(array $post) $quote = $this->getQuoteObject($post, $quoteId); + //before creating order let wait for 15 sec and re-verify if the quote is active or not + $this->logger->info("Razorpay Webhook: Waiting for 15 sec with quoteID:$quoteId."); + + sleep(15); + + $this->logger->info("Razorpay Webhook: Waiting of 15 sec over with quoteID:$quoteId."); + + //validate if the quote Order is still active + $quoteUpdated = $this->quoteRepository->get($quoteId); + + //exit if quote is not active + if (!$quoteUpdated->getIsActive()) + { + $this->logger->info("Razorpay Webhook: Quote order is inactive for quoteID: $quoteId and Razorpay payment_id(:$paymentId)"); + return; + } + $order = $this->quoteManagement->submit($quote); $payment = $order->getPayment(); diff --git a/composer.json b/composer.json index 78547a71..5367c733 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "razorpay/magento", "description": "Razorpay Magento 2.0 plugin for accepting payments.", - "version": "3.2.1", + "version": "3.2.2", "require": { "php": "~5.5.0|~5.6.0|^7.0", "razorpay/razorpay": "2.*" diff --git a/etc/module.xml b/etc/module.xml index a65c92fc..52076cb7 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - +