Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarBoljanovic committed Mar 11, 2024
2 parents 0b3fe65 + 8fda417 commit 8088e92
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/adyenofficial.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct()
{
$this->name = 'adyenofficial';
$this->tab = 'payments_gateways';
$this->version = '5.1.11';
$this->version = '5.1.12';

$this->author = $this->l('Adyen');
$this->need_instance = 0;
Expand Down
64 changes: 30 additions & 34 deletions src/classes/Utility/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class Installer
/** @var string */
private const ADYEN_QUEUE = 'adyen_queue';
/** @var string */
private const PENDING_STATE = 'Pending';
/** @var string */
private const PARTIALLY_REFUNDED_STATE = 'Partially refunded';
/** @var string */
private const CHARGEBACK_STATE = 'Chargeback';
Expand Down Expand Up @@ -207,7 +205,6 @@ public function addControllersAndHooks(): void
*/
public function deactivateCustomOrderStates(): void
{
$this->deactivateCustomOrderState(self::PENDING_STATE);
$this->deactivateCustomOrderState(self::PARTIALLY_REFUNDED_STATE);
$this->deactivateCustomOrderState(self::CHARGEBACK_STATE);
}
Expand All @@ -232,11 +229,40 @@ public function deactivateOldCustomOrderStates(): void
*/
public function activateCustomOrderStates(): void
{
$this->addCustomOrderState(self::PENDING_STATE, '#4169E1');
$this->addCustomOrderState(self::PARTIALLY_REFUNDED_STATE, '#6F8C9F');
$this->addCustomOrderState(self::CHARGEBACK_STATE, '#E74C3C');
}

/**
* @param string $name
*
* @return bool
*
* @throws PrestaShopException
* @throws PrestaShopDatabaseException
* @throws Exception
*/
public function deactivateCustomOrderState(string $name): void
{
$statusId = $this->getAllPrestaShopStatuses()[$name] ?? null;

if (!$statusId) {
return;
}

$orderState = new OrderState($statusId);

if ($orderState->module_name === $this->module->name) {
$orderState->deleted = true;

$success = $orderState->update();

if (!$success) {
throw new Exception('Adyen plugin failed to delete order state: ' . $name);
}
}
}

/**
* @return void
*
Expand Down Expand Up @@ -461,36 +487,6 @@ private function addCustomOrderState(string $name, string $color): void
}
}

/**
* @param string $name
*
* @return bool
*
* @throws PrestaShopException
* @throws PrestaShopDatabaseException
* @throws Exception
*/
private function deactivateCustomOrderState(string $name): void
{
$statusId = $this->getAllPrestaShopStatuses()[$name] ?? null;

if (!$statusId) {
return;
}

$orderState = new OrderState($statusId);

if ($orderState->module_name === $this->module->name) {
$orderState->deleted = true;

$success = $orderState->update();

if (!$success) {
throw new Exception('Adyen plugin failed to delete order state: ' . $name);
}
}
}

/**
* Drop database tables for Adyen.
*
Expand Down
2 changes: 1 addition & 1 deletion src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"php": "^7.2|^7.4|^8.0",
"ext-json": "*",
"ext-zip": "*",
"adyen/integration-core": "1.1.10",
"adyen/integration-core": "1.1.11",
"ext-simplexml": "*",
"ext-openssl": "*"
},
Expand Down
12 changes: 6 additions & 6 deletions src/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions src/upgrade/upgrade-5.1.12.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use Adyen\Core\Infrastructure\Logger\Logger;
use AdyenPayment\Classes\Bootstrap;

if (!defined('_PS_VERSION_')) {
exit;
}

require_once 'Autoloader.php';

/**
* Upgrades module to version 5.1.12.
*
* @param AdyenOfficial $module
*
* @return bool
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @throws Exception
*/
function upgrade_module_5_1_12(AdyenOfficial $module): bool
{
Autoloader::setFileExt('.php');
spl_autoload_register('Autoloader::loader');
Shop::setContext(ShopCore::CONTEXT_ALL);
$installer = new \AdyenPayment\Classes\Utility\Installer($module);
$pendingState = 'Pending';

Bootstrap::init();
try {
$installer->deactivateCustomOrderState($pendingState);
} catch (Throwable $exception) {
Logger::logError(
'Adyen plugin migration to 5.1.12 failed. Reason: ' .
$exception->getMessage() . ' .Trace: ' . $exception->getTraceAsString()
);

return false;
}

return true;
}
2 changes: 1 addition & 1 deletion src/upgrade/upgrade-5.1.9.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require_once 'Autoloader.php';

/**
* Upgrades module to version 5.0.0.
* Upgrades module to version 5.1.9.
*
* @param AdyenOfficial $module
*
Expand Down
6 changes: 0 additions & 6 deletions src/views/js/SettingsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ if (!window.AdyenFE) {
/**
* @typedef OrderStatusMappingSettings
* @property {string | null} inProgress
* @property {string | null} pending
* @property {string | null} paid
* @property {string | null} failed
* @property {string | null} refunded
* @property {string | null} cancelled
* @property {string | null} partiallyRefunded
* @property {string | null} new
* @property {string | null} chargeBack
*/

Expand Down Expand Up @@ -309,13 +307,11 @@ if (!window.AdyenFE) {
/** @type {OrderStatusMappingSettings} */
mappings = {
inProgress: null,
pending: null,
paid: null,
failed: null,
refunded: null,
partiallyRefunded: null,
cancelled: null,
new: null,
chargeBack: null
};
}
Expand All @@ -340,7 +336,6 @@ if (!window.AdyenFE) {
true,
generator.createFormFields([
getDropdownField('inProgress', mappings, 'orderStatusMapping', orderStatuses),
getDropdownField('pending', mappings, 'orderStatusMapping', orderStatuses),
getDropdownField('paid', mappings, 'orderStatusMapping', orderStatuses),
getDropdownField('failed', mappings, 'orderStatusMapping', orderStatuses),
getDropdownField('refunded', mappings, 'orderStatusMapping', orderStatuses),
Expand All @@ -352,7 +347,6 @@ if (!window.AdyenFE) {
orderStatuses,
'adlm--turned'
),
getDropdownField('new', mappings, 'orderStatusMapping', orderStatuses, 'adlm--turned'),
getDropdownField(
'chargeBack',
mappings,
Expand Down
14 changes: 2 additions & 12 deletions src/views/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,12 @@
"fields": {
"inProgress": {
"label": "In progress",
"description": "The Adyen payment status <strong>In progress</strong> should represent the following shop status:",
"placeholder": "Select status"
},
"pending": {
"label": "Pending",
"description": "The Adyen payment status <strong>Pending</strong> should represent the following shop status:",
"description": "The Adyen payment status <strong>In progress</strong>. This status is assigned when an order is initially created during the checkout process. Should represent the following shop status:",
"placeholder": "Select status"
},
"paid": {
"label": "Paid",
"description": "The Adyen payment status <strong>Paid</strong> should represent the following shop status:",
"description": "The Adyen payment status <strong>Paid</strong>. This status is assigned when an order is authorised on Adyen. Should represent the following shop status:",
"placeholder": "Select status"
},
"failed": {
Expand All @@ -505,11 +500,6 @@
"description": "The Adyen payment status <strong>Partially refunded</strong> should represent the following shop status:",
"placeholder": "Select status"
},
"new": {
"label": "New",
"description": "The Adyen payment status <strong>New</strong> should represent the following shop status:",
"placeholder": "Select status"
},
"chargeBack": {
"label": "Charge back",
"description": "The Adyen payment status <strong>Charge back</strong> should represent the following shop status:",
Expand Down

0 comments on commit 8088e92

Please sign in to comment.