How to set Payment additional data in Magento 2?

Magento 2 You can set additional data in payment using setAdditionalData( ) method defined under Quote Module Payment.php class.

Magento\Quote\Model\Quote\Payment class used for set payment related data from quote to order. This class is used for set payment method, additional data, and other payment-related data to Order.

if you want to add any extra data in payment information you can use setAdditionalData( ) function.

You can create a plugin for Payment class and call before method with setAdditionalData( ) to add extra data.

create file app\code\Rbj\Mymodule\etc\di.xml,

create file app\code\Rbj\Mymodule\Plugin\Payment.php,

Based on the above plugin you can add your custom additional data On Payment related stuff.



One Reply to “How to set Payment additional data in Magento 2?”

  1. Hi Rakesh,
    The idea with plugin definitely a good one, but we should remember to add as a first line of every such plugin an if statement veryfing that this plugin should be executed only for our own method, otherwise it will be executed for all payment methods.

    The Adapter class from MagentoPayment module provides an assign() method where we can assign a specific to our payment method observer and execute it only in scope of the payment method.

Leave a Reply