Skip to content

Commit 571f21b

Browse files
authored
Merge pull request #96 from Adyen/develop
Release 1.2.3
2 parents 2c70956 + 50b85a6 commit 571f21b

27 files changed

+518
-28
lines changed

.github/docker-compose.e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3'
22
services:
33
playwright:
4-
image: mcr.microsoft.com/playwright:v1.40.1
4+
image: mcr.microsoft.com/playwright:v1.50.1
55
shm_size: 1gb
66
ipc: host
77
cap_add:

.github/workflows/e2e-test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Magento-Hyva E2E Pipeline
22
run-name: Adyen Magento 2 Payment Plugin E2E tests
3-
on: [pull_request, workflow_dispatch]
3+
on: [pull_request, pull_request_target, workflow_dispatch]
44

55
jobs:
66
build:
@@ -23,6 +23,9 @@ jobs:
2323
DEPLOY_SAMPLEDATA: 1
2424
steps:
2525
- uses: actions/checkout@v4
26+
with:
27+
ref: ${{ github.event.pull_request.head.sha || github.ref }}
28+
fetch-depth: 0
2629

2730
- name: Set Branch Name
2831
run: |

.github/workflows/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Main CI workflow
22

33
on:
44
pull_request:
5+
pull_request_target:
56
workflow_dispatch:
67

78
jobs:
@@ -17,6 +18,7 @@ jobs:
1718
steps:
1819
- uses: actions/checkout@v4
1920
with:
21+
ref: ${{ github.event.pull_request.head.sha || github.ref }}
2022
fetch-depth: 0
2123

2224
- name: Use PHP ${{ matrix.php-version }}
@@ -42,7 +44,7 @@ jobs:
4244
ssh-keyscan gitlab.hyva.io >> ~/.ssh/known_hosts
4345
echo "${HYVA_GITLAB_SSH_KEY}" > ~/.ssh/hyva_id_rsa
4446
chmod 600 ~/.ssh/hyva_id_rsa
45-
ssh-agent -a ${SSH_AUTH_SOCK} > /dev/null
47+
ssh-agent -a ${SSH_AUTH_SOCK} > /dev/null
4648
ssh-add ~/.ssh/hyva_id_rsa
4749
4850
- name: Install the plugin

Magewire/Payment/Method/AdyenPaymentComponent.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Adyen\Hyva\Model\PaymentMethod\PaymentMethods;
1212
use Adyen\Payment\Api\AdyenOrderPaymentStatusInterface;
1313
use Adyen\Payment\Api\AdyenPaymentsDetailsInterface;
14-
use Adyen\Payment\Gateway\Request\HeaderDataBuilder;
14+
use Adyen\Payment\Gateway\Request\Header\HeaderDataBuilderInterface;
1515
use Adyen\Payment\Helper\StateData;
1616
use Adyen\Payment\Helper\Util\CheckoutStateDataValidator;
1717
use Hyva\Checkout\Model\Magewire\Component\Evaluation\EvaluationResult;
@@ -20,6 +20,7 @@
2020
use Magento\Checkout\Api\GuestPaymentInformationManagementInterface;
2121
use Magento\Checkout\Api\PaymentInformationManagementInterface;
2222
use Magento\Checkout\Model\Session;
23+
use Magento\Quote\Api\Data\PaymentExtensionFactory;
2324
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
2425
use Magewirephp\Magewire\Component;
2526
use Psr\Log\LoggerInterface;
@@ -61,7 +62,8 @@ abstract class AdyenPaymentComponent extends Component implements EvaluationInte
6162
const FRONTENDTYPE_HYVA = 'hyva';
6263

