Skip to content

Commit

Permalink
Merge branch 'main' into ECP-9423
Browse files Browse the repository at this point in the history
  • Loading branch information
SushmitaThakur authored Sep 30, 2024
2 parents acb875d + 4b98628 commit 75370d1
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 52 deletions.
8 changes: 4 additions & 4 deletions .github/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ DB_NAME=magento \
DB_USER=magento \
DB_PASSWORD=magento \
DB_PREFIX=m2_ \
ELASTICSEARCH_SERVER="<will be defined>" \
ELASTICSEARCH_PORT=9200 \
ELASTICSEARCH_INDEX_PREFIX=magento2 \
ELASTICSEARCH_TIMEOUT=15 \
OPENSEARCH_SERVER="<will be defined>" \
OPENSEARCH_PORT=9200 \
OPENSEARCH_INDEX_PREFIX=magento2 \
OPENSEARCH_TIMEOUT=15 \
ADMIN_NAME=admin \
ADMIN_LASTNAME=admin \
[email protected] \
Expand Down
1 change: 0 additions & 1 deletion .github/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ setup-mftf:
--MAGENTO_BASE_URL "https://${MAGENTO_HOST}/" \
--MAGENTO_BACKEND_NAME "${ADMIN_URLEXT}" \
--MAGENTO_ADMIN_USERNAME "${ADMIN_USERNAME}" \
--MAGENTO_ADMIN_PASSWORD "${ADMIN_PASSWORD}" \
--BROWSER chrome \
--ELASTICSEARCH_VERSION 7;
echo 'SELENIUM_HOST=selenium' >> dev/tests/acceptance/.env;
Expand Down
2 changes: 1 addition & 1 deletion .github/docker-compose.e2e.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
playwright:
image: mcr.microsoft.com/playwright:v1.47.0
image: mcr.microsoft.com/playwright:v1.47.2
shm_size: 1gb
ipc: host
cap_add:
Expand Down
10 changes: 5 additions & 5 deletions .github/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ services:
MARIADB_DATABASE: magento
MARIADB_USER: magento
MARIADB_PASSWORD: magento
elastic:
image: elasticsearch:7.17.22
container_name: elasticsearch
opensearch:
image: bitnami/opensearch:2
container_name: opensearch-container
networks:
- backend
ports:
Expand All @@ -37,7 +37,7 @@ services:
- magento2.test.com
environment:
DB_SERVER: mariadb
ELASTICSEARCH_SERVER: elasticsearch
OPENSEARCH_SERVER: opensearch-container
MAGENTO_HOST: magento2.test.com
VIRTUAL_HOST: magento2.test.com
COMPOSER_MEMORY_LIMIT: -1
Expand All @@ -52,7 +52,7 @@ services:
MAGENTO_VERSION:
depends_on:
- db
- elastic
- opensearch
volumes:
- ../:/data/extensions/workdir
- ./Makefile:/var/www/html/Makefile
Expand Down
24 changes: 10 additions & 14 deletions .github/scripts/install_magento.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,25 @@ else
exit 1
fi

USE_ELASTICSEARCH='1'
if [[ "$MAGENTO_VERSION" =~ ^2\.3 ]]; then
USE_ELASTICSEARCH='0'
fi

if [ "$USE_ELASTICSEARCH" == '1' ] && [ "$ELASTICSEARCH_SERVER" != "<will be defined>" ]; then
if [ "$OPENSEARCH_SERVER" != "<will be defined>" ]; then
MAGENTO_INSTALL_ARGS=$(echo \
--elasticsearch-host="$ELASTICSEARCH_SERVER" \
--elasticsearch-port="$ELASTICSEARCH_PORT" \
--elasticsearch-index-prefix="$ELASTICSEARCH_INDEX_PREFIX" \
--elasticsearch-timeout="$ELASTICSEARCH_TIMEOUT")
--search-engine="opensearch" \
--opensearch-host="$OPENSEARCH_SERVER" \
--opensearch-port="$OPENSEARCH_PORT" \
--opensearch-index-prefix="$OPENSEARCH_INDEX_PREFIX" \
--opensearch-timeout="$OPENSEARCH_TIMEOUT")
RET=1
while [ $RET -ne 0 ]; do
echo "Checking if $ELASTICSEARCH_SERVER is available."
curl -XGET "$ELASTICSEARCH_SERVER:$ELASTICSEARCH_PORT/_cat/health?v&pretty" >/dev/null 2>&1
echo "Checking if $OPENSEARCH_SERVER is available."
curl -XGET "$OPENSEARCH_SERVER:$OPENSEARCH_PORT/_cat/health?v&pretty" >/dev/null 2>&1
RET=$?

if [ $RET -ne 0 ]; then
echo "Connection to Elasticsearch is pending."
echo "Connection to OpenSearch is pending."
sleep 5
fi
done
echo "Elasticsearch server $ELASTICSEARCH_SERVER is available."
echo "OpenSearch server $OPENSEARCH_SERVER is available."
fi

