Jump to content
thirty bees forum
  • 0

URGENT: Yet another payment module not working


Question

Posted (edited)

Using Bellini's Interac module, which used to work fine, with the TB compatible version and TB 1.1.x - latest version. I did check the configuration table in the DB for INTERAC_OS_PENDING_PAYMENT and it had indeed the wrong order status, which I fixed, but unlike my other module, the customer still gets a 500 error and I get this in the logs:

 

Decoded exception

Too few arguments to function iemt::execPayment(), 0 passed in /home/zbookstore/public_html/modules/iemt/controllers/front/validation.php on line 51 and exactly 1 expected

in file modules/iemt/iemt.php at line 237

Source file: modules/iemt/iemt.php

218:		$this->context->controller->addJquery();
219:		$this->context->controller->addJQueryPlugin('fancybox');
220:	}
221:
222:	public function hookPayment($params)
223:	{
224:		if (!$this->active)
225:			return;
226:
227:		$validation_url = $this->context->link->getModuleLink($this->name, 'validation', array(), true);
228:		$this->context->smarty->assign(array(
229:			'iemt_validation_url' => $validation_url,
230:			'mess_error' => $this->l('Please provide a challenge answer'),
231:			'this_path_iemt' => $this->getPathUri(),
232:		));
233:
234:		return $this->display(__FILE__, 'views/templates/front/payment.tpl');
235:	}
236:
237:	public function execPayment($cart_old)
238:	{
239:		if (!$this->active)
240:			return;
241:
242:		$customer = $this->context->customer;
243:		$currency = $this->context->currency;
244:		$cart = $this->context->cart;
245:		$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
246:
247:		//todo: validate $challengeAnswer, redirect to payment page with error

Stack trace

1. modules/iemt/controllers/front/validation.php:51 source iemt->execPayment()
32:	{
33:		$cart = $this->context->cart;
34:		if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active)
35:			Tools::redirect('index.php?controller=order&step=1');
36:
37:		// Check that this payment option is still available in case the customer changed his address just before the end of the checkout process
38:		$authorized = false;
39:		foreach (Module::getPaymentModules() as $module)
40:		{
41:			if ($module['name'] == 'iemt')
42:			{
43:				$authorized = true;
44:				break;
45:			}
46:		}
47:
48:		if (!$authorized)
49:			die($this->module->l('This payment method is not available.', 'validation'));
50:
51:		$this->module->execPayment();
52:	}
53:}
2. classes/controller/Controller.php:197 source IemtValidationModuleFrontController->postProcess()
178:        } else {
179:            $this->$property = $value;
180:        }
181:    }
182:
183:    /**
184:     * Starts the controller process
185:     *
186:     * @since   1.0.0
187:     * @version 1.0.0 Initial version
188:     */
189:    public function run()
190:    {
191:        $this->init();
192:        if ($this->checkAccess()) {
193:            if (!$this->content_only && ($this->display_header || (isset($this->className) && $this->className))) {
194:                $this->setMedia();
195:            }
196:
197:            $this->postProcess();
198:
199:            if (!empty($this->redirect_after)) {
200:                $this->redirect();
201:            }
202:
203:            if (!$this->content_only && ($this->display_header || (isset($this->className) && $this->className))) {
204:                $this->initHeader();
205:            }
206:
207:            if ($this->viewAccess()) {
3. classes/controller/FrontController.php:255 source ControllerCore->run()
236:     * @see     Controller::run()
237:     * @since   1.0.0
238:     *
239:     * @version 1.0.0 Initial version
240:     */
241:    public function postProcess()
242:    {
243:    }
244:
245:    /**
246:     * Starts the controller process
247:     *
248:     * Overrides Controller::run() to allow full page cache
249:     *
250:     * @since   1.0.7
251:     */
252:    public function run()
253:    {
254:        if (! PageCache::isEnabled()) {
255:            return parent::run();
256:        }
257:
258:        $debug = Configuration::get('TB_PAGE_CACHE_DEBUG');
259:        $cacheEntry = PageCache::get();
260:        if (! $cacheEntry->exists()) {
261:            if ($debug) {
262:                header('X-thirtybees-PageCache: MISS');
263:            }
264:            return parent::run();
265:        }
4. classes/Dispatcher.php:852 source FrontControllerCore->run()
833:                    return;
834:                }
835:                break;
836:
837:            default:
838:                throw new PrestaShopException('Bad front controller chosen');
839:        }
840:
841:        // Instantiate controller
842:        try {
843:            // Loading controller
844:            $controller = Controller::getController($controllerClass);
845:
846:            // Execute hook dispatcher
847:            if (isset($paramsHookActionDispatcher)) {
848:                Hook::exec('actionDispatcher', $paramsHookActionDispatcher);
849:            }
850:
851:            // Running controller
852:            $controller->run();
853:        } catch (PrestaShopException $e) {
854:            $e->displayMessage();
855:        }
856:    }
857:
858:    /**
859:     * Retrieve the controller from url or request uri if routes are activated
860:     *
861:     * @param int|null $idShop
862:     *
5. ./index.php:33 source DispatcherCore->dispatch()
14: * If you did not receive a copy of the license and are unable to
15: * obtain it through the world-wide-web, please send an email
16: * to [email protected] so we can send you a copy immediately.
17: *
18: * DISCLAIMER
19: *
20: * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
21: * versions in the future. If you wish to customize PrestaShop for your
22: * needs please refer to https://www.thirtybees.com for more information.
23: *
24: *  @author    thirty bees <[email protected]>
25: *  @author    PrestaShop SA <[email protected]>
26: *  @copyright 2017-2018 thirty bees
27: *  @copyright 2007-2016 PrestaShop SA
28: *  @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
29: *  PrestaShop is an internationally registered trademark & property of PrestaShop SA
30: */
31:
32:require(dirname(__FILE__).'/config/config.inc.php');
33:Dispatcher::getInstance()->dispatch();
Edited by movieseals

8 answers to this question

Recommended Posts

  • 0
Posted (edited)

This error has nothing to do with newer version of TB.

this is related to PHP7+.

the message is very clear about the reason.

look at file: modules/iemt/controllers/front/validation.php on line 51.

this function require 1 argument which is not passed.

this function exists on file: modules/iemt/iemt.php at line 237, now i can't tell much about what is expected for $old_cart. but i guess you can try to pass the cart from validation.

 so try changing line 51 in validation.php file to: $this->module->execPayment($cart);

if you can show the rest of the code after line 247 it will be better.

Edited by yaniv14
  • Like 2
  • 0
Posted (edited)

Here is the whole code. I put line 50 in red, and everything from 247:

<?php
/**
 * This file is part of module Interac Email Money Transfer
 *
 *  @author    Bellini Services <[email protected]>
 *  @copyright 2007-2017 bellini-services.com
 *  @license   readme
 *
 * Your purchase grants you usage rights subject to the terms outlined by this license.
 *
 * You CAN use this module with a single, non-multi store configuration, production installation and unlimited test installations of PrestaShop.
 * You CAN make any modifications necessary to the module to make it fit your needs. However, the modified module will still remain subject to this license.
 *
 * You CANNOT redistribute the module as part of a content management system (CMS) or similar system.
 * You CANNOT resell or redistribute the module, modified, unmodified, standalone or combined with another product in any way without prior written (email) consent from bellini-services.com.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

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

class iemt extends PaymentModule
{
    private    $_html = '';
    private $_postErrors = array();

    public function __construct()
    {
        $this->name = 'iemt';
        $this->tab = 'payments_gateways';
        $this->version = '2.0.0';
        $this->ps_versions_compliancy = array('min' => '1.6', 'max' < '1.7');
        $this->author = 'Bellini Services';
        $this->controllers = array('validation');
        $this->is_eu_compatible = 0;

        $this->currencies = true;
        $this->currencies_mode = 'checkbox';
        $this->need_instance = 1;

        $this->bootstrap = true;
        parent::__construct();

        $this->displayName = $this->l('Interac Email Money Transfer');
        $this->description = $this->l('Accepts payments by Interac Email Money Transfer');
        $this->confirmUninstall = $this->l('Are you sure you want to delete your details ?');
    }

    public function install()
    {
        if (!parent::install()
            OR !$this->registerHook('adminOrder')
            OR !$this->registerHook('header')
            OR !$this->registerHook('payment')
            OR !$this->registerHook('paymentReturn'))
            return false;

        /* Set database */
        if (!Db::getInstance()->Execute('CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'interac_order` (
          `id_order` int(10) unsigned NOT NULL,
          `challenge_answer` varchar(255) NOT NULL,
          PRIMARY KEY (`id_order`)
        ) ENGINE='._MYSQL_ENGINE_.'  DEFAULT CHARSET=utf8'))
            return false;

        copy(dirname(__FILE__).'/mails/en/iemt.html', dirname(__FILE__).'/../../mails/en/iemt.html');
        copy(dirname(__FILE__).'/mails/en/iemt.txt', dirname(__FILE__).'/../../mails/en/iemt.txt');

        if (!Configuration::get('INTERAC_OS_PENDING_PAYMENT'))
        {
            $orderState = new OrderState();
            $orderState->send_email = true;
            $orderState->name = array();
            $orderState->template = array();
            foreach (Language::getLanguages() AS $language)
            {
                $orderState->name[$language['id_lang']] = 'Waiting for Interac Email Payment';
                $orderState->template[$language['id_lang']] = 'iemt';
            }
            $orderState->color = 'lightblue';
            $orderState->hidden = false;
            $orderState->delivery = false;
            $orderState->logable = false;
            $orderState->invoice = false;
            if ($orderState->add())
                copy(dirname(__FILE__).'/../../img/os/'.Configuration::get('PS_OS_CHEQUE').'.gif', dirname(__FILE__).'/../../img/os/'.(int)$orderState->id.'.gif');
            Configuration::updateValue('INTERAC_OS_PENDING_PAYMENT', (int)$orderState->id);
        }

        Configuration::updateValue('INTERAC_PAYMENT_EMAIL', Configuration::get('PS_SHOP_EMAIL'));

        return true;
    }

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

    public function getContent()
    {
        if (Tools::isSubmit('SubmitIEMT'))
        {
            $this->_postValidation();
            if (!count($this->_postErrors))
                $this->_postProcess();
            else
                foreach ($this->_postErrors as $err)
                    $this->_html .= $this->displayError($err);
        }
        else
            $this->_html .= '<br />';

        $this->_html .= $this->_displayIemt();
        $this->_html .= $this->renderForm();

        return $this->_html;
    }


    protected function _postValidation()
    {
        if (Tools::isSubmit('SubmitIEMT'))
        {
            if (!Tools::getValue('INTERAC_PAYMENT_EMAIL'))
                $this->_postErrors[] = $this->l('The Payment Email is required.');
        }
    }

    protected function _postProcess()
    {
        if (Tools::isSubmit('SubmitIEMT')) 
            Configuration::updateValue('INTERAC_PAYMENT_EMAIL', pSQL(Tools::getValue('INTERAC_PAYMENT_EMAIL')));

        $this->_html .= $this->displayConfirmation($this->l('Settings updated'));
    }

    protected function _displayIemt()
    {
        return $this->display(__FILE__, 'views/templates/hook/infos.tpl');
    }

    public function renderForm()
    {
        $fields_form = array(
            'form' => array(
                'legend' => array(
                    'title' => $this->l('Contact details'),
                    'icon' => 'icon-envelope'
                ),
                'input' => array(
                    array(
                        'type' => 'text',
                        'label' => $this->l('Payment Email'),
                        'name' => 'INTERAC_PAYMENT_EMAIL',
                        'size' => 100,
                        'required' => true
                    ),
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                )
            ),
        );

        $helper = new HelperForm();
        $helper->show_toolbar = false;
        $helper->table = $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $this->fields_form = array();
        $helper->id = (int)Tools::getValue('id_carrier');
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'SubmitIEMT';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'fields_value' => $this->getConfigFieldsValues(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id
        );

        return $helper->generateForm(array($fields_form));
    }

    public function getConfigFieldsValues()
    {
        return array(
            'INTERAC_PAYMENT_EMAIL' => Tools::getValue('INTERAC_PAYMENT_EMAIL', Configuration::get('INTERAC_PAYMENT_EMAIL')),
        );
    }

    private function isCheckout()
    {
        //return true if the controller is in the array
        $controllers = array('order', 'order-opc', 'orderopc', 'quick-order');
        $controller = Tools::getValue('controller');

        if (in_array($controller, $controllers))
            return true;
        else
            return false;
    }

    public function hookHeader()
    {
        if (!$this->active)
            return;

        $isCheckout = $this->isCheckout();
        if (!$isCheckout)
            return;

        $this->context->controller->addJquery();
        $this->context->controller->addJQueryPlugin('fancybox');
    }

    public function hookPayment($params)
    {
        if (!$this->active)
            return;

        $validation_url = $this->context->link->getModuleLink($this->name, 'validation', array(), true);
        $this->context->smarty->assign(array(
            'iemt_validation_url' => $validation_url,
            'mess_error' => $this->l('Please provide a challenge answer'),
            'this_path_iemt' => $this->getPathUri(),
        ));

        return $this->display(__FILE__, 'views/templates/front/payment.tpl');
    }

    public function execPayment($cart_old)
    {
        if (!$this->active)
            return;

        $customer = $this->context->customer;
        $currency = $this->context->currency;
        $cart = $this->context->cart;
        $total = (float)$cart->getOrderTotal(true, Cart::BOTH);

        //todo: validate $challengeAnswer, redirect to payment page with error
        $challengeAnswer = pSQL(Tools::getValue('challenge'));
        //todo: validate $challengeAnswer, redirect to payment page with error

        $mailVars = array(
            '{shop_phone}' => Configuration::get('PS_SHOP_PHONE'),
            '{payment_email}' => Configuration::get('INTERAC_PAYMENT_EMAIL'),
            '{challenge_answer}' => $challengeAnswer,
            '{history_url}' => $this->context->link->getPageLink('history', true, $this->context->language->id, null, false, $this->context->shop->id),
            '{my_account_url}' => $this->context->link->getPageLink('my-account', true, $this->context->language->id, null, false, $this->context->shop->id),
            '{guest_tracking_url}' => $this->context->link->getPageLink('guest-tracking', true, $this->context->language->id, null, false, $this->context->shop->id),
        );

        $this->validateOrder((int)$cart->id, Configuration::get('INTERAC_OS_PENDING_PAYMENT'), $total, $this->displayName, null, $mailVars, (int)$currency->id, false, $customer->secure_key, $this->context->shop);

        $order = new Order($this->currentOrder);

        if (Validate::isLoadedObject($order))
        {
            Db::getInstance()->Execute('
            INSERT INTO `'._DB_PREFIX_.'interac_order` (`id_order`, `challenge_answer`) 
            VALUES ('.(int)$order->id.', \''.pSQL($challengeAnswer).'\')');
        }

        // Redirect the user to the order confirmation page / history
        $redirect = $this->context->link->getPageLink('order-confirmation', true, null, array('id_order' => (int)$this->currentOrder, 'id_cart' => (int)$cart->id, 'key' => $customer->secure_key, 'id_module' => $this->id));
        Tools::redirect($redirect);
    }

    public function hookPaymentReturn($params)
    {
        if (!$this->active)
            return;

        if ($params['objOrder']->module != $this->name)
            return;

        $id_order = $params['objOrder']->id;

        $this->context->smarty->assign(array(
            'iemt_total_paid' => $params['objOrder']->total_paid,
            'iemt_id_currency' => $params['objOrder']->id_currency,
            'total' => $params['currency'].$params['total_to_pay'],
            'challengeAnswer' => $this->_getChallengeAnswer((int)($id_order)),
            'paymentEmail' => Configuration::get('INTERAC_PAYMENT_EMAIL'),
            'shopPhone' => Configuration::get('PS_SHOP_PHONE'),
        ));

        $this->context->smarty->assign('order_name', $params['objOrder']->getUniqReference());

        return $this->display(__FILE__, 'views/templates/front/confirmation.tpl');
    }

    public function hookAdminOrder($params)
    {
        $order = new Order((int) ($params['id_order']));
        $challengeAnswer = $this->_getChallengeAnswer((int)($order->id));

        if (!$challengeAnswer) {
            return false;
        }

        $html = '<div class="col-lg-7"><div class="panel"><h3><i class="icon-money"></i> '.$this->l('Interac Challenge Answer').'</h3><div class="row">'.
                 '<div style="float:left;">' . $this->l('Challenge Answer') . ' : ' . Tools::htmlentitiesUTF8($challengeAnswer) . '</div>'.
                 '</div></div></div>';

        return $html;
    }

    private function _getChallengeAnswer($id_order)
    {
        if (!(int)$id_order)
            return false;
        
        return Db::getInstance()->getValue('
        SELECT `challenge_answer` 
        FROM `'._DB_PREFIX_.'interac_order` 
        WHERE `id_order` = '.(int)$id_order);
    }

}
 

Edited by movieseals
  • 0
Posted

As you can see this variable is not even being used in the function.

anyway just do this and you should be fine.

18 minutes ago, yaniv14 said:

try changing line 51 in validation.php file to: $this->module->execPayment($cart);

 

  • 0
Posted
1 minute ago, yaniv14 said:

As you can see this variable is not even being used in the function.

anyway just do this and you should be fine.

 

If I change line 51 with $this->module->execPayment($cart);

now the entire site gives a 500 error.

  • 0
Posted (edited)

are you sure you are changing in the validation file?

all you need to do is to change from:

$this->module->execPayment(); to $this->module->execPayment($cart);

Edited by yaniv14
  • Like 1
  • 0
Posted
6 minutes ago, yaniv14 said:

are you sure you are changing in the validation file?

all you need to do is to change from:

$this->module->execPayment(); to $this->module->execPayment($cart);

I misunderstood you.  Rookie mistake. 😞 It works now.  Thank you so much for your assistance!

  • 0
Posted
On 3/29/2020 at 6:07 AM, datakick said:

Also, if possible, please contact developer of the module and ask them to adjust their code

Will do.  I had gone to the website and downloaded the latest update, but it still has that issue.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...