lib/boab/ecommerce-bundle/src/EventSubscriber/SMSMesengerSubscriber.php line 31

Open in your IDE?
  1. <?php 
  2. namespace Boab\EcommerceBundle\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Boab\CmsBundle\Sms\SMSGatewayInterface;
  6. use Boab\EcommerceBundle\Entity\OrderInterface;
  7. use Boab\EcommerceBundle\Event\PaymentCompletedEvent;
  8. use Boab\EcommerceBundle\Events;
  9. class SMSMesengerSubscriber implements EventSubscriberInterface
  10. {
  11.     private $smsGateway;
  12.     private $requestStack;
  13.     public function __construct(SMSGatewayInterface $smsGatewayRequestStack  $requestStack)
  14.     {
  15.         $this->smsGateway $smsGateway;
  16.         $this->requestStack $requestStack;
  17.     }
  18.     public static function getSubscribedEvents():array
  19.     {
  20.         return [
  21.             Events::PAYMENT_SUCCESS => 'onPaymentSuccess',
  22.             Events::SEND_PIN_CODE => 'onSendPin',
  23.         ];
  24.     }
  25.     public function onPaymentSuccess(PaymentCompletedEvent $event)
  26.     {
  27.         $this->sendPin($event->getOrder());    
  28.     }
  29.     public function onSendPin(OrderInterface $order)
  30.     {
  31.         $this->sendPin($order);    
  32.     }    
  33.     public function sendPin(OrderInterface $order)
  34.     {
  35.         $request $this->requestStack->getCurrentRequest();
  36.         $textSession $request->getSession()->get('TEXT_MESSAGE_SENT');
  37.         if($order->isPaid()){
  38.             $smsMessenger $this->smsGateway->create('mnotify');
  39.             $smsResponse $smsMessenger->send($order->getContactNumber(), sprintf('OrderId: %s, PIN: %s '$order->getOrderId(), $order->getPin()));
  40.             $request->getSession()->set('TEXT_MESSAGE_SENT'$order->getOrderId());
  41.         }        
  42.     }    
  43. }