Skip to content

Commit

Permalink
Merge branch 'develop' into feature/ECP-9196-change-guest-shopperRefe…
Browse files Browse the repository at this point in the history
…rence-to-cartId
  • Loading branch information
ryan-lambert-IEX authored May 29, 2024
2 parents 1c1729f + a279d22 commit e2b96b1
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 15 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release

on:
# Manual run from Github UI (e.g. for when a merged PR labels have changed)
workflow_dispatch:
inputs:
pre-release:
required: false
type: boolean
default: false
description: "This release will be labeled as non-production ready"
# Publish the current version now, useful if the automated run failed
github-release:
required: false
type: boolean
default: false
description: "Publish Github release for the current version"
# Monitor pull request events

pull_request:
types:
- closed
branches:
- main

jobs:
release:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare the next main release
uses: Adyen/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
develop-branch: main
version-files: composer.json
release-title: Adyen Magento-2 Plugin
pre-release: ${{ inputs.pre-release || false }}
# For a manual Github release
github-release: ${{ inputs.github-release || false }}
separator: .pre.beta
23 changes: 21 additions & 2 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,28 @@ public function setConfigData(
$value,
string $field,
string $xmlPrefix,
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT
string $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
int $scopeId = 0
): void {
$path = implode("/", [self::XML_PAYMENT_PREFIX, $xmlPrefix, $field]);
$this->configWriter->save($path, $value, $scope);
$this->configWriter->save($path, $value, $scope, $scopeId);
}

/**
* Deletes config data
* @param string $field
* @param string $xmlPrefix
* @param string $scope
* @param int $scopeId
* @return void
*/
public function removeConfigData(
string $field,
string $xmlPrefix,
string $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
int $scopeId = 0
): void {
$path = implode("/", [self::XML_PAYMENT_PREFIX, $xmlPrefix, $field]);
$this->configWriter->delete($path, $scope, $scopeId);
}
}
22 changes: 20 additions & 2 deletions Helper/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function ($key) {
return array_keys($filtered);
}

public function togglePaymentMethodsActivation(?bool $isActive =null): array
public function togglePaymentMethodsActivation(?bool $isActive =null, string $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, int $scopeId = 0): array
{
$enabledPaymentMethods = [];

Expand All @@ -178,13 +178,31 @@ public function togglePaymentMethodsActivation(?bool $isActive =null): array

$value = $isActive ? '1': '0';
$field = 'active';
$this->configHelper->setConfigData($value, $field, $paymentMethod);
$this->configHelper->setConfigData($value, $field, $paymentMethod, $scope, $scopeId);
$enabledPaymentMethods[] = $paymentMethod;
}

return $enabledPaymentMethods;
}

/**
* Remove activation config
* @param string $scope
* @param int $scopeId
* @return void
*/
public function removePaymentMethodsActivation(string $scope, int $scopeId) : void
{
foreach ($this->getAdyenPaymentMethods() as $paymentMethod)
{
if (in_array($paymentMethod, self::EXCLUDED_PAYMENT_METHODS)) {
continue;
}

$this->configHelper->removeConfigData('active', $paymentMethod, $scope, $scopeId);
}
}

