I am trying to use an Event Observer to run some code after the user checks out. This is what i have so far:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_submit_all_after">
<observer name="vendor_module_observer_oncheckout" instance="vendor\module\Observer\Oncheckout" />
</event>
</config>
This is the Observer File:
<?php
namespace vendor\module\Observer;
class Oncheckout implements \Magento\Framework\Event\ObserverInterface
{
public $_observer;
public function execute(\Magento\Framework\Event\Observer $observer)
{
$order = $observer->getOrder();
$orderid = $order->getId();
//adds $orderid to the database
}
}
From some research i have done, this is the correct code, and it does work successfully. However, it takes over 1 minute for the code to finish executing and redirect the user to the checkout success page.
What am i doing wrong that causes such a long delay? Without this code, the checkout success page loads up in seconds.
Thanks.
EDIT:
With some investigation, I have found that the module causes the payment-information post request to remain in the pending
state for 2.1 minutes
after further testing, the time in the pending
state is consistently 2.1 minutes every time