Zend certified PHP/Magento developer

Magento 2.3.x – Subscribe to newsletter checkbox at onepage checkpout page – error during subscription

My requirement was to add a “subscribe to newsletter” checkbox at onepage checkout page (below “terms and condition” checkbox). All the things are fine except 2 issues:

  1. The user MUST NOT be subscribed if he unchecks the checkboxes.
  2. For the very first time when the user mail is not there in DB for newletter subscription and I hit the place order button, the page is broken but if the email is already there in DB (under newsletter subscribers in admin) and the user places the order and dont uncheck the chekbox, all fine.

I played with the observer checkout_onepage_controller_success_action (code below):

< ?php
/**
 * 
 * Register to Newsletter during checkout process
 */

namespace ObserverSales;

use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoNewsletterModelSubscriber;
use MagentoFrameworkAppRequestInterface;
use PsrLogLoggerInterface;


class OrderPlaceBefore implements ObserverInterface
{
    protected $_subscriber;
    protected $_request;
    protected $_logger;

    /**
     * @param Subscriber $subscrbr
     * @param RequestInterface $request
     * @param LoggerInterface $logger
     */
    public function __construct(
        Subscriber $subscrbr,
        RequestInterface $request,
        LoggerInterface $logger
    ) {
        $this->_subscriber = $subscrbr;
        $this->_request = $request;
        $this->_logger = $logger;
    }


    /**
     * Subscribe to newsletters if customer checked the checkbox
     *
     * @param MagentoFrameworkEventObserver $observer
     * @return $this
     */
    public function execute(MagentoFrameworkEventObserver $observer)
    {
        $order = $observer->getEvent()->getOrder();
        $customerEmail = $order->getCustomerEmail();

        try {
            **//Here the conditions should go, if the checkbox is checked then only subscribe to newsletter otherwise not
            //How to get custom checkbox value after order placement? Tried with $this->_request->getpost() but not working, returning an empty array**
            $subscriber = $this->_subscriber->loadByEmail($customerEmail);

            if (!$subscriber->getId()) {
                //at this line, first time for non-existing email, the page is broken, not sure WHY??
                $this->_subscriber->subscribe($customerEmail);
            }
        } catch (Exception $e) {
            $this->_logger->critical($e->getMessage() . ' from Mynamespace-Mymodule ' . $customerEmail);
        }


        return $this;
    }
}

Not sure where I am wrong? Can you please guide?
Thanks in advance.