The Payment Provider Gateway documentation uses the Magento 2.3 (now Adobe Commerce and Magento Open Source) of the Braintree module as a reference application. The Braintree module was removed in version 2.4.0. The concepts described in this guide are still applicable to version 2.4.x, but the code samples are not supported.
Payment info rendering in Admin checkout
The payment information form rendering in Admin order creation is defined by the block class, its template and layout.
formBlockType
is one of the arguments you must configure for the payment method facade.
This block is used to display payment form on billing form in Admin panel. In
most cases it is enough to use the \Magento\Payment\Block\Form\Cc
. All payments details are displayed according to specified keys in paymentInfoKeys
option in module configuration.
Example of custom formBlockType: Braintree payment method implementation
In the integration with the Braintree payment provider, we use the \Magento\Braintree\Block\Form
class as formBlockType
. It allows displaying only card types available for configured countries:
Copied to your clipboardclass Form extends Cc{/*** Get list of available card types of order billing address country* @return array*/public function getCcAvailableTypes(){$configuredCardTypes = $this->getConfiguredCardTypes();$countryId = $this->sessionQuote->getQuote()->getBillingAddress()->getCountryId();return $this->filterCardTypesForCountry($configuredCardTypes, $countryId);}/*** Get card types available for Braintree* @return array*/private function getConfiguredCardTypes(){$types = $this->ccType->getCcTypeLabelMap();$configCardTypes = array_fill_keys($this->gatewayConfig->getAvailableCardTypes(), '');return array_intersect_key($types, $configCardTypes);}/*** Filter card types for specific country* @param array $configCardTypes* @param string $countryId* @return array*/private function filterCardTypesForCountry(array $configCardTypes, $countryId){$filtered = $configCardTypes;$countryCardTypes = $this->gatewayConfig->getCountryAvailableCardTypes($countryId);// filter card types only if specific card types are set for country...return $filtered;}}
Template
For creating a template for the payment information rendering class, you can use the default cc.phtml as example.
Then add the template to the billing form layout sales_order_create_index.xml
.
The following example adds the Braintree-specific template app/code/Magento/Payment/view/adminhtml/templates/form/cc.phtml
to the billing form layout in the Braintree module.
Copied to your clipboard<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"><body><referenceBlock name="order_create_billing_form"><action method="setMethodFormTemplate"><!-- your method code and template --><argument name="method" xsi:type="string">braintree</argument><argument name="template" xsi:type="string">Magento_Braintree::form/cc.phtml</argument></action></referenceBlock></body></page>