Skip to content

Commit

Permalink
Setting cc_type value for Carte Bancaire for PaymentsCall
Browse files Browse the repository at this point in the history
  • Loading branch information
khushboo-singhvi committed Jan 9, 2025
1 parent a619875 commit 1de3979
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 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
19 changes: 15 additions & 4 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 @@ -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);
Expand Down

0 comments on commit 1de3979

Please sign in to comment.