protected function fetchPaymentMethods(?string $country = null, ?string $shopperLocale = null): string
{
$quote = $this->getQuote();
Expand Down
2 changes: 1 addition & 1 deletion Helper/Webhook/WebhookHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(
RequestForInformationWebhookHandler $requestForInformationWebhookHandler,
ChargebackReversedWebhookHandler $chargebackReversedWebhookHandler,
SecondChargebackWebhookHandler $secondChargebackWebhookHandler,
NotificationOfChargebackWebhookHandler $notificationOfChargebackWebhookHandler,
NotificationOfChargebackWebhookHandler $notificationOfChargebackWebhookHandler
) {
$this->adyenLogger = $adyenLogger;
$this->authorisationWebhookHandler = $authorisationWebhookHandler;
Expand Down
18 changes: 16 additions & 2 deletions Model/Config/Backend/PaymentMethodsStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,22 @@ public function __construct(

public function afterSave(): PaymentMethodsStatus
{
$this->paymentMethodsHelper->togglePaymentMethodsActivation((bool) $this->getValue());
$this->paymentMethodsHelper->togglePaymentMethodsActivation(
(bool) $this->getValue(),
$this->getScope(),
$this->getScopeId()
);

return $this;
return parent::afterSave();
}

/**
* @inheritDoc
* @return PaymentMethodsStatus
*/
public function afterDelete() : PaymentMethodsStatus
{
$this->paymentMethodsHelper->removePaymentMethodsActivation($this->getScope(), $this->getScopeId());
return parent::afterDelete();
}
}
21 changes: 21 additions & 0 deletions Test/Unit/Helper/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,25 @@ public function testGetAdyenPosCloudPaymentAction()

$this->assertEquals($expectedResult, $result);
}

public function testSetConfigData()
{
$value = 'TEST_VALUE';
$field = 'test_path';
$xml_prefix = Config::XML_ADYEN_ABSTRACT_PREFIX;

$this->configWriterMock->expects($this->once())->method('save');

$this->configHelper->setConfigData($value, $field, $xml_prefix);
}

public function testRemoveConfigData()
{
$field = 'test_path';
$xml_prefix = Config::XML_ADYEN_ABSTRACT_PREFIX;

$this->configWriterMock->expects($this->once())->method('delete');

$this->configHelper->removeConfigData($field, $xml_prefix);
}
}
14 changes: 14 additions & 0 deletions Test/Unit/Helper/PaymentMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\AdyenAmountCurrency;
use Adyen\Payment\Model\Notification;
use Adyen\Payment\Model\Ui\AdyenCcConfigProvider;
use Adyen\Payment\Model\Ui\AdyenPayByLinkConfigProvider;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Adyen\Service\Checkout;
use Magento\Framework\App\Config\ScopeConfigInterface;
Expand Down Expand Up @@ -1339,4 +1341,16 @@ public function testShowLogosPaymentMethods()
$this->assertArrayHasKey('icon', $result['visa']);
$this->assertArrayHasKey('isOpenInvoice', $result['visa']);
}

public function testRemovePaymentMethodsActivation()
{
$this->dataHelperMock->method('getPaymentMethodList')->willReturn([
AdyenCcConfigProvider::CODE => 'Card',
AdyenPayByLinkConfigProvider::CODE => 'Pay by Link'
]);

$this->configHelperMock->expects($this->atLeastOnce())->method('removeConfigData');

$this->paymentMethodsHelper->removePaymentMethodsActivation('default', 0);
}
}
54 changes: 46 additions & 8 deletions Test/Unit/Model/Config/Backend/PaymentMethodsStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
use Adyen\Payment\Helper\PaymentMethods;
use Adyen\Payment\Model\Config\Backend\PaymentMethodsStatus;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;

class PaymentMethodsStatusTest extends AbstractAdyenTestCase
{
Expand All @@ -23,18 +29,50 @@ class PaymentMethodsStatusTest extends AbstractAdyenTestCase
'adyen_ideal'
];

private $paymentMethodsStatusMock;
private $paymentMethodsHelperMock;

public function setUp(): void
{
parent::setUp();

$this->paymentMethodsHelperMock = $this->createMock(PaymentMethods::class);
$this->paymentMethodsStatusMock = $this->getMockBuilder(PaymentMethodsStatus::class)
->setMethods([
'getScope',
'getScopeId'
])
->setConstructorArgs([
$this->createConfiguredMock(Context::class, [
'getEventDispatcher' => $this->createMock(ManagerInterface::class)
]),
$this->createMock(Registry::class),
$this->createMock(ScopeConfigInterface::class),
$this->createMock(TypeListInterface::class),
$this->paymentMethodsHelperMock,
$this->createMock(AbstractResource::class),
$this->createMock(AbstractDb::class),
[]
])
->getMock();

$this->paymentMethodsStatusMock->method('getScope')->willReturn('default');
$this->paymentMethodsStatusMock->method('getScopeId')->willReturn(0);
}

public function testAfterSave()
{
$paymentMethodsHelperMock = $this->createMock(PaymentMethods::class);
$paymentMethodsHelperMock->method('togglePaymentMethodsActivation')
$this->paymentMethodsHelperMock->method('togglePaymentMethodsActivation')
->willReturn(self::ENABLED_METHODS);

$objectManager = new ObjectManager($this);
$paymentMethodsStatus = $objectManager->getObject(PaymentMethodsStatus::class, [
'paymentMethodsHelper' => $paymentMethodsHelperMock
]);
$result = $this->paymentMethodsStatusMock->afterSave();

$result = $paymentMethodsStatus->afterSave();
$this->assertInstanceOf(PaymentMethodsStatus::class, $result);
}

public function testAfterDelete()
{
$result = $this->paymentMethodsStatusMock->afterDelete();

$this->assertInstanceOf(PaymentMethodsStatus::class, $result);
}
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9.5.2

0 comments on commit e2b96b1

Please sign in to comment.