1

I have Magento 2.3.5 and been using braintree's payment method but when users save a credit card to their account and try to use it an error shows up saying "The requested Payment Method is not available"

The error is triggered here: vendor\magento\module-quote\Model\Quote\Payment.php

if (!$method->isAvailable($quote) || !$methodSpecification->isApplicable($method, $quote)) {
        throw new \Magento\Framework\Exception\LocalizedException(
            __('The requested Payment Method is not available.')
        );
}

$method->isAvailable($quote) returns false when users use the saved credit card.

Using $method->getCode() returns "substitution". Don't know if it helps with something?

Thanks!

2
  • Have you tried setting "3-D secured verification" setting as "No" in Magento Backend? Aug 10, 2020 at 12:34
  • I'm going from 2.3.4-p2 to 2.4.1 and just ran into this in development. I'm seeing that the payment method passed to the server is braintree_cc_vault_xxxx where xxxx is an ID (for the vaulted card??). I'm confused that others haven't run into this as well... still thinking through how I best solve this though.
    – PromInc
    Dec 22, 2020 at 21:13

1 Answer 1

1

This is a reported bug with Magento. It appears to have been around since v2.3.5 https://github.com/magento/magento2/issues/29248

Javascript expects a unique ID to be passed to know which payment method on the page to expand (think multiple vaulted cards for the one customer).

But that is passed to PHP despite PHP expecting a more generic payment method code to know which payment validator logic to load.

Until this is patched via core code, this is a plugin that I wrote that I'm using.

File: app/code/Prominc/Quote/Plugin/Model/Quote/Payment.php

<?php

namespace Prominc\Quote\Plugin\Model\Quote;

class Payment
{

    public function beforeImportData(
        \Magento\Quote\Model\Quote\Payment $subject,
        $data
    ) {
        $vaultMethod = preg_replace( '/^([a-z_]+vault)_\d+$/i', '$1', $data['method'] );
        if( !is_null( $vaultMethod ) && $vaultMethod !== $data['method'] ) {
            $data['method'] = $vaultMethod;
        }
        return [$data];
    }

}

File: app/code/Prominc/Quote/registration.php

<?php

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'Prominc_Quote',
    __DIR__
);

File: app/code/Prominc/Quote/etc/module.xml

<?xml version="1.0" encoding="utf-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Prominc_Quote" setup_version="0.0.1">
        <sequence>
            <module name="Magento_Quote"/>
        </sequence>
    </module>
</config>

File: app/code/Prominc/Quote/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Quote\Model\Quote\Payment">
        <plugin disabled="false" name="Prominc_Quote_Plugin_Model_Quote_Payment" sortOrder="10" type="Prominc\Quote\Plugin\Model\Quote\Payment"/>
    </type>
</config>

Don't forget to run a setup:di:compile after adding this module/plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.