Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/check-payment-method-response-before-…
Browse files Browse the repository at this point in the history
…using
  • Loading branch information
candemiralp authored Feb 5, 2025
2 parents d13c568 + a230cef commit b0a1e2d
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/docker-compose.e2e.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
playwright:
image: mcr.microsoft.com/playwright:v1.49.1
image: mcr.microsoft.com/playwright:v1.50.1
shm_size: 1gb
ipc: host
cap_add:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:

- name: Archive test result artifacts
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: html-report
path: test-report
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

use Adyen\Payment\Logger\AdyenLogger;
use Exception;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem\DirectoryList;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
Expand All @@ -30,7 +28,7 @@ class DownloadApplePayDomainAssociationFile extends Action
const WELL_KNOWN_PATH = '.well-known';

public function __construct(
private readonly Context $context,
Context $context,
private readonly DirectoryList $directoryList,
private readonly File $fileIo,
private readonly AdyenLogger $adyenLogger
Expand All @@ -39,10 +37,9 @@ public function __construct(
}

/**
* @return ResultInterface|ResponseInterface
* @throws FileSystemException
* @return ResultInterface
*/
public function execute(): ResultInterface|ResponseInterface
public function execute(): ResultInterface
{
$redirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$redirect->setUrl($this->_redirect->getRefererUrl());
Expand Down
4 changes: 3 additions & 1 deletion Controller/Webhook/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ private function isAuthorised(array $response)
{
// Add CGI support
$this->fixCgiHttpAuthentication();
$merchantAccount = $this->configHelper->getMerchantAccount()
?? $this->configHelper->getMotoMerchantAccounts();

$authResult = $this->notificationReceiver->isAuthenticated(
$response,
$this->configHelper->getMerchantAccount(),
$merchantAccount,
$this->configHelper->getNotificationsUsername(),
$this->configHelper->getNotificationsPassword()
);
Expand Down
9 changes: 9 additions & 0 deletions Gateway/Response/CheckoutPaymentsDetailsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public function handle(array $handlingSubject, array $responseCollection)
$payment->setCcTransId($response['pspReference']);
$payment->setLastTransId($response['pspReference']);

//set CC Type
$ccType = $payment->getAdditionalInformation('cc_type');

if (!empty($response['additionalData']['paymentMethod']) && $ccType == null) {
$ccType = $response['additionalData']['paymentMethod'];
$payment->setAdditionalInformation('cc_type', $ccType);
$payment->setCcType($ccType);
}

// set transaction
$payment->setTransactionId($response['pspReference']);
}
Expand Down
3 changes: 2 additions & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ public function getCheckoutFrontendRegions()
'eu' => 'Default (EU - Europe)',
'au' => 'AU - Australasia',
'us' => 'US - United States',
'in' => 'IN - India'
'in' => 'IN - India',
'apse' => 'APSE - Asia Pacific Southeast'
];
}

Expand Down
6 changes: 4 additions & 2 deletions Helper/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,11 @@ public function isFullInvoiceAmountManuallyCaptured(InvoiceModel $invoice): bool
}
}

$invoiceChargedCurrency = $this->chargedCurrencyHelper->getInvoiceAmountCurrency($invoice);

$invoiceAmountCents = $this->adyenDataHelper->formatAmount(
$invoice->getGrandTotal(),
$invoice->getOrderCurrencyCode()
$invoiceChargedCurrency->getAmount(),
$invoiceChargedCurrency->getCurrencyCode()
);

