TrogloGeek / prestashop-tggatos-module

TggAtos Module for Prestashop (1.4 to 1.7), ATOS SIPS 6xx payment gateway
61 stars 34 forks source link

TggAtos only calls its constructor when receving ATOS Automatic (silent) response #7

Closed emily-d closed 11 years ago

emily-d commented 11 years ago

The TggAtos class in tggatos.php only calls its constructor when receiving the automatic response from the ATOS server (pat-sips-vdm.sips-atos.com). Nothing happens after that. Consequence, the order is not processed.

The ATOS server POST request is passed correctly to tggatos.php, but something is missing to trigger the dispatching, I guess. I was able to fix this issue with this hack :

// modules/tggatos/tggatos.php
class TggAtos extends PaymentModule 
{
...
public function __construct() 
{
    ...
    if (strpos($_SERVER['REQUEST_URI'],'/module/tggatos/silentresponse') !== false) 
    {
        $message = Tools::getValue('DATA');
        if (empty($message))
        {
            header(null, null, 500);
            exit;
        }
        $response = $this->uncypherResponse($message, TggAtosModuleResponseObject::TYPE_SILENT);
        $this->processResponse($response);
    }

Also, this is a bit more tricky cause a direct POST via CURL will not display this behavior:

curl -d "DATA=2020333535603028502c23........" https://test.com/fr/module/tggatos/silentresponse -v

/modules/tggatos/controllers/front/silentresponse.php is correctly called after tggatos.php.

Info:

Pshop 1.5.3.1
Module 3.0 latest GitHub commit
Demonstration mode.
"Force user return from bank" is not checked.
Debian Linux 6.0.6
PHP Version 5.3.3-7+squeeze15
Apache 2.2
TrogloGeek commented 11 years ago

SIPS silent response should not be routed to tggatos.php but directly to /modules/tggatos/controllers/front/silentresponse.php, which does instanciate the module. It seems like initContent() is not called on the controller. I don't remember why I did overrid initContent(), not sure it's the best function to override in this controller.

TrogloGeek commented 11 years ago

Did you check you PHP error log ? There should be an answer there. Among the alerts about the deprecated isLoggedBack() call I have to fix.

emily-d commented 11 years ago

Right now, I can't check the server logs, but using an error handler function, the only errors I spotted were :

Function isLoggedBack() is deprecated in /www/modules/tggatos/tggatos.php on line232 in file /www/classes/Tools.php on line : 1777
filemtime(): stat failed for /wwwall in file /var/www/classes/Media.php on line : 228

The second error seems benign.

TrogloGeek commented 11 years ago

Fatal errors cannot be handled afaik. You've not to check server logs, if you aren't host machine administrateur just relocate error_log within a VirtualHost, .htaccess or .user.ini, or using ini_set() in _PS_MODE_DEV_ mode specific area of config/defines.inc.php, and set _PS_MODE_DEV_ on during at least a silent response.

emily-d commented 11 years ago

I think I’ve found my problem. In silentresponse.php, $ssl is set to true but AUTO_RESPONSE_URL is set to an http address not httpS.

So when the ATOS server sends the automatic response, my server returns a 301 and the POST request is lost.

Setting $ssl to false, solves the problem. As I remember, ATOS demands that the automatic response is not received by https, so no big deal.

TrogloGeek commented 11 years ago

Thanks for reporting back, I'll consider making a workaround to avoid Prestashop redirecting the request (most probably by setting SSL configuration to off for this single request in class Configuration static cache) if it can be achieved without overload (Modules should avoid overloading anything).

e-gaulue commented 11 years ago

I can confirm, on a brand new PrestaShop 1.5.4.1, if you have $ssl to true auto-response is not dealt. It is if you set it to false.

TrogloGeek commented 11 years ago

@emily-d sorry I did misunderstand your report, @e-gaulue thanks for pointing this again