From 8c1e0d8634d1b2e1edc17ba860a0546259685164 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:51:17 +0100 Subject: [PATCH 1/4] Fix cancel PayPal Order id --- controllers/front/cancel.php | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/controllers/front/cancel.php b/controllers/front/cancel.php index ac4d507e7..d0ced054e 100644 --- a/controllers/front/cancel.php +++ b/controllers/front/cancel.php @@ -72,24 +72,19 @@ public function postProcess() $reason = isset($bodyValues['reason']) ? Tools::safeOutput($bodyValues['reason']) : null; $error = isset($bodyValues['error']) ? Tools::safeOutput($bodyValues['error']) : null; - if (empty($orderId)) { - $this->exitWithResponse([ - 'httpCode' => 400, - 'body' => 'Missing PayPal Order Id', - ]); - } - - /** @var CommandBusInterface $commandBus */ - $commandBus = $this->module->getService('ps_checkout.bus.command'); + if ($orderId) { + /** @var CommandBusInterface $commandBus */ + $commandBus = $this->module->getService('ps_checkout.bus.command'); - $commandBus->handle(new CancelCheckoutCommand( - $this->context->cart->id, - $orderId, - PsCheckoutCart::STATUS_CANCELED, - $fundingSource, - $isExpressCheckout, - $isHostedFields - )); + $commandBus->handle(new CancelCheckoutCommand( + $this->context->cart->id, + $orderId, + PsCheckoutCart::STATUS_CANCELED, + $fundingSource, + $isExpressCheckout, + $isHostedFields + )); + } $this->module->getLogger()->log( $error ? 400 : 200, @@ -97,6 +92,7 @@ public function postProcess() [ 'PayPalOrderId' => $orderId, 'FundingSource' => $fundingSource, + 'id_cart' => $this->context->cart->id, 'isExpressCheckout' => $isExpressCheckout, 'isHostedFields' => $isHostedFields, 'reason' => $reason, From 5166df5e0c8757508c42855cd5b2d79d0439c7d2 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Fri, 8 Mar 2024 18:32:06 +0100 Subject: [PATCH 2/4] Use mbo installer only for shop context --- ps_checkout.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/ps_checkout.php b/ps_checkout.php index 4b367e558..fbae2ac91 100755 --- a/ps_checkout.php +++ b/ps_checkout.php @@ -376,9 +376,6 @@ public function uninstallTabs() public function getContent() { try { - $mboInstaller = new \Prestashop\ModuleLibMboInstaller\DependencyBuilder($this); - $requiredDependencies = $mboInstaller->handleDependencies(); - $hasRequiredDependencies = $mboInstaller->areDependenciesMet(); /** @var \PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts $psAccountsFacade */ $psAccountsFacade = $this->getService('ps_accounts.facade'); /** @var \PrestaShop\PsAccountsInstaller\Installer\Presenter\InstallerPresenter $psAccountsPresenter */ @@ -387,8 +384,6 @@ public function getContent() $contextPsAccounts = $psAccountsPresenter->present($this->name); } catch (Exception $exception) { $contextPsAccounts = []; - $requiredDependencies = []; - $hasRequiredDependencies = false; $this->getLogger()->error( 'Failed to get PsAccounts context', [ @@ -422,6 +417,27 @@ public function getContent() } $this->context->controller->addJS($boSdkUrl, false); + $isShopContext = !(Shop::isFeatureActive() && Shop::getContext() !== Shop::CONTEXT_SHOP); + $requiredDependencies = []; + $hasRequiredDependencies = true; + + if ($isShopContext) { + try { + $mboInstaller = new \Prestashop\ModuleLibMboInstaller\DependencyBuilder($this); + $requiredDependencies = $mboInstaller->handleDependencies(); + $hasRequiredDependencies = $mboInstaller->areDependenciesMet(); + } catch (Exception $exception) { + $this->getLogger()->error( + 'Failed to get required dependencies', + [ + 'exception' => get_class($exception), + 'exceptionCode' => $exception->getCode(), + 'exceptionMessage' => $exception->getMessage(), + ] + ); + } + } + $this->context->smarty->assign([ 'requiredDependencies' => $requiredDependencies, 'hasRequiredDependencies' => $hasRequiredDependencies, From d85bab371fd0ddfd9d930042febbf1ca7535fec5 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:06:51 +0100 Subject: [PATCH 3/4] Fix error thrown after redirect to checkout --- _dev/js/front/src/api/ps-checkout.api.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/_dev/js/front/src/api/ps-checkout.api.js b/_dev/js/front/src/api/ps-checkout.api.js index fea682dfc..36dba4707 100644 --- a/_dev/js/front/src/api/ps-checkout.api.js +++ b/_dev/js/front/src/api/ps-checkout.api.js @@ -146,7 +146,11 @@ export class PsCheckoutApi extends BaseClass { if (isJsonResponse) { if (false === response.ok || response.status >= 400) { return response.json().then((response) => { - if (actions?.restart && response.body && 85 === response.body.error.code) { + if ( + actions?.restart && + response.body && + 85 === response.body.error.code + ) { return actions.restart(); } @@ -221,6 +225,8 @@ export class PsCheckoutApi extends BaseClass { window.location.href = new URL( this.config.checkoutCheckoutUrl ).toString(); + + return; } throw new Error(this.$('checkout.form.error.label')); From 40c05952361a4fa8262f6e1f34fd8b74e2ac7e85 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:06:41 +0100 Subject: [PATCH 4/4] Bump module version --- config.xml | 2 +- ps_checkout.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config.xml b/config.xml index 742ae303a..264e38377 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_checkout - + diff --git a/ps_checkout.php b/ps_checkout.php index fbae2ac91..f9d755058 100755 --- a/ps_checkout.php +++ b/ps_checkout.php @@ -112,7 +112,7 @@ class Ps_checkout extends PaymentModule // Needed in order to retrieve the module version easier (in api call headers) than instanciate // the module each time to get the version - const VERSION = '8.3.6.0'; + const VERSION = '8.3.6.1'; const INTEGRATION_DATE = '2022-14-06'; @@ -133,7 +133,7 @@ public function __construct() // We cannot use the const VERSION because the const is not computed by addons marketplace // when the zip is uploaded - $this->version = '8.3.6.0'; + $this->version = '8.3.6.1'; $this->author = 'PrestaShop'; $this->currencies = true; $this->currencies_mode = 'checkbox';