1

My website is on Magento 2.1.9v and I'm using SpringEdge extension for SMS notification.

Issue: when customers redirect to Pay through Paytm or PayUmoney Order Placed SMS send before they pay.

When I asked to SpringEdge Support to look into they don't have any idea to solve it.

Which event I should add to this file to over come the issue.

Springedgeextension/INSTANT/Alerts/Observer/NewOrder.php

<?php

namespace INSTANT\Alerts\Observer;
use Magento\Framework\Event\ObserverInterface;
use \Magento\Framework\Event\Observer       as Observer;
use \Magento\Framework\View\Element\Context as Context;
use \INSTANT\Alerts\Helper\Data                 as Helper;
/**
 * Customer login observer
 */
class NewOrder implements ObserverInterface
{
    /**
     * Message manager
     *
     * @var \Magento\Framework\Message\ManagerInterface
     */
    const AJAX_PARAM_NAME = 'infscroll';
    /**
     *
     */
    const AJAX_HANDLE_NAME = 'infscroll_ajax_request';

    /**
     * Https request
     *
     * @var \Zend\Http\Request
     */
    protected $_request;

    /**
     * Layout Interface
     * @var \Magento\Framework\View\LayoutInterface
     */
    protected $_layout;

    /**
     * Cache
     * @var $_cache
     */
    protected $_cache;

    /**
     * Helper for AlertsSMS Module
     * @var \INSTANT\Alerts\Helper\Data
     */
    protected $_helper;

    /**
     * Message Manager
     * @var $messageManager
     */
    protected $messageManager;

    /**
     * Username
     * @var $username
     */
    protected $username;

    /**
     * Password
     * @var $password
     */
    protected $password;

    /**
     * Sender ID
     * @var $senderId
     */
    protected $senderId;

    /**
     * Destination
     * @var $destination
     */
    protected $destination;

    /**
     * Message
     * @var $message
     */
    protected $message;

    /**
     * Whether Enabled or not
     * @var $enabled
     */
    protected $enabled;

    /**
     * Constructor
     * @param Context $context
     * @param Helper $helper _helper
     */
    public function __construct(
        Context $context,
        Helper $helper
    ) {
        $this->_helper  = $helper;
        $this->_request = $context->getRequest();
        $this->_layout  = $context->getLayout();
    }

    /**
     * The execute class
     * @param Observer $observer
     * @return void
     */
    public function execute(Observer $observer)
    {
        /**
         * Getting Module Configuration from admin panel
         */

        //Getting Username
        $this->username         = $this->_helper->getAlertsApiUsername();

        //Getting Password
        $this->password         = $this->_helper->getAlertsApiPassword();

        //Getting Sender ID
        $this->senderId         = $this->_helper->getCustomerSenderId();

        //Getting Message
        $this->message          = $this->_helper->getCustomerMessageOnOrder();

        //Getting Customer Notification value
        $this->enabled          = $this->_helper->isCustomerNotificationsEnabledOnOrder();

        if ($this->enabled == 1) {
            /**
             * Verification of API Account
             */

            //Verification of API
            $verificationResult     = $this->_helper->verifyApi($this->username, $this->password);
            if ($verificationResult  == true) {

                //Getting Order Details
                $order              =   $this->_helper->getOrder($observer);
                $orderData          =   [
                    'orderId'       =>  $order->getIncrementId(),
                    'firstname'     =>  $order->getCustomerFirstname(),
                    '$middlename'   =>  $order->getCustomerMiddlename(),
                    'lastname'      =>  $order->getCustomerLastname(),
                    'totalPrice'    =>  number_format($order->getGrandTotal(), 2),
                    'countryCode'   =>  $order->getOrderCurrencyCode(),
                    'protectCode'   =>  $order->getProtectCode(),
                    'customerDob'   =>  $order->getCustomerDob(),
                    'customerEmail' =>  $order->getCustomerEmail(),
                    'gender'        => ($order->getCustomerGender()?'Female':'Male')
                ];

                //Getting Telephone Number
                $this->destination  = $order->getBillingAddress()->getTelephone();

                //Manipulating SMS
                $this->message      = $this->_helper->manipulateSMS($this->message, $orderData);

                //Sending SMS
                $this->_helper->sendSms(
                    $this->username,
                    $this->password,
                    $this->senderId,
                    $this->destination,
                    $this->message
                );

                //Sending SMS to Admin
                if ($this->_helper->isAdminNotificationsEnabled()==1) {
                    $this->destination  = $this->_helper->getAdminSenderId();
                    $this->message      = $this->_helper->getAdminMessageForNewOrder();
                    $this->message      = $this->_helper->manipulateSMS($this->message, $orderData);
                    $this->_helper->sendSms(
                        $this->username,
                        $this->password,
                        $this->senderId,
                        $this->destination,
                        $this->message
                    );
                }
            }
        }


    }
}

please let me know if you need more information

  • You will need to check some api that sends payment notification as success or failure, and based on that you should send the sms – LAW Aug 9 '18 at 7:28
  • What is the event you are using to send the sms? – Sukumar Gorai Aug 9 '18 at 7:29
  • hey @LAW I'm new to magento I don't have deep knowledge can you tell me the default file location for this so I can read and share with you – Aayush Aug 9 '18 at 7:34
  • It is not Magento I am referring to, as this is an extension which uses the api, so there must be some list of callback functions. So you will need to go through the list of functions, format, response based on the documentation of the payment company. If they provide any kind of IPN in any response – LAW Aug 9 '18 at 7:38
  • I am not very sure about it but it seems One97\Paytm\Controller\Standard\Response is giving the response you can use this controller in observer to track the response. – LAW Aug 9 '18 at 7:53
3

You have to put check invoice exist for the order. because mostly after payment invoice is created.

if($order->hasInvoices()):

$this->_helper->sendSms(
                $this->username,
                $this->password,
                $this->senderId,
                $this->destination,
                $this->message
            );
endif;
  • where can I check in paytm/payumoney observer file or in spring-edge extension? – Aayush Aug 9 '18 at 8:00
  • @Aayush create your own observer and use sales_order_save_commit_after event. best use the sms observer event. – Qaisar Satti Aug 9 '18 at 8:02
  • Yes like this.. – Qaisar Satti Aug 9 '18 at 8:15
  • BuddsBuddy\BuddyObserver\Observer\SendMailOnOrderSuccess I created and added other files also but now emails are not working because I disable sales email like you mention. @Qaisar Satti – Aayush Sep 12 '18 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.