Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 9.0.7 #2459

Merged
merged 16 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
name: Magento 2 E2E Pipeline
run-name: Adyen Magento 2 Payment Plugin E2E tests

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

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)
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 Expand Up @@ -43,15 +42,15 @@ jobs:

- name: Install plugin
run: docker exec -u www-data magento2-container make plugin

- name: Kill Cron Jobs
run: docker exec magento2-container /etc/init.d/cron stop

- name: Checkout developer module
uses: actions/checkout@v3
with:
repository: Adyen/adyen-magento2-dev
ref: 'main'
ref: "main"
token: ${{ secrets.ADYEN_AUTOMATION_BOT_TEST_ACCESS_TOKEN }}
path: Developer

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/graphql-test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: GraphQL Tests
on: [pull_request]
on: [pull_request, pull_request_target]

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.1"]
Expand Down
76 changes: 39 additions & 37 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
name: Main CI workflow

on: [pull_request]
on: [pull_request, pull_request_target]

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' }}
runs-on: ubuntu-latest

strategy:
matrix:
php-version: [8.1]

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v1

- name: Test plugin installation
run: |
echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_USERNAME}\",\"password\":\"${MAGENTO_PASSWORD}\"}}}" > auth.json
composer install --prefer-dist
env:
CI: true
MAGENTO_USERNAME: ${{ secrets.MAGENTO_USERNAME }}
MAGENTO_PASSWORD: ${{ secrets.MAGENTO_PASSWORD }}

- name: Code Sniffer
run: vendor/bin/phpcs --extensions=php,phtml --error-severity=10 --ignore-annotations

- name: Run PHPUnit
run: vendor/bin/phpunit --coverage-clover=build/clover.xml --log-junit=build/tests-log.xml -c Test/phpunit.xml Test/Unit