6364
public function __construct(
64-
private readonly Context $context
65+
private readonly Context $context,
66+
private readonly PaymentExtensionFactory $paymentExtensionFactory
6567
) {
6668
$this->checkoutStateDataValidator = $context->getCheckoutStateDataValidator();
6769
$this->configuration = $context->getConfiguration();
@@ -102,7 +104,19 @@ public function placeOrder(array $data): void
102104
$this->handleSessionVariables($data);
103105
$quoteId = $this->session->getQuoteId();
104106
$payment = $this->session->getQuote()->getPayment();
105-
$payment->setAdditionalInformation(HeaderDataBuilder::FRONTENDTYPE, self::FRONTENDTYPE_HYVA);
107+
108+
$payment->setAdditionalInformation(
109+
HeaderDataBuilderInterface::ADDITIONAL_DATA_FRONTEND_TYPE_KEY,
110+
self::FRONTENDTYPE_HYVA
111+
);
112+
113+
if (!empty($data['extension_attributes']['agreement_ids'])) {
114+
$paymentExtension = $this->paymentExtensionFactory->create();
115+
$paymentExtension->setAgreementIds($data['extension_attributes']['agreement_ids']);
116+
117+
$payment->setExtensionAttributes($paymentExtension);
118+
}
119+
106120
$stateDataReceived = $this->collectValidatedStateData($data);
107121
//Temporary (per request) storage of state data
108122
$this->stateData->setStateData($stateDataReceived, (int) $quoteId);

Magewire/Payment/Method/CreditCard.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Adyen\Hyva\Model\CreditCard\InstallmentsManager;
1010
use Hyva\Checkout\Model\Magewire\Component\Evaluation\EvaluationResult;
1111
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultFactory;
12+
use Magento\Quote\Api\Data\PaymentExtensionFactory;
1213

1314
class CreditCard extends AdyenPaymentComponent
1415
{
@@ -18,9 +19,13 @@ class CreditCard extends AdyenPaymentComponent
1819
public function __construct(
1920
private readonly Context $context,
2021
private readonly BrandsManager $brandsManager,
21-
private readonly InstallmentsManager $installmentsManager
22+
private readonly InstallmentsManager $installmentsManager,
23+
private readonly PaymentExtensionFactory $paymentExtensionFactory
2224
) {
23-
parent::__construct($this->context);
25+
parent::__construct(
26+
$this->context,
27+
$this->paymentExtensionFactory
28+
);
2429
}
2530

2631
/**

Magewire/Payment/Method/StoredCards.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Exception;
1111
use Hyva\Checkout\Model\Magewire\Component\Evaluation\EvaluationResult;
1212
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultFactory;
13+
use Magento\Quote\Api\Data\PaymentExtensionFactory;
1314

1415
class StoredCards extends AdyenPaymentComponent
1516
{
@@ -18,9 +19,13 @@ class StoredCards extends AdyenPaymentComponent
1819
public function __construct(
1920
private readonly Context $context,
2021
private readonly InstallmentsManager $installmentsManager,
22+
private readonly PaymentExtensionFactory $paymentExtensionFactory
2123

2224
) {
23-
parent::__construct($this->context);
25+
parent::__construct(
26+
$this->context,
27+
$this->paymentExtensionFactory
28+
);
2429
}
2530

2631
/**
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Adyen\Hyva\Plugin\ViewModel\Checkout\Payment;
4+
5+
use Magento\Checkout\Model\Session as CheckoutSession;
6+
use Adyen\Payment\Helper\PaymentMethodsFilter;
7+
use Hyva\Checkout\ViewModel\Checkout\Payment\MethodList as HyvaMethodList;
8+
use Magento\Framework\Exception\LocalizedException;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
11+
class MethodList
12+
{
13+
/**
14+
* @param CheckoutSession $checkoutSession
15+
* @param PaymentMethodsFilter $paymentMethodsFilterHelper
16+
*/
17+
public function __construct(
18+
private readonly CheckoutSession $checkoutSession,
19+
private readonly PaymentMethodsFilter $paymentMethodsFilterHelper
20+
) { }
21+
22+
/**
23+
* This plugin changes the sorting order of the payment methods on the checkout
24+
* based on the sorting order of the payment methods on Adyen Customer Area.
25+
*
26+
* @param HyvaMethodList $subject
27+
* @param $result
28+
* @return array
29+
* @throws LocalizedException
30+
* @throws NoSuchEntityException
31+
*/
32+
public function afterGetList(HyvaMethodList $subject, $result): array
33+
{
34+
list($sortedMagentoPaymentMethods, $adyenPaymentMethodsResponse) = $this->paymentMethodsFilterHelper
35+
->sortAndFilterPaymentMethods($result, $this->checkoutSession->getQuote());
36+
37+
return $sortedMagentoPaymentMethods ?? $result;
38+
}
39+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This module depends on:
1414
The dependencies may be obtained like for example
1515

1616
```
17-
"adyen/module-payment": "^9.6.1",
17+
"adyen/module-payment": "^9.13.0",
1818
"hyva-themes/magento2-default-theme": "^1.3",
1919
"hyva-themes/magento2-hyva-checkout": "^1.1",
2020
```

Test/Unit/Magewire/Payment/Method/CreditCardTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Magento\Checkout\Api\GuestPaymentInformationManagementInterface;
1818
use Magento\Checkout\Api\PaymentInformationManagementInterface;
1919
use Magento\Checkout\Model\Session;
20+
use Magento\Quote\Api\Data\PaymentExtensionInterface;
21+
use Magento\Quote\Api\Data\PaymentExtensionFactory;
2022
use Magento\Quote\Model\Quote;
2123
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
2224
use Magento\Sales\Model\Order;
@@ -43,6 +45,8 @@ class CreditCardTest extends AbstractAdyenTestCase
4345
private MockObject $brandsManager;
4446
private MockObject $installmentsManager;
4547
private MockObject $quoteIdToMaskedQuoteIdMock;
48+
private MockObject $paymentExtensionFactoryMock;
49+
private MockObject $paymentExtensionMock;
4650

4751
private CreditCard $creditCard;
4852

@@ -93,6 +97,14 @@ public function setUp(): void
9397
$this->quoteIdToMaskedQuoteIdMock = $this->getMockBuilder(QuoteIdToMaskedQuoteIdInterface::class)
9498
->disableOriginalConstructor()
9599
->getMock();
100+
$this->paymentExtensionFactoryMock = $this->createGeneratedMock(
101+
PaymentExtensionFactory::class,
102+
['create']
103+
);
104+
$this->paymentExtensionMock = $this->createGeneratedMock(
105+
PaymentExtensionInterface::class,
106+
['setAgreementIds']
107+
);
96108

97109
$this->context = new Context(
98110
$this->checkoutStateDataValidator,
@@ -120,7 +132,8 @@ public function setUp(): void
120132
$this->creditCard = new CreditCard(
121133
$this->context,
122134
$this->brandsManager,
123-
$this->installmentsManager
135+
$this->installmentsManager,
136+
$this->paymentExtensionFactoryMock
124137
);
125138
}
126139

@@ -155,7 +168,12 @@ public function testGetConfiguration()
155168

156169
public function testPlaceOrder()
157170
{
158-
$data = ['stateData' => []];
171+
$data = [
172+
'stateData' => [],
173+
'extension_attributes' => [
174+
'agreement_ids' => ['1', '2']
175+
]
176+
];
159177
$paymentStatus = 'success';
160178
$quoteId = '111';
161179
$orderId = '123';
@@ -264,6 +282,10 @@ private function setPlaceOrderCommonExpectations($quoteId)
264282
$this->quote->expects($this->once())
265283
->method('getPayment')
266284
->willReturn($this->payment);
285+
286+
$this->paymentExtensionFactoryMock
287+
->method('create')
288+
->willReturn($this->paymentExtensionMock);
267289
}
268290

269291
public function testEvaluateCompletion()

0 commit comments

Comments
 (0)