<?php
namespace App\EventListener;
use App\Event\OrderEvent;
use App\Event\OrderVerifiedEvent;
use App\Event\SendOrderPincodeEvent;
use Symfony\Component\HttpFoundation\RequestStack;
use Boab\CmsBundle\Sms\SMSGatewayInterface;
use Boab\EcommerceBundle\Entity\OrderInterface;
class SMSMessengerListener
{
private $smsGateway;
private $requestStack;
public function __construct(SMSGatewayInterface $smsGateway, RequestStack $requestStack)
{
$this->smsGateway = $smsGateway;
$this->requestStack = $requestStack;
}
public function onOrderCreated(OrderEvent $event)
{
$order = $event->getOrder();
$smsMessenger = $this->smsGateway->create('mnotify');
$smsResponse = $smsMessenger->send($order->getContactNumber(), sprintf('Your OrderId is %s ', $order->getOrderId()));
}
public function onSendPincode(SendOrderPincodeEvent $event)
{
$order = $event->getOrder();
$pincode = $order->getPincode();
$smsMessenger = $this->smsGateway->create('mnotify');
$smsResponse = $smsMessenger->send($order->getContactNumber(), sprintf('Your PIN is %s ', $pincode->getPin()));
}
public function onOrderVerified(OrderVerifiedEvent $event)
{
$order = $event->getOrder();
if($order->getStatus() === OrderInterface::PENDING){
return;
}
$pincode = $order->getPincode();
$smsMessenger = $this->smsGateway->create('dtech');
$smsResponse = $smsMessenger->send($order->getContactNumber(), sprintf('Your PIN is %s ', $pincode->getPin()));
}
}