Skip to content

Commit

Permalink
Merge pull request #2317 from Adyen/develop-8
Browse files Browse the repository at this point in the history
Release 8.22.3
  • Loading branch information
RokPopov authored Nov 3, 2023
2 parents 161eba2 + 28a79d7 commit 0eab1b4
Show file tree
Hide file tree
Showing 17 changed files with 254 additions and 70 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Magento 2 E2E Pipeline
run-name: E2E tests for Adyen Magento2 Plugin
name: Magento 2 V8 E2E Pipeline
run-name: --V8-- E2E tests for Adyen Magento2 Plugin

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches-ignore: [main]
branches-ignore: [main, main-8]

jobs:
build:
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Run E2E tests
run: docker-compose -f .github/workflows/templates/docker-compose.yml run --rm playwright /e2e.sh
env:
INTEGRATION_TESTS_BRANCH: develop
INTEGRATION_TESTS_BRANCH: develop-8
MAGENTO_ADMIN_USERNAME: ${{secrets.MAGENTO_ADMIN_USERNAME}}
MAGENTO_ADMIN_PASSWORD: ${{secrets.MAGENTO_ADMIN_PASSWORD}}
MAGENTO_BASE_URL: ${{secrets.MAGENTO_BASE_URL}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mftf-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Functional Tests
on:
workflow_dispatch:
pull_request:
branches: [main]
branches: [main-8]

jobs:
build:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test-repo-e2e-release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Magento 2 Release E2E Pipeline
run-name: E2E tests against Test Repository with Express Checkout
name: Magento 2 V8 Release E2E Pipeline
run-name: --V8-- E2E tests against Test Repository with Express Checkout

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches: [main]
branches: [main-8]

jobs:
build:
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Run E2E tests
run: docker-compose -f .github/workflows/templates/docker-compose.yml run --rm playwright /e2e-all.sh
env:
INTEGRATION_TESTS_BRANCH: develop
INTEGRATION_TESTS_BRANCH: develop-8
MAGENTO_ADMIN_USERNAME: ${{secrets.MAGENTO_ADMIN_USERNAME}}
MAGENTO_ADMIN_PASSWORD: ${{secrets.MAGENTO_ADMIN_PASSWORD}}
MAGENTO_BASE_URL: ${{secrets.MAGENTO_BASE_URL}}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-repo-e2e.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Integration Test Repository Dispatch Pipeline
run-name: E2E tests against Test Repository ${{inputs.testBranch}} with Express Checkout ${{inputs.expressBranch}}
name: Adyen Payment Plugin V8 Integration Test Dispatch Pipeline
run-name: --V8-- E2E tests against Test Repository ${{inputs.testBranch}} with Express Checkout ${{inputs.expressBranch}}

on:
workflow_dispatch:
inputs:
testBranch:
description: "Integration Test Repository Pipeline"
required: true
default: "develop"
default: "develop-8"
expressBranch:
description: "Express Checkout Repository Pipeline"
required: true
Expand Down
10 changes: 9 additions & 1 deletion Controller/Process/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,15 @@ private function loadNotificationFromRequest(Notification $notification, array $

// do this to set both fields in the correct timezone
$date = new DateTime();
$notification->setCreatedAt($date);
if (isset($requestItem['eventDate'])) {
$eventDate = DateTime::createFromFormat(DATE_ATOM, $requestItem['eventDate']);
// Change webhook's timezone to server's timezone
if ($eventDate) {
$formattedEventDate = $eventDate->setTimezone($date->getTimezone());
}
}

$notification->setCreatedAt($formattedEventDate ?? $date);
$notification->setUpdatedAt($date);
}

Expand Down
130 changes: 91 additions & 39 deletions Cron/Providers/PayByLinkExpiredPaymentOrdersProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,30 @@

namespace Adyen\Payment\Cron\Providers;

use Adyen\Payment\Api\Data\OrderPaymentInterface;
use Adyen\Payment\Helper\PaymentMethods;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\Ui\AdyenPayByLinkConfigProvider;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\Search\FilterGroupBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\Exception\InputException;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderPaymentRepositoryInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;

class PayByLinkExpiredPaymentOrdersProvider implements OrdersProviderInterface
{
/**
* @var CollectionFactory $orderCollectionFactory
*/
protected $orderRepository;
/**
* @var CollectionFactory $orderCollectionFactory
*/
protected $orderPaymentRepository;
/**
* @var AdyenLogger $adyenLogger
*/
Expand All @@ -44,26 +52,22 @@ class PayByLinkExpiredPaymentOrdersProvider implements OrdersProviderInterface
*/
private $filterGroupBuilder;

/**
* ServerIpAddress constructor.
* @param OrderRepositoryInterface $orderRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param FilterBuilder $filterBuilder
* @param FilterGroupBuilder $filterGroupBuilder
*/
public function __construct(
OrderRepositoryInterface $orderRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
FilterBuilder $filterBuilder,
FilterGroupBuilder $filterGroupBuilder
) {
OrderRepositoryInterface $orderRepository,
OrderPaymentRepositoryInterface $orderPaymentRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
FilterBuilder $filterBuilder,
FilterGroupBuilder $filterGroupBuilder
)
{
$this->orderRepository = $orderRepository;
$this->orderPaymentRepository = $orderPaymentRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->filterBuilder = $filterBuilder;
$this->filterGroupBuilder = $filterGroupBuilder;
}

public function getProviderName()
public function getProviderName(): string
{
return "Adyen Pay by Link expired";
}
Expand All @@ -72,49 +76,97 @@ public function getProviderName()
* Provides orders paid with PBL in state new that have expired
*
* @return OrderInterface[]
* @throws InputException
*/
public function provide()
public function provide(): array
{
$searchCriteria = $this->searchCriteriaBuilder
->setFilterGroups([$this->getStateFilterGroup()])
->create();
$expiredOrderIds = $this->getExpiredOrderIds();

$orders = $this->orderRepository->getList($searchCriteria)->getItems();
return $this->getExpiredOrders($expiredOrderIds);
}

return $this->getOrdersWithExpiredPbl($orders);
/**
* @retrun int[]
* @throws InputException
*/
protected function getExpiredOrderIds(): array
{
$orderPayments = $this->getPendingPayByLinkPayments();
$expiredOrderIds = [];
$now = new \DateTime();

foreach ($orderPayments as $orderPayment) {
/** @var OrderPaymentInterface $orderPayment */
$paymentAdditionalInformation = $orderPayment->getAdditionalInformation();
$pblExpiryDateString = $paymentAdditionalInformation[AdyenPayByLinkConfigProvider::EXPIRES_AT_KEY] ?? false;

if ($pblExpiryDateString) {
$pblExpiryDate = \DateTime::createFromFormat(DATE_ATOM, $pblExpiryDateString);
if ($now > $pblExpiryDate) {
$expiredOrderIds[] = $orderPayment->getParentId();
}
}

}
return $expiredOrderIds;
}

/**
* @return \Magento\Framework\Api\Search\FilterGroup
* @return OrderInterface[]
* @throws InputException
*/
private function getStateFilterGroup()
protected function getExpiredOrders($expiredOrderIds): array
{
$sortOrder = new SortOrder();
$sortOrder->setField(OrderInterface::CREATED_AT)->setDirection('ASC');

$stateFilter = $this->filterBuilder->setField('state')
->setConditionType('eq')
->setValue(Order::STATE_NEW)
->create();

return $this->filterGroupBuilder->setFilters([$stateFilter])->create();
$orderIdFilter = $this->filterBuilder->setField('state')
->setConditionType('in')
->setValue($expiredOrderIds)
->create();

$filterGroup = $this->filterGroupBuilder->setFilters([$stateFilter, $orderIdFilter])->create();

$searchCriteria = $this->searchCriteriaBuilder
->setFilterGroups([$filterGroup])
->setSortOrders([$sortOrder])
->setPageSize(500)
->create();

return $this->orderRepository->getList($searchCriteria)->getItems();
}

/**
* @param $orders OrderInterface[]
* @return OrderInterface[]
* @return \Magento\Sales\Api\Data\OrderPaymentInterface[]
* @throws InputException
*/
private function getOrdersWithExpiredPbl($orders)
protected function getPendingPayByLinkPayments(): array
{
$now = new \DateTime();
$expiredOrders = [];
foreach ($orders as $order) {
$paymentAdditionalInformation = $order->getPayment()->getAdditionalInformation();
$pblExpiryDateString = $paymentAdditionalInformation[AdyenPayByLinkConfigProvider::EXPIRES_AT_KEY] ?? false;
if ($pblExpiryDateString) {
$pblExpiryDate = \DateTime::createFromFormat(DATE_ATOM, $pblExpiryDateString);
if ($now > $pblExpiryDate) {
$expiredOrders[] = $order;
}
}
}
return $expiredOrders;
$sortOrder = new SortOrder();
$sortOrder->setField('parent_id')->setDirection('DESC');
$payPerLinkFilters = [
$this->filterBuilder->setField('method')
->setConditionType('eq')
->setValue(PaymentMethods::ADYEN_PAY_BY_LINK)
->create(),
$this->filterBuilder->setField('adyen_psp_reference')
->setConditionType('null')
->create()
];

$filterGroup = $this->filterGroupBuilder->setFilters($payPerLinkFilters)->create();

$searchCriteria = $this->searchCriteriaBuilder
->setFilterGroups([$filterGroup])
->setSortOrders([$sortOrder])
->setPageSize(1000)
->create();

return $this->orderPaymentRepository->getList($searchCriteria)->getItems();
}
}
6 changes: 5 additions & 1 deletion Gateway/Http/Client/TransactionCapture.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,14 @@ private function placeMultipleCaptureRequests($service, $requestContainer, $requ
$singleResponse = $this->copyParamsToResponse($singleResponse, $request);
$response[self::MULTIPLE_AUTHORIZATIONS][] = $singleResponse;
} catch (AdyenException $e) {
$pspReference = isset($request[OrderPaymentInterface::PSPREFRENCE]) ?
$request[OrderPaymentInterface::PSPREFRENCE] :
'pspReference not set';

$message = sprintf(
'Exception occurred when attempting to capture multiple authorizations.
Authorization with pspReference %s: %s',
$request[OrderPaymentInterface::PSPREFRENCE],
$pspReference,
$e->getMessage()
);

Expand Down
13 changes: 7 additions & 6 deletions Gateway/Http/Client/TransactionMotoRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $tr
null,
$request['merchantAccount']
);
$service = new \Adyen\Service\Modification($client);

$service = $this->adyenHelper->createAdyenCheckoutService($client);
$this->adyenHelper
->logRequest($request, Client::API_PAYMENT_VERSION, '/pal/servlet/Payment/{version}/refund');
->logRequest($request, Client::API_CHECKOUT_VERSION, '/refunds');
try {
$response = $service->refund($request);
$response = $service->refunds($request);

// Add amount original reference and amount information to response
$response[self::REFUND_AMOUNT] = $request['modificationAmount']['value'];
$response[self::REFUND_CURRENCY] = $request['modificationAmount']['currency'];
$response[self::ORIGINAL_REFERENCE] = $request['originalReference'];
$response[self::REFUND_AMOUNT] = $request['amount']['value'];
$response[self::REFUND_CURRENCY] = $request['amount']['currency'];
$response[self::ORIGINAL_REFERENCE] = $request['paymentPspReference'];
} catch (\Adyen\AdyenException $e) {
$response = ['error' => $e->getMessage()];
}
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/RefundDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function build(array $buildSubject): array
->addFieldToFilter('payment_id', $payment->getId());

// partial refund if multiple payments check refund strategy
if ($orderPaymentCollection->getSize() > self::REFUND_STRATEGY_ASCENDING_ORDER) {
if ($orderPaymentCollection->getSize() > 1) {
$refundStrategy = $this->adyenHelper->getAdyenAbstractConfigData(
'partial_payments_refund_strategy',
$storeId
Expand Down
11 changes: 7 additions & 4 deletions Helper/AdyenOrderPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Adyen\Payment\Model\Order\PaymentFactory;
use Adyen\Payment\Model\ResourceModel\Order\Payment as OrderPaymentResourceModel;
use Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory as AdyenOrderPaymentCollection;
use DateTime;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Exception\AlreadyExistsException;
Expand Down Expand Up @@ -210,7 +211,9 @@ public function createAdyenOrderPayment(Order $order, Notification $notification
$pspReference = $notification->getPspreference();

try {
$date = new \DateTime();
$date = new DateTime();
$eventDate = DateTime::createFromFormat('Y-m-d H:i:s', $notification->getCreatedAt());

$adyenOrderPayment = $this->adyenOrderPaymentFactory->create();
$adyenOrderPayment->setPspreference($pspReference);
$adyenOrderPayment->setMerchantReference($merchantReference);
Expand All @@ -219,7 +222,7 @@ public function createAdyenOrderPayment(Order $order, Notification $notification
$adyenOrderPayment->setCaptureStatus($captureStatus);
$adyenOrderPayment->setAmount($amount);
$adyenOrderPayment->setTotalRefunded(0);
$adyenOrderPayment->setCreatedAt($date);
$adyenOrderPayment->setCreatedAt($eventDate);
$adyenOrderPayment->setUpdatedAt($date);
$this->orderPaymentResourceModel->save($adyenOrderPayment);
} catch (\Exception $e) {
Expand Down Expand Up @@ -249,7 +252,7 @@ public function refundAdyenOrderPayment(OrderPaymentInterface $adyenOrderPayment
{
$amountRefunded = $adyenOrderPayment->getTotalRefunded() +
$this->adyenDataHelper->originalAmount($notification->getAmountValue(), $notification->getAmountCurrency());
$adyenOrderPayment->setUpdatedAt(new \DateTime());
$adyenOrderPayment->setUpdatedAt(new DateTime());
$adyenOrderPayment->setTotalRefunded($amountRefunded);
$adyenOrderPayment->save();

Expand All @@ -266,7 +269,7 @@ public function refundAdyenOrderPayment(OrderPaymentInterface $adyenOrderPayment
public function refundFullyAdyenOrderPayment(OrderPaymentInterface $adyenOrderPayment): OrderPaymentInterface
{
$amountRefunded = $adyenOrderPayment->getAmount();
$adyenOrderPayment->setUpdatedAt(new \DateTime());
$adyenOrderPayment->setUpdatedAt(new DateTime());
$adyenOrderPayment->setTotalRefunded($amountRefunded);
$adyenOrderPayment->save();

Expand Down
2 changes: 1 addition & 1 deletion Model/ResourceModel/Order/Payment/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function addPaymentFilterAscending($paymentId)
public function addPaymentFilterDescending($paymentId)
{
$this->addFieldToFilter('payment_id', $paymentId);
$this->getSelect()->order(['created_at DESC', 'entity_id DESC']);
$this->getSelect()->order(['created_at DESC']);
return $this;
}
}
9 changes: 9 additions & 0 deletions Test/Unit/AbstractAdyenTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,13 @@ protected function createAdyenOrderPaymentCollection(?int $entityId = null): Moc

return $adyenOrderPaymentCollectionFactory;
}

protected function invokeMethod(&$object, $methodName, array $parameters = [])
{
$reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);

return $method->invokeArgs($object, $parameters);
}
}
Loading

0 comments on commit 0eab1b4

Please sign in to comment.