Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v4.4.0 #578

Merged
merged 62 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
228a338
chore(deps): update pre-commit repositories
alma-renovate-bot[bot] Aug 12, 2024
0949007
Merge pull request #560 from alma/chore/backport-main-to-develop
Benjamin-Freoua-Alma Aug 12, 2024
c22f3b3
Merge pull request #559 from alma/renovate/pre-commit-repositories
Benjamin-Freoua-Alma Aug 12, 2024
2cd681e
feat: test to log Header IPN
Benjamin-Freoua-Alma Aug 13, 2024
193b1e9
feat: remove SoC log add IPN log
Benjamin-Freoua-Alma Aug 13, 2024
d811486
test(fix): update unknown namespace in unit test
FranceBe Aug 16, 2024
ad5de72
test(report): add coverage report in HTML
FranceBe Aug 16, 2024
5230bf9
chore(class): create dedicated class for custom error handling to gen…
FranceBe Aug 16, 2024
ab5a194
Merge pull request #562 from alma/chore/add-html-coverage-report
FranceBe Aug 26, 2024
df6ef78
chore(deps): update pre-commit hook returntocorp/semgrep to v1.86.0
alma-renovate-bot[bot] Sep 9, 2024
e854f0a
feat: WIP Hmac
Benjamin-Freoua-Alma Sep 9, 2024
4156082
chore(deps): update github actions (#564)
alma-renovate-bot[bot] Sep 9, 2024
83614c8
Merge pull request #563 from alma/renovate/pre-commit-repositories
Benjamin-Freoua-Alma Sep 11, 2024
a5c2774
fix: install module if container of getService Ps_account is null
Benjamin-Freoua-Alma Sep 13, 2024
1cda5b7
fix: Inpage on prestashop 1.6 with third party module of checkout
Benjamin-Freoua-Alma Sep 13, 2024
cafd35a
Merge pull request #566 from alma/fix/ecom-2057-ps-fix-inpage-on-pres…
Benjamin-Freoua-Alma Sep 16, 2024
d09496c
fix: review [FRA]
Benjamin-Freoua-Alma Sep 16, 2024
ae4d78a
chore(deps): update pre-commit hook returntocorp/semgrep to v1.87.0
alma-renovate-bot[bot] Sep 16, 2024
4fc6808
fix: check if key templateVars exist
Benjamin-Freoua-Alma Sep 16, 2024
5a59c00
fix: review [FRA] refacto check compatibility Ps Account
Benjamin-Freoua-Alma Sep 16, 2024
3e8f8ed
feat: set our product detail in our template
Benjamin-Freoua-Alma Sep 16, 2024
98f9c0f
Merge pull request #567 from alma/renovate/pre-commit-repositories
Benjamin-Freoua-Alma Sep 17, 2024
3cb1d11
feat: add HMAC Payment Validation Prestashop
Benjamin-Freoua-Alma Sep 17, 2024
9c1692e
fix: remove condition to display insurance widget if layout is not empty
Benjamin-Freoua-Alma Sep 17, 2024
c9256c6
fix: add verification in insurance js if add to cart button doesn't e…
Benjamin-Freoua-Alma Sep 17, 2024
38a838f
fix: event add to cart for insurance if add to cart button isn't defa…
Benjamin-Freoua-Alma Sep 17, 2024
48dda19
fix: add verification in insurance js if add to cart button doesn't e…
Benjamin-Freoua-Alma Sep 17, 2024
34c3cc1
fix: review [FRA] alias not needed
Benjamin-Freoua-Alma Sep 18, 2024
e4d74b0
fix: review [FRA] function to get addToCart
Benjamin-Freoua-Alma Sep 18, 2024
1d95d6b
Merge pull request #565 from alma/fix/ecom-2056-ps-fix-install-module…
Benjamin-Freoua-Alma Sep 18, 2024
acee6c0
feat: review [FRA] replace let to const for addToCart variable
Benjamin-Freoua-Alma Sep 18, 2024
1b856f5
feat: review [FRA]
Benjamin-Freoua-Alma Sep 18, 2024
c418043
Merge pull request #568 from alma/feature/ecom-2062-ps-fix-insurance-…
Benjamin-Freoua-Alma Sep 18, 2024
3b1a65a
feat: review [FRA]
Benjamin-Freoua-Alma Sep 19, 2024
831d45c
chore(naming): rename function to be clearer
FranceBe Sep 25, 2024
38454b8
Merge pull request #561 from alma/feature/ecom-1818-ps-add-hmac-verif…
Benjamin-Freoua-Alma Sep 25, 2024
ea78820
feat: Change state insurance product according insurance config state
Benjamin-Freoua-Alma Sep 18, 2024
e37cfd0
Merge pull request #571 from alma/chore/rename-variable
Benjamin-Freoua-Alma Sep 30, 2024
2cf9974
feat: add hmac verification on ipn
joyet-simon Oct 1, 2024
d951d30
fix: setContainer Ps Account install module
Benjamin-Freoua-Alma Oct 1, 2024
ae2939e
Merge pull request #569 from alma/feature/ecom-2003-ps-remove-insuran…
Benjamin-Freoua-Alma Oct 1, 2024
6260062
Merge pull request #575 from alma/feature/ecom-2070-ps-integrate-cred…
joyet-simon Oct 1, 2024
f6e32f5
Merge pull request #576 from alma/fix/ecom-2112-ps-fix-setcontainer-p…
Benjamin-Freoua-Alma Oct 1, 2024
2071c24
fix: paymentValidation in validation controller since HMAC
Benjamin-Freoua-Alma Sep 26, 2024
c66099c
fix: unit test
Benjamin-Freoua-Alma Sep 26, 2024
21672bb
fix: Review [MAR] renaming
Benjamin-Freoua-Alma Sep 27, 2024
3b0bbe2
fix: HMAC get the right APIKey
Benjamin-Freoua-Alma Sep 30, 2024
8ecbbcd
fix: add verification if header X-Alma-Signature doesn't exist
Benjamin-Freoua-Alma Oct 1, 2024
add5006
fix: automatique height insurance widget
Benjamin-Freoua-Alma Sep 26, 2024
d5b95e3
fix: WIP handle height widget insurance + Need to refresh productDeta…
Benjamin-Freoua-Alma Sep 26, 2024
0a196d1
fix: refresh data from productDetails + get button add-to-cart Ravate
Benjamin-Freoua-Alma Oct 1, 2024
9db8cd3
fix: refresh data widget after change product reference
Benjamin-Freoua-Alma Oct 1, 2024
84d178e
fix: change remove insurance product with product since ps 1.7.1
Benjamin-Freoua-Alma Oct 1, 2024
63bdef3
Merge pull request #573 from alma/fix/ecom-2102-ps-fix-paymentvalidat…
Benjamin-Freoua-Alma Oct 2, 2024
3359a85
fix: change data widget on change reference
Benjamin-Freoua-Alma Oct 2, 2024
4322c41
Merge pull request #572 from alma/fix/ecom-2095-ps-fix-handle-height-…
Benjamin-Freoua-Alma Oct 2, 2024
a463a2f
fix: display widget on PS 1.7.0.6
Benjamin-Freoua-Alma Oct 2, 2024
83cdf64
Merge pull request #577 from alma/fix/ecom-2113-ps-fix-display-widget…
Benjamin-Freoua-Alma Oct 2, 2024
0bb45da
chore: update version
Benjamin-Freoua-Alma Oct 7, 2024
0109d9a
chore: update translation
Benjamin-Freoua-Alma Oct 7, 2024
7f1e8bb
fix: Review [FRA]
Benjamin-Freoua-Alma Oct 7, 2024
78cdb51
fix: Review [FRA]
Benjamin-Freoua-Alma Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -114,7 +114,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
Loading