2

I have created events.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="payment_method_assign_data">
        <observer name="sample_payment_gateway_data_assign" instance="Magento\SamplePaymentGateway\Observer\DataAssignObserver" />
    </event>
    <event name="sales_order_place_after">
        <observer name="process_gateway_redirect" instance="Magento\SamplePaymentGateway\Observer\ProcessGatewayRedirect" />
    </event>
</config>

The observer class is as follows:

<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\SamplePaymentGateway\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class ProcessGatewayRedirect extends ObserverInterface
{
    /**
     * @param Observer $observer
     * @return void
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    { 
        die('order');
        $orderId = $observer->getEvent()->getOrderIds();
        $base_url = $this->_storeManager->getStore()->getBaseUrl();
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $order = $objectManager->create('\Magento\Sales\Model\Order') ->load($orderId[0]);
        $payment = $order->getPayment();


        $method = $payment->getMethodInstance();
        $methodTitle = $method->getTitle();

        $order_data= $order->getData();
        $status = $this->checkoutSession->getLastOrderStatus();

        $increment_id = $order_data['increment_id'];
        $redirect = $objectManager->get('\Magento\Framework\App\Response\Http');
        $redirect->setRedirect($base_url.'custompayment/index/redirect/id/'.$increment_id.'');
        return;

    }
}

When I run php bin/magento setup:di:compile command in terminal I get the following fatal error. It vanishes when I comment all the code in observer class. I am understanding nothing what it is saying. I am stuck with it since a week. Please help me.

Fatal error:  Class Magento\SamplePaymentGateway\Observer\ProcessGatewayRedirect cannot extend from interface Magento\Framework\Event\ObserverInterface in /var/www/html/m4/app/code/Magento/SamplePaymentGateway/Observer/ProcessGatewayRedirect.php on line 39

PHP Stack trace:
PHP   1. {main}() /var/www/html/m4/bin/magento:0
PHP   2. Magento\Framework\Console\Cli->run() /var/www/html/m4/bin/magento:23
PHP   3. Magento\Framework\Console\Cli->doRun() /var/www/html/m4/vendor/symfony/console/Symfony/Component/Console/Application.php:126
PHP   4. Magento\Framework\Console\Cli->doRun() /var/www/html/m4/vendor/magento/framework/Console/Cli.php:96
PHP   5. Magento\Framework\Console\Cli->doRunCommand() /var/www/html/m4/vendor/symfony/console/Symfony/Component/Console/Application.php:195
PHP   6. Magento\Setup\Console\Command\DiCompileCommand->run() /var/www/html/m4/vendor/symfony/console/Symfony/Component/Console/Application.php:874
PHP   7. Magento\Setup\Console\Command\DiCompileCommand->execute() /var/www/html/m4/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
PHP   8. Magento\Setup\Module\Di\App\Task\Manager->process() /var/www/html/m4/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php:187
PHP   9. Magento\Setup\Module\Di\App\Task\Operation\RepositoryGenerator->doOperation() /var/www/html/m4/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php:56
PHP  10. Magento\Setup\Module\Di\Code\Reader\ClassesScanner->getList() /var/www/html/m4/setup/src/Magento/Setup/Module/Di/App/Task/Operation/RepositoryGenerator.php:61
PHP  11. class_exists() /var/www/html/m4/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php:69
PHP  12. spl_autoload_call() /var/www/html/m4/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php:69
PHP  13. Composer\Autoload\ClassLoader->loadClass() /var/www/html/m4/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php:69
PHP  14. Composer\Autoload\includeFile() /var/www/html/m4/vendor/composer/ClassLoader.php:301

Fatal error: Class Magento\SamplePaymentGateway\Observer\ProcessGatewayRedirect cannot extend from interface Magento\Framework\Event\ObserverInterface in /var/www/html/m4/app/code/Magento/SamplePaymentGateway/Observer/ProcessGatewayRedirect.php on line 39

Call Stack:
    0.0001     363912   1. {main}() /var/www/html/m4/bin/magento:0
    8.1208   31555992   2. Magento\Framework\Console\Cli->run() /var/www/html/m4/bin/magento:23
    8.1213   31575552   3. Magento\Framework\Console\Cli->doRun() /var/www/html/m4/vendor/symfony/console/Symfony/Component/Console/Application.php:126
    8.1213   31575552   4. Magento\Framework\Console\Cli->doRun() /var/www/html/m4/vendor/magento/framework/Console/Cli.php:96
    8.1214   31575552   5. Magento\Framework\Console\Cli->doRunCommand() /var/www/html/m4/vendor/symfony/console/Symfony/Component/Console/Application.php:195
    8.1214   31575552   6. Magento\Setup\Console\Command\DiCompileCommand->run() /var/www/html/m4/vendor/symfony/console/Symfony/Component/Console/Application.php:874
    8.1216   31577160   7. Magento\Setup\Console\Command\DiCompileCommand->execute() /var/www/html/m4/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
   14.0789   43461576   8. Magento\Setup\Module\Di\App\Task\Manager->process() /var/www/html/m4/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php:187
   14.7288   48151568   9. Magento\Setup\Module\Di\App\Task\Operation\RepositoryGenerator->doOperation() /var/www/html/m4/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php:56
   69.8750  158384184  10. Magento\Setup\Module\Di\Code\Reader\ClassesScanner->getList() /var/www/html/m4/setup/src/Magento/Setup/Module/Di/App/Task/Operation/RepositoryGenerator.php:61
   69.8883  158508928  11. class_exists() /var/www/html/m4/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php:69
   69.8883  158509024  12. spl_autoload_call() /var/www/html/m4/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php:69
   69.8883  158509200  13. Composer\Autoload\ClassLoader->loadClass() /var/www/html/m4/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassesScanner.php:69
   69.8884  158509328  14. Composer\Autoload\includeFile() /var/www/html/m4/vendor/composer/ClassLoader.php:301
1
  • 2
    It’s an interface u must use implements Commented Dec 9, 2017 at 8:07

1 Answer 1

1

Replace extends by implements:

class ProcessGatewayRedirect implements ObserverInterface
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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