Skip to content

Commit

Permalink
Merge branch 'main' into ECP-9359
Browse files Browse the repository at this point in the history
  • Loading branch information
candemiralp authored Sep 9, 2024
2 parents 8f32e1c + df61ed5 commit 230491f
Show file tree
Hide file tree
Showing 20 changed files with 187 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ flush:
enable-express:
bin/magento module:enable Adyen_ExpressCheckout
bin/magento setup:upgrade
bin/magento config:set payment/adyen_express/show_google_pay_on "1,2,3"
bin/magento config:set payment/adyen_express/show_apple_pay_on "1,2,3"
bin/magento config:set payment/adyen_googlepay/express_show_on "1,2,3"
bin/magento config:set payment/adyen_applepay/express_show_on "1,2,3"
bin/magento cache:clean

# Full plugin setup
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
name: "CodeQL"

on:
push:
branches: [ "develop", "develop-6", "develop-7", "develop-8", "main", "main-6", "main-7", "main-8" ]
pull_request:
branches: [ "develop", "main" ]
paths-ignore:
- 'view/base/web/js/**'
schedule:
- cron: "6 1 * * 0"

jobs:
analyze:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
expressBranch:
description: "Express Checkout Repository Pipeline"
required: true
default: "develop"
default: "main"
testGroup:
description: "Test group"
required: true
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/e2e-test-express-checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ run-name: Adyen Magento 2 Express Checkout Plugin E2E tests
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize]
branches: [main]
pull_request_target:
branches: [main]

jobs:
build:
if: |
${{
github.event.pull_request.draft == false &&
(github.actor != 'renovate[bot]' || github.actor != 'lgtm-com[bot]')
}}
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) || (github.event_name == 'workflow_dispatch')
environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }}
runs-on:
group: larger-runners
labels: ubuntu-latest-8-cores
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Magento 2 E2E Pipeline
run-name: Adyen Magento 2 Payment Plugin E2E tests

on:
pull_request:
types: [opened, synchronize, ready_for_review]
pull_request_target:
types: [opened, synchronize, ready_for_review]
on: [pull_request, pull_request_target]

jobs:
build:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ on:
pull_request:
pull_request_target:
workflow_dispatch:
push:
branches: [main]

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) || (github.event_name == 'push') || (github.event_name == 'workflow_dispatch')
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) || (github.event_name == 'workflow_dispatch')
environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }}
runs-on: ubuntu-latest

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/mftf-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ on:
workflow_dispatch:
pull_request:
branches: [main]
pull_request_target:
branches: [main]

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:
include:
Expand Down
6 changes: 3 additions & 3 deletions Helper/OpenInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function getImageUrl($item): string
$product = $item->getProduct();
$imageUrl = "";

