I am working on a custom payment method. I am stuck in between where one of my methods required Payment object of \Magento\Payment\Model\InfoInterface

But I am getting Magento\Sales\Model\Order\Payment\Interceptor

from order object.

How Can I get this Payment object of \Magento\Payment\Model\InfoInterface?



You can try Following if your request builder is executing:

namespace Vendor\Module\Gateway\Payment\Request;

use Magento\Payment\Gateway\Request\BuilderInterface;
use Magento\Payment\Gateway\Helper\SubjectReader;

class Yourclass implements BuilderInterface

    public function build(array $buildSubject)
        $paymentDO = SubjectReader::readPayment($buildSubject);

       $paymentInfo = $paymentDO->getPayment()  //this will give you  \Magento\Payment\Model\InfoInterface

You refer above as example basically you need to use $paymentDO->getPayment() following code in your class as used in above.

  • Can I get this payment object by order object '$this->order->getPayment()'? – Charlie Feb 16 '18 at 11:16
  • I am not using request builder – Charlie Feb 16 '18 at 11:23
  • Could you share you code where you want to get InfoInterface , because as per I know if you are using magento2 pattern of building payment gateway you can get you InfoInterface in both request and response by using this SubjectReader::readPayment($buildSubject) if you need some where else mention in your question. – Shashank Gupta Feb 16 '18 at 11:29
  • My payment method is bit custom which is not using the magento2 Gatway. I am trying this is controller – Charlie Feb 16 '18 at 11:31
  • @Charlie have you got answer? – sivakumar Sep 12 '18 at 14:40

I found an example of where an object of type \Magento\Payment\Model\InfoInterface can be found and how it is instantiated.

you may want to look at the file \Magento\Sales\Model\Order\Pdf\AbstractPdf

line $paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();

this line shows you how the invoice for an order is generated. This specific line extracts the payment information for the order. And the variable $order->getPayment() specifically is an object of type \Magento\Payment\Model\InfoInterface

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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