Adyen / adyen-magento2

Adyen Payment plugin for Magento2
MIT License
155 stars 211 forks source link

[PW-5546] Error: Call to undefined method PayPal\Braintree\Gateway\Data\Order\OrderAdapter #1168

Closed draper87 closed 2 years ago

draper87 commented 3 years ago

Describe the bug On a clean install of Magento 2.4.3 with no other third-party plugins other than Adyen 7.2.0, when we try to place an order with Adyen the result is a generic error message "Something went wrong with your request. Please try again later.". After checked the log file var/log/system.log we've discovered this:

main.CRITICAL: Error: Call to undefined method PayPal\Braintree\Gateway\Data\Order\OrderAdapter::getQuoteId() in /var/www/html/vendor/adyen/module-payment/Gateway/Response/StateDataCleanupHandler.php:48 Stack trace:

After checking di.xml of Adyen It seems to me that both Adyen and Braintree are using a preference over the same Class Magento\Payment\Gateway\Data\Order\OrderAdapter

I'm not sure what's going on here, how can I solve this without uninstall Braintree (actually I tried to disable Braintree's modules and Adyen stop to work).

To Reproduce Steps to reproduce the behavior:

  1. After adding a product to cart go to Checkout and fill customers data.
  2. On payment page fill credit card number, expiry Date and CVC number.
  3. Click on Place Order.

Expected behavior I'm expecting to place the order without getting any error.

Magento version 2.4.3

Plugin version 7.2.0 (test mode)

Screenshots Screenshot from 2021-10-07 10-51-24

Desktop (please complete the following information):

acampos1916 commented 3 years ago

Hello @draper87, thank you for this report. Maybe this could happen if the Braintree module is loaded after Adyen's, even if disabled. We are investigating this to find a different solution to getting the quoteId.

anupwankhede commented 3 years ago

Hello we are getting same error. Wondering how can we fix it. Appreciate if find quick resolution please

acampos1916 commented 3 years ago

Hello @anupwankhede, working on a solution for this, will keep you updated.

Djohn12 commented 2 years ago

Hello,

I can see this issue is closed but we're still reproducing the bug with backend orders on a magento 2.4.3-p1 instance using adyen/module-payment 8.1.1

Error log is :

Error: Call to undefined method PayPal\Braintree\Gateway\Data\Order\OrderAdapter::getQuoteId() in /magento_code/vendor/adyen/module-payment/Gateway/Request/CcBackendAuthorizationDataBuilder.php:54

Do you have any workaround or fix for this issue ? Thanks in advance

igi8819 commented 2 years ago

@acampos1916

I can still replicate this issue in adyen/module-payment:8.2.3

It is not ideal, but maybe this can be a fix:

1) remove this line from adyen di.xml <preference for="Magento\Payment\Gateway\Data\Order\OrderAdapter" type="Adyen\Payment\Gateway\Data\Order\OrderAdapter"/>

2) include db connection into "Gateway/Request/CcBackendAuthorizationDataBuilder.php" and get quote_id form sales_order table.

namespace Adyen\Payment\Gateway\Request;

use Adyen\Payment\Helper\StateData;
use Adyen\Payment\Observer\AdyenCcDataAssignObserver;
use Magento\Framework\App\ResourceConnection;
use Magento\Payment\Gateway\Data\PaymentDataObject;
use Magento\Payment\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Request\BuilderInterface;

class CcBackendAuthorizationDataBuilder implements BuilderInterface
{
    /**
     * @var StateData
     */
    private $stateData;

    /**
     * @var ResourceConnection
     */
    private $connection;

    public function __construct(StateData $stateData, ResourceConnection $connection)
    {
        $this->stateData = $stateData;
        $this->connection = $connection;
    }

    /**
     * @param array $buildSubject
     * @return array
     */
    public function build(array $buildSubject): array
    {
        /** @var PaymentDataObject $paymentDataObject */
        $paymentDataObject = SubjectReader::readPayment($buildSubject);
        $payment = $paymentDataObject->getPayment();
        $order = $paymentDataObject->getOrder();

        $quoteId = $this->getQuoteId($order->getId());
        $requestBody = $this->stateData->getStateData($quoteId);

        // if installments is set add it into the request
        $installments = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS) ?: 0;
        if ($installments > 0) {
            $requestBody['installments']['value'] = $installments;
        }

