Create a Plugin for Save Payment Information Checkout Magento 2.

You can create a Plugin for the method SavePaymentInformation() in Magento 2 to add your logic before or after Payment information is saved.

The method will be called after a click on the Place order button from the second step of the Checkout page.

Original Class to create plugin:
Magento\Checkout\Model\PaymentInformationManagement

You can create a before or after plugin as per your requirement.

Create a global scope di.xml file,

Create a Plugin Class for the Before saves payment information, We have used Before Plugin type,

Before Plugin:
$cartId: You get the current quote Cart id, You can get the details of the active quote by cart id from the method.

$paymentMethod contains the Payment related information, Payment method, Payment additional data

The $billingAddress field contains the billing data of the checkout billing section.

You can create an after plugin also for the above method if you need to do some logic after the Payment method successfully saved.

Above Code snippet, Save Payment Information Plugin for adding extra logic after or before Payment data save in Magento 2.

Leave a Reply