Skip to content

Commit

Permalink
Removed 1.7 PS version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
L3RAZ committed Jan 8, 2025
1 parent c644657 commit 7f0e5b0
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 432 deletions.
138 changes: 7 additions & 131 deletions ps_checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@

class Ps_checkout extends PaymentModule
{
/**
* Default hook to install
* 1.6 and 1.7
*
* @var array
*/
const HOOK_LIST = [
'displayAdminAfterHeader',
'displayOrderConfirmation',
Expand All @@ -47,14 +41,6 @@ class Ps_checkout extends PaymentModule
'displayPaymentReturn',
'displayOrderDetail',
'moduleRoutes',
];

/**
* Hook to install for 1.7
*
* @var array
*/
const HOOK_LIST_17 = [
'paymentOptions',
'actionCartUpdateQuantityBefore',
'displayInvoiceLegalFreeText',
Expand All @@ -69,18 +55,6 @@ class Ps_checkout extends PaymentModule
'AdminPaypalOnboardingPrestashopCheckout',
];

/**
* Hook to install for 1.6
*
* @var array
*/
const HOOK_LIST_16 = [
'actionBeforeCartUpdateQty',
'actionAfterDeleteProductInCart',
'displayPayment',
'displayCartTotalPriceLabel',
];

public $configurationList = [
'PS_CHECKOUT_INTENT' => 'CAPTURE',
'PS_CHECKOUT_MODE' => 'LIVE',
Expand Down Expand Up @@ -116,7 +90,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.4.2.1';
const VERSION = '9.4.2.1';

const INTEGRATION_DATE = '2024-04-01';

Expand Down Expand Up @@ -152,7 +126,7 @@ public function __construct()
$this->description = $this->l('Provide the most commonly used payment methods to your customers in this all-in-one module, and manage all your sales in a centralized interface.');

$this->confirmUninstall = $this->l('Are you sure you want to uninstall this module?');
$this->ps_versions_compliancy = ['min' => '8.0.0', 'max' => _PS_VERSION_];
$this->ps_versions_compliancy = ['min' => '9.0.0', 'max' => _PS_VERSION_];

// $this->disableSegment = false;
}
Expand All @@ -170,7 +144,6 @@ public function install()
$savedGroupShopId = Shop::getContextShopGroupID();
Shop::setContext(Shop::CONTEXT_ALL);

// Install for both 1.7 and 1.6
$result = parent::install() &&
$this->installConfiguration() &&
$this->installHooks() &&
Expand All @@ -197,22 +170,8 @@ public function install()
public function installHooks()
{
$result = (bool) $this->registerHook(self::HOOK_LIST);
/** @var \PrestaShop\Module\PrestashopCheckout\ShopContext $shopContext */
$shopContext = $this->getService(\PrestaShop\Module\PrestashopCheckout\ShopContext::class);

// Install specific to prestashop 1.6
if (!$shopContext->isShop17()) {
$result = $result && $this->registerHook(self::HOOK_LIST_16);
$this->updatePosition(\Hook::getIdByName('payment'), false, 1);

return $result;
}

// Install specific to prestashop 1.7
if ($shopContext->isShop17()) {
$result = $result && $this->registerHook(self::HOOK_LIST_17);
$this->updatePosition(\Hook::getIdByName('paymentOptions'), false, 1);
}
$this->updatePosition(\Hook::getIdByName('paymentOptions'), false, 1);

return $result;
}
Expand Down Expand Up @@ -459,26 +418,6 @@ public function hookActionObjectProductInCartDeleteAfter()
$this->hookActionCartUpdateQuantityBefore();
}

/**
* This hook is called only in PrestaShop 1.6.1 to 1.6.1.24
* Deprecated since PrestaShop 1.7.0.0
*/
public function hookActionAfterDeleteProductInCart()
{
if (!$this->merchantIsValid()) {
return;
}

/** @var \PrestaShop\Module\PrestashopCheckout\ShopContext $shopContext */
$shopContext = $this->getService(\PrestaShop\Module\PrestashopCheckout\ShopContext::class);

if ($shopContext->isShop17()) {
return;
}

$this->hookActionCartUpdateQuantityBefore();
}

/**
* This hook is called only since PrestaShop 1.7.0.0
*/
Expand Down Expand Up @@ -507,26 +446,6 @@ public function hookActionCartUpdateQuantityBefore()
}
}

