Skip to content

Commit

Permalink
Add CRON job for notifications using CRON mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hipaybot committed Mar 3, 2025
1 parent 758b908 commit 3daeb05
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
9 changes: 7 additions & 2 deletions bin/docker/images/prestashop/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,13 @@ EOF
#===================================#
# ADD CRON
#===================================#
#crontab -l | { cat; echo "*/5 * * * * php /var/www/html/modules/hipay_enterprise/cron.php > /var/log/cron.log"; } | crontab -
#service cron start
if [[ $PS_DOMAIN != "localhost"* ]]; then
crontab -l | {
cat
echo "*/5 * * * * /usr/local/bin/php /var/www/html/modules/hipay_enterprise/cron/handle-hipay-notifs.php >> /var/log/cron.log 2>&1"
} | crontab -
service cron start
fi
fi

if [ "$ENVIRONMENT" = "$ENV_DEVELOPMENT" ]; then
Expand Down
37 changes: 37 additions & 0 deletions src/hipay_enterprise/cron/handle-hipay-notifs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

require_once dirname(__DIR__, 3) . '/config/config.inc.php';

$moduleName = 'hipay_enterprise';
$module = Module::getInstanceByName($moduleName);
if (!$module || !$module->active) {
die('HiPay module disabled !' . PHP_EOL);
}

$config = $module->hipayConfigTool->getConfigHipay();

if (!$config['account']['global']['notification_cron']) {
die('HiPay CRON mode disabled !' . PHP_EOL);
}

$token = $config['account']['global']['notification_cron_token'];

$url = \Configuration::get('PS_SHOP_DOMAIN') . '/index.php?fc=module&module=' . $moduleName . '&controller=dispatch&token=' . $token;

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);

curl_close($ch);

if ($error) {
error_log('Error cURL : ' . $error);
} else {
error_log('Request sent successfully ! Response (' . $httpCode . ') : ' . $response);
}

echo date('[Y-m-d H:i:s]') . ' - CRON job completed' . PHP_EOL;

0 comments on commit 3daeb05

Please sign in to comment.