        return [
            'body' => $requestBody
        ];
    }

    /**
     * Get quote id
     * 
     * @param int $orderId
     * @return int
     */
    private function getQuoteId($orderId)
    {
        $sql = $this->connection->getConnection()
            ->select()
            ->from($this->connection->getTableName('sales_order'), ['quote_id'])
            ->where('entity_id = ?', $orderId);

        return (int)$this->connection->getConnection()->fetchOne($sql);
    }
}
vahir2016 commented 2 years ago

Hello,

Same issue with Adyen 8.2.3 and Magento EE 2.4.3.

vahir2016 commented 2 years ago

@acampos1916

I can still replicate this issue in adyen/module-payment:8.2.3

It is not ideal, but maybe this can be a fix:

  1. remove this line from adyen di.xml <preference for="Magento\Payment\Gateway\Data\Order\OrderAdapter" type="Adyen\Payment\Gateway\Data\Order\OrderAdapter"/>
  2. include db connection into "Gateway/Request/CcBackendAuthorizationDataBuilder.php" and get quote_id form sales_order table.
namespace Adyen\Payment\Gateway\Request;

use Adyen\Payment\Helper\StateData;
use Adyen\Payment\Observer\AdyenCcDataAssignObserver;
use Magento\Framework\App\ResourceConnection;
use Magento\Payment\Gateway\Data\PaymentDataObject;
use Magento\Payment\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Request\BuilderInterface;

class CcBackendAuthorizationDataBuilder implements BuilderInterface
{
    /**
     * @var StateData
     */
    private $stateData;

    /**
     * @var ResourceConnection
     */
    private $connection;

    public function __construct(StateData $stateData, ResourceConnection $connection)
    {
        $this->stateData = $stateData;
        $this->connection = $connection;
    }

    /**
     * @param array $buildSubject
     * @return array
     */
    public function build(array $buildSubject): array
    {
        /** @var PaymentDataObject $paymentDataObject */
        $paymentDataObject = SubjectReader::readPayment($buildSubject);
        $payment = $paymentDataObject->getPayment();
        $order = $paymentDataObject->getOrder();

        $quoteId = $this->getQuoteId($order->getId());
        $requestBody = $this->stateData->getStateData($quoteId);

        // if installments is set add it into the request
        $installments = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS) ?: 0;
        if ($installments > 0) {
            $requestBody['installments']['value'] = $installments;
        }

        return [
            'body' => $requestBody
        ];
    }

    /**
     * Get quote id
     * 
     * @param int $orderId
     * @return int
     */
    private function getQuoteId($orderId)
    {
        $sql = $this->connection->getConnection()
            ->select()
            ->from($this->connection->getTableName('sales_order'), ['quote_id'])
            ->where('entity_id = ?', $orderId);

        return (int)$this->connection->getConnection()->fetchOne($sql);
    }
}

Not working from backoffice when I tried to create an order.

Morerice commented 2 years ago

Hi guys,

Apologies for the delay. I am re-opening this issue since it seems that it is occurring more frequently. Based on the previous comments it seems that it is occurring exclusively on Magento v2.4.3.

Best regards, Jean Adyen

Winfle commented 1 year ago

This issue appears at 8.17.0

lrotherfield-function commented 1 year ago

@Morerice as reported by @Winfle, I too am seeing this on 8.18 when trying to checkout with a 3DS enabled card stored in vault.

The change in 8.17 causes this issue: https://github.com/Adyen/adyen-magento2/blob/b8c9105b80ebd5b42c3023d5e91b88f8ae6e3426/Gateway/Request/RecurringVaultDataBuilder.php#L51

This was changed in: https://github.com/Adyen/adyen-magento2/commit/b660e9dac3f7d5bb0d45e68a3145df6a1f8cde27#diff-0e0587b967adaa49d80ffcf95d7ace94ee9c4d963f5a139a84954c9a0db890ccL36

lrotherfield-function commented 1 year ago

@acampos1916 Do you need me to open a new issue for this now that it is reintroduced in 8.17 and 8.18?