/**
* This hook is called only in PrestaShop 1.6.1 to 1.6.1.24
* Deprecated since PrestaShop 1.7.0.0
*/
public function hookActionBeforeCartUpdateQty()
{
if (!$this->merchantIsValid()) {
return;
}

/** @var \PrestaShop\Module\PrestashopCheckout\ShopContext $shopContext */
$shopContext = $this->getService(\PrestaShop\Module\PrestashopCheckout\ShopContext::class);

if ($shopContext->isShop17()) {
return;
}

$this->hookActionCartUpdateQuantityBefore();
}

/**
* Add payment option at the checkout in the front office (prestashop 1.6)
*/
Expand Down Expand Up @@ -563,12 +482,10 @@ public function hookDisplayPayment()

$this->context->smarty->assign([
'cancelTranslatedText' => $this->l('Choose another payment method'),
'is17' => $shopContext->isShop17(),
'isExpressCheckout' => $isExpressCheckout,
'modulePath' => $this->getPathUri(),
'paymentOptions' => $paymentOptions,
'isHostedFieldsAvailable' => $configurationPayPal->isHostedFieldsEnabled() && in_array($configurationPayPal->getCardHostedFieldsStatus(), ['SUBSCRIBED', 'LIMITED'], true),
'isOnePageCheckout16' => !$shopContext->isShop17() && (bool) Configuration::get('PS_ORDER_PROCESS_TYPE'),
'spinnerPath' => $this->getPathUri() . 'views/img/tail-spin.svg',
'loaderTranslatedText' => $this->l('Please wait, loading additional payment methods.'),
'paypalLogoPath' => $this->getPathUri() . 'views/img/paypal_express.png',
Expand Down Expand Up @@ -770,15 +687,11 @@ public function hookDisplayAdminAfterHeader()
$paypalConfiguration = $this->getService(\PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration::class);
/** @var \PrestaShop\Module\PrestashopCheckout\Repository\PsAccountRepository $psAccount */
$psAccount = $this->getService(\PrestaShop\Module\PrestashopCheckout\Repository\PsAccountRepository::class);
/** @var \PrestaShop\Module\PrestashopCheckout\ShopContext $shopContext */
$shopContext = $this->getService(\PrestaShop\Module\PrestashopCheckout\ShopContext::class);
/** @var \PrestaShop\Module\PrestashopCheckout\Presenter\Store\Modules\ContextModule $moduleContext */
$moduleContext = $this->getService(\PrestaShop\Module\PrestashopCheckout\Presenter\Store\Modules\ContextModule::class);
$isShop17 = $shopContext->isShop17();
$isFullyOnboarded = $psAccount->onBoardingIsCompleted() && $paypalConfiguration->getMerchantId();

if ('AdminPayment' === Tools::getValue('controller') && $isShop17) {
// Display on PrestaShop 1.7.x.x only
if ('AdminPayment' === Tools::getValue('controller')) {
$moduleManager = \PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder::getInstance()->build();
if (in_array($this->getShopDefaultCountryCode(), ['FR', 'IT'])
&& $moduleManager->isEnabled('ps_checkout')
Expand All @@ -801,20 +714,18 @@ public function hookDisplayAdminAfterHeader()
$template = 'views/templates/hook/adminAfterHeader/promotionBlock.tpl';
} elseif ('AdminCountries' === Tools::getValue('controller') && $isFullyOnboarded) {
$params = [
'isShop17' => $isShop17,
'codesType' => 'countries',
'incompatibleCodes' => $paypalConfiguration->getIncompatibleCountryCodes(),
'paypalLink' => 'https://developer.paypal.com/docs/api/reference/country-codes/#',
'paymentPreferencesLink' => $moduleContext->getGeneratedLink($isShop17 ? 'AdminPaymentPreferences' : 'AdminPayment'),
'paymentPreferencesLink' => $moduleContext->getGeneratedLink('AdminPayment'),
];
$template = 'views/templates/hook/adminAfterHeader/incompatibleCodes.tpl';
} elseif ('AdminCurrencies' === Tools::getValue('controller') && $isFullyOnboarded) {
$params = [
'isShop17' => $isShop17,
'codesType' => 'currencies',
'incompatibleCodes' => $paypalConfiguration->getIncompatibleCurrencyCodes(),
'paypalLink' => 'https://developer.paypal.com/docs/api/reference/currency-codes/#',
'paymentPreferencesLink' => $moduleContext->getGeneratedLink($isShop17 ? 'AdminPaymentPreferences' : 'AdminPayment'),
'paymentPreferencesLink' => $moduleContext->getGeneratedLink('AdminPayment'),
];
$template = 'views/templates/hook/adminAfterHeader/incompatibleCodes.tpl';
} else {
Expand Down Expand Up @@ -1168,12 +1079,6 @@ public function hookActionFrontControllerSetMedia()
*/
public function addCheckboxCarrierRestrictionsForModule(array $shopsList = [])
{
/** @var \PrestaShop\Module\PrestashopCheckout\ShopContext $shopContext */
$shopContext = $this->getService(\PrestaShop\Module\PrestashopCheckout\ShopContext::class);
if (false === $shopContext->isShop17()) {
return true;
}

$shopsList = empty($shopsList) ? Shop::getShops(true, null, true) : $shopsList;
$carriersList = Carrier::getCarriers((int) Context::getContext()->language->id, false, false, false, null, Carrier::ALL_CARRIERS);
$allCarriers = array_column($carriersList, 'id_reference');
Expand Down Expand Up @@ -1468,9 +1373,6 @@ public function hookDisplayPaymentTop()
return '';
}

/** @var \PrestaShop\Module\PrestashopCheckout\ShopContext $shopContext */
$shopContext = $this->getService(\PrestaShop\Module\PrestashopCheckout\ShopContext::class);

/** @var \PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository $psCheckoutCartRepository */
$psCheckoutCartRepository = $this->getService(\PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository::class);

Expand All @@ -1481,9 +1383,7 @@ public function hookDisplayPaymentTop()

$this->context->smarty->assign([
'cancelTranslatedText' => $this->l('Choose another payment method'),
'is17' => $shopContext->isShop17(),
'isExpressCheckout' => $isExpressCheckout,
'isOnePageCheckout16' => !$shopContext->isShop17() && (bool) Configuration::get('PS_ORDER_PROCESS_TYPE'),
'spinnerPath' => $this->getPathUri() . 'views/img/tail-spin.svg',
'loaderTranslatedText' => $this->l('Please wait, loading additional payment methods.'),
'paypalLogoPath' => $this->getPathUri() . 'views/img/paypal_express.png',
Expand Down Expand Up @@ -1562,34 +1462,10 @@ public function hookDisplayPaymentByBinaries(array $params)
*/
private function getCheckoutPageUrl()
{
/** @var \PrestaShop\Module\PrestashopCheckout\ShopContext $shopContext */
$shopContext = $this->getService(\PrestaShop\Module\PrestashopCheckout\ShopContext::class);

if ($shopContext->isShop17()) {
return $this->context->link->getPageLink(
'order',
true,
(int) $this->context->language->id
);
}

// PrestaShop 1.6 legacy native one page checkout
if (1 === (int) Configuration::get('PS_ORDER_PROCESS_TYPE')) {
return $this->context->link->getPageLink(
'order-opc',
true,
(int) $this->context->language->id
);
}

// PrestaShop 1.6 standard checkout
return $this->context->link->getPageLink(
'order',
true,
(int) $this->context->language->id,
[
'step' => 1,
]
(int) $this->context->language->id
);
}

Expand Down
8 changes: 1 addition & 7 deletions src/Adapter/LanguageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ public function getLanguage($idLang)
{
$language = \Language::getLanguage($idLang);

if (false === $this->shopContext->isShop17()) {
$locale = explode('-', $language['language_code']);
$locale[1] = strtoupper($locale[1]);
$language['locale'] = implode('_', $locale);
} else {
$language['locale'] = str_replace('-', '_', $language['locale']);
}
$language['locale'] = str_replace('-', '_', $language['locale']);

return $language;
}
Expand Down
31 changes: 8 additions & 23 deletions src/Adapter/LinkAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,19 @@ public function __construct(\Link $link = null)
public function getAdminLink($controller, $withToken = true, $sfRouteParams = [], $params = [])
{
$shop = \Context::getContext()->shop;
/** @var \Ps_checkout $module */
$module = \Module::getInstanceByName('ps_checkout');
/** @var ShopContext $shopContext */
$shopContext = $module->getService(ShopContext::class);

if ($shopContext->isShop17()) {
$adminLink = $this->link->getAdminLink($controller, $withToken, $sfRouteParams, $params);
$adminLink = $this->link->getAdminLink($controller, $withToken, $sfRouteParams, $params);

if ($shop->virtual_uri !== '') {
$adminLink = str_replace($shop->physical_uri . $shop->virtual_uri, $shop->physical_uri, $adminLink);
}

// We have problems with links in our zoid application, since some links generated don't have domain they redirect to CDN domain
// Routes that use new symfony router are returned without the domain
if (strpos($adminLink, 'http') !== 0) {
return \Tools::getShopDomainSsl(true) . $adminLink;
}

return $adminLink;
if ($shop->virtual_uri !== '') {
$adminLink = str_replace($shop->physical_uri . $shop->virtual_uri, $shop->physical_uri, $adminLink);
}

$paramsAsString = '';
foreach ($params as $key => $value) {
$paramsAsString .= "&$key=$value";
// We have problems with links in our zoid application, since some links generated don't have domain they redirect to CDN domain
// Routes that use new symfony router are returned without the domain
if (strpos($adminLink, 'http') !== 0) {
return \Tools::getShopDomainSsl(true) . $adminLink;
}

$link = \Tools::getShopDomainSsl(true) . __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_) . '/' . $this->link->getAdminLink($controller, $withToken) . $paramsAsString;

return $shop->virtual_uri !== '' ? str_replace($shop->physical_uri . $shop->virtual_uri, $shop->physical_uri, $link) : $link;
return $adminLink;
}
}
11 changes: 2 additions & 9 deletions src/Handler/CreatePaypalOrderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,7 @@ public function handle($expressCheckout = false, $isCardPayment = false, $update
$builder->setPaypalOrderId($paypalOrderId);
}

if ($shopContext->isShop17()) {
// Build full payload in 1.7
$builder->buildFullPayload();
} else {
// if on 1.6 always build minimal payload
$builder->buildMinimalPayload();
}
$builder->buildFullPayload();

$payload = $builder->presentPayload()->getArray();

Expand All @@ -102,8 +96,7 @@ public function handle($expressCheckout = false, $isCardPayment = false, $update
} catch (PayPalException $exception) {
$previousException = $exception->getPrevious();
$response = method_exists($previousException, 'getResponse') ? $previousException->getResponse() : null;
// Retry with minimal payload when full payload failed (only on 1.7)
if ($response && substr((string) $response->getStatusCode(), 0, 1) === '4' && $shopContext->isShop17()) {
if ($response && substr((string) $response->getStatusCode(), 0, 1) === '4') {
$builder->buildMinimalPayload();
$payload = $builder->presentPayload()->getArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,7 @@ public function handle(CreatePayPalOrderCommand $command)
$builder->setSavePaymentMethod($command->vault());
$builder->setVault($command->getPaymentTokenId() || $command->vault());

if ($this->shopContext->isShop17()) {
// Build full payload in 1.7
$builder->buildFullPayload();
} else {
// if on 1.6 always build minimal payload
$builder->buildMinimalPayload();
}
$builder->buildFullPayload();

$response = $this->maaslandHttpClient->createOrder($builder->presentPayload()->getArray());
$order = json_decode($response->getBody(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,7 @@ public function __invoke(UpdatePayPalOrderCommand $command)
$builder->setIsCard($command->getFundingSource() === 'card' && $command->isHostedFields());
$builder->setExpressCheckout($command->isExpressCheckout());

if ($this->shopContext->isShop17()) {
// Build full payload in 1.7
$builder->buildFullPayload();
} else {
// if on 1.6 always build minimal payload
$builder->buildMinimalPayload();
}
$builder->buildFullPayload();

$payload = $builder->presentPayload()->getArray();
$needToUpdate = false;
Expand Down
1 change: 0 additions & 1 deletion src/PayPal/Order/PayPalOrderSummaryView.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public function getTemplateVars()
'approvalLink' => $this->orderPayPalDataProvider->getApprovalLink(),
'payerActionLink' => $this->orderPayPalDataProvider->getPayActionLink(),
'contactUsLink' => $this->router->getContactLink($this->orderDataProvider->getOrderId()),
'isShop17' => $this->shopContext->isShop17(),
'translations' => $this->orderPayPalPresenter->getSummaryTranslations(),
'vault' => $this->orderPayPalDataProvider->isIntentToVault(),
'tokenIdentifier' => $this->orderPayPalDataProvider->getPaymentTokenIdentifier(),
Expand Down
Loading

0 comments on commit 7f0e5b0

Please sign in to comment.