- name: Fix code coverage paths
run: sed -i "s;`pwd`/;;g" build/*.xml

- name: SonarCloud Scan
if: ${{ env.SONAR_TOKEN }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v1

- name: Test plugin installation
run: |
echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_USERNAME}\",\"password\":\"${MAGENTO_PASSWORD}\"}}}" > auth.json
composer install --prefer-dist
env:
CI: true
MAGENTO_USERNAME: ${{ secrets.MAGENTO_USERNAME }}
MAGENTO_PASSWORD: ${{ secrets.MAGENTO_PASSWORD }}

- name: Code Sniffer
run: vendor/bin/phpcs --extensions=php,phtml --error-severity=10 --ignore-annotations

- name: Run PHPUnit
run: vendor/bin/phpunit --coverage-clover=build/clover.xml --log-junit=build/tests-log.xml -c Test/phpunit.xml Test/Unit

- name: Fix code coverage paths
run: sed -i "s;`pwd`/;;g" build/*.xml

- name: SonarCloud Scan
if: ${{ env.SONAR_TOKEN }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4 changes: 3 additions & 1 deletion .github/workflows/restapi-test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: REST API Tests
on: [pull_request]
on: [pull_request, pull_request_target]

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.1"]
Expand Down
16 changes: 8 additions & 8 deletions Block/Checkout/Multishipping/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@

class Success extends \Magento\Multishipping\Block\Checkout\Success
{
const FINAL_RESULT_CODES = array(
PaymentResponseHandler::AUTHORISED,
PaymentResponseHandler::PENDING,
PaymentResponseHandler::REFUSED,
PaymentResponseHandler::PRESENT_TO_SHOPPER
);
const ACTION_REQUIRED_STATUSES = [
PaymentResponseHandler::REDIRECT_SHOPPER,
PaymentResponseHandler::IDENTIFY_SHOPPER,
PaymentResponseHandler::CHALLENGE_SHOPPER,
PaymentResponseHandler::PENDING
];

/**
* @var bool
Expand Down Expand Up @@ -122,7 +122,7 @@ public function __construct(
public function renderAction()
{
foreach ($this->paymentResponseEntities as $paymentResponseEntity) {
if (!in_array($paymentResponseEntity['result_code'], self::FINAL_RESULT_CODES)) {
if (in_array($paymentResponseEntity['result_code'], self::ACTION_REQUIRED_STATUSES)) {
return true;
}
}
Expand Down Expand Up @@ -189,7 +189,7 @@ private function setOrderInfo($orderIds)
public function getIsPaymentCompleted(int $orderId)
{
// TODO check for all completed responses, not only Authorised, Refused, Pending or PresentToShopper
return in_array($this->ordersInfo[$orderId]['resultCode'], self::FINAL_RESULT_CODES);
return !in_array($this->ordersInfo[$orderId]['resultCode'], self::ACTION_REQUIRED_STATUSES);
}

public function getPaymentButtonLabel(int $orderId)
Expand Down
1 change: 1 addition & 0 deletions Controller/Return/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ protected function validatePayloadAndReturnResponse(array $result): array

$request["details"] = $details;
$requestOptions['idempotencyKey'] = $this->idempotencyHelper->generateIdempotencyKey($request);
$requestOptions['headers'] = $this->adyenDataHelper->buildRequestHeaders();

try {
$response = $service->paymentsDetails($request, $requestOptions);
Expand Down
1 change: 1 addition & 0 deletions Gateway/Http/Client/TransactionCancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function placeRequest(TransferInterface $transferObject): array
$headers['idempotencyExtraData'] ?? null
);
$requestOptions['idempotencyKey'] = $idempotencyKey;
$requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders();
$this->adyenHelper->logRequest($requests, Client::API_CHECKOUT_VERSION, '/cancels');
try {
$responses = $service->cancels($requests, $requestOptions);
Expand Down
1 change: 1 addition & 0 deletions Gateway/Http/Client/TransactionCapture.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function placeRequest(TransferInterface $transferObject): array
);

$requestOptions['idempotencyKey'] = $idempotencyKey;
$requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders();

if (array_key_exists(self::MULTIPLE_AUTHORIZATIONS, $request)) {
return $this->placeMultipleCaptureRequests($service, $request, $requestOptions);
Expand Down
1 change: 1 addition & 0 deletions Gateway/Http/Client/TransactionDonate.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function placeRequest(TransferInterface $transferObject)
);

$requestOptions['idempotencyKey'] = $idempotencyKey;
$requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders();

$this->adyenHelper->logRequest($request, Client::API_CHECKOUT_VERSION, 'donations');
try {
Expand Down
1 change: 1 addition & 0 deletions Gateway/Http/Client/TransactionPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function placeRequest(TransferInterface $transferObject): array
$headers['idempotencyExtraData'] ?? null
);
$requestOptions['idempotencyKey'] = $idempotencyKey;
$requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders();

$this->adyenHelper->logRequest($request, Client::API_CHECKOUT_VERSION, '/payments');
$response = $service->payments($request, $requestOptions);
Expand Down
1 change: 1 addition & 0 deletions Gateway/Http/Client/TransactionPaymentLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function placeRequest(TransferInterface $transferObject): array
);

$requestOptions['idempotencyKey'] = $idempotencyKey;
$requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders();

$this->adyenHelper->logRequest($request, Client::API_CHECKOUT_VERSION, '/paymentLinks');
try {
Expand Down
3 changes: 2 additions & 1 deletion Gateway/Http/Client/TransactionRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ public function placeRequest(TransferInterface $transferObject): array
$headers['idempotencyExtraData'] ?? null
);
$requestOptions['idempotencyKey'] = $idempotencyKey;
$this->adyenHelper->logRequest($request, Client::API_CHECKOUT_VERSION, '/refunds');
$requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders();

$this->adyenHelper->logRequest($request, Client::API_CHECKOUT_VERSION, '/refunds');
try {
$response = $service->refunds($request, $requestOptions);
// Add amount original reference and amount information to response
Expand Down
4 changes: 0 additions & 4 deletions Gateway/Request/CheckoutDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ public function build(array $buildSubject): array

$requestBody['additionalData']['allow3DS2'] = true;

if (isset($requestBodyPaymentMethod)) {
$requestBody['paymentMethod'] = $requestBodyPaymentMethod;
}

return [
'body' => $requestBody
];
Expand Down
3 changes: 2 additions & 1 deletion Gateway/Request/GiftcardDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function build(array $buildSubject): array
{
/** @var PaymentDataObject $paymentDataObject */
$paymentDataObject = SubjectReader::readPayment($buildSubject);
$order = $paymentDataObject->getOrder();
$payment = $paymentDataObject->getPayment();
$order = $payment->getOrder();

$request = [];

Expand Down
4 changes: 4 additions & 0 deletions Gateway/Response/PaymentPosCloudHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public function handle(array $handlingSubject, array $response)
);
$payment->setAdditionalInformation('additionalData', $paymentResponseDecoded['additionalData']);

if (isset($paymentResponseDecoded['additionalData']['pspReference'])) {
$payment->setAdditionalInformation('pspReference', $paymentResponseDecoded['additionalData']['pspReference']);
}