$invoiceCapturedAmountCents = $this->adyenDataHelper->formatAmount(
Expand Down
3 changes: 2 additions & 1 deletion Helper/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class PaymentMethods extends AbstractHelper
const ADYEN_ONE_CLICK = 'adyen_oneclick';
const ADYEN_PAY_BY_LINK = 'adyen_pay_by_link';
const ADYEN_PREFIX = 'adyen_';
const ADYEN_CC_VAULT = 'adyen_cc_vault';
const METHODS_WITH_BRAND_LOGO = [
"giftcard"
];
Expand Down Expand Up @@ -958,7 +959,7 @@ public function compareOrderAndWebhookPaymentMethods(Order $order, Notification

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

// If it is a wallet method OR a card OR the methods match exactly, return true
if ($isWalletPaymentMethod || $isCardPaymentMethod || strcmp($notificationPaymentMethod, $orderPaymentMethod) === 0) {
Expand Down
24 changes: 21 additions & 3 deletions Helper/PaymentResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Adyen\Payment\Helper;

use Adyen\Model\Checkout\CancelOrderRequest;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Logger\AdyenLogger;
use Adyen\Payment\Model\ResourceModel\PaymentResponse\CollectionFactory as PaymentResponseCollectionFactory;
use Exception;
Expand All @@ -24,7 +23,6 @@
use Magento\Sales\Model\OrderRepository;
use Magento\Sales\Model\ResourceModel\Order;
use Magento\Sales\Model\Order as OrderModel;
use Adyen\Payment\Helper\Data;
use Magento\Framework\Mail\Exception\InvalidArgumentException;
use Adyen\Client;

Expand Down Expand Up @@ -65,6 +63,7 @@ class PaymentResponseHandler
private StateData $stateDataHelper;
private PaymentResponseCollectionFactory $paymentResponseCollectionFactory;
private Config $configHelper;
private PaymentMethods $paymentMethodsHelper;

public function __construct(
AdyenLogger $adyenLogger,
Expand All @@ -77,7 +76,8 @@ public function __construct(
HistoryFactory $orderHistoryFactory,
StateData $stateDataHelper,
PaymentResponseCollectionFactory $paymentResponseCollectionFactory,
Config $configHelper
Config $configHelper,
PaymentMethods $paymentMethodsHelper
) {
$this->adyenLogger = $adyenLogger;
$this->vaultHelper = $vaultHelper;
Expand All @@ -90,6 +90,7 @@ public function __construct(
$this->stateDataHelper = $stateDataHelper;
$this->paymentResponseCollectionFactory = $paymentResponseCollectionFactory;
$this->configHelper = $configHelper;
$this->paymentMethodsHelper = $paymentMethodsHelper;
}

public function formatPaymentResponse(
Expand Down Expand Up @@ -159,6 +160,12 @@ public function handlePaymentsDetailsResponse(
$this->adyenLogger->addAdyenResult('Updating the order');
$payment = $order->getPayment();

//Check magento Payment Method
$paymentMethodInstance = $payment->getMethodInstance();
$isWalletPaymentMethod = $this->paymentMethodsHelper->isWalletPaymentMethod($paymentMethodInstance);
$isCardPaymentMethod = $payment->getMethod() === PaymentMethods::ADYEN_CC ||
$payment->getMethod() === PaymentMethods::ADYEN_CC_VAULT;

$authResult = $paymentsDetailsResponse['authResult'] ?? $paymentsDetailsResponse['resultCode'] ?? null;
if (is_null($authResult)) {
// In case the result is unknown we log the request and don't update the history
Expand Down Expand Up @@ -211,6 +218,17 @@ public function handlePaymentsDetailsResponse(
$payment->setAdditionalInformation('donationToken', $paymentsDetailsResponse['donationToken']);
}

$ccType = $payment->getAdditionalInformation('cc_type');

if (!empty($paymentsDetailsResponse['additionalData']['paymentMethod']) &&
is_null($ccType) &&
($isWalletPaymentMethod || $isCardPaymentMethod)
) {
$ccType = $paymentsDetailsResponse['additionalData']['paymentMethod'];
$payment->setAdditionalInformation('cc_type', $ccType);
$payment->setCcType($ccType);
}

// Handle recurring details
$this->vaultHelper->handlePaymentResponseRecurringDetails($payment, $paymentsDetailsResponse);

Expand Down
9 changes: 8 additions & 1 deletion Model/Api/PaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* See LICENSE.txt for license details.
*
* Author: Adyen <[email protected]>
* @deprecated This class is deprecated and will be removed in a future release.
* Use an alternative service or class for similar requests.
*/

namespace Adyen\Payment\Model\Api;
Expand Down Expand Up @@ -87,8 +89,10 @@ public function __construct(
}

/**
* @deprecated This method is deprecated and will be removed in a future release.
*
* @param Payment $payment
* @return mixed
* @return array
* @throws LocalizedException
* @throws NoSuchEntityException
*/
Expand Down Expand Up @@ -134,6 +138,7 @@ public function authorise3d(Payment $payment): array
}

/**
* @deprecated This method is redundant and no more used with the current flow. Will be deleted in the future releases.
* @param string $shopperReference
* @param int $storeId
* @return array
Expand Down Expand Up @@ -182,6 +187,7 @@ public function getRecurringContractsForShopper(string $shopperReference, int $s
}

/**
* @deprecated This method is a part of deprecated parent and will be removed in the future releases.
* @param string $shopperReference
* @param int $storeId
* @param string $recurringType
Expand All @@ -208,6 +214,7 @@ public function listRecurringContractByType(string $shopperReference, int $store
}

/**
* @deprecated This method is redundant and will be removed in the coming major release.
* @param string $recurringDetailReference
* @param string $shopperReference
* @param int $storeId
Expand Down
7 changes: 6 additions & 1 deletion Model/Ui/AdyenCcConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Adyen\Payment\Helper\PaymentMethods;
use Adyen\Payment\Helper\Vault;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\App\Request\Http;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\UrlInterface;
Expand All @@ -38,6 +39,7 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
private Config $configHelper;
private PaymentMethods $paymentMethodsHelper;
private Vault $vaultHelper;
private Http $httpRequest;

public function __construct(
Data $adyenHelper,
Expand All @@ -49,7 +51,8 @@ public function __construct(
SerializerInterface $serializer,
Config $configHelper,
PaymentMethods $paymentMethodsHelper,
Vault $vaultHelper
Vault $vaultHelper,
Http $httpRequest
) {
$this->adyenHelper = $adyenHelper;
$this->request = $request;
Expand All @@ -61,6 +64,7 @@ public function __construct(
$this->configHelper = $configHelper;
$this->paymentMethodsHelper = $paymentMethodsHelper;
$this->vaultHelper = $vaultHelper;
$this->httpRequest = $httpRequest;
}

public function getConfig(): array
Expand Down Expand Up @@ -111,6 +115,7 @@ public function getConfig(): array
$config['payment']['adyenCc']['isCardRecurringEnabled'] = $cardRecurringEnabled;
$config['payment']['adyenCc']['icons'] = $this->getIcons();
$config['payment']['adyenCc']['isClickToPayEnabled'] = $this->configHelper->isClickToPayEnabled($storeId);
$config['payment']['adyenCc']['controllerName'] = $this->httpRequest->getControllerName();

// has installments by default false
$config['payment']['adyenCc']['hasInstallments'] = false;
Expand Down
22 changes: 20 additions & 2 deletions Test/Unit/Gateway/Response/CheckoutPaymentsDetailsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ public function testIfPartialPaymentHandlesLastPaymentResponse()
]
],
1 => [
'additionalData' => [],
'additionalData' => [
'paymentMethod' => 'VI',
],
'amount' => [],
'resultCode' => 'Authorised',
'pspReference' => 'ABC12345',
'paymentMethod' => [
'name' => 'card',
'type' => 'CreditCard',
'type' => 'VI',
]
]
];
Expand Down Expand Up @@ -146,6 +148,22 @@ public function testIfPartialPaymentHandlesLastPaymentResponse()
->method('setTransactionId')
->with('ABC12345');

$this->paymentMock
->expects($this->once())
->method('getAdditionalInformation')
->with('cc_type')
->willReturn(null);

$this->paymentMock
->expects($this->once())
->method('setAdditionalInformation')
->with('cc_type', 'VI');

$this->paymentMock
->expects($this->once())
->method('setCcType')
->with('VI');

$this->applyGenericMockExpectations();

$this->checkoutPaymentsDetailsHandler->handle($this->handlingSubject, $responseCollection);
Expand Down
6 changes: 4 additions & 2 deletions Test/Unit/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ public function testGetCheckoutFrontendRegions()
'eu' => 'Default (EU - Europe)',
'au' => 'AU - Australasia',
'us' => 'US - United States',
'in' => 'IN - India'
'in' => 'IN - India',
'apse' => 'APSE - Asia Pacific Southeast'
];

$actualResult = $this->dataHelper->getCheckoutFrontendRegions();
Expand Down Expand Up @@ -1803,7 +1804,8 @@ public function getCheckoutFrontendRegionsShouldReturnAnArray()
'eu' => 'Default (EU - Europe)',
'au' => 'AU - Australasia',
'us' => 'US - United States',
'in' => 'IN - India'
'in' => 'IN - India',
'apse' => 'APSE - Asia Pacific Southeast'
], $this->dataHelper->getRecurringTypes());
}

Expand Down
22 changes: 21 additions & 1 deletion Test/Unit/Helper/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ public function testHandleCaptureWebhook()
$adyenAmountCurrencyMock->method('getAmount')->willReturn(10);
$adyenAmountCurrencyMock->method('getCurrencyCode')->willReturn('EUR');

$invoiceAmountCurrency = $this->createMock(AdyenAmountCurrency::class);

$chargedCurrencyMock = $this->createMock(ChargedCurrency::class);
$chargedCurrencyMock->method('getOrderAmountCurrency')->willReturn($adyenAmountCurrencyMock);
$chargedCurrencyMock->method('getInvoiceAmountCurrency')->willReturn($invoiceAmountCurrency);

$invoiceHelper = $this->createInvoiceHelper(
$contextMock,
Expand Down Expand Up @@ -277,6 +280,17 @@ public function testIsFullInvoiceAmountManuallyCaptured()
],
]);

$invoiceAmountCurrency = $this->createMock(AdyenAmountCurrency::class);
$invoiceAmountCurrency->expects($this->once())
->method('getAmount')
->willReturn(1000);
$invoiceAmountCurrency->expects($this->once())
->method('getCurrencyCode')
->willReturn('EUR');

$chargedCurrencyMock = $this->createMock(ChargedCurrency::class);
$chargedCurrencyMock->method('getInvoiceAmountCurrency')->willReturn($invoiceAmountCurrency);

$invoiceHelper = $this->createInvoiceHelper(
null,
null,
Expand All @@ -286,7 +300,13 @@ public function testIsFullInvoiceAmountManuallyCaptured()
null,
null,
null,
$adyenInvoiceCollectionMock
$adyenInvoiceCollectionMock,
null,
null,
null,
null,
null,
$chargedCurrencyMock
);

$invoiceMock = $this->createConfiguredMock(InvoiceModel::class, [
Expand Down
Loading

0 comments on commit b0a1e2d

Please sign in to comment.