adyen-magento2: [PW-6382] GraphQL PlaceOrder dont work

Describe the bug

  • it is not possible to check out via adyen_cc via GraphQLResolver
    Magento\QuoteGraphQl\Model\Resolver\PlaceOrder::resolve

To Reproduce Execute Query setPaymentMethodOnCart

 mutation setPaymentMethodOnCart(
        $cart_id: String!
        $payment_method: String!
        $additional_data: AdyenAdditionalDataCc
    ) {
        setPaymentMethodOnCart(
            input: {
                cart_id: $cart_id
                payment_method: {
                    code: $payment_method
                    adyen_additional_data_cc: $additional_data
                }
            }
        ) {
            cart {
                id
                selected_payment_method {
                    code
                    title
                }
            }
        }
    }

Variables:

{
	cart_id: 'my_cart_id',
	payment_method: 'adyen_cc',
	additional_data: {
		cc_type: 'mc',
		stateData:  JSON.stringify(onChangeData)
	}
}

Execute Query placeOrder

    mutation placeOrder($cartId: String!) {
        placeOrder(input: { cart_id: $cartId }) @connection(key: "placeOrder") {
            order {
                order_number
            }
        }
    }

Variables:

{
cartId: 'my_cart_id'
}

Error

AdyenLoggerTest.INFO: JSON Response to Adyen:{"status":422,"errorCode":"14_006","message":"Required object 'paymentMethod' is not provided.","errorType":"validation","pspReference":"851638437550915E"} {"is_exception":false} []

I started with debugging session at Magento\QuoteGraphQl\Model\Resolver\PlaceOrder::resolve he loads the payment correct and pushes it correct to Adyen logic looks like the module lost this information a plugin observer etc.

Expected behavior Should be possible to place an order with adyen_cc

Magento version 2.4.3

Plugin version dev-feature/graphql-reapply

Screenshots

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 23 (13 by maintainers)

Most upvoted comments

It’s a must-have to be documented somewhere. An insane amount of time and effort has been wasted before I found the reason for the error and its workaround…

Hi @jesse-deboer,

Apologies for the late reply. This issue was fixed on v8.2.2.

Best, Jean

So, this would mean that you need to save the stateData to something like localStorage if there is a step after the payment method like a review step right?

Also, I can’t find any documentation on Payload JSON String with orderId, details, paymentData and threeDSAuthenticationOnly.

What is details and what is paymentData, where can I get this information? This is also not documented anywhere in the Headless Magento intergration docs.

Hi @larsroettig and @Bartlomiejsz,

This issue will occur when the setPaymentMethodOnCart and the placeOrder calls are done separately.

However, if both the mutation calls are done in the same request (which essentially is the alternative to this deprecated mutation), this issue should not occur. Example request:

mutation setPaymentMethodAndPlaceOrder(
    $cartId: String!
    $stateData: String!
) {
    setPaymentMethodOnCart(
        input: {
            cart_id: $cartId
            payment_method: {
                code: "adyen_cc"
                adyen_additional_data_cc: {
                    cc_type: "VI"
                    stateData: $stateData
                }
            }    
        }
    ) {
        cart {
            selected_payment_method {
                code
                title
            }
        }
    }

    placeOrder(
        input: {
            cart_id: $cartId
        }
    ) {
        order {
            order_id
            adyen_payment_status {
                isFinal
                resultCode
                additionalData
                action
            }
        }
    }
}

Thanks, Jean Adyen

We are running into this same issue and the proposed fix does not seem to solve the issue, using version 8 of the module on Magento 2.4.3-p1 with PHP 7.4

I’m also confused as to the adyen_additional_data_cc being used in the mutation as that is reported to not exist.

Hi @acampos1916 @larsroettig Since I don’t have possibility these days to submit PR with changes that I’m making to make placeOrder work I will share it here, so you could use it if you need it quickly: I’m adding following plugin in graphql/di.xml:

    <type name="Magento\Quote\Api\PaymentMethodManagementInterface">
        <plugin name="Namespace_Adyen::setAdyenStateData"
                type="Namespace\Adyen\Plugin\Quote\Api\PaymentMethodManagement"/>
    </type>

with following content:

<?php

declare(strict_types=1);

namespace Namespace\Adyen\Plugin\Quote\Api;

use Adyen\Payment\Api\AdyenStateDataInterface;
use Exception;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Quote\Api\PaymentMethodManagementInterface as Subject;

class PaymentMethodManagement
{
    private AdyenStateDataInterface $adyenStateData;

    /**
     * @param AdyenStateDataInterface $adyenStateData
     */
    public function __construct(
        AdyenStateDataInterface $adyenStateData
    ) {
        $this->adyenStateData = $adyenStateData;
    }

    /**
     * @param Subject $subject
     * @param string $result
     * @param int $cartId
     * @param PaymentInterface $method
     * @return string
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function afterSet(Subject $subject, string $result, $cartId, PaymentInterface $method): string
    {
        if (strpos($method->getMethod(), 'adyen') !== 0) {
            return $result;
        }

        try {
            $this->adyenStateData->save(
                $method->getAdditionalData()['stateData'] ?? '',
                $cartId
            );

            // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
        } catch (Exception $e) {
            //
        }

        return $result;
    }
}

@acampos1916 if you have possibility, feel free to adjust it if needed and add to graphql PR