I created custom extension to achieve this
etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Authorizenet\Model\Directpost" type="MyVendor\MyModule\Model\Directpost" />
</config>
Model\Directpost.php
namespace MyVendor\MyModule\Model;
class Directpost extends \Magento\Authorizenet\Model\Directpost
{
protected function fillPaymentByResponse(\Magento\Framework\DataObject $payment)
{
parent::fillPaymentByResponse($payment);
$response = $this->getResponse();
$payment->setCcType($response->getXCardType());
}
}
view/adminhtml/layout/sales_order_view.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="payment_additional_info">
<block class="MyVendor\MyModule\Block\Payment" name="authorizenet_additional" template="MyVendor_MyModule::order/view/info/authorizenet_additional.phtml" />
</referenceContainer>
</body>
</page>
view/adminhtml/templates/order/view/info/authorizenet_additional.phtml
<p>Last 4 digits: <?php echo $block->getCcLast4(); ?></p>
<p>CC Type: <?php echo $block->getCcType(); ?></p>
<p>Total Amount: <?php echo $this->helper('Magento\Framework\Pricing\Helper\Data')->currency($block->getAmountPaid(),true,false); ?></p>
Block/Payment.php
namespace MyVendor\MyModule\Block;
class Payment extends \Magento\Sales\Block\Order\Info
{
public function toHtml() {
return $this->getOrder()->getPayment()->getMethod()=='authorizenet_directpost' ? parent::toHtml() : '';
}
public function getCcLast4()
{
return $this->getOrder()->getPayment()->decrypt($this->getOrder()->getPayment()->getCcLast4());
}
public function getAmountPaid()
{
return $this->getOrder()->getPayment()->getAmountPaid();
}
public function getCcType()
{
return $this->getOrder()->getPayment()->getCcType();
}
}
So I found that last digits was stored in db already, and for saving card type I needed to extend Directpost model a little.
And then just retrieve all required data from order payment model
Best Answer
There's a great post about this on stackoverflow. You can check the answers here: https://stackoverflow.com/questions/72768/how-do-you-detect-credit-card-type-based-on-number.
The two post important excerpts:
And a full class actually