I create an order programmatically like this:
$store = $this->storeManager->getStore();
$websiteId = $this->storeManager->getStore()->getWebsiteId();
$customer = $this->_customerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->loadByEmail($email);
$quote = $this->quote->create();
$quote->setStore($store);
$customer = $this->_customerRepoInterface->getById($customer->getEntityId());
$quote->setCurrency();
$quote->assignCustomer($customer);
foreach ($productsOrder as $productOrder) {
$productId = $productOrder['product_id'];
$qty = $productOrder['qty'];
$product = $this->_product->load($productId);
$price = $product->getPrice();
$product->setPrice($price);
$quote->addProduct(
$product,
intval($qty)
);
}
$quote->getBillingAddress()->addData($address);
$quote->getShippingAddress()->addData($address);
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod($shippingMethod);
$quote->setPaymentMethod($paymentMethod);
$quote->setInventoryProcessed(false);
$quote->save();
$quote->getPayment()->importData(['method' => $paymentMethod]);
$quote->collectTotals()->save();
$order = $this->quoteManagement->submit($quote);
how can i apply coupon code in here and validate the coupon code?