bitpay / magento2-plugin

Magento2.x payment plugin for Bitpay.com
MIT License
13 stars 24 forks source link

Wrong way to insert method code into the config-provider #11

Closed evgk closed 7 years ago

evgk commented 7 years ago

This code causes conflict with other payment modules(specifically, the standard Authorize DirectPost):

    <virtualType name="Bitpay\Core\Model\ConfigProvider" type="Magento\Payment\Model\CcGenericConfigProvider">
        <arguments>
            <argument name="methodCodes" xsi:type="array">
                <item name="bitpay" xsi:type="const">Bitpay\Core\Model\Method\Bitcoin::CODE</item>
            </argument>
        </arguments>
    </virtualType>

The reason is a bit subtle - since it's a virtualType based on CcGenericConfigProvider, the loop in this file: vendor/magento/module-checkout/Model/CompositeConfigProvider.php

        foreach ($this->configProviders as $configProvider) {
            $config = array_merge_recursive($config, $configProvider->getConfig());
        }

will call getConfig() on CcGenericConfigProvider twice. Note that the getConfig function will get called on ./vendor/magento/module-payment/Model/CcGenericConfigProvider.php - not on Bitpay/Core/Model/ConfigProvider.php. This will lead to the recursive merge of the payment configuration, and wrong values for e.g. availableTypes in the authorizenet_directpost will lead to the failed validation: ccform":{"availableTypes":{"authorizenet_directpost":{"AE":"American Express","VI":"Visa" this is normal configuration, this is the failing one: ccform":{"availableTypes":{"authorizenet_directpost":{"AE":["American Express","American Express"],"VI":["Visa","Visa"]...

Since the virtual type is actually not used, suggested PR fixes this issue by removing the injection of a custom config provider and adding bitpay method code to CcGenericConfigProvider the same way it's added in most other payment methods.

MarcinKozak commented 7 years ago

@evgk Fixed in the Pull Request #27

evgk commented 7 years ago

Okay.