if ($image = $product->getSmallImage()) {
if ($product && $image = $product->getSmallImage()) {
$imageUrl = $this->imageHelper->init($product, 'product_page_image_small')
->setImageFile($image)
->getUrl();
Expand Down Expand Up @@ -187,14 +187,14 @@ protected function formatLineItem(AdyenAmountCurrency $itemAmountCurrency, $item
$product = $item->getProduct();

return [
'id' => $product->getId(),
'id' => $product ? $product->getId() : $item->getProductId(),
'amountExcludingTax' => $formattedPriceExcludingTax,
'amountIncludingTax' => $formattedPriceIncludingTax,
'taxAmount' => $formattedTaxAmount,
'description' => $item->getName(),
'quantity' => (int) ($qty ?? $item->getQty()),
'taxPercentage' => $formattedTaxPercentage,
'productUrl' => $product->getUrlModel()->getUrl($product),
'productUrl' => $product ? $product->getUrlModel()->getUrl($product) : '',
'imageUrl' => $this->getImageUrl($item)
];
}
Expand Down
12 changes: 7 additions & 5 deletions Helper/PaymentResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\Sales\Model\Order\Status\HistoryFactory;
use Magento\Sales\Model\OrderRepository;
use Magento\Sales\Model\ResourceModel\Order;
use Magento\Sales\Model\Order as OrderModel;

class PaymentResponseHandler
{
Expand Down Expand Up @@ -173,8 +174,9 @@ public function handlePaymentsDetailsResponse(
$paymentMethod
);

if (!empty($paymentsDetailsResponse['resultCode'])) {
$payment->setAdditionalInformation('resultCode', $paymentsDetailsResponse['resultCode']);
$resultCode = $paymentsDetailsResponse['resultCode'];
if (!empty($resultCode)) {
$payment->setAdditionalInformation('resultCode', $resultCode);
}

if (!empty($paymentsDetailsResponse['action'])) {
Expand All @@ -201,7 +203,7 @@ public function handlePaymentsDetailsResponse(
$this->vaultHelper->handlePaymentResponseRecurringDetails($payment, $paymentsDetailsResponse);

// If the response is valid, update the order status.
if (!in_array($paymentsDetailsResponse['resultCode'], PaymentResponseHandler::ACTION_REQUIRED_STATUSES)) {
if (!in_array($resultCode, PaymentResponseHandler::ACTION_REQUIRED_STATUSES) && $order->getState() === OrderModel::STATE_PENDING_PAYMENT) {
/*
* Change order state from pending_payment to new and expect authorisation webhook
* if no additional action is required according to /paymentsDetails response.
Expand All @@ -218,7 +220,7 @@ public function handlePaymentsDetailsResponse(
$this->adyenLogger->error(__('Error cleaning the payment state data: %s', $exception->getMessage()));
}

switch ($paymentsDetailsResponse['resultCode']) {
switch ($resultCode) {
case self::AUTHORISED:
if (!empty($paymentsDetailsResponse['pspReference'])) {
// set pspReference as transactionId
Expand Down Expand Up @@ -294,7 +296,7 @@ public function handlePaymentsDetailsResponse(
$this->adyenLogger->error(
sprintf("Payment details call failed for action, resultCode is %s Raw API responds: %s.
Cancel or Hold the order on OFFER_CLOSED notification.",
$paymentsDetailsResponse['resultCode'],
$resultCode,
json_encode($paymentsDetailsResponse)
));

Expand Down
2 changes: 1 addition & 1 deletion Model/Method/TxVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class TxVariant
{
private ?string $card;
private ?string $card = null;
private string $paymentMethod;

public function __construct(string $txVariant)
Expand Down
53 changes: 53 additions & 0 deletions Model/Resolver/StoreConfig/StoreLocale.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2024 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/
declare(strict_types=1);

namespace Adyen\Payment\Model\Resolver\StoreConfig;

use Adyen\Payment\Helper\Data;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
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;

/**
* @param Data $adyenHelper
*/
public function __construct(
Data $adyenHelper
) {
$this->adyenHelper = $adyenHelper;
}

/**
* @param Context $context
* @inheritDoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
): ?string {
/** @var StoreInterface $store */
$store = $context->getExtensionAttributes()->getStore();
return $this->adyenHelper->getStoreLocale((int)$store->getId());
}
}
6 changes: 6 additions & 0 deletions Test/Unit/AbstractAdyenTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ protected function createMockWithMethods(string $originalClassName, array $exist
/**
* Mock a class dynamically generated by Magento. In future additionalMethods have to be split
* similar to createMockWithMethods since setMethods is deprecated
*
* @psalm-template RealInstanceType of object
*
* @psalm-param class-string<RealInstanceType> $originalClassName
*
* @psalm-return MockObject&RealInstanceType
*/
protected function createGeneratedMock(string $originalClassName, array $additionalMethods = []): MockObject
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PHPUnit\Framework\TestCase;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Adyen\Payment\Exception\GraphQlAdyenException;
use Magento\Framework\GraphQl\Query;

class GetAdyenPaymentMethodsBalanceTest extends TestCase
{
Expand Down
91 changes: 91 additions & 0 deletions Test/Unit/Model/Resolver/StoreConfig/StoreLocaleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2024 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <[email protected]>
*/
declare(strict_types=1);

namespace Adyen\Payment\Test\Unit\Model\Resolver\StoreConfig;

use Adyen\Payment\Helper\Data;
use Adyen\Payment\Model\Resolver\StoreConfig\StoreLocale;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\GraphQl\Model\Query\Context;
use Magento\GraphQl\Model\Query\ContextExtensionInterface;
use Magento\Store\Model\Store;
use PHPUnit\Framework\MockObject\MockObject;

/**
* @coversDefaultClass \Adyen\Payment\Model\Resolver\StoreConfig\StoreLocale
*/
class StoreLocaleTest extends AbstractAdyenTestCase
{
private MockObject&Context $contextMock;
private MockObject&Field $fieldMock;
private MockObject&ResolveInfo $infoMock;
private MockObject&Data $dataHelperMock;
private MockObject&ContextExtensionInterface $contextExtensionMock;
private StoreLocale $storeLocale;

protected function setUp(): void
{
$this->contextExtensionMock = $this->createGeneratedMock(
ContextExtensionInterface::class,
['getStore']
);

$this->contextMock = $this->getMockBuilder(Context::class)
->disableOriginalConstructor()
->onlyMethods(['getExtensionAttributes'])
->getMock();

$this->fieldMock = $this->createMock(Field::class);
$this->infoMock = $this->createMock(ResolveInfo::class);

$this->dataHelperMock = $this->getMockBuilder(Data::class)
->disableOriginalConstructor()
->onlyMethods(['getStoreLocale'])
->getMock();

$this->storeLocale = new StoreLocale($this->dataHelperMock);
}

/**
* @return void
* @throws \Exception
* @covers ::resolve
*/
public function testGetStoreLocale(): void
{
$storeMock = $this->createConfiguredMock(Store::class, [
'getId' => 1,
]);

$this->contextExtensionMock
->expects($this->once())
->method('getStore')
->willReturn($storeMock);

$this->contextMock
->expects($this->once())
->method('getExtensionAttributes')
->willReturn($this->contextExtensionMock);

$this->dataHelperMock
->expects($this->once())
->method('getStoreLocale')
->willReturn('fr_FR');

$this->assertEquals(
'fr_FR',
$this->storeLocale->resolve($this->fieldMock, $this->contextMock, $this->infoMock, [], [])
);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"magento/framework": ">=103.0.4",
"magento/module-vault": ">=101.2.4",
"magento/module-multishipping": ">=100.4.4",
"magento/module-graph-ql": ">=100.4.4",
"ext-json": "*"
},
"require-dev": {
Expand Down
6 changes: 3 additions & 3 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@
<adyen_directEbanking>
<active>0</active>
<model>AdyenPaymentDirectEbankingFacade</model>
<title>Sofort</title>
<title>Klarna Debit Risk</title>
<allowspecific>0</allowspecific>
<sort_order>0</sort_order>
<payment_action>authorize</payment_action>
Expand All @@ -893,7 +893,7 @@
<group>adyen-alternative-payment-method</group>
</adyen_directEbanking>
<adyen_directEbanking_vault>
<title>Stored Sofort</title>
<title>Stored Klarna Debit Risk</title>
<model>AdyenPaymentDirectEbankingVaultFacade</model>
</adyen_directEbanking_vault>
<adyen_ebanking_FI>
Expand Down Expand Up @@ -2209,4 +2209,4 @@
</adyen_dana_vault>
</payment>
</default>
</config>
</config>
1 change: 1 addition & 0 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,5 @@ type StoreConfig @doc(description: "The type contains information about a store
adyen_title_renderer: String @doc(description: "Adyen Render Mode for Payment Method.")
adyen_return_path_error: String @doc(description: "Adyen Return path in case of error")
adyen_checkout_frontend_region: String @doc(description: "Adyen front end resources region.")
adyen_store_locale : String @doc(description: "Adyen store locale.") @resolver(class: "Adyen\\Payment\\Model\\Resolver\\StoreConfig\\StoreLocale")
}
Loading

0 comments on commit 230491f

Please sign in to comment.