if [[ -e /tmp/magento.tar.gz ]]; then
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/e2e-test-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
labels: ubuntu-latest-8-cores
timeout-minutes: 25
env:
PHP_VERSION: "8.1"
MAGENTO_VERSION: "2.4.5"
PHP_VERSION: "8.3"
MAGENTO_VERSION: "2.4.7-p2"
ADYEN_API_KEY: ${{secrets.ADYEN_API_KEY}}
ADYEN_CLIENT_KEY: ${{secrets.ADYEN_CLIENT_KEY}}
ADYEN_MERCHANT: ${{secrets.ADYEN_MERCHANT}}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/e2e-test-express-checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
labels: ubuntu-latest-8-cores
timeout-minutes: 20
env:
PHP_VERSION: "8.1"
MAGENTO_VERSION: "2.4.5"
PHP_VERSION: "8.3"
MAGENTO_VERSION: "2.4.7-p2"
ADYEN_API_KEY: ${{secrets.ADYEN_API_KEY}}
ADYEN_CLIENT_KEY: ${{secrets.ADYEN_CLIENT_KEY}}
ADYEN_MERCHANT: ${{secrets.ADYEN_MERCHANT}}
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ jobs:
build:
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository)
environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }}
strategy:
matrix:
php-version: ["8.3"]
magento-version: ["2.4.7-p2"]
runs-on:
group: larger-runners
labels: ubuntu-latest-8-cores
timeout-minutes: 25
env:
PHP_VERSION: "8.1"
MAGENTO_VERSION: "2.4.5"
PHP_VERSION: ${{ matrix.php-version }}
MAGENTO_VERSION: ${{ matrix.magento-version }}
ADYEN_API_KEY: ${{secrets.ADYEN_API_KEY}}
ADYEN_CLIENT_KEY: ${{secrets.ADYEN_CLIENT_KEY}}
ADYEN_MERCHANT: ${{secrets.ADYEN_MERCHANT}}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/graphql-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }}
strategy:
matrix:
php-version: ["8.1"]
magento-version: ["2.4.5"]
php-version: ["8.2"]
magento-version: ["2.4.6-p7"]
runs-on: ubuntu-latest
env:
PHP_VERSION: ${{ matrix.php-version }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/mftf-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
strategy:
matrix:
include:
- php-version: '8.1'
magento-version: '2.4.5'
- php-version: '8.3'
magento-version: '2.4.7-p2'
runs-on: ubuntu-latest
env:
PHP_VERSION: ${{ matrix.php-version }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/restapi-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }}
strategy:
matrix:
php-version: ["8.1"]
magento-version: ["2.4.5"]
php-version: [8.3]
magento-version: [2.4.7-p2]
runs-on: ubuntu-latest
env:
PHP_VERSION: ${{ matrix.php-version }}
Expand Down
6 changes: 5 additions & 1 deletion Cron/WebhookProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public function doProcessWebhook()

// Loop through and process notifications.
$count = 0;
$queued = 0;

/** @var Notification[] $notifications */
foreach ($notifications as $notification) {
// ignore duplicate notification
Expand Down Expand Up @@ -128,6 +130,7 @@ public function doProcessWebhook()

if ($this->configHelper->useQueueProcessor()) {
$this->notificationPublisher->execute($notification);
$queued++;
$count++;
} elseif ($this->webhookHelper->processNotification($notification)) {
$count++;
Expand All @@ -139,7 +142,8 @@ public function doProcessWebhook()
"Cronjob updated %s notification(s)", $count
), [
'pspReference' => $notification->getPspreference(),
'merchantReference' => $notification->getMerchantReference()
'merchantReference' => $notification->getMerchantReference(),
'queued' => $queued
]);
}
}
Expand Down
20 changes: 17 additions & 3 deletions Model/Queue/Notification/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,43 @@
namespace Adyen\Payment\Model\Queue\Notification;

use Adyen\Payment\Api\Data\NotificationInterface;
use Adyen\Payment\Model\ResourceModel\Notification;
use Exception;
use Magento\Framework\MessageQueue\PublisherInterface;

