From 6c33a35bddbc21b406230d14ca4aa0d0293c6826 Mon Sep 17 00:00:00 2001
From: khushboos
Date: Mon, 9 Dec 2024 12:31:59 +0530
Subject: [PATCH 01/12] Fixing refund response handler if an exception is
thrown
---
Gateway/Http/Client/TransactionRefund.php | 2 +
.../Http/Client/TransactionRefundTest.php | 43 +++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/Gateway/Http/Client/TransactionRefund.php b/Gateway/Http/Client/TransactionRefund.php
index 3484c030d0..238f18fb79 100644
--- a/Gateway/Http/Client/TransactionRefund.php
+++ b/Gateway/Http/Client/TransactionRefund.php
@@ -88,6 +88,8 @@ public function placeRequest(TransferInterface $transferObject): array
$this->adyenHelper->logResponse($responseData);
} catch (AdyenException $e) {
$this->adyenHelper->logAdyenException($e);
+ $responseData['error'] = $e->getMessage();
+ $responseData['errorCode'] = $e->getAdyenErrorCode();
}
$responses[] = $responseData;
}
diff --git a/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php b/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php
index 3d98825999..21b2730451 100644
--- a/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php
+++ b/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php
@@ -21,6 +21,7 @@
use Adyen\Service\Checkout\ModificationsApi;
use Magento\Payment\Gateway\Http\TransferInterface;
use PHPUnit\Framework\MockObject\MockObject;
+use Adyen\AdyenException;
class TransactionRefundTest extends AbstractAdyenTestCase
{
@@ -102,4 +103,46 @@ public function testPlaceRequestIncludesHeadersInRequest()
$this->assertCount(1, $responses);
$this->assertArrayHasKey('pspReference', $responses[0]);
}
+
+ public function testPlaceRequestHandlesException()
+ {
+ $requestBody = [
+ 'amount' => ['value' => 1000, 'currency' => 'EUR'],
+ 'paymentPspReference' => '123456789'
+ ];
+
+ $headers = ['idempotencyExtraData' => ['order_id' => '1001']];
+
+ $transferObjectMock = $this->createConfiguredMock(TransferInterface::class, [
+ 'getBody' => [$requestBody],
+ 'getHeaders' => $headers,
+ 'getClientConfig' => []
+ ]);
+
+ $serviceMock = $this->createMock(ModificationsApi::class);
+ $adyenClientMock = $this->createMock(Client::class);
+
+ $this->adyenHelperMock->method('initializeAdyenClientWithClientConfig')->willReturn($adyenClientMock);
+ $this->adyenHelperMock->method('initializeModificationsApi')->willReturn($serviceMock);
+ $this->adyenHelperMock->method('buildRequestHeaders')->willReturn(['custom-header' => 'value']);
+
+ $this->idempotencyHelperMock->expects($this->once())
+ ->method('generateIdempotencyKey')
+ ->with($requestBody, $headers['idempotencyExtraData'])
+ ->willReturn('generated_idempotency_key');
+
+ $serviceMock->expects($this->once())
+ ->method('refundCapturedPayment')
+ ->willThrowException(new AdyenException());
+
+ $this->adyenHelperMock->expects($this->once())
+ ->method('logAdyenException')
+ ->with($this->isInstanceOf(AdyenException::class));
+
+ $responses = $this->transactionRefund->placeRequest($transferObjectMock);
+ $this->assertIsArray($responses);
+ $this->assertCount(1, $responses);
+ $this->assertArrayHasKey('error', $responses[0]);
+ $this->assertArrayHasKey('errorCode', $responses[0]);
+ }
}
From 8e6a869c4b7fff007c4908afe6b70ba8f1891b70 Mon Sep 17 00:00:00 2001
From: Pieter Zandbergen
Date: Fri, 13 Dec 2024 15:06:21 +0100
Subject: [PATCH 02/12] fix: Handle errors on placeOrder mutations (#2799)
The PlaceOrder resolver does not necessary return an order, in case of errors. See https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/QuoteGraphQl/Model/Resolver/PlaceOrder.php#L106
Co-authored-by: Can Demiralp
---
Plugin/GraphQlPlaceOrderAddCartId.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Plugin/GraphQlPlaceOrderAddCartId.php b/Plugin/GraphQlPlaceOrderAddCartId.php
index ee360eb04f..bf88af05b8 100644
--- a/Plugin/GraphQlPlaceOrderAddCartId.php
+++ b/Plugin/GraphQlPlaceOrderAddCartId.php
@@ -59,6 +59,10 @@ public function __construct(
*/
public function afterResolve(PlaceOrder $placeOrder, array $result): array
{
+ if (!isset($result['order'])) {
+ return $result;
+ }
+
try {
$cart = $this->quoteHelper->getQuoteByOrderIncrementId($result['order']['order_number']);
$maskedId = $this->quoteIdToMaskedQuoteId->execute($cart->getId());
From ea6e8fc242761ce02e6c07bb03c4e1aa19ff3413 Mon Sep 17 00:00:00 2001
From: Pieter Zandbergen
Date: Fri, 13 Dec 2024 15:06:58 +0100
Subject: [PATCH 03/12] fix: Sort Search Result when fetching Order by Quote ID
(#2824)
* fix: Sort Search Result when fetching Order by Quote ID
Multiple orders might exist for the same Quote. We should be using the most recent Order when dealing with the Payment.
* fix: Updated Unit Test for OrderRepository
* fix: Missing create call on Sort Order Builder
---------
Co-authored-by: Khushboo
Co-authored-by: Can Demiralp
---
Model/Sales/OrderRepository.php | 9 +++++++++
Test/Unit/Model/Sales/OrderRepositoryTest.php | 20 +++++++++++++++++--
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/Model/Sales/OrderRepository.php b/Model/Sales/OrderRepository.php
index d51680b268..0919294075 100644
--- a/Model/Sales/OrderRepository.php
+++ b/Model/Sales/OrderRepository.php
@@ -16,6 +16,7 @@
use Magento\Framework\Api\Search\FilterGroupBuilder;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
+use Magento\Framework\Api\SortOrderBuilder;
use Magento\Framework\Serialize\Serializer\Json as JsonSerializer;
use Magento\Payment\Api\Data\PaymentAdditionalInfoInterfaceFactory;
use Magento\Sales\Api\Data\OrderExtensionFactory;
@@ -28,6 +29,7 @@
class OrderRepository extends SalesOrderRepository
{
private SearchCriteriaBuilder $searchCriteriaBuilder;
+ private SortOrderBuilder $sortOrderBuilder;
private FilterBuilder $filterBuilder;
private FilterGroupBuilder $filterGroupBuilder;
@@ -35,6 +37,7 @@ public function __construct(
SearchCriteriaBuilder $searchCriteriaBuilder,
FilterBuilder $filterBuilder,
FilterGroupBuilder $filterGroupBuilder,
+ SortOrderBuilder $sortOrderBuilder,
Metadata $metadata,
SearchResultFactory $searchResultFactory,
CollectionProcessorInterface $collectionProcessor = null,
@@ -56,6 +59,7 @@ public function __construct(
);
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
+ $this->sortOrderBuilder = $sortOrderBuilder;
$this->filterBuilder = $filterBuilder;
$this->filterGroupBuilder = $filterGroupBuilder;
}
@@ -68,9 +72,14 @@ public function getOrderByQuoteId(int $quoteId): OrderInterface|false
->create();
$quoteIdFilterGroup = $this->filterGroupBuilder->setFilters([$quoteIdFilter])->create();
+ $sortOrder = $this->sortOrderBuilder->setField('entity_id')
+ ->setDescendingDirection()
+ ->create();
$searchCriteria = $this->searchCriteriaBuilder
->setFilterGroups([$quoteIdFilterGroup])
+ ->setSortOrders([$sortOrder])
+ ->setPageSize(1)
->create();
$orders = $this->getList($searchCriteria)->getItems();
diff --git a/Test/Unit/Model/Sales/OrderRepositoryTest.php b/Test/Unit/Model/Sales/OrderRepositoryTest.php
index 261640f068..a0e9714810 100644
--- a/Test/Unit/Model/Sales/OrderRepositoryTest.php
+++ b/Test/Unit/Model/Sales/OrderRepositoryTest.php
@@ -19,6 +19,8 @@
use Magento\Framework\Api\Search\FilterGroupBuilder;
use Magento\Framework\Api\SearchCriteria;
use Magento\Framework\Api\SearchCriteriaBuilder;
+use Magento\Framework\Api\SortOrder;
+use Magento\Framework\Api\SortOrderBuilder;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderSearchResultInterface;
use ReflectionClass;
@@ -41,10 +43,15 @@ public function testGetOrderByQuoteId()
$filterGroupBuilderMock->method('create')
->willReturn($this->createMock(FilterGroup::class));
+ $sortOrderBuilderMock = $this->createPartialMock(SortOrderBuilder::class, ['create']);
+ $sortOrderBuilderMock->method('create')
+ ->willReturn($this->createMock(SortOrder::class));
+
$orderRepository = $this->buildOrderRepositoryClass(
$searchCriteriaBuilderMock,
$filterBuilderMock,
- $filterGroupBuilderMock
+ $filterGroupBuilderMock,
+ $sortOrderBuilderMock
);
$order = $orderRepository->getOrderByQuoteId($quoteId);
@@ -54,7 +61,8 @@ public function testGetOrderByQuoteId()
public function buildOrderRepositoryClass(
$searchCriteriaBuilderMock = null,
$filterBuilderMock = null,
- $filterGroupBuilderMock = null
+ $filterGroupBuilderMock = null,
+ $sortOrderBuilderMock = null
): OrderRepository {
if (is_null($searchCriteriaBuilderMock)) {
$searchCriteriaBuilderMock = $this->createMock(SearchCriteriaBuilder::class);
@@ -68,6 +76,10 @@ public function buildOrderRepositoryClass(
$filterGroupBuilderMock = $this->createMock(FilterGroupBuilder::class);
}
+ if (is_null($sortOrderBuilderMock)) {
+ $sortOrderBuilderMock = $this->createMock(SortOrderBuilder::class);
+ }
+
$orderRepositoryPartialMock = $this->getMockBuilder(OrderRepository::class)
->setMethods(['getList'])
->disableOriginalConstructor()
@@ -87,6 +99,10 @@ public function buildOrderRepositoryClass(
$filterGroupBuilderProperty->setAccessible(true);
$filterGroupBuilderProperty->setValue($orderRepositoryPartialMock, $filterGroupBuilderMock);
+ $sortOrderBuilderProperty = $reflection->getProperty('sortOrderBuilder');
+ $sortOrderBuilderProperty->setAccessible(true);
+ $sortOrderBuilderProperty->setValue($orderRepositoryPartialMock, $sortOrderBuilderMock);
+
$orderSearchResultMock = $this->createConfiguredMock(OrderSearchResultInterface::class, [
'getItems' => [$this->createMock(OrderInterface::class)]
]);
From 218c5918add2377e855c0c856e4d93e20712c5d7 Mon Sep 17 00:00:00 2001
From: khushboos
Date: Mon, 16 Dec 2024 16:40:36 +0530
Subject: [PATCH 04/12] Fixing errors from security point of view
---
view/frontend/web/template/payment/cc-form.html | 2 +-
view/frontend/web/template/payment/cc-vault-form.html | 4 ++--
view/frontend/web/template/payment/pm-vault-form.html | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/view/frontend/web/template/payment/cc-form.html b/view/frontend/web/template/payment/cc-form.html
index b93b74ee04..a0df9a907b 100755
--- a/view/frontend/web/template/payment/cc-form.html
+++ b/view/frontend/web/template/payment/cc-form.html
@@ -63,7 +63,7 @@
-
+
diff --git a/view/frontend/web/template/payment/cc-vault-form.html b/view/frontend/web/template/payment/cc-vault-form.html
index ddc824d3c9..515ed6ba91 100644
--- a/view/frontend/web/template/payment/cc-vault-form.html
+++ b/view/frontend/web/template/payment/cc-vault-form.html
@@ -21,7 +21,7 @@
value: getId(),
click: selectPaymentMethod,
checked: isChecked,
- visible: isRadioButtonVisible()"/>
+ visible: isRadioButtonVisible()">
]]>
- Apple Pay Certificate
- Adyen\Payment\Model\Config\Adminhtml\ApplepayCertificateButton
+ Apple Pay domain association file
+ Adyen\Payment\Model\Config\Adminhtml\ApplePayDomainAssociationFileButton
RatePAY Device Ident SId
diff --git a/view/adminhtml/templates/config/applepay_button.phtml b/view/adminhtml/templates/config/applepay_button.phtml
deleted file mode 100644
index e57195c9fe..0000000000
--- a/view/adminhtml/templates/config/applepay_button.phtml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
diff --git a/view/adminhtml/templates/config/applepay_domain_association_file_button.phtml b/view/adminhtml/templates/config/applepay_domain_association_file_button.phtml
new file mode 100644
index 0000000000..a25f333024
--- /dev/null
+++ b/view/adminhtml/templates/config/applepay_domain_association_file_button.phtml
@@ -0,0 +1,4 @@
+
+
From 6c468e019cc060556437d0885ccd3320334ba0f9 Mon Sep 17 00:00:00 2001
From: candemiralp <20255503+candemiralp@users.noreply.github.com>
Date: Tue, 24 Dec 2024 09:48:37 +0000
Subject: [PATCH 11/12] chore(release): bump to 9.12.2
---
VERSION | 2 +-
composer.json | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/VERSION b/VERSION
index 69dd356299..be62bf9b12 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-9.12.1
+9.12.2
diff --git a/composer.json b/composer.json
index a9a2f6eeca..6c775c9348 100755
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
"name": "adyen/module-payment",
"description": "Official Magento2 Plugin to connect to Payment Service Provider Adyen.",
"type": "magento2-module",
- "version": "9.12.1",
+ "version": "9.12.2",
"license": "MIT",
"repositories": [
{
From 3ab803cad41af20fa75954a21cde45586c5e59de Mon Sep 17 00:00:00 2001
From: Sushmita Thakur
Date: Tue, 24 Dec 2024 19:35:07 +0100
Subject: [PATCH 12/12] [ECP-9482] Refactor Header Data Builder For Transaction
Clients (#2819)
* [ECP-9482-1] Added HeaderDataBuilderInterface, moved header builder to separate directory, updated constants in the observers, updated frontend type values to `luma`, added HeaderDataBuilder in the authorization flow for cancel, capture, refund, donate, payByLink, and pos transaction clients in di.xml
* [ECP-9482-1] Removed HeaderDataBuilder from pos transaction client, updated the headers in all transaction clients
* [ECP-9482-1] Updated Tests
* [ECP-9482-1] Updated constants in data helper
* [ECP-9482-1] Updated header in refund request options
* [ECP-9482-1] Updated header in capture request options, revert donation header updates
* [ECP-9482-1] Updated format
* [ECP-9482-1] Remove capture test update
* [ECP-9482-1] Update DataTest for new frontend type constant
* [ECP-9482-1] Update Constants use in Data, remove unused constant for `headless` from HeaderDataBuilderInterface
* [ECP-9482-1] Set frontendType in JS renderers to be `default`
* [ECP-9482-1] Set placeorder method
* [ECP-9482-1] Remove unused variable
* [ECP-9482-1] fix formatting issue
* [ECP-9482-1] reverse the frontend type change for giftcard
* [ECP-9482-1] Added unit test for TransactionPaymentLinks
* [ECP-9482-1] Added unit test for initializePaymentLinksApi in DataTest
* [ECP-9482-1] Optimized TrasactionPaymentLinks test
* [ECP-9482-1] Remove unused classes
---------
Co-authored-by: sushmita
---
Gateway/Http/Client/TransactionCancel.php | 2 +-
Gateway/Http/Client/TransactionCapture.php | 6 +-
.../Http/Client/TransactionPaymentLinks.php | 8 +-
Gateway/Http/Client/TransactionRefund.php | 7 +-
.../{ => Header}/HeaderDataBuilder.php | 7 +-
.../Header/HeaderDataBuilderInterface.php | 15 +++
Helper/Data.php | 24 ++--
Observer/AdyenCcDataAssignObserver.php | 4 +-
.../AdyenPaymentMethodDataAssignObserver.php | 4 +-
.../Client/TransactionPaymentLinksTest.php | 120 ++++++++++++++++++
.../Http/Client/TransactionRefundTest.php | 2 -
.../{ => Header}/HeaderDataBuilderTest.php | 2 +-
Test/Unit/Helper/DataTest.php | 17 ++-
etc/di.xml | 18 ++-
.../method-renderer/adyen-cc-vault-method.js | 2 +-
.../method-renderer/adyen-pm-method.js | 4 +-
.../method-renderer/adyen-pm-vault-method.js | 9 ++
17 files changed, 207 insertions(+), 44 deletions(-)
rename Gateway/Request/{ => Header}/HeaderDataBuilder.php (84%)
create mode 100644 Gateway/Request/Header/HeaderDataBuilderInterface.php
create mode 100644 Test/Unit/Gateway/Http/Client/TransactionPaymentLinksTest.php
rename Test/Unit/Gateway/Request/{ => Header}/HeaderDataBuilderTest.php (97%)
diff --git a/Gateway/Http/Client/TransactionCancel.php b/Gateway/Http/Client/TransactionCancel.php
index 707412d06d..f7d1406469 100644
--- a/Gateway/Http/Client/TransactionCancel.php
+++ b/Gateway/Http/Client/TransactionCancel.php
@@ -66,7 +66,7 @@ public function placeRequest(TransferInterface $transferObject): array
$headers['idempotencyExtraData'] ?? null
);
$requestOptions['idempotencyKey'] = $idempotencyKey;
- $requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders();
+ $requestOptions['headers'] = $headers;
$this->adyenHelper->logRequest($request, Client::API_CHECKOUT_VERSION, '/cancels');
$request['applicationInfo'] = $this->adyenHelper->buildApplicationInfo($client);
$paymentCancelRequest = new PaymentCancelRequest($request);
diff --git a/Gateway/Http/Client/TransactionCapture.php b/Gateway/Http/Client/TransactionCapture.php
index ad699a9ba6..0ed6dbb109 100644
--- a/Gateway/Http/Client/TransactionCapture.php
+++ b/Gateway/Http/Client/TransactionCapture.php
@@ -72,12 +72,14 @@ public function placeRequest(TransferInterface $transferObject): array
{
$request = $transferObject->getBody();
$headers = $transferObject->getHeaders();
+ $idempotencyKeyExtraData = $headers['idempotencyExtraData'];
+ unset($headers['idempotencyExtraData']);
$clientConfig = $transferObject->getClientConfig();
$client = $this->adyenHelper->initializeAdyenClientWithClientConfig($clientConfig);
$service = $this->adyenHelper->initializeModificationsApi($client);
- $requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders();
+ $requestOptions['headers'] = $headers;
$request['applicationInfo'] = $this->adyenHelper->buildApplicationInfo($client);
if (array_key_exists(self::MULTIPLE_AUTHORIZATIONS, $request)) {
@@ -86,7 +88,7 @@ public function placeRequest(TransferInterface $transferObject): array
$idempotencyKey = $this->idempotencyHelper->generateIdempotencyKey(
$request,
- $headers['idempotencyExtraData'] ?? null
+ $idempotencyKeyExtraData ?? null
);
$requestOptions['idempotencyKey'] = $idempotencyKey;
diff --git a/Gateway/Http/Client/TransactionPaymentLinks.php b/Gateway/Http/Client/TransactionPaymentLinks.php
index c43d5d81bf..71e0f8237a 100644
--- a/Gateway/Http/Client/TransactionPaymentLinks.php
+++ b/Gateway/Http/Client/TransactionPaymentLinks.php
@@ -55,10 +55,12 @@ public function placeRequest(TransferInterface $transferObject): array
{
$request = $transferObject->getBody();
$headers = $transferObject->getHeaders();
+ $idempotencyKeyExtraData = $headers['idempotencyExtraData'] ?? null;
+ unset($headers['idempotencyExtraData']);
$clientConfig = $transferObject->getClientConfig();
$client = $this->adyenHelper->initializeAdyenClientWithClientConfig($clientConfig);
- $service = new PaymentLinksApi($client);
+ $service = $this->adyenHelper->initializePaymentLinksApi($client);
// If the payment links call is already done return the request
if (!empty($request['resultCode'])) {
@@ -68,11 +70,11 @@ public function placeRequest(TransferInterface $transferObject): array
$idempotencyKey = $this->idempotencyHelper->generateIdempotencyKey(
$request,
- $headers['idempotencyExtraData'] ?? null
+ $idempotencyKeyExtraData
);
$requestOptions['idempotencyKey'] = $idempotencyKey;
- $requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders();
+ $requestOptions['headers'] = $headers;
$request['applicationInfo'] = $this->adyenHelper->buildApplicationInfo($client);
$this->adyenHelper->logRequest($request, Client::API_CHECKOUT_VERSION, '/paymentLinks');
diff --git a/Gateway/Http/Client/TransactionRefund.php b/Gateway/Http/Client/TransactionRefund.php
index 238f18fb79..6474c300de 100644
--- a/Gateway/Http/Client/TransactionRefund.php
+++ b/Gateway/Http/Client/TransactionRefund.php
@@ -56,6 +56,8 @@ public function placeRequest(TransferInterface $transferObject): array
{
$requests = $transferObject->getBody();
$headers = $transferObject->getHeaders();
+ $idempotencyKeyExtraData = $headers['idempotencyExtraData'];
+ unset($headers['idempotencyExtraData']);
$clientConfig = $transferObject->getClientConfig();
$client = $this->adyenHelper->initializeAdyenClientWithClientConfig($clientConfig);
@@ -66,10 +68,11 @@ public function placeRequest(TransferInterface $transferObject): array
$responseData = [];
$idempotencyKey = $this->idempotencyHelper->generateIdempotencyKey(
$request,
- $headers['idempotencyExtraData'] ?? null
+ $idempotencyKeyExtraData ?? null
);
$requestOptions['idempotencyKey'] = $idempotencyKey;
- $requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders();
+ $requestOptions['headers'] = $headers;
+
$this->adyenHelper->logRequest($request, Client::API_CHECKOUT_VERSION, '/refunds');
$request['applicationInfo'] = $this->adyenHelper->buildApplicationInfo($client);
$paymentRefundRequest = new PaymentRefundRequest($request);
diff --git a/Gateway/Request/HeaderDataBuilder.php b/Gateway/Request/Header/HeaderDataBuilder.php
similarity index 84%
rename from Gateway/Request/HeaderDataBuilder.php
rename to Gateway/Request/Header/HeaderDataBuilder.php
index 66cd1aa703..d2c772f1e6 100644
--- a/Gateway/Request/HeaderDataBuilder.php
+++ b/Gateway/Request/Header/HeaderDataBuilder.php
@@ -9,18 +9,15 @@
* Author: Adyen
*/
-namespace Adyen\Payment\Gateway\Request;
+namespace Adyen\Payment\Gateway\Request\Header;
use Adyen\Payment\Helper\Data;
use Magento\Payment\Gateway\Data\PaymentDataObject;
use Magento\Payment\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Request\BuilderInterface;
-class HeaderDataBuilder implements BuilderInterface
+class HeaderDataBuilder implements BuilderInterface, HeaderDataBuilderInterface
{
- const FRONTENDTYPE = 'external-platform-frontendtype';
- const FRONTENDTYPE_HEADLESS = 'headless';
-
/**
* @var Data
*/
diff --git a/Gateway/Request/Header/HeaderDataBuilderInterface.php b/Gateway/Request/Header/HeaderDataBuilderInterface.php
new file mode 100644
index 0000000000..ac10244854
--- /dev/null
+++ b/Gateway/Request/Header/HeaderDataBuilderInterface.php
@@ -0,0 +1,15 @@
+getMagentoDetails();
$headers = [
- 'external-platform-name' => $magentoDetails['name'],
- 'external-platform-version' => $magentoDetails['version'],
- 'external-platform-edition' => $magentoDetails['edition'],
- 'merchant-application-name' => $this->getModuleName(),
- 'merchant-application-version' => $this->getModuleVersion()
+ HeaderDataBuilderInterface::EXTERNAL_PLATFORM_NAME => $magentoDetails['name'],
+ HeaderDataBuilderInterface::EXTERNAL_PLATFORM_VERSION => $magentoDetails['version'],
+ HeaderDataBuilderInterface::EXTERNAL_PLATFORM_EDITION => $magentoDetails['edition'],
+ HeaderDataBuilderInterface::MERCHANT_APPLICATION_NAME => $this->getModuleName(),
+ HeaderDataBuilderInterface::MERCHANT_APPLICATION_VERSION => $this->getModuleVersion()
];
- if(isset($payment) && !is_null($payment->getAdditionalInformation(HeaderDataBuilder::FRONTENDTYPE))) {
- $headers[HeaderDataBuilder::FRONTENDTYPE] =
- $payment->getAdditionalInformation(HeaderDataBuilder::FRONTENDTYPE);
+ if(isset($payment) && !is_null($payment->getAdditionalInformation(HeaderDataBuilderInterface::ADDITIONAL_DATA_FRONTEND_TYPE_KEY))) {
+ $headers[HeaderDataBuilderInterface::EXTERNAL_PLATFORM_FRONTEND_TYPE] =
+ $payment->getAdditionalInformation(HeaderDataBuilderInterface::ADDITIONAL_DATA_FRONTEND_TYPE_KEY);
}
return $headers;
@@ -1248,6 +1249,11 @@ public function initializeOrdersApi(Client $client): OrdersApi
return new OrdersApi($client);
}
+ public function initializePaymentLinksApi(Client $client):PaymentLinksApi
+ {
+ return new PaymentLinksApi($client);
+ }
+
/**
* @param Client $client
* @return PosPayment
diff --git a/Observer/AdyenCcDataAssignObserver.php b/Observer/AdyenCcDataAssignObserver.php
index 6168deebb3..79ed087eab 100644
--- a/Observer/AdyenCcDataAssignObserver.php
+++ b/Observer/AdyenCcDataAssignObserver.php
@@ -19,7 +19,7 @@
use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;
-use Adyen\Payment\Gateway\Request\HeaderDataBuilder;
+use Adyen\Payment\Gateway\Request\Header\HeaderDataBuilderInterface;
class AdyenCcDataAssignObserver extends AbstractDataAssignObserver
{
@@ -46,7 +46,7 @@ class AdyenCcDataAssignObserver extends AbstractDataAssignObserver
self::CC_TYPE,
self::RETURN_URL,
self::RECURRING_PROCESSING_MODEL,
- HeaderDataBuilder::FRONTENDTYPE
+ HeaderDataBuilderInterface::ADDITIONAL_DATA_FRONTEND_TYPE_KEY
];
/**
diff --git a/Observer/AdyenPaymentMethodDataAssignObserver.php b/Observer/AdyenPaymentMethodDataAssignObserver.php
index e90ce7b0a0..efe803a0fc 100644
--- a/Observer/AdyenPaymentMethodDataAssignObserver.php
+++ b/Observer/AdyenPaymentMethodDataAssignObserver.php
@@ -11,7 +11,7 @@
namespace Adyen\Payment\Observer;
-use Adyen\Payment\Gateway\Request\HeaderDataBuilder;
+use Adyen\Payment\Gateway\Request\Header\HeaderDataBuilderInterface;
use Adyen\Payment\Helper\StateData;
use Adyen\Payment\Helper\Util\CheckoutStateDataValidator;
use Adyen\Payment\Helper\Util\DataArrayValidator;
@@ -39,7 +39,7 @@ class AdyenPaymentMethodDataAssignObserver extends AbstractDataAssignObserver
self::RETURN_URL,
self::RECURRING_PROCESSING_MODEL,
self::CC_NUMBER,
- HeaderDataBuilder::FRONTENDTYPE
+ HeaderDataBuilderInterface::ADDITIONAL_DATA_FRONTEND_TYPE_KEY
];
protected CheckoutStateDataValidator $checkoutStateDataValidator;
diff --git a/Test/Unit/Gateway/Http/Client/TransactionPaymentLinksTest.php b/Test/Unit/Gateway/Http/Client/TransactionPaymentLinksTest.php
new file mode 100644
index 0000000000..c52733c959
--- /dev/null
+++ b/Test/Unit/Gateway/Http/Client/TransactionPaymentLinksTest.php
@@ -0,0 +1,120 @@
+adyenHelperMock = $this->createMock(Data::class);
+ $this->idempotencyHelperMock = $this->createMock(Idempotency::class);
+ $this->transferObjectMock = $this->createMock(TransferInterface::class);
+ $this->applicationInfoMock = $this->createMock(ApplicationInfo::class);
+ $this->adyenHelperMock->method('buildApplicationInfo')->willReturn($this->applicationInfoMock);
+ $this->transferObjectMock->method('getClientConfig')->willReturn([]);
+ $this->clientMock = $this->createMock(Client::class);
+ $this->adyenHelperMock->method('initializeAdyenClientWithClientConfig')->willReturn($this->clientMock);
+ $this->paymentLinksApiMock = $this->createMock(PaymentLinksApi::class);
+ $this->adyenHelperMock
+ ->method('initializePaymentLinksApi')
+ ->with($this->clientMock)
+ ->willReturn($this->paymentLinksApiMock);
+
+ $this->transactionPaymentLinks = new TransactionPaymentLinks(
+ $this->adyenHelperMock,
+ $this->idempotencyHelperMock
+ );
+ }
+
+ public function testSuccessfulPlaceRequest()
+ {
+ $requestBody = [
+ 'allowedPaymentMethods' => ['ideal','giropay'],
+ 'amount' => ['value' => 1000, 'currency' => 'EUR'],
+ 'applicationInfo' => $this->applicationInfoMock
+ ];
+
+ $headers = [ 'idempotencyExtraData' => [], 'header' => 'some-data'];
+ $idempotencyKey = 'generated_idempotency_key';
+
+ $this->transferObjectMock->method('getBody')->willReturn($requestBody);
+ $this->transferObjectMock->method('getHeaders')->willReturn($headers);
+
+ $this->idempotencyHelperMock->expects($this->once())
+ ->method('generateIdempotencyKey')
+ ->with($requestBody, $headers['idempotencyExtraData'])
+ ->willReturn('generated_idempotency_key');
+
+ $this->paymentLinksApiMock->expects($this->once())
+ ->method('paymentLinks')
+ ->with(
+ $this->callback(function (PaymentLinkRequest $paymentLinkRequest) use ($requestBody) {
+ $amount = $paymentLinkRequest->getAmount();
+ $this->assertEquals($amount, ['value' => 1000, 'currency' => 'EUR']);
+ $allowedPaymentMethods = $paymentLinkRequest->getAllowedPaymentMethods();
+ $this->assertEquals($allowedPaymentMethods, ['ideal', 'giropay']);
+ return true;
+ }),
+ $this->callback(function ($requestOptions) use ($idempotencyKey, $headers) {
+ $this->assertArrayHasKey('idempotencyKey', $requestOptions);
+ $this->assertArrayHasKey('headers', $requestOptions);
+ $this->assertEquals($idempotencyKey, $requestOptions['idempotencyKey']);
+ $this->assertEquals(['header' => 'some-data'], $requestOptions['headers']);
+ return true;
+ })
+ )->willReturn(new PaymentLinkResponse(['url' => 'https://paymentlink.com']));
+
+ $response = $this->transactionPaymentLinks->placeRequest($this->transferObjectMock);
+ $this->assertIsArray($response);
+ $this->assertArrayHasKey('url', $response);
+ }
+
+ public function testRequestWithAdyenException()
+ {
+ $requestBody = [
+ 'amount' => ['currency' => 'EUR', 'value' => 1000],
+ 'merchantAccount' => 'TestMerchant',
+ 'reference' => 'TestReference',
+ ];
+ $this->transferObjectMock->method('getBody')->willReturn($requestBody);
+ $this->transferObjectMock->method('getHeaders')->willReturn([]);
+ $this->transferObjectMock->method('getClientConfig')->willReturn([]);
+
+ $this->paymentLinksApiMock
+ ->method('paymentLinks')
+ ->willThrowException(new AdyenException());
+
+ $response = $this->transactionPaymentLinks->placeRequest($this->transferObjectMock);
+
+ $this->assertArrayHasKey('error', $response);
+ }
+
+ public function testRequestWithResultCodePresent()
+ {
+ $requestBody = ['resultCode' => 'Authorised'];
+ $this->transferObjectMock->method('getBody')->willReturn($requestBody);
+
+ $response = $this->transactionPaymentLinks->placeRequest($this->transferObjectMock);
+ $this->assertEquals($requestBody, $response);
+ }
+
+}
diff --git a/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php b/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php
index 21b2730451..3ba9370ac4 100644
--- a/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php
+++ b/Test/Unit/Gateway/Http/Client/TransactionRefundTest.php
@@ -71,7 +71,6 @@ public function testPlaceRequestIncludesHeadersInRequest()
$this->adyenHelperMock->method('initializeAdyenClientWithClientConfig')->willReturn($adyenClientMock);
$this->adyenHelperMock->method('initializeModificationsApi')->willReturn($serviceMock);
- $this->adyenHelperMock->method('buildRequestHeaders')->willReturn(['custom-header' => 'value']);
$this->idempotencyHelperMock->expects($this->once())
->method('generateIdempotencyKey')
@@ -91,7 +90,6 @@ public function testPlaceRequestIncludesHeadersInRequest()
$this->assertArrayHasKey('idempotencyKey', $requestOptions);
$this->assertArrayHasKey('headers', $requestOptions);
$this->assertEquals('generated_idempotency_key', $requestOptions['idempotencyKey']);
- $this->assertArrayHasKey('custom-header', $requestOptions['headers']);
return true;
})
)
diff --git a/Test/Unit/Gateway/Request/HeaderDataBuilderTest.php b/Test/Unit/Gateway/Request/Header/HeaderDataBuilderTest.php
similarity index 97%
rename from Test/Unit/Gateway/Request/HeaderDataBuilderTest.php
rename to Test/Unit/Gateway/Request/Header/HeaderDataBuilderTest.php
index 7c15e659a1..b270347fb1 100644
--- a/Test/Unit/Gateway/Request/HeaderDataBuilderTest.php
+++ b/Test/Unit/Gateway/Request/Header/HeaderDataBuilderTest.php
@@ -2,7 +2,7 @@
namespace Adyen\Payment\Test\Unit\Gateway\Request;
-use Adyen\Payment\Gateway\Request\HeaderDataBuilder;
+use Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Adyen\Payment\Helper\Data;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
diff --git a/Test/Unit/Helper/DataTest.php b/Test/Unit/Helper/DataTest.php
index ffb82e21cc..ffc52261e3 100755
--- a/Test/Unit/Helper/DataTest.php
+++ b/Test/Unit/Helper/DataTest.php
@@ -15,7 +15,7 @@
use Adyen\Config as AdyenConfig;
use Adyen\Model\Checkout\ApplicationInfo;
use Adyen\Model\Checkout\CommonField;
-use Adyen\Payment\Gateway\Request\HeaderDataBuilder;
+use Adyen\Payment\Gateway\Request\Header\HeaderDataBuilderInterface;
use Adyen\Payment\Helper\Config as ConfigHelper;
use Adyen\Payment\Helper\Data;
use Adyen\Payment\Helper\Locale;
@@ -27,6 +27,7 @@
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Adyen\Service\Checkout\ModificationsApi;
use Adyen\Service\Checkout\OrdersApi;
+use Adyen\Service\Checkout\PaymentLinksApi;
use Adyen\Service\Checkout\PaymentsApi;
use Adyen\Service\RecurringApi;
use Magento\Backend\Helper\Data as BackendHelper;
@@ -1090,15 +1091,15 @@ public function testBuildRequestHeadersWithNonNullFrontendType()
// Set up expectations for the getAdditionalInformation method
$payment->method('getAdditionalInformation')
- ->with(HeaderDataBuilder::FRONTENDTYPE)
+ ->with(HeaderDataBuilderInterface::ADDITIONAL_DATA_FRONTEND_TYPE_KEY)
->willReturn('some_frontend_type');
// Call the method under test
$result = $this->dataHelper->buildRequestHeaders($payment);
// Assert that the 'frontend-type' header is correctly set
- $this->assertArrayHasKey(HeaderDataBuilder::FRONTENDTYPE, $result);
- $this->assertEquals('some_frontend_type', $result[HeaderDataBuilder::FRONTENDTYPE]);
+ $this->assertArrayHasKey(HeaderDataBuilderInterface::EXTERNAL_PLATFORM_FRONTEND_TYPE, $result);
+ $this->assertEquals('some_frontend_type', $result[HeaderDataBuilderInterface::EXTERNAL_PLATFORM_FRONTEND_TYPE]);
// Assert other headers as needed
}
@@ -1110,7 +1111,7 @@ public function testBuildRequestHeadersWithoutPayment()
$result = $this->dataHelper->buildRequestHeaders();
// Assert that the 'frontend-type' header is not set
- $this->assertArrayNotHasKey(HeaderDataBuilder::FRONTENDTYPE, $result);
+ $this->assertArrayNotHasKey(HeaderDataBuilderInterface::EXTERNAL_PLATFORM_FRONTEND_TYPE, $result);
}
public function testLogResponse()
@@ -1892,6 +1893,12 @@ public function testInitializeOrdersApi()
$this->assertInstanceOf(OrdersApi::class, $service);
}
+ public function testInitializePaymentLinksApi()
+ {
+ $service = $this->dataHelper->initializePaymentLinksApi($this->clientMock);
+ $this->assertInstanceOf(PaymentLinksApi::class, $service);
+ }
+
public function testLogAdyenException()
{
$this->store->method('getId')->willReturn(1);
diff --git a/etc/di.xml b/etc/di.xml
index aefb9b552a..880ffe546c 100755
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -1079,7 +1079,7 @@
- Adyen\Payment\Gateway\Request\ReturnUrlDataBuilder
- Adyen\Payment\Gateway\Request\ChannelDataBuilder
- Adyen\Payment\Gateway\Request\OriginDataBuilder
- - Adyen\Payment\Gateway\Request\HeaderDataBuilder
+ - Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder
- Adyen\Payment\Gateway\Request\GiftcardDataBuilder
@@ -1113,6 +1113,7 @@
- Adyen\Payment\Gateway\Request\PaymentDataBuilder
- Adyen\Payment\Gateway\Request\DescriptionDataBuilder
- Adyen\Payment\Gateway\Request\CheckoutDataBuilder
+ - Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder
@@ -1132,7 +1133,7 @@
- Adyen\Payment\Gateway\Request\BrowserInfoDataBuilder
- Adyen\Payment\Gateway\Request\RecurringVaultDataBuilder
- Adyen\Payment\Gateway\Request\ShopperInteractionDataBuilder
- - Adyen\Payment\Gateway\Request\HeaderDataBuilder
+ - Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder
- Adyen\Payment\Gateway\Request\GiftcardDataBuilder
@@ -1152,7 +1153,7 @@
- Adyen\Payment\Gateway\Request\BrowserInfoDataBuilder
- Adyen\Payment\Gateway\Request\RecurringVaultDataBuilder
- Adyen\Payment\Gateway\Request\ShopperInteractionDataBuilder
- - Adyen\Payment\Gateway\Request\HeaderDataBuilder
+ - Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder
- Adyen\Payment\Gateway\Request\GiftcardDataBuilder
@@ -1200,7 +1201,7 @@
- Adyen\Payment\Gateway\Request\RecurringDataBuilder
- Adyen\Payment\Gateway\Request\ShopperInteractionDataBuilder
- Adyen\Payment\Gateway\Request\CheckoutDataBuilder
- - Adyen\Payment\Gateway\Request\HeaderDataBuilder
+ - Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder
- Adyen\Payment\Gateway\Request\ReturnUrlDataBuilder
- Adyen\Payment\Gateway\Request\ChannelDataBuilder
- Adyen\Payment\Gateway\Request\OriginDataBuilder
@@ -1220,7 +1221,7 @@
- Adyen\Payment\Gateway\Request\BrowserInfoDataBuilder
- Adyen\Payment\Gateway\Request\ShopperInteractionDataBuilder
- Adyen\Payment\Gateway\Request\CheckoutDataBuilder
- - Adyen\Payment\Gateway\Request\HeaderDataBuilder
+ - Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder
- Adyen\Payment\Gateway\Request\ReturnUrlDataBuilder
- Adyen\Payment\Gateway\Request\ChannelDataBuilder
- Adyen\Payment\Gateway\Request\OriginDataBuilder
@@ -1248,7 +1249,7 @@
- Adyen\Payment\Gateway\Request\RecurringDataBuilder
- Adyen\Payment\Gateway\Request\ShopperInteractionDataBuilder
- Adyen\Payment\Gateway\Request\CheckoutDataBuilder
- - Adyen\Payment\Gateway\Request\HeaderDataBuilder
+ - Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder
- Adyen\Payment\Gateway\Request\ReturnUrlDataBuilder
- Adyen\Payment\Gateway\Request\ChannelDataBuilder
- Adyen\Payment\Gateway\Request\OriginDataBuilder
@@ -1269,6 +1270,7 @@
- Adyen\Payment\Gateway\Request\MerchantAccountDataBuilder
- Adyen\Payment\Gateway\Request\CaptureDataBuilder
+ - Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder
@@ -1286,6 +1288,7 @@
- Adyen\Payment\Gateway\Request\RefundDataBuilder
+ - Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder
@@ -1302,6 +1305,7 @@
- Adyen\Payment\Gateway\Request\CancelDataBuilder
+ - Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder
@@ -4559,4 +4563,4 @@
adyen_doku_mandiri_va
-
\ No newline at end of file
+
diff --git a/view/frontend/web/js/view/payment/method-renderer/adyen-cc-vault-method.js b/view/frontend/web/js/view/payment/method-renderer/adyen-cc-vault-method.js
index dbad6e1d5a..45a44078e1 100644
--- a/view/frontend/web/js/view/payment/method-renderer/adyen-cc-vault-method.js
+++ b/view/frontend/web/js/view/payment/method-renderer/adyen-cc-vault-method.js
@@ -260,7 +260,7 @@ define([
stateData: stateData,
public_hash: this.publicHash,
numberOfInstallments: this.installment(),
- frontendType: 'luma'
+ frontendType: 'default'
},
};
},
diff --git a/view/frontend/web/js/view/payment/method-renderer/adyen-pm-method.js b/view/frontend/web/js/view/payment/method-renderer/adyen-pm-method.js
index f6bf2dffc9..c3918236f7 100755
--- a/view/frontend/web/js/view/payment/method-renderer/adyen-pm-method.js
+++ b/view/frontend/web/js/view/payment/method-renderer/adyen-pm-method.js
@@ -155,7 +155,7 @@ define(
fullScreenLoader.stopLoader();
errorProcessor.process(error, this.currentMessageContainer);
},
-
+
renderCheckoutComponent: function() {
let methodCode = this.getMethodCode();
let configuration = this.buildComponentConfiguration(this.paymentMethod(), this.paymentMethodsExtraInfo());
@@ -294,7 +294,7 @@ define(
let additionalData = {};
additionalData.brand_code = this.paymentMethod().type;
- additionalData.frontendType = 'luma';
+ additionalData.frontendType = 'default';
let stateData;
if (this.paymentComponent) {
diff --git a/view/frontend/web/js/view/payment/method-renderer/adyen-pm-vault-method.js b/view/frontend/web/js/view/payment/method-renderer/adyen-pm-vault-method.js
index 5452313181..3f56674671 100644
--- a/view/frontend/web/js/view/payment/method-renderer/adyen-pm-vault-method.js
+++ b/view/frontend/web/js/view/payment/method-renderer/adyen-pm-vault-method.js
@@ -54,6 +54,15 @@ define([
*/
getIcons: function (type) {
return this.details.icon;
+ },
+ getData: function () {
+ return {
+ method: this.code,
+ additional_data: {
+ public_hash: this.publicHash,
+ frontendType: 'default'
+ },
+ };
}
});
});