Skip to content

Commit

Permalink
Merge branch 'main' into ECP-9520
Browse files Browse the repository at this point in the history
  • Loading branch information
khushboo-singhvi authored Jan 15, 2025
2 parents c8cdb47 + 8417b45 commit ac9b162
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 10 deletions.
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/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
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
44 changes: 43 additions & 1 deletion Test/Unit/Helper/PaymentResponseHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Adyen\Payment\Helper\Data;
use Adyen\Payment\Helper\Quote;
use Adyen\Payment\Helper\Order as OrderHelper;
use Adyen\Payment\Model\Method\Adapter;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Exception;
use Magento\Framework\Exception\AlreadyExistsException;
Expand All @@ -31,6 +32,7 @@
use Adyen\Payment\Model\ResourceModel\PaymentResponse\Collection;
use Adyen\Payment\Model\ResourceModel\PaymentResponse\CollectionFactory;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Helper\PaymentMethods;
use ReflectionClass;

class PaymentResponseHandlerTest extends AbstractAdyenTestCase
Expand All @@ -51,6 +53,9 @@ class PaymentResponseHandlerTest extends AbstractAdyenTestCase
protected function setUp(): void
{
$this->paymentMock = $this->createMock(Payment::class);
// Mock the payment method
$this->paymentMethodInstanceMock = $this->createMock(Adapter::class);

$this->orderMock = $this->createMock(\Magento\Sales\Model\Order::class);
$this->adyenLoggerMock = $this->createMock(AdyenLogger::class);
$this->vaultHelperMock = $this->createMock(Vault::class);
Expand All @@ -64,6 +69,7 @@ protected function setUp(): void
]);
$this->stateDataHelperMock = $this->createMock(StateData::class);
$this->configHelperMock = $this->createMock(Config::class);
$this->paymentMethodsHelperMock = $this->createMock(PaymentMethods::class);

$this->paymentResponseMockForFactory = $this->createMock(Collection::class);

Expand All @@ -80,6 +86,7 @@ protected function setUp(): void
$this->orderMock->method('getPayment')->willReturn($this->paymentMock);
$this->orderMock->method('getStatus')->willReturn('pending');
$this->orderMock->method('getIncrementId')->willReturn('00123456');
$this->paymentMock->method('getMethodInstance')->willReturn($this->paymentMethodInstanceMock);

$this->orderHelperMock->method('setStatusOrderCreation')->willReturn($this->orderMock);

Expand All @@ -94,7 +101,8 @@ protected function setUp(): void
$this->orderHistoryFactoryMock,
$this->stateDataHelperMock,
$this->paymentResponseCollectionFactoryMock,
$this->configHelperMock
$this->configHelperMock,
$this->paymentMethodsHelperMock
);
}

Expand Down Expand Up @@ -597,4 +605,38 @@ public function testOrderStatusUpdateWhenResponseIsValid()

$this->paymentResponseHandler->handlePaymentsDetailsResponse($paymentsDetailsResponse, $this->orderMock);
}

public function testHandlePaymentsDetailsResponseSetsCcType()
{

// Mock the method `isWalletPaymentMethod` in your helper if it's being checked
$this->paymentMethodsHelperMock->method('isWalletPaymentMethod')
->with($this->paymentMethodInstanceMock)
->willReturn(false); // Assuming false for this test case

// Payment details response with a payment method brand
$paymentsDetailsResponse = [
'resultCode' => PaymentResponseHandler::AUTHORISED,
'paymentMethod' => [
'brand' => 'VI'
],
'merchantReference' => '00123456'
];

// Expect the `setCcType` method to be called on the payment object with the correct value
$this->paymentMock
->method('setCcType')
->with($this->equalTo('VI'));

// Call the method under test
$result = $this->paymentResponseHandler->handlePaymentsDetailsResponse(
$paymentsDetailsResponse,
$this->orderMock
);

// Assert the response is as expected
$this->assertTrue($result);
}


}
1 change: 1 addition & 0 deletions etc/queue_consumer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/consumer.xsd">
<consumer name="adyen.notification"
queue="adyen.notification"
connection="amqp"
handler="Adyen\Payment\Model\Queue\Notification\Consumer::execute"/>
</config>
4 changes: 3 additions & 1 deletion etc/queue_publisher.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/publisher.xsd">
<publisher topic="adyen.notification"/>
<publisher topic="adyen.notification">
<connection name="amqp" exchange="magento"/>
</publisher>
</config>
2 changes: 1 addition & 1 deletion etc/queue_topology.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
<exchange name="magento" type="topic">
<exchange name="magento" type="topic" connection="amqp">
<binding id="NotificationBinding"
topic="adyen.notification"
destinationType="queue"
Expand Down

0 comments on commit ac9b162

Please sign in to comment.