4

After customer create order with Authorize.net, the info in Payment Information in admin view order says "Credit Card Direct Post (Authorize.net) The order was placed using USD.". How can I add type of card and last 4 digits to this block also?

1
  • The current implementation of Authorize.net payment method in Magento does not allow to display credit card details because it does not store any details about cards.
    – joni jones
    Commented Jan 18, 2017 at 14:29

1 Answer 1

5

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

1
  • 1
    Very useful module, thanks! wouldn't you mind if I will put this code on github for those who dont like cut&paste?
    – Viperet
    Commented Aug 9, 2017 at 9:28

Your Answer

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

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