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

PIPRES-342: PsAccounts and cloudsync connect #826

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
079fd0e
PIPRES-113: Billie payment method (#784)
mandan2 Aug 28, 2023
d15fcd7
Version bump and upgrade file fix (#800)
mandan2 Sep 4, 2023
2b005ce
debug mode enabling
SimonasB88 Aug 1, 2023
ab1e88b
ps1784 test spec updates
SimonasB88 Aug 21, 2023
bd42720
in3 payment wip
SimonasB88 Aug 21, 2023
244c8bd
ps1784 test updates
SimonasB88 Aug 22, 2023
74d0fe5
disabling debug mode
SimonasB88 Aug 28, 2023
eda6ae1
Revert "disabling debug mode"
SimonasB88 Aug 28, 2023
cf3cf99
Update 02_mollie.ps8.EnablingPaymentsOrdersAPI.specs.js
SimonasB88 Aug 28, 2023
4e9072a
ps8 debug mode disabling
SimonasB88 Sep 4, 2023
848313a
small typo fix
SimonasB88 Sep 4, 2023
916c6c5
temporary disabling the error checking
SimonasB88 Sep 5, 2023
990734f
PIPRES-338: Mixed cart subscription listing improvements (#812)
mandan2 Sep 19, 2023
3c64995
ps8 debug mode
SimonasB88 Sep 11, 2023
3681979
Update E2E_On_PR.yml
SimonasB88 Sep 11, 2023
27fd3b7
Update 03_mollie.ps8.PaymentTests.js
SimonasB88 Oct 2, 2023
271064b
PIPRES-261: Separate carrier for recurring orders improvements (#821)
mandan2 Oct 3, 2023
5416e3d
PIPRES-342: PsAccounts and cloudsync connect
mandan2 Oct 9, 2023
2cf995e
phpstan and minor ps_evenbus install tweaks
mandan2 Oct 9, 2023
aaafca6
phpstan and csfixer
mandan2 Oct 9, 2023
4cfd2a4
phpstan and upgrade file fix
mandan2 Oct 9, 2023
9bb239f
fix
mandan2 Oct 9, 2023
a4f1ca7
replaced concrete logger to interface
mandan2 Oct 9, 2023
c93bd9f
checking if cdns are provided
mandan2 Oct 10, 2023
41fdd9b
added message log for ps_accounts install fallback
mandan2 Oct 10, 2023
038bea3
dynamic ps_accounts version method
mandan2 Oct 10, 2023
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
20 changes: 10 additions & 10 deletions .docker/.htaccess8
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ SetEnv HTTP_MOD_REWRITE On
RewriteEngine on


#Domain: demoshop8.ngrok.io
#Domain: demoshop8debug.ngrok.io
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api(?:/(.*))?$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
RewriteRule ^upload/.+$ %{ENV:REWRITEBASE}index.php [QSA,L]

# Images
RewriteCond %{HTTP_HOST} ^demoshop8.ngrok.io$
RewriteCond %{HTTP_HOST} ^demoshop8debug.ngrok.io$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^demoshop8.ngrok.io$
RewriteCond %{HTTP_HOST} ^demoshop8debug.ngrok.io$
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteCond %{HTTP_HOST} ^demoshop8.ngrok.io$
RewriteCond %{HTTP_HOST} ^demoshop8debug.ngrok.io$
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteCond %{HTTP_HOST} ^demoshop8.ngrok.io$
RewriteCond %{HTTP_HOST} ^demoshop8debug.ngrok.io$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteCond %{HTTP_HOST} ^demoshop8.ngrok.io$
RewriteCond %{HTTP_HOST} ^demoshop8debug.ngrok.io$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteCond %{HTTP_HOST} ^demoshop8.ngrok.io$
RewriteCond %{HTTP_HOST} ^demoshop8debug.ngrok.io$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteCond %{HTTP_HOST} ^demoshop8.ngrok.io$
RewriteCond %{HTTP_HOST} ^demoshop8debug.ngrok.io$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteCond %{HTTP_HOST} ^demoshop8.ngrok.io$
RewriteCond %{HTTP_HOST} ^demoshop8debug.ngrok.io$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^demoshop8.ngrok.io$
RewriteCond %{HTTP_HOST} ^demoshop8debug.ngrok.io$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/E2E_On_PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ jobs:
include:
- prestashop: 'PS1785'
make: 'make e2eh1785'
subdomain: 'demoshop1785'
subdomain: 'demoshop1785debug'
port: '8002'
yml: 'docker-compose.1785.yml'
url: 'https://demoshop1785.ngrok.io'
test_spec: '**/cypress/e2e/ps1785/**'
TestRailID: R4954
- prestashop: 'PS8'
make: 'make e2eh8'
subdomain: 'demoshop8'
subdomain: 'demoshop8debug'
port: '8142'
yml: 'docker-compose.8.yml'
url: 'https://demoshop8.ngrok.io'
url: 'https://demoshop8debug.ngrok.io'
test_spec: '**/cypress/e2e/ps8/**'
TestRailID: R6470
env:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"webmozart/assert": "^1.11",
"symfony/http-client": "^4.4",
"http-interop/http-factory-guzzle": "^1.1",
"php-http/message-factory": "^1.1"
"php-http/message-factory": "^1.1",
"prestashop/prestashop-accounts-installer": "^1.0.4"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
Expand Down
188 changes: 160 additions & 28 deletions controllers/admin/AdminMollieSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@

declare(strict_types=1);

use Mollie\Adapter\ConfigurationAdapter;
use Mollie\Adapter\ToolsAdapter;
use Mollie\Builder\Content\BaseInfoBlock;
use Mollie\Builder\Content\UpdateMessageInfoBlock;
use Mollie\Config\Config;
use Mollie\Logger\PrestaLoggerInterface;
use Mollie\Repository\ModuleRepository;
use Mollie\Service\Content\TemplateParserInterface;
use Mollie\Service\SettingsSaveService;
use PrestaShop\Module\PsEventbus\Service\PresenterService;
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder;
use PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleNotInstalledException;
use PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts;
use PrestaShop\PsAccountsInstaller\Installer\Installer as PsAccountsInstaller;

class AdminMollieSettingsController extends ModuleAdminController
{
private const FILE_NAME = 'AdminMollieSettingsController';

/** @var Mollie */
public $module;

Expand All @@ -13,48 +30,76 @@ public function __construct()
$this->bootstrap = true;
}

public function postProcess()
public function initContent(): void
{
/** @var \Mollie\Repository\ModuleRepository $moduleRepository */
$moduleRepository = $this->module->getService(\Mollie\Repository\ModuleRepository::class);
$moduleDatabaseVersion = $moduleRepository->getModuleDatabaseVersion($this->module->name);
$needsUpgrade = Tools::version_compare($this->module->version, $moduleDatabaseVersion, '>');
if ($needsUpgrade) {
$this->context->controller->errors[] = $this->module->l('Please upgrade Mollie module');
$this->setEnvironmentForAccounts();
$this->setEnvironmentForCloudSync();

return;
}
$this->content .= $this->context->smarty->fetch($this->module->getLocalPath() . '/views/templates/admin/_configure/configuration.tpl');

$isShopContext = Shop::getContext() === Shop::CONTEXT_SHOP;
$this->content .= $this->displayModuleSettings();

if (!$isShopContext) {
$this->context->controller->errors[] = $this->module->l('Select the shop that you want to configure');
$this->addJs($this->module->getPathUri() . '/views/js/admin/_configure/configuration.js');

return;
}
parent::initContent();
}

public function postProcess()
{
/** @var ConfigurationAdapter $configuration */
$configuration = $this->module->getService(ConfigurationAdapter::class);

/** @var \Mollie\Service\Content\TemplateParserInterface $templateParser */
$templateParser = $this->module->getService(\Mollie\Service\Content\TemplateParserInterface::class);
/** @var ToolsAdapter $tools */
$tools = $this->module->getService(ToolsAdapter::class);

$isSubmitted = (bool) Tools::isSubmit("submit{$this->module->name}");
$isSubmitted = $tools->isSubmit("submit{$this->module->name}");

/* @phpstan-ignore-next-line */
if (false === Configuration::get(Mollie\Config\Config::MOLLIE_STATUS_AWAITING) && !$isSubmitted) {
if (!$isSubmitted && !$configuration->get(Config::MOLLIE_STATUS_AWAITING)) {
$this->context->controller->errors[] = $this->module->l('Select an order status for \"Status for Awaiting payments\" in the \"Advanced settings\" tab');
}

$errors = [];

if (Tools::isSubmit("submit{$this->module->name}")) {
/** @var \Mollie\Service\SettingsSaveService $saveSettingsService */
$saveSettingsService = $this->module->getService(\Mollie\Service\SettingsSaveService::class);
if ($tools->isSubmit("submit{$this->module->name}")) {
/** @var SettingsSaveService $saveSettingsService */
$saveSettingsService = $this->module->getService(SettingsSaveService::class);

$resultMessages = $saveSettingsService->saveSettings($errors);

if (!empty($errors)) {
$this->context->controller->errors = $resultMessages;
$this->context->controller->errors = array_merge(
$this->context->controller->errors,
$resultMessages
);
} else {
$this->context->controller->confirmations = $resultMessages;
$this->context->controller->confirmations = array_merge(
$this->context->controller->confirmations,
$resultMessages
);
}
}
}

private function displayModuleSettings(): string
{
/** @var ModuleRepository $moduleRepository */
$moduleRepository = $this->module->getService(ModuleRepository::class);

$moduleDatabaseVersion = $moduleRepository->getModuleDatabaseVersion($this->module->name);
$needsUpgrade = Tools::version_compare($this->module->version, $moduleDatabaseVersion, '>');

if ($needsUpgrade) {
$this->context->controller->errors[] = $this->module->l('Please upgrade Mollie module');

return '';
}

if (\Shop::getContext() !== \Shop::CONTEXT_SHOP) {
$this->context->controller->errors[] = $this->module->l('Select the shop that you want to configure');

return '';
}

Media::addJsDef([
'description_message' => addslashes($this->module->l('Enter a description')),
Expand All @@ -71,6 +116,9 @@ public function postProcess()
'not_valid_file_message' => addslashes($this->module->l('Invalid file: %s%')),
]);

/** @var TemplateParserInterface $templateParser */
$templateParser = $this->module->getService(TemplateParserInterface::class);

$this->context->controller->addJS($this->module->getPathUri() . 'views/js/method_countries.js');
$this->context->controller->addJS($this->module->getPathUri() . 'views/js/validation.js');
$this->context->controller->addJS($this->module->getPathUri() . 'views/js/admin/settings.js');
Expand All @@ -87,8 +135,9 @@ public function postProcess()
$this->module->getLocalPath() . 'views/templates/admin/logo.tpl'
);

/** @var \Mollie\Builder\Content\UpdateMessageInfoBlock $updateMessageInfoBlock */
$updateMessageInfoBlock = $this->module->getService(\Mollie\Builder\Content\UpdateMessageInfoBlock::class);
/** @var UpdateMessageInfoBlock $updateMessageInfoBlock */
$updateMessageInfoBlock = $this->module->getService(UpdateMessageInfoBlock::class);

$updateMessageInfoBlockData = $updateMessageInfoBlock->setAddons(false);

$html .= $templateParser->parseTemplate(
Expand All @@ -97,8 +146,9 @@ public function postProcess()
$this->module->getLocalPath() . 'views/templates/admin/updateMessage.tpl'
);

/** @var \Mollie\Builder\Content\BaseInfoBlock $baseInfoBlock */
$baseInfoBlock = $this->module->getService(\Mollie\Builder\Content\BaseInfoBlock::class);
/** @var BaseInfoBlock $baseInfoBlock */
$baseInfoBlock = $this->module->getService(BaseInfoBlock::class);

$this->context->smarty->assign($baseInfoBlock->buildParams());

/** @var \Mollie\Builder\FormBuilder $settingsFormBuilder */
Expand All @@ -112,6 +162,88 @@ public function postProcess()
$this->context->controller->errors[] = $this->module->l('The database tables are missing. Reset the module.');
}

$this->content .= $html;
return $html;
}

private function setEnvironmentForAccounts(): void
{
/** @var PrestaLoggerInterface $logger */
$logger = $this->module->getService(PrestaLoggerInterface::class);

try {
/** @var PsAccounts $accountsFacade */
$accountsFacade = $this->module->getService(PsAccounts::class);

$psAccountsPresenter = $accountsFacade->getPsAccountsPresenter();
$psAccountsService = $accountsFacade->getPsAccountsService();
} catch (ModuleNotInstalledException $exception) {
try {
/** @var PsAccountsInstaller $prestashopAccountsInstaller */
$prestashopAccountsInstaller = $this->module->getService(PsAccountsInstaller::class);

if (!$prestashopAccountsInstaller->install()) {
$this->context->controller->errors[] =
$this->module->l('Failed to install Prestashop Accounts module. Please contact support.');

return;
}
} catch (\Throwable $exception) {
$logger->error('"PrestaShop Accounts" install failed.', [
'Exception message' => $exception->getMessage(),
'Exception code' => $exception->getCode(),
]);

$this->context->controller->errors[] =
$this->module->l('Failed to install Prestashop Accounts module. Please contact support.');

return;
}

$psAccountsPresenter = $accountsFacade->getPsAccountsPresenter();
$psAccountsService = $accountsFacade->getPsAccountsService();
} catch (\Throwable $exception) {
$logger->error('"PrestaShop Accounts" unknown error.', [
'Exception message' => $exception->getMessage(),
'Exception code' => $exception->getCode(),
]);

$this->context->controller->errors[] =
$this->module->l('"PrestaShop Accounts" initialization failed.', self::FILE_NAME);

return;
}

Media::addJsDef([
'contextPsAccounts' => $psAccountsPresenter->present(),
]);

$this->context->smarty->assign([
'urlAccountsCdn' => $psAccountsService->getAccountsCdn(),
]);
}

private function setEnvironmentForCloudSync(): void
{
$moduleManager = ModuleManagerBuilder::getInstance()->build();

if (!$moduleManager->isInstalled('ps_eventbus')) {
return;
}

/** @var \Ps_eventbus $eventbusModule */
$eventbusModule = \Module::getInstanceByName('ps_eventbus');

if (version_compare($eventbusModule->version, '1.9.0', '>=')) {
/** @var PresenterService $eventbusPresenterService */
$eventbusPresenterService = $eventbusModule->getService(PresenterService::class);

Media::addJsDef([
'contextPsEventbus' => $eventbusPresenterService->expose($this->module, ['orders']),
]);
}

$this->context->smarty->assign([
'cloudSyncPathCDC' => Config::PRESTASHOP_CLOUDSYNC_CDN,
]);
}
}
4 changes: 2 additions & 2 deletions cypress/e2e/ps1785/03_mollie.ps1785.PaymentTestsOrdersAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,11 @@ it('C339355: 18 Check if customerId is passed during the 2nd payment using Singl
it('C339356: 19 Credit Card Order BO Shipping, Refunding [Orders API]', () => {
cy.OrderRefundingShippingOrdersAPI()
})
it('C339357: 20 IN3 Checkouting [Orders API]', () => {
it.only('C339357: 20 IN3 Checkouting [Orders API]', () => {
cy.visit('/de/index.php?controller=history')
cy.get('a').click()
cy.contains('Reorder').click()
cy.contains('NL').click()
cy.contains('DE').click()
//Billing country LT, DE etc.
cy.get('.clearfix > .btn').click()
cy.get('#js-delivery > .continue').click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('PS8 Enabling Payments', () => {
it('C339341: 04 Enabling All payments in Module BO [Orders API]', () => {
cy.visit('/admin1/')
cy.OpeningModuleDashboardURL()
cy.ConfOrdersAPI1784()
cy.ConfOrdersAPI8()
cy.get('[type="submit"]').first().click({force:true})
cy.get('[class="alert alert-success"]').should('be.visible')
})
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
DB_PASSWD: $${DB_PASSWD}
DB_NAME: prestashop
DB_SERVER: mysql
PS_DOMAIN: demoshop8.ngrok.io:8142
PS_DOMAIN: demoshop8debug.ngrok.io:8142
PS_FOLDER_INSTALL: install
PS_FOLDER_ADMIN: admin1
depends_on:
Expand Down
Loading
Loading