mollie / magento2

Mollie Payments for Magento 2
https://www.mollie.com
Other
98 stars 50 forks source link

[ISSUE] Unable to fetch issuers in GraphQL #710

Closed DuckThom closed 7 months ago

DuckThom commented 8 months ago

Describe the bug

Mollie\Payment\Service\Mollie\GetIssuers::execute(): Argument #3 ($type) must be of type string, null given, called in <project_path>/vendor/mollie/magento2/Service/Mollie/GetIssuers.php on line 113

Used versions

To Reproduce Steps to reproduce the behavior:

  1. Query the cart with the mollie_available_issuers field

Expected behavior A list of issuers is returned

Actual behavior The exception is thrown

report.ERROR: Mollie\Payment\Service\Mollie\GetIssuers::execute(): Argument #3 ($type) must be of type string, null given, called in <project_path>/vendor/mollie/magento2/Service/Mollie/GetIssuers.php on line 113

GraphQL (122:13)
121:             title
122:             mollie_available_issuers {
                 ^
123:                 code
 [] []

Screenshots If applicable, add screenshots to help explain your problem.

Additional context

Due to the added strict typing in multiple methods, the exception is now thrown where previously a NULL type was valid. One such place is the $type parameter in: \Mollie\Payment\Service\Mollie\GetIssuers::execute

    /**
     * @param MollieApiClient $mollieApi
     * @param string $method
     * @param string $type On of: dropdown, radio, none
     * @return array|null
     */
    public function execute(MollieApiClient $mollieApi, string $method, string $type)

This method is called within the same class, in the getForGraphql method

        $issuers = $this->execute(
            $mollieApi,
            $method,
            $this->general->getIssuerListType($method)
        );

However, most of the payment methods do not have a list type in de default config, which makes $this->general->getIssuerListType($method) return NULL.

For example, in etc/config.xml, the payment method mollie_methods_ideal has <issuer_list_type>radio</issuer_list_type>. But, mollie_methods_klarna doesn't have this set, making it NULL.

This can also be seen when adding debug logging to vendor/mollie/magento2/Service/Mollie/GetIssuers.php to show all the methods with their issuer list type:

    /**
     * @param $storeId
     * @param $method
     * @return array|null
     */
    public function getForGraphql($storeId, string $method): ?array
    {
        $mollieApi = $this->mollieModel->getMollieApi($storeId);

        // Debug logging
        $type = $this->general->getIssuerListType($method);
        $type = $type === null ? 'NULL' : $type;
        \Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class)->error("$method - {$type}");

Output:

[2023-10-25T13:38:59.746292+00:00] report.ERROR: mollie_methods_ideal - radio [] []
[2023-10-25T13:38:59.748416+00:00] report.ERROR: mollie_methods_klarnapaylater - NULL [] []
[2023-10-25T13:38:59.748924+00:00] report.ERROR: mollie_methods_applepay - NULL [] []
[2023-10-25T13:38:59.749382+00:00] report.ERROR: mollie_methods_creditcard - NULL [] []
[2023-10-25T13:38:59.749869+00:00] report.ERROR: mollie_methods_paypal - NULL [] []
[2023-10-25T13:38:59.750301+00:00] report.ERROR: mollie_methods_in3 - NULL [] []
[2023-10-25T13:38:59.750681+00:00] report.ERROR: mollie_methods_banktransfer - NULL [] []
[2023-10-25T13:38:59.751057+00:00] report.ERROR: mollie_methods_bancontact - NULL [] []
[2023-10-25T13:38:59.751542+00:00] report.ERROR: mollie_methods_giftcard - dropdown []

Workaround / Patch

diff --git a/vendor/mollie/magento2/Helper/General.php b/vendor/mollie/magento2/Helper/General.php
--- a/vendor/mollie/magento2/Helper/General.php 
+++ b/vendor/mollie/magento2/Helper/General.php (date 1698242758607)
@@ -387,7 +387,7 @@
     public function getIssuerListType(string $method): string
     {
         $methodXpath = str_replace('%method%', $method, self::XPATH_ISSUER_LIST_TYPE);
-        return $this->getStoreConfig($methodXpath);
+        return $this->getStoreConfig($methodXpath) ?? 'none';
     }

     /**
Frank-Magmodules commented 8 months ago

Thank you, @DuckThom, for bringing this issue to our attention. We will investigate your problem and its solution, and we will provide you with a response shortly. We appreciate your comprehensive report!

Frank-Magmodules commented 8 months ago

Hi there @DuckThom,

Again, thank you for opening this issue. We were able to reproduce this issue, and we solved it in almost the same way as your proposal. Next to that, to this from happening again, we’ve added a test to our end 2 end tests that checks if an order can be placed & paid through the GraphQL API. This will be included in our upcoming release. We appreciate your patience and for providing a clear description of the issue. Thank you.

simonmaass commented 8 months ago

any idea when this patch will be released?

Frank-Magmodules commented 7 months ago

Hi, @simonmaass, we are currently engaged in the manual Q&A process for the upcoming release. If everything goes smoothly, you can expect the release within this week. In the worst-case scenario, it will be resolved by Monday. We appreciate your patience!

simonmaass commented 7 months ago

@Frank-Magmodules thank you for the info!

Frank-Magmodules commented 7 months ago

Hello @simonmaass and @DuckThom, excited to inform you that we've successfully addressed the issue with the latest release, v2.32.3. I'm marking the issue as closed for now, but please feel free to reopen it if necessary.