class Publisher
{
private const TOPIC_NAME = "adyen.notification";
public const TOPIC_NAME = "adyen.notification";

/** @var PublisherInterface $publisher */
private $publisher;

/** @var Notification $notificationResource */
private $notificationResource;

/**
* @param PublisherInterface $publisher
* @param Notification $notificationResource
*/
public function __construct(PublisherInterface $publisher)
{
public function __construct(
PublisherInterface $publisher,
Notification $notificationResource
) {
$this->publisher = $publisher;
$this->notificationResource = $notificationResource;
}

/**
* @param NotificationInterface $notification
* @return void
* @throws Exception
*/
public function execute(NotificationInterface $notification): void
{
// Set processing=true to skip adding duplicate queue entries
$notification->setProcessing(true);
$this->notificationResource->save($notification);

$this->publisher->publish(self::TOPIC_NAME, $notification);
}
}
6 changes: 2 additions & 4 deletions Model/Resolver/StoreConfig/StoreLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\GraphQl\Model\Query\Context;
use Magento\Store\Api\Data\StoreInterface;
use Reflet\GraphQlFaker\Attribute\FakeResolver;
use Reflet\GraphQlFaker\Model\Resolver\NullResolver;

class StoreLocale implements ResolverInterface
{
protected Data $dataHelper;
protected Data $adyenHelper;

/**
* @param Data $adyenHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
Data $adyenHelper
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The schedule for the current maintained branches is:
| Plugin Major Version | Release Date | Level 1 Support ends | Level 2 Support ends | Level 3 Support ends |
| :----- |:--------------|:---------------------|:---------------------|:---------------------|
| Version 8 | November 2021 | January 2024 | May 2024 | January 2025 |
| Version 9 | October 2023 | -- | -- | -- |
| Version 9 | October 2023 | December 2025 | May 2026 | December 2026 |

Or, visualised as a calendar:

Expand Down
67 changes: 67 additions & 0 deletions Test/Unit/Model/Queue/Notification/ConsumerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Adyen\Payment\Test\Unit\Model\Queue\Notification;

use Adyen\Payment\Helper\Webhook;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\Notification;
use Adyen\Payment\Model\Queue\Notification\Consumer;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;

class ConsumerTest extends AbstractAdyenTestCase
{
/** @var Webhook|MockObject $webhookMock */
private $webhookMock;

/** @var AdyenLogger|MockObject $adyenLoggerMock */
private $adyenLoggerMock;

/** @var Notification|MockObject $notificationMock */
private $notificationMock;

/** @var Consumer $consumer */
private $consumer;

/**
* @return void
*/
protected function setUp(): void
{
$this->webhookMock = $this->createMock(Webhook::class);
$this->adyenLoggerMock = $this->createMock(AdyenLogger::class);
$this->notificationMock = $this->createMock(Notification::class);
$this->consumer = new Consumer($this->webhookMock, $this->adyenLoggerMock);
}

/**
* @return void
* @throws Exception
*/
public function testExecute(): void
{
$this->webhookMock->expects($this->once())
->method('processNotification')
->with($this->notificationMock)
->willReturn(true);

$this->assertTrue($this->consumer->execute($this->notificationMock));
}

/**
* @return void
* @throws Exception
*/
public function testExecuteThrowsException(): void
{
$this->webhookMock->expects($this->once())
->method('processNotification')
->with($this->notificationMock)
->willThrowException(new Exception());
$this->adyenLoggerMock->expects($this->once())->method('addAdyenWarning');

$this->expectException(Exception::class);
$this->consumer->execute($this->notificationMock);
}
}
31 changes: 31 additions & 0 deletions Test/Unit/Model/Queue/Notification/PublisherTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Adyen\Payment\Test\Unit\Model\Queue\Notification;

use Adyen\Payment\Model\Notification;
use Adyen\Payment\Model\Queue\Notification\Publisher;
use Adyen\Payment\Model\ResourceModel\Notification as NotificationResourceModel;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Exception;
use Magento\Framework\MessageQueue\PublisherInterface;

class PublisherTest extends AbstractAdyenTestCase
{
/**
* @return void
* @throws Exception
*/
public function testExecute(): void
{
$publisherMock = $this->createMock(PublisherInterface::class);
$notificationResourceMock = $this->createMock(NotificationResourceModel::class);
$notificationMock = $this->createMock(Notification::class);

$notificationMock->expects($this->once())->method('setProcessing')->with(true);
$notificationResourceMock->expects($this->once())->method('save')->with($notificationMock);
$publisherMock->expects($this->once())->method('publish')->with(Publisher::TOPIC_NAME, $notificationMock);

$publisher = new Publisher($publisherMock, $notificationResourceMock);
$publisher->execute($notificationMock);
}
}
2 changes: 1 addition & 1 deletion etc/adminhtml/system/adyen_testing_performance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<label>Webhook processor</label>
<source_model>Adyen\Payment\Model\Config\Source\NotificationProcessor</source_model>
<config_path>payment/adyen_abstract/webhook_notification_processor</config_path>
<comment>Use cron or queue (async) to process webhook notifications</comment>
<comment>Use cron or queue (async) to process webhook notifications. Queue performs better if you have AMQP service installed, like RabbitMQ.</comment>
</field>
<field id="notifications_ip_check" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Check webhook's IP address</label>
Expand Down
1 change: 0 additions & 1 deletion etc/queue_consumer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/consumer.xsd">
<consumer name="adyen.notification"
queue="adyen.notification"
connection="amqp"
handler="Adyen\Payment\Model\Queue\Notification\Consumer::execute"/>
</config>
Loading

0 comments on commit 75370d1

Please sign in to comment.