Skip to content

Commit

Permalink
Merge pull request #578 from alma/release/v4.4.0
Browse files Browse the repository at this point in the history
Release v4.4.0
  • Loading branch information
Benjamin-Freoua-Alma authored Oct 7, 2024
2 parents 1581cc4 + 78cdb51 commit 27dc9b1
Show file tree
Hide file tree
Showing 59 changed files with 1,570 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backport-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
git reset --hard main
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
uses: peter-evans/create-pull-request@v7
with:
commit-message: 'chore: backport main to develop'
title: Backport main to develop
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hotfix-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
./scripts/update-files-with-release-version.sh ${{ steps.release-drafter.outputs.tag_name }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
uses: peter-evans/create-pull-request@v7
with:
commit-message: 'chore: update version'
title: Release ${{ steps.release-drafter.outputs.tag_name }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
cc <@france.berut> <@khadija.cherif>
- name: Send changelog to Slack
uses: slackapi/slack-github-action@v1.26.0
uses: slackapi/slack-github-action@v1.27.0
with:
channel-id: CR9C57YM6
slack-message: ${{ steps.slack-markdown-release-notes.outputs.text }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
repositories: alma-installments-prestashop

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.github-token.outputs.token }}
commit-message: 'chore: update version'
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.28.0
rev: v3.29.0
hooks:
- id: commitizen
name: Check commit message format
Expand Down Expand Up @@ -39,7 +39,7 @@ repos:
stages: [commit]

- repo: https://github.com/returntocorp/semgrep
rev: v1.83.0
rev: v1.87.0
hooks:
- id: semgrep
args:
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## v4.4.0 - 2024-10-07

### Changes

### 🚀 New Features

- feat: In page is now available for Credit (#575)
- feat: Remove insurance in cart when deactivated (#569)
- feat: HMAC verification on IPN callback for security (#561)

### 🐛 Bug Fixes

- fix: handle the height automatically of the insurance widget (#572)
- fix: install module if container of getService Ps_account is null (#565)
- fix: Inpage on prestashop 1.6 with third party module of checkout (#566)

#### Contributors

@Benjamin-Freoua-Alma, @FranceBe, @alma-renovate-bot, @alma-renovate-bot[bot], @github-actions and @joyet-simon

## v4.3.0 - 2024-08-12

### Changes
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ tasks:
deps:
- tools:install
cmds:
- php ./alma/vendor/bin/phpcs -p alma --standard=PHPCompatibility -s --runtime-set testVersion 5.6-8.1 --ignore=\*/vendor/\*
- php ./alma/vendor/bin/phpcs -p alma --standard=PHPCompatibility -s --runtime-set testVersion 5.6-8.1 --ignore=\*/vendor/\*,\*/.coverage/\*

crowdin:
internal: true
Expand Down
60 changes: 32 additions & 28 deletions alma/alma.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class Alma extends PaymentModule
{
const VERSION = '4.3.0';
const VERSION = '4.4.0';

public $_path;
public $local_path;
Expand Down Expand Up @@ -80,7 +80,7 @@ public function __construct()
{
$this->name = 'alma';
$this->tab = 'payments_gateways';
$this->version = '4.3.0';
$this->version = '4.4.0';
$this->author = 'Alma';
$this->need_instance = false;
$this->bootstrap = true;
Expand Down Expand Up @@ -123,41 +123,30 @@ public function __construct()
$this->tabsHelper = new \Alma\PrestaShop\Helpers\Admin\TabsHelper();

$this->toolsHelper = new \Alma\PrestaShop\Helpers\ToolsHelper();

$this->handlePSModule();
}

/**
* @return void
*
* @throws \Alma\PrestaShop\Exceptions\CompatibilityPsAccountException
*/
public function handlePSModule()
public function checkCompatibilityPSModule()
{
if (_PS_MODE_DEV_ === true) {
throw new \Alma\PrestaShop\Exceptions\CompatibilityPsAccountException('[Alma] Debug mode is activated');
}

if (
$this->checkCompatibilityPSModule()
&& $this->container === null
!class_exists(\Symfony\Component\Config\ConfigCache::class)
|| !class_exists(\PrestaShop\ModuleLibServiceContainer\DependencyInjection\ServiceContainer::class)
) {
$this->container = new \PrestaShop\ModuleLibServiceContainer\DependencyInjection\ServiceContainer(
$this->name,
$this->getLocalPath()
);
throw new \Alma\PrestaShop\Exceptions\CompatibilityPsAccountException('[Alma] Classes don\'t exist for PS Account');
}
}

/**
* @return bool
*/
public function checkCompatibilityPSModule()
{
if (
$this->toolsHelper->psVersionCompare('1.6', '<')
|| !class_exists(\Symfony\Component\Config\ConfigCache::class)
|| !class_exists(\PrestaShop\ModuleLibServiceContainer\DependencyInjection\ServiceContainer::class)
|| _PS_MODE_DEV_ === true
) {
return false;
throw new \Alma\PrestaShop\Exceptions\CompatibilityPsAccountException('[Alma] Prestashop version lower than 1.6');
}

return true;
}

/**
Expand Down Expand Up @@ -232,8 +221,12 @@ private function checkCoreInstall($coreInstall)
*/
public function install()
{
if ($this->checkCompatibilityPSModule()) {
try {
$this->checkCompatibilityPSModule();
$this->setContainer();
$this->getService('alma.ps_accounts_installer')->install();
} catch (\Alma\PrestaShop\Exceptions\CompatibilityPsAccountException $e) {
\Alma\PrestaShop\Logger::instance()->info($e->getMessage());
}

$coreInstall = parent::install();
Expand Down Expand Up @@ -266,6 +259,14 @@ public function getService($serviceName)
return $this->container->getService($serviceName);
}

public function setContainer()
{
$this->container = new \PrestaShop\ModuleLibServiceContainer\DependencyInjection\ServiceContainer(
$this->name,
$this->getLocalPath()
);
}

/**
* @return bool
*
Expand Down Expand Up @@ -589,6 +590,8 @@ public function getContent()

try {
$hasPSAccount = $this->renderPSAccount();
} catch (\Alma\PrestaShop\Exceptions\CompatibilityPsAccountException $e) {
$hasPSAccount = false;
} catch (\PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleNotInstalledException $e) {
$hasPSAccount = false;
$suggestPSAccount = true;
Expand All @@ -599,12 +602,13 @@ public function getContent()

/**
* @return bool
*
* @throws \Alma\PrestaShop\Exceptions\CompatibilityPsAccountException
*/
public function renderPSAccount()
{
if (!$this->checkCompatibilityPSModule()) {
return false;
}
$this->checkCompatibilityPSModule();
$this->setContainer();

try {
$accountsFacade = $this->getService('alma.ps_accounts_facade');
Expand Down
2 changes: 1 addition & 1 deletion alma/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"require": {
"php": "^5.6 || ~7.0 || ~7.1 || ~7.2 || ~7.3 || ~7.4 || ~8.0 || ~8.1",
"alma/alma-php-client": "^2.1.0",
"alma/alma-php-client": "^2.2.0",
"ext-json": "*",
"ext-openssl": "*",
"prestashop/prestashop-accounts-installer": "^v1.0.4",
Expand Down
34 changes: 31 additions & 3 deletions alma/controllers/admin/AdminAlmaInsuranceConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
}

use Alma\PrestaShop\Builders\Admin\InsuranceHelperBuilder;
use Alma\PrestaShop\Builders\Services\InsuranceProductServiceBuilder;
use Alma\PrestaShop\Exceptions\InsuranceProductException;
use Alma\PrestaShop\Exceptions\WrongParamsException;
use Alma\PrestaShop\Helpers\Admin\AdminInsuranceHelper;
use Alma\PrestaShop\Helpers\ConfigurationHelper;
use Alma\PrestaShop\Helpers\ConstantsHelper;
use Alma\PrestaShop\Logger;
use Alma\PrestaShop\Services\InsuranceProductService;
use Alma\PrestaShop\Traits\AjaxTrait;

class AdminAlmaInsuranceConfigurationController extends ModuleAdminController
Expand All @@ -44,13 +48,19 @@ class AdminAlmaInsuranceConfigurationController extends ModuleAdminController
* @var ConfigurationHelper
*/
private $configurationHelper;
/**
* @var InsuranceProductService
*/
protected $insuranceProductService;

public function __construct()
{
$this->bootstrap = true;
$insuranceHelperBuilder = new InsuranceHelperBuilder();
$this->insuranceHelper = $insuranceHelperBuilder->getInstance();
$this->configurationHelper = new ConfigurationHelper();
$insuranceProductServiceBuilder = new InsuranceProductServiceBuilder();
$this->insuranceProductService = $insuranceProductServiceBuilder->getInstance();
parent::__construct();
}

Expand Down Expand Up @@ -88,20 +98,38 @@ public function ajaxProcessSaveConfigInsurance()
{
try {
$config = Tools::getValue('config');
$savedInsuranceStatus = $config[AdminInsuranceHelper::$fieldsDbInsuranceToIframeParamNames[ConstantsHelper::ALMA_ACTIVATE_INSURANCE]];

$this->insuranceHelper->saveConfigInsurance($config);
$this->insuranceProductService->handleInsuranceProductState($savedInsuranceStatus);

if ($savedInsuranceStatus === 'false') {
$this->insuranceProductService->removeInsuranceProductsNotOrdered();
}

$this->ajaxRenderAndExit(json_encode([
'success' => true,
'message' => $this->module->l('Your configuration has been saved', 'AdminAlmaInsuranceConfiguration'),
])
);
} catch (\Exception $e) {
Logger::instance()->error('Error creating Alma configuration insurance: ' . $e->getMessage());
} catch (InsuranceProductException $e) {
Logger::instance()->error('[Alma] Error insurance product during change configuration: ' . $e->getMessage());
$this->ajaxRenderAndExit(json_encode([
'error' => [
'msg' => sprintf(
$this->module->l('[Alma] Error insurance product during change configuration: %1$s', 'AdminAlmaInsuranceConfiguration'),
$e->getMessage()
),
'code' => $e->getCode(),
],
])
);
} catch (WrongParamsException $e) {
Logger::instance()->error('[Alma] Error creating Alma configuration insurance: ' . $e->getMessage());
$this->ajaxRenderAndExit(json_encode([
'error' => [
'msg' => sprintf(
$this->module->l('Error creating configuration Alma insurance: %1$s', 'AdminAlmaInsuranceConfiguration'),
$this->module->l('[Alma] Error creating configuration Alma insurance: %1$s', 'AdminAlmaInsuranceConfiguration'),
$e->getMessage()
),
'code' => $e->getCode(),
Expand Down
37 changes: 30 additions & 7 deletions alma/controllers/front/ipn.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
*/

use Alma\PrestaShop\API\MismatchException;
use Alma\PrestaShop\Exceptions\RefundException;
use Alma\PrestaShop\Builders\Validators\PaymentValidationBuilder;
use Alma\PrestaShop\Exceptions\PaymentValidationException;
use Alma\PrestaShop\Helpers\SettingsHelper;
use Alma\PrestaShop\Logger;
use Alma\PrestaShop\Traits\AjaxTrait;
use Alma\PrestaShop\Validators\PaymentValidation;
Expand All @@ -40,8 +42,21 @@ class AlmaIpnModuleFrontController extends ModuleFrontController
{
use AjaxTrait;

/**
* @var bool
*/
public $ssl = true;

/**
* @var Context
*/
public $context;

/**
* @var PaymentValidation
*/
protected $paymentValidation;

/**
* IPN constructor
*
Expand All @@ -51,14 +66,15 @@ public function __construct()
{
parent::__construct();
$this->context = Context::getContext();
$paymentValidationBuilder = new PaymentValidationBuilder();
$this->paymentValidation = $paymentValidationBuilder->getInstance();
}

/**
* @return void
*
* @throws PrestaShopException
* @throws RefundException
* @throws MismatchException
* @throws Exception
*/
public function postProcess()
{
Expand All @@ -67,18 +83,25 @@ public function postProcess()
header('Content-Type: application/json');

$paymentId = Tools::getValue('pid');
$validator = new PaymentValidation($this->context, $this->module);
if (!array_key_exists('HTTP_X_ALMA_SIGNATURE', $_SERVER)) {
$msg = 'Header key X-Alma-Signature doesn\'t exist';
Logger::instance()->error('[Alma] IPN Payment Validation Error - Message : ' . $msg);
$this->ajaxRenderAndExit(json_encode(['error' => $msg]), 500);
}

try {
$validator->validatePayment($paymentId);
$this->paymentValidation->checkSignature($paymentId, SettingsHelper::getActiveAPIKey(), $_SERVER['HTTP_X_ALMA_SIGNATURE']);
$this->paymentValidation->validatePayment($paymentId);
$this->ajaxRenderAndExit(json_encode(['success' => true]));
} catch (PaymentValidationException $e) {
Logger::instance()->error('[Alma] IPN Payment Validation Error - Message : ' . $e->getMessage());
$this->ajaxRenderAndExit(json_encode(['error' => $e->getMessage()]), 500);
} catch (PaymentValidationError $e) {
Logger::instance()->error('ipn payment_validation_error - Message : ' . $e->getMessage());
$this->ajaxRenderAndExit(json_encode(['error' => $e->getMessage()]), 500);
} catch (MismatchException $e) {
Logger::instance()->error('ipn payment_validation_mismatch_error - Message : ' . $e->getMessage());
$this->ajaxRenderAndExit(json_encode(['error' => $e->getMessage()]), 200);
}

$this->ajaxRenderAndExit(json_encode(['success' => true]));
}
}
2 changes: 1 addition & 1 deletion alma/controllers/front/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function postProcess()
$this->ajaxErrorAndDie();
}

if ($this->paymentData->isInPage($data)) {
if ($this->paymentData->isInPage()) {
$this->ajaxRenderAndExit(json_encode($payment));
}

Expand Down
Loading

0 comments on commit 27dc9b1

Please sign in to comment.