How to Use Payment Extension Attributes in Magento 2

How to Use Payment Extension Attributes in Magento 2

Magento 2 is the leading E-commerce platform that provides improved scalability and flexibility for an online store.

An example of Magento 2’s flexibility is that store owners can customize and overwrite the core features of its framework according to the business requirements.

One such requirement is to add custom fields into our entities. To serve this purpose, Magento 2 offers a flexible and declarative way to extend functionality that is called extension attributes.

Magento 2 extension attributes are primarily containers used for adding an additional piece of information to our entities that allow adding additional custom data into an entity such as Product, Customer, Order, etc.

The below solution is the method to use payment extension attributes in Magento 2 that allows saving the custom field values in the database.

For example, the customers enter custom messages or comments while placing the order, and to save these comments, you need to pass it with the payment details using knockout JS.

The below method shows the same:

Method to Use Payment Extension Attributes in Magento 2

  1. Create registration.php file at app\code\Vendor\Module

  2. Create module.xml file at app\code\Vendor\Module\etc

  3. Create an extension_attributes.xml file at app\code\Vendor\Module\etc

  4. Create a requirejs-config.js file at app\code\Vendor\Module\view\frontend

  5. Create place-order-mixin.js file at app\code\Vendor\Module\view\frontend\web\js\order

  6. Create custom-assigner.js at app\code\Vendor\Module\view\frontend\js\order

  7. Create set-payment-information-mixin.js at app\code\Vendor\Module\view\frontend\js\order

  8. Create di.xml at app\code\Vendor\Module\etc

  9. Create SavePaymentPlugin.php at Vendor\Module\Plugin\Model

  10. Create GuestSavePaymentPlugin.php at Vendor\Module\Plugin\Model

Now you can easily save your additional field’s data after placing an order.


If you have any doubts regarding this post, don’t be confused; just mention them in the Comments section below.

I would be glad to help.

Feel free to share the solution with Magento Community via social media.

Thank You.

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

(based on 13 Reviews)

Kanchi is a Magento Developer at Meetanshi. Apart from that, she is into dancing. In her free time, she likes to make handmade art and craft.

Leave a reply:

Your email address will not be published.