$this->vaultHelper->handlePaymentResponseRecurringDetails(
$payment->getOrder()->getPayment(),
$paymentResponseDecoded
Expand Down
27 changes: 24 additions & 3 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1146,9 +1146,9 @@ public function initializeAdyenClient(
$client->setRegion($checkoutFrontendRegion);
}

$moduleVersion = $this->getModuleVersion();
$client->setMerchantApplication($this->getModuleName(), $moduleVersion);
$client->setExternalPlatform($this->productMetadata->getName(), $this->productMetadata->getVersion(), 'Adyen');
$client->setMerchantApplication($this->getModuleName(), $this->getModuleVersion());
$platformData = $this->getMagentoDetails();
$client->setExternalPlatform($platformData['name'], $platformData['version'], 'Adyen');
if ($isDemo) {
$client->setEnvironment(Environment::TEST);
} else {
Expand All @@ -1158,6 +1158,27 @@ public function initializeAdyenClient(
return $client;
}

public function getMagentoDetails()
{
return [
'name' => $this->productMetadata->getName(),
'version' => $this->productMetadata->getVersion(),
'edition' => $this->productMetadata->getEdition(),
];
}

public function buildRequestHeaders()
{
$magentoDetails = $this->getMagentoDetails();
return [
'external-platform-name' => $this->getModuleName(),
'external-platform-version' => $this->getModuleVersion(),
'merchant-application-name' => $magentoDetails['name'],
'merchant-application-version' => $magentoDetails['version'],
'merchant-application-edition' => $magentoDetails['edition'],
];
}

/**
* @throws AdyenException
* @throws NoSuchEntityException
Expand Down
34 changes: 13 additions & 21 deletions Helper/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\Asset\Repository;
Expand All @@ -29,7 +30,6 @@
use Magento\Payment\Helper\Data as MagentoDataHelper;
use Magento\Payment\Model\MethodInterface;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\PaymentMethodInterface;
use Magento\Sales\Model\Order;
use Adyen\Payment\Helper\Data as AdyenDataHelper;
use Magento\Store\Model\ScopeInterface;
Expand Down Expand Up @@ -266,9 +266,10 @@ protected function setQuote(\Magento\Quote\Model\Quote $quote): void
$this->quote = $quote;
}

protected function getCurrentShopperReference(): ?int
protected function getCurrentShopperReference(): ?string
{
return $this->getQuote()->getCustomerId();
$customerId = $this->getQuote()->getCustomerId();
return $customerId ? (string)$customerId : null;
}

protected function getPaymentMethodsRequest(
Expand Down Expand Up @@ -380,21 +381,6 @@ protected function addExtraConfigurationToPaymentMethods(
return $paymentMethodsExtraDetails;
}

public function isWalletTxVariant(string $notificationPaymentMethod): bool
{
$walletPaymentMethods = [
'googlepay',
'paywithgoogle',
'wechatpayWeb',
'amazonpay',
'applepay',
'wechatpayQR',
'alipay',
'alipay_hk'
];
return in_array($notificationPaymentMethod, $walletPaymentMethods);
}

public function isWalletPaymentMethod(MethodInterface $paymentMethodInstance): bool
{
return boolval($paymentMethodInstance->getConfigData('is_wallet'));
Expand Down Expand Up @@ -627,12 +613,18 @@ public function isAutoCapture(Order $order, string $notificationPaymentMethod):

public function compareOrderAndWebhookPaymentMethods(Order $order, Notification $notification): bool
{
// For cards, it can be 'VI', 'MI',... For alternatives, it can be 'ideal', 'directEbanking',...
$orderPaymentMethod = $order->getPayment()->getCcType();
$paymentMethodInstance = $order->getPayment()->getMethodInstance();

if ($this->isAlternativePaymentMethod($paymentMethodInstance)) {
$orderPaymentMethod = $this->getAlternativePaymentMethodTxVariant($paymentMethodInstance);
} else {
$orderPaymentMethod = $order->getPayment()->getCcType();
}

$notificationPaymentMethod = $notification->getPaymentMethod();

// Returns if the payment method is wallet like wechatpayWeb, amazonpay, applepay, paywithgoogle
$isWalletPaymentMethod = $this->isWalletTxVariant($orderPaymentMethod);
$isWalletPaymentMethod = $this->isWalletPaymentMethod($paymentMethodInstance);
$isCardPaymentMethod = $order->getPayment()->getMethod() === 'adyen_cc' || $order->getPayment()->getMethod() === 'adyen_oneclick';

// If it is a wallet method OR a card OR the methods match exactly, return true
Expand Down
Loading