Skip to content

Commit

Permalink
Merge branch 'main' into ECP-9521
Browse files Browse the repository at this point in the history
  • Loading branch information
khushboo-singhvi authored Jan 15, 2025
2 parents d3743ea + 4b53a16 commit 4e2945a
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 105 deletions.
7 changes: 5 additions & 2 deletions Gateway/Request/CheckoutDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,11 @@ public function build(array $buildSubject): array
unset($requestBody['installments']);
}

$requestBody['additionalData']['allow3DS2'] =
$this->configHelper->getThreeDSFlow($storeId) === ThreeDSFlow::THREEDS_NATIVE;
$threeDSFlow = $this->configHelper->getThreeDSFlow($order->getStoreId());
$requestBody['authenticationData']['threeDSRequestData']['nativeThreeDS'] =
$threeDSFlow === ThreeDSFlow::THREEDS_NATIVE ?
ThreeDSFlow::THREEDS_PREFERRED :
ThreeDSFlow::THREEDS_DISABLED;

return [
'body' => $requestBody
Expand Down
7 changes: 5 additions & 2 deletions Gateway/Request/RecurringVaultDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ public function build(array $buildSubject): array
* `allow3DS: true` flag is required to trigger the native 3DS challenge.
* Otherwise, shopper will be redirected to the issuer for challenge.
*/
$requestBody['additionalData']['allow3DS2'] =
$this->configHelper->getThreeDSFlow($order->getStoreId()) === ThreeDSFlow::THREEDS_NATIVE;
$threeDSFlow = $this->configHelper->getThreeDSFlow($order->getStoreId());
$requestBody['authenticationData']['threeDSRequestData']['nativeThreeDS'] =
$threeDSFlow === ThreeDSFlow::THREEDS_NATIVE ?
ThreeDSFlow::THREEDS_PREFERRED :
ThreeDSFlow::THREEDS_DISABLED;

// Due to new VISA compliance requirements, holderName is added to the payments call
$requestBody['paymentMethod']['holderName'] = $details['cardHolderName'] ?? null;
Expand Down
127 changes: 34 additions & 93 deletions Helper/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,107 +45,47 @@
class Invoice extends AbstractHelper
{
/**
* @var AdyenLogger
* @param Context $context
* @param AdyenLogger $adyenLogger
* @param Data $adyenDataHelper
* @param InvoiceRepositoryInterface $invoiceRepository
* @param InvoiceFactory $adyenInvoiceFactory
* @param AdyenInvoiceResourceModel $adyenInvoiceResourceModel
* @param OrderPaymentResourceModel $orderPaymentResourceModel
* @param PaymentFactory $adyenOrderPaymentFactory
* @param Collection $adyenInvoiceCollection
* @param MagentoInvoiceFactory $magentoInvoiceFactory
* @param \Magento\Sales\Model\ResourceModel\Order $magentoOrderResourceModel
* @param Config $configHelper
* @param InvoiceSender $invoiceSender
* @param Transaction $transaction
* @param ChargedCurrency $chargedCurrencyHelper
*/
protected $adyenLogger;

/**
* @var Data
*/
protected $adyenDataHelper;

/**
* @var InvoiceRepositoryInterface
*/
protected $invoiceRepository;

/**
* @var \Magento\Sales\Model\ResourceModel\Order
*/
protected $magentoOrderResourceModel;

/**
* @var InvoiceFactory
*/
protected $adyenInvoiceFactory;

/**
* @var AdyenInvoiceResourceModel
*/
protected $adyenInvoiceResourceModel;

/**
* @var Collection
*/
protected $adyenInvoiceCollection;

/**
* @var OrderPaymentResourceModel
*/
protected $orderPaymentResourceModel;

/**
* @var PaymentFactory
*/
protected $adyenOrderPaymentFactory;

/**
* @var MagentoInvoiceFactory
*/
protected $magentoInvoiceFactory;

/**
* @var Config
*/
protected $configHelper;

/**
* @var InvoiceSender
*/
protected $invoiceSender;

/**
* @var Transaction
*/
protected $transaction;

public function __construct(
Context $context,
AdyenLogger $adyenLogger,
Data $adyenDataHelper,
InvoiceRepositoryInterface $invoiceRepository,
InvoiceFactory $adyenInvoiceFactory,
AdyenInvoiceResourceModel $adyenInvoiceResourceModel,
OrderPaymentResourceModel $orderPaymentResourceModel,
PaymentFactory $paymentFactory,
Collection $adyenInvoiceCollection,
MagentoInvoiceFactory $magentoInvoiceFactory,
\Magento\Sales\Model\ResourceModel\Order $magentoOrderResourceModel,
Config $configHelper,
InvoiceSender $invoiceSender,
Transaction $transaction
protected readonly Context $context,
protected readonly AdyenLogger $adyenLogger,
protected readonly Data $adyenDataHelper,
protected readonly InvoiceRepositoryInterface $invoiceRepository,
protected readonly InvoiceFactory $adyenInvoiceFactory,
protected readonly AdyenInvoiceResourceModel $adyenInvoiceResourceModel,
protected readonly OrderPaymentResourceModel $orderPaymentResourceModel,
protected readonly PaymentFactory $adyenOrderPaymentFactory,
protected readonly Collection $adyenInvoiceCollection,
protected readonly MagentoInvoiceFactory $magentoInvoiceFactory,
protected readonly \Magento\Sales\Model\ResourceModel\Order $magentoOrderResourceModel,
protected readonly Config $configHelper,
protected readonly InvoiceSender $invoiceSender,
protected readonly Transaction $transaction,
protected readonly ChargedCurrency $chargedCurrencyHelper
) {
parent::__construct($context);
$this->adyenLogger = $adyenLogger;
$this->adyenDataHelper = $adyenDataHelper;
$this->invoiceRepository = $invoiceRepository;
$this->adyenInvoiceFactory = $adyenInvoiceFactory;
$this->adyenInvoiceResourceModel = $adyenInvoiceResourceModel;
$this->orderPaymentResourceModel = $orderPaymentResourceModel;
$this->adyenOrderPaymentFactory = $paymentFactory;
$this->adyenInvoiceCollection = $adyenInvoiceCollection;
$this->magentoInvoiceFactory = $magentoInvoiceFactory;
$this->magentoOrderResourceModel = $magentoOrderResourceModel;
$this->configHelper = $configHelper;
$this->invoiceSender = $invoiceSender;
$this->transaction = $transaction;
}

/**
* @param Order $order
* @param Notification $notification
* @param bool $isAutoCapture
* @return InvoiceModel
* @return InvoiceModel|null
* @throws LocalizedException
*/
public function createInvoice(Order $order, Notification $notification, bool $isAutoCapture): ?InvoiceModel
Expand Down Expand Up @@ -287,9 +227,10 @@ public function handleCaptureWebhook(Order $order, Notification $notification):
{
$invoiceFactory = $this->adyenInvoiceFactory->create();
$adyenInvoice = $this->adyenInvoiceResourceModel->getAdyenInvoiceByCaptureWebhook($order, $notification);
$chargedCurrency = $this->chargedCurrencyHelper->getOrderAmountCurrency($order, false);
$formattedAdyenOrderAmount = $this->adyenDataHelper->formatAmount(
$order->getBaseGrandTotal(),
$order->getOrderCurrencyCode()
$chargedCurrency->getAmount(),
$chargedCurrency->getCurrencyCode()
);
$notificationAmount = $notification->getAmountValue();
$isFullAmountCaptured = $formattedAdyenOrderAmount == $notificationAmount;
Expand Down
2 changes: 2 additions & 0 deletions Model/Config/Source/ThreeDSFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ThreeDSFlow implements OptionSourceInterface
{
const THREEDS_NATIVE = 'native';
const THREEDS_REDIRECT = 'redirect';
const THREEDS_PREFERRED = 'preferred';
const THREEDS_DISABLED = 'disabled';

/**
* @return array
Expand Down
2 changes: 1 addition & 1 deletion Test/Unit/Gateway/Request/CheckoutDataBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ public function testAllowThreeDSFlag()

$request = $this->checkoutDataBuilder->build($buildSubject);

$this->assertTrue($request['body']['additionalData']['allow3DS2']);
$this->assertArrayHasKey('nativeThreeDS', $request['body']['authenticationData']['threeDSRequestData']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testBuild($paymentMethodCode, $tokenDetails, $tokenType, $isInst
$this->assertArrayHasKey('recurringProcessingModel', $request['body']);

if ($tokenType === PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD) {
$this->assertArrayHasKey('allow3DS2', $request['body']['additionalData']);
$this->assertArrayHasKey('nativeThreeDS', $request['body']['authenticationData']['threeDSRequestData']);
$this->assertArrayHasKey('holderName', $request['body']['paymentMethod']);
} else {
$this->assertArrayNotHasKey('additionalData', $request['body']);
Expand Down
22 changes: 19 additions & 3 deletions Test/Unit/Helper/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
namespace Adyen\Payment\Test\Unit\Helper;

use Adyen\Payment\Api\Data\InvoiceInterface;
use Adyen\Payment\Helper\ChargedCurrency;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Helper\Data;
use Adyen\Payment\Helper\Invoice;
use Adyen\Payment\Model\AdyenAmountCurrency;
use Adyen\Payment\Model\InvoiceFactory;
use Adyen\Payment\Model\Order\Payment;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
Expand Down Expand Up @@ -162,6 +164,13 @@ public function testHandleCaptureWebhook()
$transactionMock = $this->createGeneratedMock(Transaction::class, ['addObject']);
$transactionMock->method('addObject')->willReturn($invoiceMock);

$adyenAmountCurrencyMock = $this->createMock(AdyenAmountCurrency::class);
$adyenAmountCurrencyMock->method('getAmount')->willReturn(10);
$adyenAmountCurrencyMock->method('getCurrencyCode')->willReturn('EUR');

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

$invoiceHelper = $this->createInvoiceHelper(
$contextMock,
null,
Expand All @@ -176,7 +185,8 @@ public function testHandleCaptureWebhook()
$magentoOrderResourceModelMock,
null,
null,
$transactionMock
$transactionMock,
$chargedCurrencyMock
);

$orderPaymentMock = $this->createConfiguredMock(MagentoOrder\Payment::class, [
Expand Down Expand Up @@ -425,7 +435,8 @@ protected function createInvoiceHelper(
$magentoOrderResourceModelMock = null,
$adyenConfigHelperMock = null,
$invoiceSenderMock = null,
$transactionMock = null
$transactionMock = null,
$chargedCurrencyMock = null
): Invoice {

if (is_null($contextMock)) {
Expand Down Expand Up @@ -484,6 +495,10 @@ protected function createInvoiceHelper(
$transactionMock = $this->createGeneratedMock(Transaction::class);
}

if (is_null($chargedCurrencyMock)) {
$chargedCurrencyMock = $this->createMock(ChargedCurrency::class);
}

return new Invoice(
$contextMock,
$adyenLoggerMock,
Expand All @@ -498,7 +513,8 @@ protected function createInvoiceHelper(
$magentoOrderResourceModelMock,
$adyenConfigHelperMock,
$invoiceSenderMock,
$transactionMock
$transactionMock,
$chargedCurrencyMock
);
}
}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.12.2
9.13.0
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.2",
"version": "9.13.0",
"license": "MIT",
"repositories": [
{
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2558,4 +2558,4 @@
</adyen_doku_mandiri_va>
</payment>
</default>
</config>
</config>

0 comments on commit 4e2945a

Please sign in to comment.