From 1de3979ba378bc54959bee82996e9be4d577e271 Mon Sep 17 00:00:00 2001 From: khushboos Date: Thu, 9 Jan 2025 13:18:20 +0100 Subject: [PATCH] Setting cc_type value for Carte Bancaire for PaymentsCall --- .../CheckoutPaymentsDetailsHandler.php | 9 +++++++++ Helper/PaymentMethods.php | 3 ++- Helper/PaymentResponseHandler.php | 19 +++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Gateway/Response/CheckoutPaymentsDetailsHandler.php b/Gateway/Response/CheckoutPaymentsDetailsHandler.php index d9183c611..1731b7db1 100644 --- a/Gateway/Response/CheckoutPaymentsDetailsHandler.php +++ b/Gateway/Response/CheckoutPaymentsDetailsHandler.php @@ -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']); } diff --git a/Helper/PaymentMethods.php b/Helper/PaymentMethods.php index f8972d18c..ed057ca4e 100644 --- a/Helper/PaymentMethods.php +++ b/Helper/PaymentMethods.php @@ -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" ]; @@ -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) { diff --git a/Helper/PaymentResponseHandler.php b/Helper/PaymentResponseHandler.php index f42c6dc98..845cb1d92 100644 --- a/Helper/PaymentResponseHandler.php +++ b/Helper/PaymentResponseHandler.php @@ -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; @@ -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; @@ -65,6 +63,7 @@ class PaymentResponseHandler private StateData $stateDataHelper; private PaymentResponseCollectionFactory $paymentResponseCollectionFactory; private Config $configHelper; + private PaymentMethods $paymentMethodsHelper; public function __construct( AdyenLogger $adyenLogger, @@ -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; @@ -90,6 +90,7 @@ public function __construct( $this->stateDataHelper = $stateDataHelper; $this->paymentResponseCollectionFactory = $paymentResponseCollectionFactory; $this->configHelper = $configHelper; + $this->paymentMethodsHelper = $paymentMethodsHelper; } public function formatPaymentResponse( @@ -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 @@ -213,7 +220,11 @@ public function handlePaymentsDetailsResponse( $ccType = $payment->getAdditionalInformation('cc_type'); - if (!empty($paymentsDetailsResponse['additionalData']['paymentMethod']) && $ccType == null) { + if (!empty($paymentsDetailsResponse['additionalData']['paymentMethod']) && + !is_null($ccType) && + $isWalletPaymentMethod && + $isCardPaymentMethod + ) { $ccType = $paymentsDetailsResponse['additionalData']['paymentMethod']; $payment->setAdditionalInformation('cc_type', $ccType); $payment->setCcType($ccType);