Margus Pala
Margus Pala

Reputation: 8673

Prestashop module payment hook not triggering

Prestashop 1.6.1.6 needs to make some API calls in the payment hook. However for some reason the hook is not triggering and hookPayment method is not executing. When comparing with Paypal module that has also hookPayment then this hook is executed. What I am doing wrong?

Module code is as simple as possible

<?php

if (!defined('_PS_VERSION_'))
    exit;

class TestModule extends Module
{

    public function __construct()
    {
        $this->name = 'testmodule';
        $this->tab = 'shipping_logistics';
        $this->version = '1.0.0';
        $this->author = 'Firstname Lastname';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('Test Module');
        $this->description = $this->l('Description of my module.');

        $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
    }

    public function install()
    {
        if (!parent::install() || !$this->registerHook('payment'))
            return false;
        return true;
    }

    public function uninstall()
    {
        if (!parent::uninstall())
            return false;
        return true;
    }

    public function hookPayment($params)
    {
        ddd($params);
    }
}

After installing the hook is registered in database

mysql> select * from module where id_module=75;
+-----------+------------+--------+---------+
| id_module | name       | active | version |
+-----------+------------+--------+---------+
|        75 | testmodule |      1 | 1.0.0   |
+-----------+------------+--------+---------+
1 row in set (0,00 sec)

mysql> select * from hook_module where id_module=75;
+-----------+---------+---------+----------+
| id_module | id_shop | id_hook | position |
+-----------+---------+---------+----------+
|        75 |       1 |       1 |        4 |
+-----------+---------+---------+----------+
1 row in set (0,00 sec)

mysql> select * from hook where id_hook=1;
+---------+----------------+---------+-----------------------------------------------------+----------+-----------+
| id_hook | name           | title   | description                                         | position | live_edit |
+---------+----------------+---------+-----------------------------------------------------+----------+-----------+
|       1 | displayPayment | Payment | This hook displays new elements on the payment page |        1 |         1 |
+---------+----------------+---------+-----------------------------------------------------+----------+-----------+
1 row in set (0,00 sec)

Upvotes: 0

Views: 1900

Answers (2)

Margus Pala
Margus Pala

Reputation: 8673

PrestaShop module needs to extend PaymentModule during the installation for the ability to trigger payment hook. Just changing the extends nor reset do not help.

Upvotes: 2

Mathias_
Mathias_

Reputation: 323

You made a typo in your function name, it says public function hoolPayment($params), but should be public function hookPayment($params).

Upvotes: 2

Related Questions